Jump to content

Recommended Posts

Posted (edited)

I am trying to create an entity with a gui that displays slots for their armor, mainhand, offhand, and a 10 slot inventory. Currently my gui will open when the entity is right-clicked by the player, but it is unfortunately NOT interactable.

 

Entity Super Class - SiegeEntity:

  Reveal hidden contents

Entity Class - PeasantEntity:

  Reveal hidden contents

Container Class:

  Reveal hidden contents

Container Screen Class:

  Reveal hidden contents

ContainerTypes Class:

  Reveal hidden contents

ClientEventBusSubscriber:

  Reveal hidden contents

Main Class:

  Reveal hidden contents

I will be converting from Inventory to ItemHandler soon, but for now I just want the container to open.

 

--SOLUTION--

Main Entity Class:

  Reveal hidden contents

ContainerFactory:

  Reveal hidden contents

ScreenFactory:

  Reveal hidden contents

Container Class:

  Reveal hidden contents

Screen Class:

  Reveal hidden contents

 

Edited by OuiOuiCroissant
Updated with solution
Posted

Update!

I have discovered that I MUST use the required constructor:

  Reveal hidden contents

However, I need both the Screen and Container classes to identify the entity they belong to.

 

I bet I can pass getEntityID through the PacketBuffer parameter of Container class. Do I make a new PacketBuffer in the createMenu method and give it Unpooled.buffer()?

  Reveal hidden contents

When I read it in the Container class it throws an IndexOutOfBoundsException. I will need to read up on how PacketBuffer works. I will update if I figure it out.

  Reveal hidden contents

 

Posted

IContainerFactory doesn't have a PacketBuffer field, it only exists as a parameter in its create() method. Where does an instance of PacketBuffer come from? Or should I create my own static instance in my container factory?

 

Implementing IContainerFactory on my container factory has me implement a create() method:

  Reveal hidden contents

But I cannot make a static instance of my container, right? And create() is not a static method so I can't call it from somewhere else. I have nothing to pass into widowId or playerInv from here either.

  Reveal hidden contents

 

Posted

I just meant a static field to pass into NetworkHooks.openGui(ServerPlayerEntity, INamedContainerProvider, Consumer<PacketBuffer>) like so:

  Reveal hidden contents

 

So far my container factory looks like:

  Reveal hidden contents

And I made a screen factory:

  Reveal hidden contents

Will both of these create() methods be run if I run NetworkHooks.openGui(ServerPlayerEntity, INamedContainerProvider, Consumer<PacketBuffer>) on the server side?

 

Thank you so much for your patience and help.

Posted

Something I implement? As in I implement an interface? Or do you mean I create a new instance of PacketBuffer like so:

ContainerProvider:

  Reveal hidden contents

Here are my other classes as they currently are:

EntityClass:

  Reveal hidden contents

Container Factory:

  Reveal hidden contents

Screen Factory:

  Reveal hidden contents

Container:

  Reveal hidden contents
Posted

Like so?

  Reveal hidden contents

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.