Jump to content

[SOLVED][1.14] How to change a loot table dynamically?


Recommended Posts

I am creating a new block which can contain some items,

and, now, if the block is destroyed, only the block is dropped.

I want to make it possible to drop not only the block but also items in it.

I read the code of HopperTileEntity and I think extending LocableLootTileIntity is a key,

but I cannot understand which methods are important.

Would you tell me how to change a loot table dynamically?


Edited by serena41605866
Link to comment
Share on other sites

I think your block needs to mimic the HopperBlock's onReplaced method. The loot information in the hopper's tile entity is for items that can have loot tables associated with them which is not what you're asking for (you just want to drop current inventory sounds like). Also check out the ChestBlock or BarrelBlock code.

Link to comment
Share on other sites

Yes, you should override your block's onReplaced() method and drop any contained items there.  Note that dropping the contents of a tile entity's inventory is a different operation from dropping the tile entity's own block (which should be done by a loot table in 1.14).


Please don't make your tile entity a subclass of LockableLootTileEntity, which uses the vanilla IInventory system.  Instead use Forge capabilities, and store your items in an IItemHandler implementation (most likely ItemStackHandler or a subclass of that).  If you insist on using vanilla IInventory, don't be surprised when people complain that your block's inventory is not accessible by any other mods...

Edited by desht
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.