Jump to content

Recommended Posts

Posted

Hey there! I am new to modding and got a problem with my mod! I am running forge:1.16.5-36.2.2

I created a button that (should) delete an item in a slot of a container.

That container belongs to a block. The block has a Container, a ContainerScreen and a TileEntity.

The slots work fine, i can put items in it and I can take Items out.

The problem is a function, that deletes an item in a slot. Everytime that function gets called, the item disappears.

When clicking the empty slot or closing and reopening the gui that item reappears

Here is some code i tested

public void destroyItem() {
        Slot slot = this.inventorySlots.get(0);
        ItemStack stack = slot.getStack();

        Soulstones.LOGGER.info("TE ITEM: " + te.getItems().get(0).getDisplayName());
        Soulstones.LOGGER.info("SLOT ITEM: " + slot.getStack().getDisplayName());

        slot.putStack(ItemStack.EMPTY);
        te.setInventorySlotContents(0, ItemStack.EMPTY);
        NonNullList<ItemStack> items = te.getItems();
        items.set(0, ItemStack.EMPTY);
        te.setItems(items);
        slot.onSlotChanged();
        detectAndSendChanges();

        Soulstones.LOGGER.info("TE ITEM: " + te.getItems().get(0).getDisplayName());
        Soulstones.LOGGER.info("SLOT ITEM: " + slot.getStack().getDisplayName());
    }

The slot with index 0 is the correct slot. te is the TileEntity bound to this container. The logger also says that the ItemStack is empty.

I hope anyone can help me with that.

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.