Jump to content

[1.12.2] Chest with ScrollBar updates only visually


Keitaro

Recommended Posts

I'm working on a chest with a scrollbar and visually it work's fine, but after i scroll the inventory, all slots have the index 0 if clicked.

I think my idea of how to update the inventory is wrong or i am missing something.

I update the slots of my container, based on a rowOffset for the inventory.

 

This is the function of the container:

private void updateSlots() {
        if(this.te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
            IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            int slotOffsetPlayer = 4 * 9;

            // Update own slots
            for (int row = 0; row < CHEST_ROWS; ++row) {
                for (int col = 0; col < CHEST_COLUMNS; ++col) {
                    int x = CHEST_OFFSET_X + col * 18;
                    int y = CHEST_OFFSET_Y + row * 18;
                    this.inventorySlots.set(slotOffsetPlayer + (col + row * CHEST_COLUMNS), new SlotItemHandler(inventory, col + (row + rowOffset) * CHEST_COLUMNS, x, y));
                }
            }
        }
    }

 

Like i said the content get's displayed correctly, but whichever slot i click, i always interact with the slot with index 0.

I changed the order in which the slots are added to the container from Chest, Player, Hotbar to Hotbar, Player, Chest

and now i can still interact with the player's inventory and hotbar.

But all slots i changed are inaccessible.

 

In my first attempt i used a second inventory, which held the visible inventory and synced it back and forth with the whole inventory.

But i didn't use capabilities for this, and switched after i read that by using the ItemHandlerCapability i do not have to sync the client manually with the server via packets.

Because of that i rewrote the whole container and tried it first without the second inventory.

 

Am i just missing something after i update the slots or do i still need the second temporary inventory?

Edited by Keitaro
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.