Minecraftforge: Provide a TE for getDrops

Created on 13 Jan 2018  路  13Comments  路  Source: MinecraftForge/MinecraftForge

Currently, to access TE data in getDrops, you have to do some trickery involving deleting the block later than normal (see patches to BlockFlowerPot).

However, recently a nullable TileEntity argument was added in vanilla to harvestBlock, which means we can just pass it directly to getDrops (via a threadlocal similar to the silk check state).

This would make it easier/more intuitive to read TE data for getDrops instead of having to do tricks.

Stale

Most helpful comment

When harvesting by digging, getdrops is called after the block (and TE) are already deleted from the world.

All 13 comments

There's not any trickery needed. You have an IBlockAccess and a BlockPos. You can grab the tile yourself without issue - I do this all the time with CoFH stuff.

I've had issues with this myself as well. Yes, you have world access in Block::getDrops, but the TE is almost always null. I've had to override Block::onRemovedByPlayer to change the order block breaking happens in order to make it work.

When harvesting by digging, getdrops is called after the block (and TE) are already deleted from the world.

KingLemming, that is exactly what "some trickery involving deleting the block later than normal" meant...

The current state is that it's a confusing mess.

Looking at the related PR, this is scheduled to be fixed in 1.13.

For now, @McJty demonstrates an example workaround here: https://twitter.com/McJty/status/1002546886161596416

That is the standard workaround everyone has been using for ages...

You might not find it useful. I left it here for those who might.

It's not a nice workaround, this change makes it much nicer.

Personally, I simply implement my own harvestBlock, as shown here. It's the cleanest solution I've found, though coremods which modify harvestBlock might not like it . . .

...and then people ask why implementing breaking a plant with a hoe is such a big deal in the Farming Station...

This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___." or "Here's a screenshot of this issue on the latest version"). Thank you for your contributions!

This issue has been automatically closed because it has not had activity in a long time. Please feel free to reopen it or create a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NovaViper picture NovaViper  路  3Comments

williewillus picture williewillus  路  3Comments

juliand665 picture juliand665  路  3Comments

MSandro picture MSandro  路  3Comments

ErikBigDev picture ErikBigDev  路  3Comments