From c53a0ba5f6f71da384a45a07685f8e25c3f91a29 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 23 Sep 2020 16:06:27 +0100 Subject: Unify block entity pickup conversion - Removed normal BlockHandler knowledge of block entities during conversion + Added cBlockEntity::ConvertToPickups that handles it --- src/Chunk.cpp | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a2dd73b51..8f72d7c0f 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -930,20 +930,34 @@ void cChunk::ApplyWeatherToTop() cItems cChunk::PickupsFromBlock(Vector3i a_RelPos, const cEntity * a_Digger, const cItem * a_Tool) { - BLOCKTYPE blockType; - NIBBLETYPE blockMeta; - GetBlockTypeMeta(a_RelPos, blockType, blockMeta); - auto blockEntity = GetBlockEntityRel(a_RelPos); - cItems pickups (0); - auto toolHandler = a_Tool ? a_Tool->GetHandler() : cItemHandler::GetItemHandler(E_ITEM_EMPTY); - auto canHarvestBlock = toolHandler->CanHarvestBlock(blockType); - if (canHarvestBlock) - { - pickups = cBlockHandler::For(blockType).ConvertToPickups(blockMeta, blockEntity, a_Digger, a_Tool); - } - auto absPos = RelativeToAbsolute(a_RelPos); - cRoot::Get()->GetPluginManager()->CallHookBlockToPickups(*m_World, absPos, blockType, blockMeta, blockEntity, a_Digger, a_Tool, pickups); - return pickups; + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + GetBlockTypeMeta(a_RelPos, BlockType, BlockMeta); + + cItems Pickups; + const auto BlockEntity = GetBlockEntityRel(a_RelPos); + + const auto ToolHandler = (a_Tool != nullptr) ? a_Tool->GetHandler() : cItemHandler::GetItemHandler(E_ITEM_EMPTY); + if (ToolHandler->CanHarvestBlock(BlockType)) + { + Pickups = cBlockHandler::For(BlockType).ConvertToPickups(BlockMeta, a_Digger, a_Tool); + + if (BlockEntity != nullptr) + { + auto BlockEntityPickups = BlockEntity->ConvertToPickups(); + Pickups.insert(Pickups.end(), std::make_move_iterator(BlockEntityPickups.begin()), std::make_move_iterator(BlockEntityPickups.end())); + } + } + + // TODO: this should be in cWorld::DropBlockAsPickups. When it's here we can't check the return value and cancel spawning: + cRoot::Get()->GetPluginManager()->CallHookBlockToPickups( + *m_World, + cChunkDef::RelativeToAbsolute(a_RelPos, GetPos()), + BlockType, BlockMeta, BlockEntity, + a_Digger, a_Tool, Pickups + ); + + return Pickups; } -- cgit v1.2.3