Hook into falling entity drops for BlockFalling classes
AechtRob opened this issue · 2 comments
It looks like dropt doesn't change the drops which happen when a falling block hits a half slab or similar. Is it possible to enhance the mod so that for any (modded or vanilla) block it also checks if there is an associated falling entity with its own drops, and amends them too?
Maybe. It's not pretty, but something like this might work... for vanilla blocks at least. This may break down if a large number of blocks dropped at the same time, ie. a large-scale player orchestrated sand drop. I don't really see another way to do it though. I'm leaving these notes here for future me if I ever do it.
Use the EntityJoinWorldEvent
to determine when an instance of EntityFallingBlock
joins the world, and:
- Use an AT or method handle to retrieve the
IBlockState
from the falling entity. - Use an AT or method handle to retrieve the
ORIGIN
data parameter from the falling entity. - Use an AT or method handle to retrieve the falling entity's data manager.
- Use the data manager and
ORIGIN
data parameter to retrieve the falling entity's originBlockPos
. - Use the same method that the
EntityFallingBlock
uses to determine the block's drops and place them in a list. - Pass the drop list,
BlockPos
andIBlockState
to Dropt's rule locator. - If a rule matches and is returned, set the falling entity's
captureDrops
flag to true and cache the falling entity, the falling entity'sBlockPos
, the rule, and the falling entity'scapturedDrops
list.
Each server tick, iterate the falling entity cache, and:
- If the
capturedDrops
list is not empty, the falling entity has broken- pass the cached
BlockPos
, rule, andcapturedDrops
list to Dropt's drop modifier - remove the falling entity cache entry
- pass the cached
- Else if the falling entity is dead
- remove the falling entity cache entry