Add SetOpen() and IsOpen() to BlockDoor.h and fix door redstone bug.
This commit is contained in:
parent
2eca98a41a
commit
b4ba220934
@ -20,12 +20,12 @@ public:
|
|||||||
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
||||||
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override;
|
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override;
|
||||||
virtual const char * GetStepSound(void) override;
|
virtual const char * GetStepSound(void) override;
|
||||||
|
|
||||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override;
|
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override;
|
||||||
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override;
|
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override;
|
||||||
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override;
|
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override;
|
||||||
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override;
|
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override;
|
||||||
|
|
||||||
virtual bool GetPlacementBlockTypeMeta(
|
virtual bool GetPlacementBlockTypeMeta(
|
||||||
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
||||||
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
||||||
@ -52,7 +52,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
{
|
{
|
||||||
a_Pickups.push_back(cItem((m_BlockType == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR, 1, 0));
|
a_Pickups.push_back(cItem((m_BlockType == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR, 1, 0));
|
||||||
@ -77,8 +77,8 @@ public:
|
|||||||
{
|
{
|
||||||
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
|
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CanReplaceBlock(BLOCKTYPE a_BlockType)
|
bool CanReplaceBlock(BLOCKTYPE a_BlockType)
|
||||||
{
|
{
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
@ -99,7 +99,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Converts the player's yaw to placed door's blockmeta
|
/** Converts the player's yaw to placed door's blockmeta */
|
||||||
inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
|
inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
|
||||||
{
|
{
|
||||||
ASSERT((a_Yaw >= -180) && (a_Yaw < 180));
|
ASSERT((a_Yaw >= -180) && (a_Yaw < 180));
|
||||||
@ -128,21 +128,92 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns true if the specified blocktype is any kind of door
|
/** Returns true if the specified blocktype is any kind of door */
|
||||||
inline static bool IsDoor(BLOCKTYPE a_Block)
|
inline static bool IsDoor(BLOCKTYPE a_Block)
|
||||||
{
|
{
|
||||||
return (a_Block == E_BLOCK_WOODEN_DOOR) || (a_Block == E_BLOCK_IRON_DOOR);
|
return (a_Block == E_BLOCK_WOODEN_DOOR) || (a_Block == E_BLOCK_IRON_DOOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns the metadata for the opposite door state (open vs closed)
|
/** Returns the metadata for the opposite door state (open vs closed) */
|
||||||
static NIBBLETYPE ChangeStateMetaData(NIBBLETYPE a_MetaData)
|
static NIBBLETYPE ChangeStateMetaData(NIBBLETYPE a_MetaData)
|
||||||
{
|
{
|
||||||
return a_MetaData ^ 4;
|
return a_MetaData ^ 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Changes the door at the specified coords from open to close or vice versa
|
static bool IsOpen(cChunkInterface & a_ChunkInterface, int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ)
|
||||||
|
{
|
||||||
|
BLOCKTYPE Block;
|
||||||
|
NIBBLETYPE Meta;
|
||||||
|
a_ChunkInterface.GetBlockTypeMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Block, Meta);
|
||||||
|
|
||||||
|
if (!IsDoor(Block))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (!IsDoor(Block) || ((Meta & 0x4) == a_Open))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change the door
|
||||||
|
if (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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int OtherPartY = a_BlockY;
|
||||||
|
if (Meta & 0x8)
|
||||||
|
{
|
||||||
|
// 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--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** 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_X, int a_Y, int a_Z)
|
||||||
{
|
{
|
||||||
NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_X, a_Y, a_Z);
|
NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_X, a_Y, a_Z);
|
||||||
|
@ -906,8 +906,11 @@ void cIncrementalRedstoneSimulator::HandleDoor(int a_RelBlockX, int a_RelBlockY,
|
|||||||
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true))
|
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true))
|
||||||
{
|
{
|
||||||
cChunkInterface ChunkInterface(m_World.GetChunkMap());
|
cChunkInterface ChunkInterface(m_World.GetChunkMap());
|
||||||
cBlockDoorHandler::ChangeDoor(ChunkInterface, a_RelBlockX, a_RelBlockY, a_RelBlockZ);
|
if (!cBlockDoorHandler::IsOpen(ChunkInterface, BlockX, a_RelBlockY, BlockZ))
|
||||||
m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0);
|
{
|
||||||
|
cBlockDoorHandler::SetOpen(ChunkInterface, BlockX, a_RelBlockY, BlockZ, true);
|
||||||
|
m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0);
|
||||||
|
}
|
||||||
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true);
|
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -916,8 +919,11 @@ void cIncrementalRedstoneSimulator::HandleDoor(int a_RelBlockX, int a_RelBlockY,
|
|||||||
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false))
|
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false))
|
||||||
{
|
{
|
||||||
cChunkInterface ChunkInterface(m_World.GetChunkMap());
|
cChunkInterface ChunkInterface(m_World.GetChunkMap());
|
||||||
cBlockDoorHandler::ChangeDoor(ChunkInterface, a_RelBlockX, a_RelBlockY, a_RelBlockZ);
|
if (cBlockDoorHandler::IsOpen(ChunkInterface, BlockX, a_RelBlockY, BlockZ))
|
||||||
m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0);
|
{
|
||||||
|
cBlockDoorHandler::SetOpen(ChunkInterface, BlockX, a_RelBlockY, BlockZ, false);
|
||||||
|
m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0);
|
||||||
|
}
|
||||||
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false);
|
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user