Externalized saved tmpfs contents.

This commit is contained in:
Florian Nücke 2014-08-23 22:46:19 +02:00
parent a36a0b525c
commit 08e203a36f
2 changed files with 20 additions and 9 deletions

View File

@ -31,13 +31,12 @@ object SaveHandler {
scheduleSave(owner.world, owner.x, owner.z, nbt, name, data)
}
def scheduleSave(owner: Owner, nbt: NBTTagCompound, name: String, save: NBTTagCompound => Unit) {
scheduleSave(owner, nbt, name, writeNBT(save))
}
def scheduleSave(container: Container, nbt: NBTTagCompound, name: String, save: NBTTagCompound => Unit) {
val tmpNbt = new NBTTagCompound()
save(tmpNbt)
val baos = new ByteArrayOutputStream()
val dos = new DataOutputStream(baos)
CompressedStreamTools.write(tmpNbt, dos)
scheduleSave(container.world, math.round(container.xPosition - 0.5).toInt, math.round(container.zPosition - 0.5).toInt, nbt, name, baos.toByteArray)
scheduleSave(container.world, math.round(container.xPosition - 0.5).toInt, math.round(container.zPosition - 0.5).toInt, nbt, name, writeNBT(save))
}
def scheduleSave(world: World, x: Int, z: Int, nbt: NBTTagCompound, name: String, data: Array[Byte]) {
@ -53,6 +52,15 @@ object SaveHandler {
scheduleSave(dimension, chunk, name, data)
}
private def writeNBT(save: NBTTagCompound => Unit) = {
val tmpNbt = new NBTTagCompound()
save(tmpNbt)
val baos = new ByteArrayOutputStream()
val dos = new DataOutputStream(baos)
CompressedStreamTools.write(tmpNbt, dos)
baos.toByteArray
}
def loadNBT(nbt: NBTTagCompound, name: String): NBTTagCompound = {
val data = load(nbt, name)
val bais = new ByteArrayInputStream(data)

View File

@ -9,7 +9,7 @@ import li.cil.oc.api.machine._
import li.cil.oc.api.network._
import li.cil.oc.api.{FileSystem, Network, machine}
import li.cil.oc.common.component.ManagedComponent
import li.cil.oc.common.tileentity
import li.cil.oc.common.{SaveHandler, tileentity}
import li.cil.oc.server.PacketSender
import li.cil.oc.server.driver.Registry
import li.cil.oc.server.network.{ArgumentsImpl, Callbacks}
@ -574,7 +574,10 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
_components ++= nbt.getTagList("components").iterator[NBTTagCompound].map(c =>
c.getString("address") -> c.getString("name"))
tmp.foreach(fs => fs.load(nbt.getCompoundTag("tmp")))
tmp.foreach(fs => {
if (nbt.hasKey("tmp")) fs.load(nbt.getCompoundTag("tmp"))
else fs.load(SaveHandler.loadNBT(nbt, node.address + "_tmp"))
})
if (state.size > 0 && state.top != Machine.State.Stopped && init()) try {
architecture.load(nbt)
@ -645,7 +648,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
}
nbt.setTag("components", componentsNbt)
tmp.foreach(fs => nbt.setNewCompoundTag("tmp", fs.save))
tmp.foreach(fs => SaveHandler.scheduleSave(owner, nbt, node.address + "_tmp", fs.save _))
if (state.top != Machine.State.Stopped) try {
architecture.save(nbt)