diff options
Diffstat (limited to '')
-rw-r--r-- | src/Items/ItemMinecart.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index 603d3f9c5..d108c2ca8 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -1,8 +1,6 @@ #pragma once -#include "../Entities/Minecart.h" - @@ -21,18 +19,25 @@ public: + + 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 < 0) + // Must be used on a block + if (a_ClickedBlockFace < 0) { return false; } // Check that there's rail in there: - BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE Block = a_World->GetBlock(a_ClickedBlockPos); switch (Block) { case E_BLOCK_MINECART_TRACKS: @@ -50,15 +55,14 @@ public: } } - double x = static_cast<double>(a_BlockX) + 0.5; - double y = static_cast<double>(a_BlockY) + 0.5; - double z = static_cast<double>(a_BlockZ) + 0.5; - - if (a_World->SpawnMinecart(x, y, z, m_ItemType) == cEntity::INVALID_ID) + // Spawn the minecart: + auto SpawnPos = Vector3d(a_ClickedBlockPos) + Vector3d(0.5, 0.5, 0.5); + if (a_World->SpawnMinecart(SpawnPos, m_ItemType) == cEntity::INVALID_ID) { return false; } + // Remove the item from inventory: if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); |