summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-11-02 01:50:03 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-11-02 01:50:03 +0100
commit72ec10f26dc2c86786aa8006120d69e2ec331536 (patch)
tree1a12b1cca1409a9e9eb91f16df0d0411e4aea4f0
parentFixed compile error (portals) (diff)
downloadcuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar.gz
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar.bz2
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar.lz
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar.xz
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.tar.zst
cuberite-72ec10f26dc2c86786aa8006120d69e2ec331536.zip
-rw-r--r--VC2008/MCServer.vcproj6
-rw-r--r--source/Blocks/BlockHandler.cpp2
-rw-r--r--source/Blocks/BlockPortal.h108
3 files changed, 115 insertions, 1 deletions
diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj
index cb8cf9f81..a5b43348a 100644
--- a/VC2008/MCServer.vcproj
+++ b/VC2008/MCServer.vcproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
@@ -2260,6 +2260,10 @@
>
</File>
<File
+ RelativePath="..\source\blocks\BlockPortal.h"
+ >
+ </File>
+ <File
RelativePath="..\source\Blocks\BlockPumpkin.h"
>
</File>
diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp
index e59fee8ee..cd07b3021 100644
--- a/source/Blocks/BlockHandler.cpp
+++ b/source/Blocks/BlockHandler.cpp
@@ -44,6 +44,7 @@
#include "BlockOre.h"
#include "BlockPiston.h"
#include "BlockPlanks.h"
+#include "BlockPortal.h"
#include "BlockPumpkin.h"
#include "BlockRail.h"
#include "BlockRedstone.h"
@@ -159,6 +160,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType);
case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( );
case E_BLOCK_PLANKS: return new cBlockPlanksHandler (a_BlockType);
+ case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType);
case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType);
case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType);
case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType);
diff --git a/source/Blocks/BlockPortal.h b/source/Blocks/BlockPortal.h
new file mode 100644
index 000000000..c56f0cbc8
--- /dev/null
+++ b/source/Blocks/BlockPortal.h
@@ -0,0 +1,108 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+
+
+
+
+
+class cBlockPortalHandler :
+ public cBlockHandler
+{
+public:
+ cBlockPortalHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
+ {
+ // We set to zero so MCS doesn't stop you from building weird portals like vanilla does
+ // CanBeAt doesn't do anything if meta is zero
+ // We set to zero because the client sends meta = 2 to the server (it calculates rotation itself)
+
+ a_BlockType = m_BlockType;
+ a_BlockMeta = 0;
+ return true;
+ }
+
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ return; // No pickups
+ }
+
+
+ virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
+ {
+ if ((a_RelY - 1 < 0) || (a_RelY + 1 > cChunkDef::Height))
+ {
+ return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1
+ }
+
+ switch (a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ))
+ {
+ case 0x1:
+ {
+ static const struct
+ {
+ int x, y, z;
+ } PortalCheck[] =
+ {
+ { 0, 1, 0},
+ { 0,-1, 0},
+ { 1, 0, 0},
+ {-1, 0, 0},
+ } ;
+
+ for (int i = 0; i < ARRAYCOUNT(PortalCheck); i++)
+ {
+ BLOCKTYPE Block;
+ a_Chunk.UnboundedRelGetBlockType(a_RelX + PortalCheck[i].x, a_RelY + PortalCheck[i].y, a_RelZ + PortalCheck[i].z, Block);
+
+ if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
+ {
+ return false;
+ }
+ }
+ break;
+ }
+ case 0x2:
+ {
+ static const struct
+ {
+ int x, y, z;
+ } PortalCheck[] =
+ {
+ { 0, 1, 0},
+ { 0,-1, 0},
+ { 0, 0, -1},
+ { 0, 0, 1},
+ } ;
+
+ for (int i = 0; i < ARRAYCOUNT(PortalCheck); i++)
+ {
+ BLOCKTYPE Block;
+ a_Chunk.UnboundedRelGetBlockType(a_RelX + PortalCheck[i].x, a_RelY + PortalCheck[i].y, a_RelZ + PortalCheck[i].z, Block);
+
+ if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
+ {
+ return false;
+ }
+ }
+ break;
+ }
+ }
+ return true;
+ }
+} ;
+
+
+
+