diff options
author | Mattes D <github@xoft.cz> | 2020-04-21 22:19:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 22:19:22 +0200 |
commit | 487f9a2aa9b5497495cef1ac3b9c7a603e69f862 (patch) | |
tree | 054a846942f414060e29c72f4a717c8a89e70893 /src/Items/ItemBoat.h | |
parent | Delet SpawnObject params (diff) | |
download | cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.gz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.bz2 cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.lz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.xz cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.zst cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.zip |
Diffstat (limited to 'src/Items/ItemBoat.h')
-rw-r--r-- | src/Items/ItemBoat.h | 42 |
1 files changed, 22 insertions, 20 deletions
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; |