diff options
author | Mattes D <github@xoft.cz> | 2020-04-21 22:19:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 22:19:22 +0200 |
commit | 487f9a2aa9b5497495cef1ac3b9c7a603e69f862 (patch) | |
tree | 054a846942f414060e29c72f4a717c8a89e70893 /src/Items/ItemDoor.h | |
parent | Delet SpawnObject params (diff) | |
download | cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.gz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.bz2 cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.lz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.xz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.zst cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.zip |
Diffstat (limited to 'src/Items/ItemDoor.h')
-rw-r--r-- | src/Items/ItemDoor.h | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/Items/ItemDoor.h b/src/Items/ItemDoor.h index 790e08ffc..aec6bc0fe 100644 --- a/src/Items/ItemDoor.h +++ b/src/Items/ItemDoor.h @@ -9,38 +9,45 @@ -class cItemDoorHandler : +class cItemDoorHandler: public cItemHandler { + using Super = cItemHandler; + public: - cItemDoorHandler(int a_ItemType) : - cItemHandler(a_ItemType) + + cItemDoorHandler(int a_ItemType): + Super(a_ItemType) { } + + virtual bool GetBlocksToPlace( cWorld & a_World, cPlayer & a_Player, const cItem & a_EquippedItem, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, - int a_CursorX, int a_CursorY, int a_CursorZ, + const Vector3i a_PlacedBlockPos, + eBlockFace a_ClickedBlockFace, + const Vector3i a_CursorPos, sSetBlockVector & a_BlocksToSet ) override { // Vanilla only allows door placement while clicking on the top face of the block below the door: - if (a_BlockFace != BLOCK_FACE_TOP) + if (a_ClickedBlockFace != BLOCK_FACE_TOP) { return false; } // Door (bottom block) can be placed in Y range of [1, 254]: - if ((a_BlockY < 1) || (a_BlockY >= cChunkDef::Height - 2)) + if ((a_PlacedBlockPos.y < 1) || (a_PlacedBlockPos.y >= cChunkDef::Height - 2)) { return false; } // The door needs a compatible block below it: - if (!cBlockDoorHandler::CanBeOn(a_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ), a_World.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ))) + auto BelowPos = a_PlacedBlockPos.addedY(-1); + if (!cBlockDoorHandler::CanBeOn(a_World.GetBlock(BelowPos), a_World.GetBlockMeta(BelowPos))) { return false; } @@ -64,8 +71,9 @@ public: } // Check the two blocks that will get replaced by the door: - BLOCKTYPE LowerBlockType = a_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); - BLOCKTYPE UpperBlockType = a_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ); + auto UpperBlockPos = a_PlacedBlockPos.addedY(1); + BLOCKTYPE LowerBlockType = a_World.GetBlock(a_PlacedBlockPos); + BLOCKTYPE UpperBlockType = a_World.GetBlock(UpperBlockPos); if ( !cBlockDoorHandler::CanReplaceBlock(LowerBlockType) || !cBlockDoorHandler::CanReplaceBlock(UpperBlockType)) @@ -78,10 +86,10 @@ public: Vector3i RelDirToOutside = cBlockDoorHandler::GetRelativeDirectionToOutside(LowerBlockMeta); Vector3i LeftNeighborPos = RelDirToOutside; LeftNeighborPos.TurnCW(); - LeftNeighborPos.Move(a_BlockX, a_BlockY, a_BlockZ); + LeftNeighborPos.Move(a_PlacedBlockPos); Vector3i RightNeighborPos = RelDirToOutside; RightNeighborPos.TurnCCW(); - RightNeighborPos.Move(a_BlockX, a_BlockY, a_BlockZ); + RightNeighborPos.Move(a_PlacedBlockPos); // Decide whether the hinge is on the left (default) or on the right: NIBBLETYPE UpperBlockMeta = 0x08; @@ -89,7 +97,7 @@ public: BLOCKTYPE RightNeighborBlock = a_World.GetBlock(RightNeighborPos); /* // DEBUG: - FLOGD("Door being placed at {0}", Vector3i{a_BlockX, a_BlockY, a_BlockZ}); + FLOGD("Door being placed at {0}", a_PlacedBlockPos); FLOGD("RelDirToOutside: {0}", RelDirToOutside); FLOGD("Left neighbor at {0}: {1} ({2})", LeftNeighborPos, LeftNeighborBlock, ItemTypeToString(LeftNeighborBlock)); FLOGD("Right neighbor at {0}: {1} ({2})", RightNeighborPos, RightNeighborBlock, ItemTypeToString(RightNeighborBlock)); @@ -108,12 +116,14 @@ public: } // Set the blocks: - a_BlocksToSet.emplace_back(a_BlockX, a_BlockY, a_BlockZ, BlockType, LowerBlockMeta); - a_BlocksToSet.emplace_back(a_BlockX, a_BlockY + 1, a_BlockZ, BlockType, UpperBlockMeta); + a_BlocksToSet.emplace_back(a_PlacedBlockPos, BlockType, LowerBlockMeta); + a_BlocksToSet.emplace_back(UpperBlockPos, BlockType, UpperBlockMeta); return true; } + + virtual bool IsPlaceable(void) override { return true; |