Esempio n. 1
0
  @Override
  public void readFromNBT(NBTTagCompound nbtTagCompound) {

    super.readFromNBT(nbtTagCompound);
    NBTTagList tagList = nbtTagCompound.getTagList("Inventory", 10);
    inv = new ItemStack[this.getSizeInventory()];
    for (int i = 0; i < tagList.tagCount(); ++i) {
      NBTTagCompound tagCompound = (NBTTagCompound) tagList.getCompoundTagAt(i);
      byte slot = tagCompound.getByte("Slot");
      if (slot >= 0 && slot < inv.length) {
        inv[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
      }
    }
  }
Esempio n. 2
0
  @Override
  public void writeToNBT(NBTTagCompound nbtTagCompound) {
    super.writeToNBT(nbtTagCompound);

    NBTTagList list = new NBTTagList();
    for (int currentIndex = 0; currentIndex < inv.length; ++currentIndex) {
      if (inv[currentIndex] != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setByte("Slot", (byte) currentIndex);
        inv[currentIndex].writeToNBT(nbt);
        list.appendTag(nbt);
      }
    }
    nbtTagCompound.setTag("Inventory", list);
  }