Unify block entity pickup conversion
- Removed normal BlockHandler knowledge of block entities during conversion + Added cBlockEntity::ConvertToPickups that handles it
This commit is contained in:
committed by
Alexander Harkness
parent
1a60164848
commit
c53a0ba5f6
@@ -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)
|
||||
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, blockEntity, a_Digger, a_Tool);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
auto absPos = RelativeToAbsolute(a_RelPos);
|
||||
cRoot::Get()->GetPluginManager()->CallHookBlockToPickups(*m_World, absPos, blockType, blockMeta, blockEntity, a_Digger, a_Tool, pickups);
|
||||
return pickups;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user