summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemItemFrame.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Items/ItemItemFrame.h')
-rw-r--r--src/Items/ItemItemFrame.h60
1 files changed, 34 insertions, 26 deletions
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<cItemFrame>(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<cItemFrame>(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;
}
};