From 60c10ef248a2f571f4653363155e1eefdeab23ff Mon Sep 17 00:00:00 2001 From: morsmordere <35617773+morsmordere@users.noreply.github.com> Date: Thu, 25 Jun 2020 20:23:47 -0400 Subject: Cactus cannot be placed on a forbidden blocks (#4767) Co-authored-by: Franklin T Kong Co-authored-by: aiugai Fixes #4641 Overrode GetPlacementBlockTypeMeta for CactusBlock, which gets called before a player places the cactus block, so it returns true if the placement is allowed or false if not, in which case the cactus does not drop as a block but stays in the player's hand which is the expected behavior. Tested in Minecraft client 1.12.2. --- src/Blocks/BlockCactus.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src') diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 0c3577898..15d585eac 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -23,6 +23,40 @@ public: + /** Called before a cactus block is placed by a player, overrides cItemHandler::GetPlacementBlockTypeMeta(). + Calls CanBeAt function to determine if a cactus block can be placed on a given block. */ + bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, + cPlayer & a_Player, + const Vector3i a_PlacedBlockPos, + eBlockFace a_ClickedBlockFace, + const Vector3i a_CursorPos, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + if ( + a_Player.GetWorld()->DoWithChunkAt(a_PlacedBlockPos, + [this, a_PlacedBlockPos, &a_ChunkInterface](cChunk & a_Chunk) + { + auto RelPos = cChunkDef::AbsoluteToRelative(a_PlacedBlockPos); + return CanBeAt(a_ChunkInterface, RelPos, a_Chunk); + } + )) + { + a_BlockType = m_BlockType; + // Setting a_BlockMeta to meta copied from the lowest 4 bits of the player's equipped item's damage value. + NIBBLETYPE Meta = static_cast(a_Player.GetEquippedItem().m_ItemDamage); + a_BlockMeta = Meta & 0x0f; + return true; + } + + return false; + } + + + + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) override { if (a_RelPos.y <= 0) -- cgit v1.2.3