summaryrefslogtreecommitdiffstats
path: root/src/Chunk.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-09-23 17:06:27 +0200
committerAlexander Harkness <me@bearbin.net>2020-09-25 11:07:01 +0200
commitc53a0ba5f6f71da384a45a07685f8e25c3f91a29 (patch)
treebc8d016d1f5c5b5206b3b4f5580295bd91bb6099 /src/Chunk.cpp
parentSmall cleanup in Jukeboxes (diff)
downloadcuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.gz
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.bz2
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.lz
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.xz
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.zst
cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.zip
Diffstat (limited to '')
-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;
}