From a62b2b1be2103d7de2fd66c7304b7473e369be3c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 May 2021 14:25:10 +0100 Subject: Move item placement into item handlers (#5184) * Move item placement into item handlers + Add appropriate CanBeAt checks in cPlayer::PlaceBlocks, into which all placement handlers call. * Partly addresses #5157 * Fixes #4878 * Fixes #2919 * Fixes #4629 * Fixes #4239 * Fixes #4849 Co-authored-by: changyong guo Co-authored-by: Xotheus Co-authored-by: Krist Pregracke * Review fixes * Update APIDesc.lua * Rename Co-authored-by: changyong guo Co-authored-by: Xotheus Co-authored-by: Krist Pregracke --- src/Blocks/BlockCactus.h | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) (limited to 'src/Blocks/BlockCactus.h') diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 2e7cc7db2..23c4d3421 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -18,47 +18,13 @@ public: private: - /** 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 - ) const override + virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const 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) const override - { - if (a_RelPos.y <= 0) + if (a_Position.y <= 0) { return false; } - BLOCKTYPE Surface = a_Chunk.GetBlock(a_RelPos.addedY(-1)); + BLOCKTYPE Surface = a_Chunk.GetBlock(a_Position.addedY(-1)); if ((Surface != E_BLOCK_SAND) && (Surface != E_BLOCK_CACTUS)) { // Cactus can only be placed on sand and itself @@ -78,7 +44,7 @@ private: BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; if ( - a_Chunk.UnboundedRelGetBlock(a_RelPos + Coords[i], BlockType, BlockMeta) && + a_Chunk.UnboundedRelGetBlock(a_Position + Coords[i], BlockType, BlockMeta) && ( cBlockInfo::IsSolid(BlockType) || (BlockType == E_BLOCK_LAVA) || -- cgit v1.2.3