Jump to content

[1.15.2] How To Open GUI From Item?


Jack Richard
 Share

Recommended Posts

5 hours ago, Jack Richard said:

I've been trying to open a GUI when an item is right clicked.

NetworkHooks#openGui called in Item#onItemRightClick. It should only be on the logical server, and your container reference will probably need to be an IForgeContainerType.

5 hours ago, Jack Richard said:

I need to also figure out how to create a tile entity for this, if possible?

TileEntity -> Block as ItemStack -> Item. You will need to store the information using NBT tags on the stack by either doing it manually or through the recommended way of capabilities.

Link to comment
Share on other sites

2 hours ago, ChampionAsh5357 said:

NetworkHooks#openGui called in Item#onItemRightClick. It should only be on the logical server, and your container reference will probably need to be an IForgeContainerType.

TileEntity -> Block as ItemStack -> Item. You will need to store the information using NBT tags on the stack by either doing it manually or through the recommended way of capabilities.

Thanks for the help, I'm now able to open the GUI, but I'm still looking for a way to get NBT data from the item to the Screen class. I'm not able to get an instance of the TileEntity, due to it not having a block position, is there any way around this?

 

Thanks again.

Link to comment
Share on other sites

3 hours ago, Jack Richard said:

Thanks for the help, I'm now able to open the GUI, but I'm still looking for a way to get NBT data from the item to the Screen class. I'm not able to get an instance of the TileEntity, due to it not having a block position, is there any way around this?

I mean, yes. You have an item. Items don't have tile entities.

The NBT data is stored in the ItemStack, which is available on the client through the player. It must be the currently held item, if it was right clicked. Although you might have to send over the Hand using the extra data that openGui lets you pass.

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.

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

 Share



×
×
  • Create New...

Important Information

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