Jump to content

Solved 1.20.4 How can I edit the contents of a tile entity from outside?


Recommended Posts

Posted (edited)

Hello! I have a tile entity and want it so if a player is holding an item and right clicks my tile entity, the item will be inserted in slot 5. How can I do this? I have a use() and made it so the inventory gui will open if you shift right click the block.

Edited by Bunnly
Solved
Posted

On the server for the Item's useOn, you need to get hold of the block's IItemHandler capability and use that to modify the inventory.

https://forge.gemwire.uk/wiki/Capabilities

The block can be found using the UseOnContext.hitResult

See also (in case you need to override the default rules):

https://github.com/MinecraftForge/MinecraftForge/blob/f09fd1f05b39df98f6415b44478b13723cee74cd/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java#L125

 

Alternatively, if it is your block, you can change Block.use() to check what the player is holding when they right click from the passed Player/InteractionHand.

 

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Bunnly changed the title to Solved 1.20.4 How can I edit the contents of a tile entity from outside?

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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