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/ItemBottle.h | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/Items/ItemBottle.h') diff --git a/src/Items/ItemBottle.h b/src/Items/ItemBottle.h index 319bc708f..2f4d8f93f 100644 --- a/src/Items/ItemBottle.h +++ b/src/Items/ItemBottle.h @@ -9,19 +9,28 @@ -class cItemBottleHandler : +class cItemBottleHandler: public cItemHandler { + using Super = cItemHandler; + public: - cItemBottleHandler() : - cItemHandler(E_ITEM_GLASS_BOTTLE) + + cItemBottleHandler(): + Super(E_ITEM_GLASS_BOTTLE) { } + + + + /** Searches for a water source block in the line of sight. + Returns true and sets a_BlockPos if a water source block is found within line-of-sight. + Returns false if not. */ bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos) { - class cCallbacks : + class cCallbacks: public cBlockTracer::cCallbacks { public: @@ -29,7 +38,7 @@ public: bool m_HasHitFluid; - cCallbacks(void) : + cCallbacks(): m_HasHitFluid(false) { } @@ -49,31 +58,32 @@ public: return false; } } Callbacks; - - cLineBlockTracer Tracer(*a_World, Callbacks); - Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); - Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); - - Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); - + auto Start = a_Player->GetEyePosition() + a_Player->GetLookVector(); + auto End = a_Player->GetEyePosition() + a_Player->GetLookVector() * 5; + cLineBlockTracer::Trace(*a_World, Callbacks, Start, End); if (!Callbacks.m_HasHitFluid) { return false; } - a_BlockPos = Callbacks.m_Pos; return true; } + + 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 - ) override + 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) + if (a_ClickedBlockFace != BLOCK_FACE_NONE) { return false; } -- cgit v1.2.3