Hey guys,
I started creating my own backpack and stumpled upon a problem.
I created the Inventory for it (not posting all methods because unnecessary)
Now I wonder. I can save and read it from nbt. Do I need to create the inventory from the nbt every time I want to access it, and save it after I created it? If not where do I store it? Since I cant store it in the item class im confused..
public class InventoryBackpack implements IInventory{
public static InventoryBackpack readFromNBT(NBTTagCompound compound)
{
InventoryBackpack backpack = new InventoryBackpack();
NBTTagList list = compound.getTagList(LIST_TAG, 10);
if(list!=null)
{
for( byte b=0; b<list.tagCount(); b++)
{
NBTTagCompound comp = (NBTTagCompound) list.get(b);
backpack.setInventorySlotContents(comp.getByte("id"), ItemStack.loadItemStackFromNBT(comp));
}
}
return backpack;
}
private static final String LIST_TAG="BACKPACK_TAG";
private ItemStack[] items;
public void writeToNBT(NBTTagCompound compound)
{
NBTTagList tag = new NBTTagList();
for (byte b = 0; b < items.length; b++) {
if(items[b]==null) continue;
NBTTagCompound comp = new NBTTagCompound();
comp.setByte("id", b);
items[b].writeToNBT(comp);
tag.appendTag(comp);
}
compound.setTag(LIST_TAG, tag);
}