From 748b121703fa28b10933f4432c09391e66179118 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 28 Mar 2021 14:40:57 +0100 Subject: Unify DoWithBlockEntity (#5168) + DoWith calls now broadcast the block entity and mark the chunk dirty + Add block entity change queue to synchronise BE updates with block updates * Fixed a few incorrect assertions about BE type - Remove manual overloads --- src/Items/ItemMobHead.h | 58 +++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'src/Items/ItemMobHead.h') diff --git a/src/Items/ItemMobHead.h b/src/Items/ItemMobHead.h index ef16f6c96..f1e963e1f 100644 --- a/src/Items/ItemMobHead.h +++ b/src/Items/ItemMobHead.h @@ -75,26 +75,22 @@ public: auto BlockMeta = static_cast(a_ClickedBlockFace); // Use a callback to set the properties of the mob head block entity: - a_World.DoWithBlockEntityAt(a_PlacePos.x, a_PlacePos.y, a_PlacePos.z, [&](cBlockEntity & a_BlockEntity) - { - if (a_BlockEntity.GetBlockType() != E_BLOCK_HEAD) - { - return false; - } - auto & MobHeadEntity = static_cast(a_BlockEntity); + a_World.DoWithBlockEntityAt(a_PlacePos, [&](cBlockEntity & a_BlockEntity) + { + ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_HEAD); - int Rotation = 0; - if (BlockMeta == 1) - { - Rotation = FloorC(a_Player.GetYaw() * 16.0f / 360.0f + 0.5f) & 0x0f; - } + auto & MobHeadEntity = static_cast(a_BlockEntity); - MobHeadEntity.SetType(HeadType); - MobHeadEntity.SetRotation(static_cast(Rotation)); - MobHeadEntity.GetWorld()->BroadcastBlockEntity(MobHeadEntity.GetPos()); - return false; + int Rotation = 0; + if (BlockMeta == 1) + { + Rotation = FloorC(a_Player.GetYaw() * 16.0f / 360.0f + 0.5f) & 0x0f; } - ); + + MobHeadEntity.SetType(HeadType); + MobHeadEntity.SetRotation(static_cast(Rotation)); + return false; + }); } @@ -243,23 +239,23 @@ public: return false; } - // If it is a mob head, check the correct head type using the block entity: - if (BlockType == E_BLOCK_HEAD) - { - bool IsWitherHead = false; - a_World.DoWithBlockEntityAt(BlockX, BlockY, BlockZ, [&](cBlockEntity & a_Entity) + // If it is a mob head, check it's a wither skull using the block entity: + if ( + (BlockType == E_BLOCK_HEAD) && + !a_World.DoWithBlockEntityAt({ BlockX, BlockY, BlockZ }, [&](cBlockEntity & a_BlockEntity) + { + if (a_BlockEntity.GetBlockType() != E_BLOCK_HEAD) { - ASSERT(a_Entity.GetBlockType() == E_BLOCK_HEAD); - auto & MobHead = static_cast(a_Entity); - IsWitherHead = (MobHead.GetType() == SKULL_TYPE_WITHER); - return true; + return false; } - ); - if (!IsWitherHead) - { - return false; - } + + return static_cast(a_BlockEntity).GetType() == SKULL_TYPE_WITHER; + }) + ) + { + return false; } + // Matched, continue checking AirBlocks.emplace_back(BlockX, BlockY, BlockZ, E_BLOCK_AIR, 0); } // for i - a_Image -- cgit v1.2.3