diff --git a/src/main/scala/li/cil/oc/common/item/Tablet.scala b/src/main/scala/li/cil/oc/common/item/Tablet.scala index b98af7faa..ec1dfa130 100644 --- a/src/main/scala/li/cil/oc/common/item/Tablet.scala +++ b/src/main/scala/li/cil/oc/common/item/Tablet.scala @@ -227,6 +227,8 @@ class TabletWrapper(var stack: ItemStack, var player: EntityPlayer) extends Comp val tablet = if (world.isRemote) null else new component.Tablet(this) + var autoSave = true + private var isInitialized = !world.isRemote private var lastRunning = false @@ -250,7 +252,7 @@ class TabletWrapper(var stack: ItemStack, var player: EntityPlayer) extends Comp } } - def writeToNBT() { + def writeToNBT(clearState: Boolean = true) { if (!stack.hasTagCompound) { stack.setTagCompound(new NBTTagCompound()) } @@ -262,9 +264,11 @@ class TabletWrapper(var stack: ItemStack, var player: EntityPlayer) extends Comp data.setNewCompoundTag(Settings.namespace + "component", tablet.save) data.setNewCompoundTag(Settings.namespace + "data", machine.save) - // Force tablets into stopped state to avoid errors when trying to - // load deleted machine states. - data.getCompoundTag(Settings.namespace + "data").removeTag("state") + if (clearState) { + // Force tablets into stopped state to avoid errors when trying to + // load deleted machine states. + data.getCompoundTag(Settings.namespace + "data").removeTag("state") + } } save(data) } @@ -272,7 +276,6 @@ class TabletWrapper(var stack: ItemStack, var player: EntityPlayer) extends Comp readFromNBT() if (!world.isRemote) { api.Network.joinNewNetwork(machine.node) - machine.stop() val charge = math.max(0, this.data.energy - tablet.node.globalBuffer) tablet.node.changeBuffer(charge) writeToNBT() @@ -483,6 +486,8 @@ object Tablet { // Force re-load on world change, in case some components store a // reference to the world object. if (holder.worldObj != wrapper.world) { + wrapper.writeToNBT(clearState = false) + wrapper.autoSave = false cache.invalidate(id) cache.cleanUp() wrapper = cache.get(id, this) @@ -502,12 +507,12 @@ object Tablet { val tablet = e.getValue if (tablet.node != null) { // Server. - tablet.writeToNBT() + if (tablet.autoSave) tablet.writeToNBT() tablet.machine.stop() for (node <- tablet.machine.node.network.nodes) { node.remove() } - tablet.writeToNBT() + if (tablet.autoSave) tablet.writeToNBT() } }