Scourrge Posted August 4, 2020 Posted August 4, 2020 Hi, I would like to ask what is the best way to replace taken stack from container for a new one. I've tried to do it in 2 ways. 1. Implement it within removeStackFromSlot like this: @Override public ItemStack removeStackFromSlot(int index) { int maxPossibleItemStackSize = contents.getSlotLimit(index); ItemStack newStack = new ItemStack(CommonEvents.keysItem); CompoundNBT nbt = newStack.getOrCreateTag(); if(!KeysItem.hasKeysGenerated(nbt)){ KeysItem.generateKeys(nbt); } ItemStack takenStack = contents.extractItem(index, maxPossibleItemStackSize, false); this.setInventorySlotContents(index, newStack); return takenStack; } But this doesn't work at all. 2. Implement it within markDirty like this: @Override public void markDirty() { markDirtyNotification.invoke(); if(this.getStackInSlot(0) == ItemStack.EMPTY) { ItemStack newStack = new ItemStack(CommonEvents.keysItem); CompoundNBT nbt = newStack.getOrCreateTag(); if (!KeysItem.hasKeysGenerated(nbt)) { KeysItem.generateKeys(nbt); } this.setInventorySlotContents(0, newStack); } } This works, but somehow inconsistently, that even the taken stack with generated NBT properties gets replaced for a new one and that is not exactly what I want. I need to extract exactly the Item Stack that is currently in the container and after it was taken away generate a new one instead. Thank you in advance Quote
poopoodice Posted August 4, 2020 Posted August 4, 2020 I think you should be able to do it with Slot.onTake() Quote
Recommended Posts
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.