Posted November 6, 201410 yr Hi, all! What i have?: I have new custom inventory. At this inventory i have custom slot for backpack. If i put backpack into this slot, appear new slots. What i need?: If i put backpack into custom slot and put some items into new backpack slots it need to be save for this backpack. So, if i remove backpack from slot, backpack slots save for backpack. if i put backpack, backpack slots appear and items, which saved for this backpack, appear into backpack slots. How i realized it?: I realized it in my BackpackSlot (Custom slot in my inventory). I do it with NBT. private ItemStack lastItem; private int lastType; public void onSlotChanged() { ItemStack is = this.invEx.getBackpack(); int type = this.invEx.bagTypeInv; if(is != null && is.getItem() instanceof ItemBackpack) { lastItem = this.invEx.getBackpack(); lastType = this.invEx.bagTypeInv; this.invEx.bagTypeInv = ((ItemBackpack)this.getStack().getItem()).bagTypeItem; if(type != 3) { this.readSlots(is, type * 6); } else { this.readSlots(is, type * 5); } } else { if(lastType != 3) { this.writeSlots(lastItem, lastType * 6); } else { this.writeSlots(lastItem, lastType * 5); } this.invEx.bagTypeInv = 0; } } public void readSlots(ItemStack item, int slotsToClear) { int slotsCount = 3 + slotsToClear); if(item.stackTagCompound != null) { NBTTagList nbttaglist = item.stackTagCompound.getTagList("Items1", 10); for (int i = 0; i <= nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i); byte b0 = nbttagcompound1.getByte("Slot"); if (b0 >= 3 && b0 < slotsCount) { this.invEx.invslots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } } } public static boolean isDo = false; public void writeSlots(ItemStack item, int slotsToClear) { int slotsCount = 3 + slotsToClear; if(!isDo) { if(item != null) { item.stackTagCompound = new NBTTagCompound(); NBTTagList nbttaglist = new NBTTagList(); for(int i = 3; i < slotsCount; ++i) { if (this.invEx.invslots[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.invEx.invslots[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } this.invEx.setInventorySlotContents(i, (ItemStack)null); } item.stackTagCompound.setTag("Items1", nbttaglist); } isDo = true; } } Boolean 'isDo' automaticaly set to false into TickHandler. If it was not, then the first recorded items, and then instead of them null. What do it code?: This code should work, but it is packed with bugs. For example, I can put on a backpack will preserve things for him, then put on another click on an empty slot and somehow pull out the things that have been preserved for the first out of the void. They are, as it were left on the server. Or, I can take a completely empty backpack, and there will be things that have been stored for a completely different backpack that I've been deleted. So, how i can realize/fix 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.