Jump to content

[1.18.2] GUI for custom entity with inventory


GnRSlashSP

Recommended Posts

Hey,

My entity extends TamableAnimal that finally extends Mob and I am using handItems and armorItems (both are a List of ItemStacks).
Everything is working, I can put and remove items from these 'inventories', I can render items above entity head at client side, very well.

But now, I don't know how to create a custom gui screen to interact with these inventories. Gui normally requires containers, but I don't have a container here, just list of itemstacks.
Can someone help me a little here?

Tks
†GnR† Slash

†GnR† Slash

can one man truly make a difference?

Link to comment
Share on other sites

4 hours ago, GnRSlashSP said:

Gui normally requires containers, but I don't have a container here, just list of itemstacks.

You can use EntityEquipmentInvWrapper to get an item handler wrapping handItems and armorItems, which you can then use to create the slots in a ContainerMenu.

Link to comment
Share on other sites

On 8/14/2022 at 3:49 AM, vemerion said:

You can use EntityEquipmentInvWrapper to get an item handler wrapping handItems and armorItems, which you can then use to create the slots in a ContainerMenu.

Thank you for this tip. I think I did it right because it is working on single and multiplayer!
This is what I did with inventory:

I put this inside entity constructor:

handsInvWrapper = new EntityHandsInvWrapper(this);

So, I created this inside the Container:

antItemHandler = antEntity.handsInvWrapper;

antItemHandler is a IItemHandler class.

 

thank you again!

Edited by GnRSlashSP
I did it! it is working!

†GnR† Slash

can one man truly make a difference?

Link to comment
Share on other sites

Another question:

I have these public functions in my custom entity:

1. void setDropItem(boolean value);
2. void setHomePos();

I am implementing this using network messages, but I want to know if messages is the best way or there is another forge functions do deal with these.

From gui:
a. player can use a checkbox to write on item 1
b. player can use a button to activate item 2

I'll send send a message from gui to the server -> my entity, every time player clicks the button or changes the checkbox.
Am I doing it correctly with messages?

Thanks

†GnR† Slash

can one man truly make a difference?

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