mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 16:57:32 -04:00
Somewhat hacky, seems to work fine from initial tests (single and multiplayer) but will need broader testing.
This commit is contained in:
parent
9deaf7101f
commit
a03966748e
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user