Jump to content

Recommended Posts

Posted (edited)
  On 11/18/2019 at 12:00 PM, diesieben07 said:

EntityPlayer#openContainer to get the currently open Container. Then Container#inventorySlots to get all Slots. Then Slot#getStack to get the ItemStack in that slot.

Expand  

It doesn't work. It seems to always access the player inventory.

Edited by Codemetry
Posted (edited)
  On 11/18/2019 at 12:00 PM, diesieben07 said:

EntityPlayer#openContainer to get the currently open Container. Then Container#inventorySlots to get all Slots. Then Slot#getStack to get the ItemStack in that slot.

Expand  

Firstly, EntityPlayer#openContainer is assigned the container of the opened chest AFTER the initialization (GuiScreen#initGui) of the opened GuiChest (the container is stored in GuiContainer). So, I changed to try to access the chest contents in InitGuiEvent.Post event handler.

 

Secondly, I found that the container stored in GuiContainer is a ContainerChest containing the player inventory AND the chest inventory. Therefore, it is not accurate to access the container and directly get the item stacks via it. Then, I found that ContainerChest#getLowerChestInventory returns the chest inventory (somehow it is called lower inventory).

 

Finally, I checked the runtime type of the inventory returned by ContainerChest#getLowerChestInventory. It turns out to be ContainerLocalMenu. The only place which constructs new ContainerLocalMenus is NetHandlerPlayClient#handleOpenWindow. However, the method accepts a packet that does not store the chest inventory contents.

 

Where did I go wrong? How do I access the chest contents?

Edited by Codemetry
Posted (edited)
  On 11/19/2019 at 12:17 PM, diesieben07 said:

Doesn't matter.

 

There is no event. The chest contents could change at any point. Please explain what exactly you are trying to achieve.

Expand  

Read the contents of a chest upon opening, and detect its changes.

I wanted the packet name to check the source code and see if there is any way I can detect.

Edited by Codemetry

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.