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/ItemMinecart.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/Items/ItemMinecart.h') 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(a_BlockX) + 0.5; - double y = static_cast(a_BlockY) + 0.5; - double z = static_cast(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(); -- cgit v1.2.3