summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-05-30 22:22:42 +0200
committerHowaner <franzi.moos@googlemail.com>2014-05-30 22:22:42 +0200
commitd8e16f8c1fa771f77ef7505b45b9114b1f75aa61 (patch)
tree19094bb3577f1076c5644fcb77462cc727bdecfc /src
parentAdd SetOpen() and IsOpen() to BlockDoor.h and fix door redstone bug. (diff)
downloadcuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar.gz
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar.bz2
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar.lz
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar.xz
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.tar.zst
cuberite-d8e16f8c1fa771f77ef7505b45b9114b1f75aa61.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockDoor.cpp2
-rw-r--r--src/Blocks/BlockDoor.h102
2 files changed, 27 insertions, 77 deletions
diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp
index 479c68153..fb2d6f2dc 100644
--- a/src/Blocks/BlockDoor.cpp
+++ b/src/Blocks/BlockDoor.cpp
@@ -62,7 +62,7 @@ void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, c
a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if (Meta & 8)
+ if (Meta & 0x8)
{
// Current block is top of the door
a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player);
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index b5bfe4082..c1e4de9d4 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -135,113 +135,63 @@ public:
}
- /** Returns the metadata for the opposite door state (open vs closed) */
- static NIBBLETYPE ChangeStateMetaData(NIBBLETYPE a_MetaData)
+ static NIBBLETYPE IsOpen(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- return a_MetaData ^ 4;
+ NIBBLETYPE Meta = GetMetaFromRightDoor(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
+ return ((Meta & 0x4) != 0);
}
- static bool IsOpen(cChunkInterface & a_ChunkInterface, int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ)
+ static NIBBLETYPE GetMetaFromRightDoor(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- BLOCKTYPE Block;
- NIBBLETYPE Meta;
- a_ChunkInterface.GetBlockTypeMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Block, Meta);
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if (!IsDoor(Block))
+ if ((Meta & 0x8) != 0)
{
- return false;
+ NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ);
+ return (DownMeta & 0x7) | 0x8 | (((Meta & 0x1) != 0) ? 16 : 0);
+ }
+ else
+ {
+ NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ);
+ return (Meta & 0x7) | (((UpMeta & 0x1) != 0) ? 16 : 0);
}
-
- return ((Meta & 0x4) == 4);
}
static void SetOpen(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open)
{
- BLOCKTYPE Block;
- NIBBLETYPE Meta;
- a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta);
+ BLOCKTYPE Block = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE Meta = GetMetaFromRightDoor(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
- if (!IsDoor(Block) || ((Meta & 0x4) == a_Open))
+ if (!IsDoor(Block))
{
return;
}
- // Change the door
- if (a_Open)
+ bool Opened = (Meta & 0x4) != 0;
+ if (Opened == a_Open)
{
- a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4);
- }
- else
- {
- a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0xFFFFFFFB);
+ return;
}
- int OtherPartY = a_BlockY;
- if (Meta & 0x8)
+ // Change the door
+ NIBBLETYPE NewMeta = (Meta & 0x7) ^ 0x4;
+ if ((Meta & 0x8) == 0)
{
- // Current block is top of the door
- a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY - 1, a_BlockZ, Block, Meta);
- if (IsDoor(Block) && !(Meta & 0x8))
- {
- OtherPartY--;
- }
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, NewMeta);
}
else
{
- // Current block is bottom of the door
- a_ChunkInterface.GetBlockTypeMeta(a_BlockX, a_BlockY + 1, a_BlockZ, Block, Meta);
- if (IsDoor(Block) && (Meta & 0x8))
- {
- OtherPartY++;
- }
- }
-
- // Change the other door part
- if (a_BlockY != OtherPartY)
- {
- if (a_Open)
- {
- a_ChunkInterface.SetBlockMeta(a_BlockX, OtherPartY, a_BlockZ, Meta | 0x4);
- }
- else
- {
- a_ChunkInterface.SetBlockMeta(a_BlockX, OtherPartY, a_BlockZ, Meta & 0xFFFFFFFB);
- }
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ, NewMeta);
}
}
/** Changes the door at the specified coords from open to close or vice versa */
- static void ChangeDoor(cChunkInterface & a_ChunkInterface, int a_X, int a_Y, int a_Z)
+ static void ChangeDoor(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_X, a_Y, a_Z);
-
- a_ChunkInterface.SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData(OldMetaData));
-
- if (OldMetaData & 8)
- {
- // Current block is top of the door
- BLOCKTYPE BottomBlock = a_ChunkInterface.GetBlock(a_X, a_Y - 1, a_Z);
- NIBBLETYPE BottomMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y - 1, a_Z);
-
- if (IsDoor(BottomBlock) && !(BottomMeta & 8))
- {
- a_ChunkInterface.SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData(BottomMeta));
- }
- }
- else
- {
- // Current block is bottom of the door
- BLOCKTYPE TopBlock = a_ChunkInterface.GetBlock(a_X, a_Y + 1, a_Z);
- NIBBLETYPE TopMeta = a_ChunkInterface.GetBlockMeta(a_X, a_Y + 1, a_Z);
-
- if (IsDoor(TopBlock) && (TopMeta & 8))
- {
- a_ChunkInterface.SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData(TopMeta));
- }
- }
+ SetOpen(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, !IsOpen(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ));
}
} ;