mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
Externalized saved tmpfs contents.
This commit is contained in:
parent
a36a0b525c
commit
08e203a36f
@ -31,13 +31,12 @@ object SaveHandler {
|
|||||||
scheduleSave(owner.world, owner.x, owner.z, nbt, name, data)
|
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) {
|
def scheduleSave(container: Container, nbt: NBTTagCompound, name: String, save: NBTTagCompound => Unit) {
|
||||||
val tmpNbt = new NBTTagCompound()
|
scheduleSave(container.world, math.round(container.xPosition - 0.5).toInt, math.round(container.zPosition - 0.5).toInt, nbt, name, writeNBT(save))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def scheduleSave(world: World, x: Int, z: Int, nbt: NBTTagCompound, name: String, data: Array[Byte]) {
|
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)
|
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 = {
|
def loadNBT(nbt: NBTTagCompound, name: String): NBTTagCompound = {
|
||||||
val data = load(nbt, name)
|
val data = load(nbt, name)
|
||||||
val bais = new ByteArrayInputStream(data)
|
val bais = new ByteArrayInputStream(data)
|
||||||
|
@ -9,7 +9,7 @@ import li.cil.oc.api.machine._
|
|||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.api.{FileSystem, Network, machine}
|
import li.cil.oc.api.{FileSystem, Network, machine}
|
||||||
import li.cil.oc.common.component.ManagedComponent
|
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.PacketSender
|
||||||
import li.cil.oc.server.driver.Registry
|
import li.cil.oc.server.driver.Registry
|
||||||
import li.cil.oc.server.network.{ArgumentsImpl, Callbacks}
|
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 =>
|
_components ++= nbt.getTagList("components").iterator[NBTTagCompound].map(c =>
|
||||||
c.getString("address") -> c.getString("name"))
|
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 {
|
if (state.size > 0 && state.top != Machine.State.Stopped && init()) try {
|
||||||
architecture.load(nbt)
|
architecture.load(nbt)
|
||||||
@ -645,7 +648,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
|||||||
}
|
}
|
||||||
nbt.setTag("components", componentsNbt)
|
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 {
|
if (state.top != Machine.State.Stopped) try {
|
||||||
architecture.save(nbt)
|
architecture.save(nbt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user