Posted November 18, 20195 yr How do I read the items in an opened chest (chest gui opened), on client side?
November 19, 20195 yr Author 15 hours ago, 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. It doesn't work. It seems to always access the player inventory. Edited November 19, 20195 yr by Codemetry
November 19, 20195 yr Author 16 hours ago, 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. 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 November 19, 20195 yr by Codemetry
November 19, 20195 yr Author 2 hours ago, diesieben07 said: Inventory contents are sent later in a separate packet. Do you know the packet type name? Which event should I handle and access the chest contents inside the event handler? Edited November 19, 20195 yr by Codemetry
November 19, 20195 yr Author 3 minutes ago, 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. 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 November 19, 20195 yr by Codemetry
November 19, 20195 yr Author 4 hours ago, diesieben07 said: There is no better way than to check every tick. How do I check if the chest contents are loaded?
November 20, 20195 yr Author 8 hours ago, diesieben07 said: You can't. There is no way to tell client-side whether you are looking at an empty inventory or the contents have not arrived yet. Thanks for helping me.
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.