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.