From 487f9a2aa9b5497495cef1ac3b9c7a603e69f862 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 21 Apr 2020 22:19:22 +0200 Subject: Vector3 in Handlers (#4680) Refactored all cBlockHandler and cItemHandler descendants to use Vector3. --- src/Items/ItemItemFrame.h | 60 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'src/Items/ItemItemFrame.h') diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 7845701fe..bcc325701 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -9,51 +9,59 @@ -class cItemItemFrameHandler : +class cItemItemFrameHandler: public cItemHandler { + using Super = cItemHandler; + public: - cItemItemFrameHandler(int a_ItemType) - : cItemHandler(a_ItemType) - { + cItemItemFrameHandler(int a_ItemType): + Super(a_ItemType) + { } + + virtual bool OnItemUse( - cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace + cWorld * a_World, + cPlayer * a_Player, + cBlockPluginInterface & a_PluginInterface, + const cItem & a_HeldItem, + const Vector3i a_ClickedBlockPos, + eBlockFace a_ClickedBlockFace ) override { - if ((a_BlockFace == BLOCK_FACE_NONE) || (a_BlockFace == BLOCK_FACE_YP) || (a_BlockFace == BLOCK_FACE_YM)) + // Can only place on a side face: + if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM)) { - // Client sends this if clicked on top or bottom face return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); // Make sure block that will be occupied is free - BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); // We want the clicked block, so go back again - - if (Block == E_BLOCK_AIR) + // Make sure block that will be occupied by the item frame is free now: + auto PlacePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace); + BLOCKTYPE Block = a_World->GetBlock(PlacePos); + if (Block != E_BLOCK_AIR) { - auto ItemFrame = cpp14::make_unique(a_BlockFace, Vector3i{a_BlockX, a_BlockY, a_BlockZ}); - auto ItemFramePtr = ItemFrame.get(); - if (!ItemFramePtr->Initialize(std::move(ItemFrame), *a_World)) - { - return false; - } - - if (!a_Player->IsGameModeCreative()) - { - a_Player->GetInventory().RemoveOneEquippedItem(); - } + return false; + } - return true; + // Place the item frame: + auto ItemFrame = cpp14::make_unique(a_ClickedBlockFace, a_ClickedBlockPos); + auto ItemFramePtr = ItemFrame.get(); + if (!ItemFramePtr->Initialize(std::move(ItemFrame), *a_World)) + { + return false; + } + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); } - return false; + + return true; } }; -- cgit v1.2.3