summaryrefslogtreecommitdiffstats
path: root/src/Chunk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chunk.cpp')
-rw-r--r--src/Chunk.cpp42
1 files changed, 28 insertions, 14 deletions
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;
}