From 98950af634cca62af08ddf8c07b77f46165578a8 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 9 Jul 2014 16:53:01 +0200 Subject: [PATCH 1/7] Fixed Bucket placing --- src/Items/ItemBucket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 68c89dd85..fa98587ea 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -41,7 +41,7 @@ public: bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { - if (a_BlockFace > 0) + if (a_BlockFace < 0) { return false; } From a11ad977ce9465c6c37050f7b9a82f1884645a34 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 10 Jul 2014 16:10:42 +0200 Subject: [PATCH 2/7] Fixed Bucket Placing --- src/Items/ItemBucket.h | 63 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index fa98587ea..41b7c82bc 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -41,7 +41,7 @@ public: bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { - if (a_BlockFace < 0) + if (a_BlockFace > 0) { return false; } @@ -95,18 +95,24 @@ public: bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock) { - if (a_BlockFace < 0) + if (a_BlockFace > 0) { return false; } + + Vector3i BlockPos; + if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos)) + { + return false; + } - BLOCKTYPE CurrentBlock = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE CurrentBlock = a_World->GetBlock(BlockPos); bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); if (!CanWashAway) { // The block pointed at cannot be washed away, so put fluid on top of it / on its sides - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - CurrentBlock = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + //AddFaceDirection(BlockPos.x, BlockPos.y, BlockPos.z, a_BlockFace); + CurrentBlock = a_World->GetBlock(BlockPos); } if ( !CanWashAway && @@ -149,7 +155,7 @@ public: } } - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_FluidBlock, 0); + a_World->SetBlock(BlockPos.x, BlockPos.y, BlockPos.z, a_FluidBlock, 0); return true; } @@ -201,5 +207,50 @@ public: BlockPos.Set(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z); return true; } + + + bool GetPlaceableBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & BlockPos) + { + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + Vector3i m_Pos; + bool m_HasHitLastBlock; + + cCallbacks(void) : + m_HasHitLastBlock(false) + { + } + + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (a_BlockType != E_BLOCK_AIR) + { + m_HasHitLastBlock = true; + return true; + } + + m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + + 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); + + if (!Callbacks.m_HasHitLastBlock) + { + return false; + } + + + BlockPos.Set(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z); + return true; + } }; From 47ceb9e79db2a30dd5b5e48dd28f9c6f14ed2fc3 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 10 Jul 2014 16:36:28 +0200 Subject: [PATCH 3/7] Maybe fixed whitespaces --- src/Items/ItemBucket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 41b7c82bc..5c8d5f741 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -105,7 +105,7 @@ public: { return false; } - + BLOCKTYPE CurrentBlock = a_World->GetBlock(BlockPos); bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); if (!CanWashAway) From 944c04a209492826365b3785ccf1ed1fc70e122c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 10 Jul 2014 16:38:19 +0200 Subject: [PATCH 4/7] Maybe fixed whitespaces --- src/Items/ItemBucket.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 5c8d5f741..ab884ced6 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -99,13 +99,13 @@ public: { return false; } - - Vector3i BlockPos; - if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos)) - { - return false; - } - + + Vector3i BlockPos; + if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos)) + { + return false; + } + BLOCKTYPE CurrentBlock = a_World->GetBlock(BlockPos); bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); if (!CanWashAway) From a8efb620881cd744cfd3cc74316a39bfec80b897 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 10 Jul 2014 17:46:07 +0200 Subject: [PATCH 5/7] Changes --- src/Items/ItemBucket.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index ab884ced6..b31266f35 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -100,19 +100,19 @@ public: return false; } + BLOCKTYPE CurrentBlock; Vector3i BlockPos; - if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos)) + if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos, CurrentBlock)) { return false; } - BLOCKTYPE CurrentBlock = a_World->GetBlock(BlockPos); bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); if (!CanWashAway) { // The block pointed at cannot be washed away, so put fluid on top of it / on its sides - //AddFaceDirection(BlockPos.x, BlockPos.y, BlockPos.z, a_BlockFace); - CurrentBlock = a_World->GetBlock(BlockPos); + // AddFaceDirection(BlockPos.x, BlockPos.y, BlockPos.z, a_BlockFace); + // CurrentBlock = a_World->GetBlock(BlockPos); } if ( !CanWashAway && @@ -161,7 +161,7 @@ public: } - bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & BlockPos) + bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos) { class cCallbacks : public cBlockTracer::cCallbacks @@ -204,19 +204,20 @@ public: } - BlockPos.Set(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z); + a_BlockPos = Callbacks.m_Pos; return true; } - bool GetPlaceableBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & BlockPos) + bool GetPlaceableBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType) { class cCallbacks : public cBlockTracer::cCallbacks { public: - Vector3i m_Pos; - bool m_HasHitLastBlock; + Vector3i m_Pos; + bool m_HasHitLastBlock; + BLOCKTYPE m_LastBlock; cCallbacks(void) : @@ -226,15 +227,16 @@ public: virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { - if (a_BlockType != E_BLOCK_AIR) - { - m_HasHitLastBlock = true; - return true; - } - - m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); - - return false; + if (a_BlockType != E_BLOCK_AIR) + { + m_HasHitLastBlock = true; + return true; + } + + m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + m_LastBlock = a_BlockType; + + return false; } } Callbacks; @@ -249,8 +251,8 @@ public: return false; } - - BlockPos.Set(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z); + a_BlockPos = Callbacks.m_Pos; + a_BlockType = Callbacks.m_LastBlock; return true; } }; From ca6bcacdb9216237a25c05b2887ea69c6066356b Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 11 Jul 2014 17:58:35 +0200 Subject: [PATCH 6/7] Changes --- src/Items/ItemBucket.h | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index b31266f35..e7214d852 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -41,7 +41,7 @@ public: bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { - if (a_BlockFace > 0) + if (a_BlockFace != BLOCK_FACE_NONE) { return false; } @@ -95,38 +95,18 @@ public: bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock) { - if (a_BlockFace > 0) + if (a_BlockFace != BLOCK_FACE_NONE) { return false; } BLOCKTYPE CurrentBlock; Vector3i BlockPos; - if (!GetPlaceableBlockFromTrace(a_World, a_Player, BlockPos, CurrentBlock)) + if (!GetPlacementCoordsFromTrace(a_World, a_Player, BlockPos, CurrentBlock)) { return false; } - bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); - if (!CanWashAway) - { - // The block pointed at cannot be washed away, so put fluid on top of it / on its sides - // AddFaceDirection(BlockPos.x, BlockPos.y, BlockPos.z, a_BlockFace); - // CurrentBlock = a_World->GetBlock(BlockPos); - } - if ( - !CanWashAway && - (CurrentBlock != E_BLOCK_AIR) && - (CurrentBlock != E_BLOCK_WATER) && - (CurrentBlock != E_BLOCK_STATIONARY_WATER) && - (CurrentBlock != E_BLOCK_LAVA) && - (CurrentBlock != E_BLOCK_STATIONARY_LAVA) - ) - { - // Cannot place water here - return false; - } - if (a_Player->GetGameMode() != gmCreative) { // Remove fluid bucket, add empty bucket: @@ -144,6 +124,7 @@ public: } // Wash away anything that was there prior to placing: + bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); if (CanWashAway) { cBlockHandler * Handler = BlockHandler(CurrentBlock); @@ -209,7 +190,7 @@ public: } - bool GetPlaceableBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType) + bool GetPlacementCoordsFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType) { class cCallbacks : public cBlockTracer::cCallbacks @@ -229,6 +210,17 @@ public: { if (a_BlockType != E_BLOCK_AIR) { + bool CanWashAway = cFluidSimulator::CanWashAway(m_LastBlock); + if ( + !CanWashAway && + (m_LastBlock != E_BLOCK_AIR) && + !IsBlockWater(m_LastBlock) && + !IsBlockLava(m_LastBlock) + ) + { + return true; + } + m_HasHitLastBlock = true; return true; } From 68668d7a6eb3a989fc331f68fb660fff19b2f069 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Jul 2014 12:44:59 +0200 Subject: [PATCH 7/7] Changes --- src/Items/ItemBucket.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index e7214d852..b3f008229 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -124,8 +124,7 @@ public: } // Wash away anything that was there prior to placing: - bool CanWashAway = cFluidSimulator::CanWashAway(CurrentBlock); - if (CanWashAway) + if (cFluidSimulator::CanWashAway(CurrentBlock)) { cBlockHandler * Handler = BlockHandler(CurrentBlock); if (Handler->DoesDropOnUnsuitable()) @@ -188,9 +187,9 @@ public: a_BlockPos = Callbacks.m_Pos; return true; } - - - bool GetPlacementCoordsFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType) + + + bool GetPlacementCoordsFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType) { class cCallbacks : public cBlockTracer::cCallbacks