@Override public void writeToByteBuf(ByteBuf buf) { NBTTagCompound settingsTag = new NBTTagCompound(); writeSettingToNBT(settingsTag); NetworkUtil.writeNBTTagCompound(settingsTag, buf); buf.writeInt(snapshot == null ? 0 : snapshot.size()); if (snapshot == null) { return; } for (ItemStack item : snapshot) { NBTTagCompound itemRoot = new NBTTagCompound(); item.writeToNBT(itemRoot); NetworkUtil.writeNBTTagCompound(itemRoot, buf); } }
@Override public void readFromByteBuf(ByteBuf buf) { NBTTagCompound settingsTag = NetworkUtil.readNBTTagCompound(buf); readSettingsFromNBT(settingsTag); int numItems = buf.readInt(); if (numItems == 0) { snapshot = null; return; } snapshot = new ArrayList<ItemStack>(numItems); for (int i = 0; i < numItems; i++) { NBTTagCompound itemTag = NetworkUtil.readNBTTagCompound(buf); ItemStack item = ItemStack.loadItemStackFromNBT(itemTag); if (item != null) { snapshot.add(item); } } }