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/ItemBoat.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/Items/ItemBoat.h') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 682b68ff2..b6af554c5 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -22,24 +22,32 @@ 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 != BLOCK_FACE_YM) && (a_BlockFace != BLOCK_FACE_NONE)) + // Only allow placing blocks on top of blocks, or when not in range of dest block: + if ((a_ClickedBlockFace != BLOCK_FACE_YM) && (a_ClickedBlockFace != BLOCK_FACE_NONE)) { return false; } - class cCallbacks : + // Find the actual placement position by tracing line of sight until non-air block: + class cCallbacks: public cBlockTracer::cCallbacks { public: Vector3d m_Pos; bool m_HasFound; - cCallbacks(void) : + cCallbacks(): m_HasFound(false) { } @@ -55,27 +63,21 @@ 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_HasFound) { return false; } - auto x = Callbacks.m_Pos.x; - auto y = Callbacks.m_Pos.y; - auto z = Callbacks.m_Pos.z; - auto bx = FloorC(x); - auto by = FloorC(y); - auto bz = FloorC(z); - // Block above must be air to spawn a boat (prevents spawning a boat underwater) - BLOCKTYPE BlockAbove = a_World->GetBlock(bx, by + 1, bz); + auto PosAbove = Callbacks.m_Pos.Floor().addedY(1); + if (!cChunkDef::IsValidHeight(PosAbove.y)) + { + return false; + } + BLOCKTYPE BlockAbove = a_World->GetBlock(PosAbove); if (BlockAbove != E_BLOCK_AIR) { return false; -- cgit v1.2.3