@Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); int index = 0; for (Node node : nodes) { // See readFromNBT() regarding host check. if (node != null && node.host() == this) { final NBTTagCompound nodeNbt = new NBTTagCompound(); node.save(nodeNbt); nbt.setCompoundTag("oc:node" + index, nodeNbt); } ++index; } }
@Override public void readFromNBT(final NBTTagCompound nbt) { super.readFromNBT(nbt); int index = 0; for (Node node : nodes) { // The host check may be superfluous for you. It's just there to allow // some special cases, where getNode() returns some node managed by // some other instance (for example when you have multiple internal // nodes in this tile entity). if (node != null && node.host() == this) { // This restores the node's address, which is required for networks // to continue working without interruption across loads. If the // node is a power connector this is also required to restore the // internal energy buffer of the node. node.load(nbt.getCompoundTag("oc:node" + index)); } ++index; } }