mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
fixed file system labels not being saved. oops.
This commit is contained in:
parent
6d54fffdbe
commit
b5bd97807c
@ -1,11 +1,13 @@
|
||||
package li.cil.oc.api.fs;
|
||||
|
||||
import li.cil.oc.api.Persistable;
|
||||
|
||||
/**
|
||||
* Used by file system components to get and set the file system's label.
|
||||
*
|
||||
* @see li.cil.oc.api.FileSystem#asManagedEnvironment(FileSystem, Label)
|
||||
*/
|
||||
public interface Label {
|
||||
public interface Label extends Persistable {
|
||||
/**
|
||||
* Get the current value of this label.
|
||||
* <p/>
|
||||
|
@ -37,5 +37,5 @@
|
||||
@cpw.mods.fml.common.API(
|
||||
owner = "OpenComputers|Core",
|
||||
provides = "OpenComputersAPI",
|
||||
apiVersion = "1.3.0")
|
||||
apiVersion = "1.4.0")
|
||||
package li.cil.oc.api;
|
@ -489,7 +489,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def installedMemory = 96 * 1024
|
||||
override def installedMemory = 128 * 1024
|
||||
|
||||
override def tier = 0
|
||||
|
||||
|
@ -245,6 +245,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC
|
||||
}
|
||||
})
|
||||
|
||||
label.load(nbt.getCompoundTag("label"))
|
||||
fileSystem.load(nbt.getCompoundTag("fs"))
|
||||
}
|
||||
|
||||
@ -264,6 +265,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC
|
||||
}
|
||||
nbt.setTag("owners", ownersNbt)
|
||||
|
||||
nbt.setNewCompoundTag("label", label.save)
|
||||
nbt.setNewCompoundTag("fs", fileSystem.save)
|
||||
}
|
||||
|
||||
|
@ -72,17 +72,32 @@ object FileSystem extends Item {
|
||||
override def setLabel(value: String) {
|
||||
media.setLabel(stack, value)
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound) {}
|
||||
|
||||
override def save(nbt: NBTTagCompound) {}
|
||||
}
|
||||
|
||||
private class ItemLabel(val stack: ItemStack) extends Label {
|
||||
override def getLabel =
|
||||
if (dataTag(stack).hasKey(Settings.namespace + "fs.label"))
|
||||
dataTag(stack).getString(Settings.namespace + "fs.label")
|
||||
else null
|
||||
var label: Option[String] = None
|
||||
|
||||
override def getLabel = label.orNull
|
||||
|
||||
override def setLabel(value: String) {
|
||||
dataTag(stack).setString(Settings.namespace + "fs.label",
|
||||
if (value.length > 16) value.substring(0, 16) else value)
|
||||
label = Option(if (value != null && value.length > 16) value.substring(0, 16) else value)
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound) {
|
||||
if (dataTag(stack).hasKey(Settings.namespace + "fs.label")) {
|
||||
label = Option(dataTag(stack).getString(Settings.namespace + "fs.label"))
|
||||
}
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound) {
|
||||
label match {
|
||||
case Some(value) => dataTag(stack).setString(Settings.namespace + "fs.label", value)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import li.cil.oc.api.fs.Label
|
||||
import li.cil.oc.server.component
|
||||
import li.cil.oc.{Settings, api}
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
object FileSystem extends api.detail.FileSystemAPI {
|
||||
override def fromClass(clazz: Class[_], domain: String, root: String): api.fs.FileSystem = {
|
||||
@ -84,6 +85,10 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
def setLabel(value: String) = throw new IllegalArgumentException("label is read only")
|
||||
|
||||
def getLabel = label
|
||||
|
||||
override def load(nbt: NBTTagCompound) {}
|
||||
|
||||
override def save(nbt: NBTTagCompound) {}
|
||||
}
|
||||
|
||||
private class ReadOnlyFileSystem(protected val root: io.File)
|
||||
|
@ -474,7 +474,7 @@ function filesystem.open(path, mode)
|
||||
|
||||
local function cleanup(self)
|
||||
if not self.handle then return end
|
||||
self.fs.close(self.handle)
|
||||
pcall(self.fs.close, self.handle)
|
||||
end
|
||||
local metatable = {__index = fileStream,
|
||||
__gc = cleanup,
|
||||
|
Loading…
x
Reference in New Issue
Block a user