Hacky hack to avoid filesystems flushing to real HDD when sending client descriptor packets.

This commit is contained in:
Florian Nücke 2016-01-02 15:44:40 +01:00
parent 5ca28b2d92
commit fb88a19e10
3 changed files with 27 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly
import li.cil.oc.OpenComputers
import li.cil.oc.Settings
import li.cil.oc.client.Sound
import li.cil.oc.server.fs.FileSystem
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.SideTracker
import net.minecraft.nbt.NBTTagCompound
@ -88,10 +89,16 @@ trait TileEntity extends net.minecraft.tileentity.TileEntity {
override def getDescriptionPacket = {
val nbt = new NBTTagCompound()
FileSystem.savingForClients = true
try {
try writeToNBTForClient(nbt) catch {
case e: Throwable => OpenComputers.log.warn("There was a problem writing a TileEntity description packet. Please report this if you see it!", e)
}
if (nbt.hasNoTags) null else new S35PacketUpdateTileEntity(x, y, z, -1, nbt)
} finally {
FileSystem.savingForClients = false
}
}
override def onDataPacket(manager: NetworkManager, packet: S35PacketUpdateTileEntity) {

View File

@ -5,15 +5,16 @@ import java.io.IOException
import li.cil.oc.Settings
import li.cil.oc.api.Network
import li.cil.oc.api.network.EnvironmentHost
import li.cil.oc.api.fs.Label
import li.cil.oc.api.fs.Mode
import li.cil.oc.api.fs.{FileSystem => IFileSystem}
import li.cil.oc.api.machine.Arguments
import li.cil.oc.api.machine.Callback
import li.cil.oc.api.machine.Context
import li.cil.oc.api.network.EnvironmentHost
import li.cil.oc.api.network._
import li.cil.oc.api.prefab
import li.cil.oc.server.fs.FileSystem
import li.cil.oc.server.{PacketSender => ServerPacketSender}
import li.cil.oc.util.ExtendedNBT._
import net.minecraft.nbt.NBTTagCompound
@ -282,6 +283,11 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
override def save(nbt: NBTTagCompound) = fileSystem.synchronized {
super.save(nbt)
if (label != null) {
label.save(nbt)
}
if (!FileSystem.savingForClients) {
val ownersNbt = new NBTTagList()
for ((address, handles) <- owners) {
val ownerNbt = new NBTTagCompound()
@ -291,11 +297,9 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
}
nbt.setTag("owners", ownersNbt)
if (label != null) {
label.save(nbt)
}
nbt.setNewCompoundTag("fs", fileSystem.save)
}
}
// ----------------------------------------------------------------------- //

View File

@ -22,6 +22,8 @@ import net.minecraftforge.common.DimensionManager
import scala.util.Try
object FileSystem extends api.detail.FileSystemAPI {
var savingForClients = false
lazy val isCaseInsensitive = Settings.get.forceCaseInsensitive || (try {
val uuid = UUID.randomUUID().toString
val lowerCase = new io.File(DimensionManager.getCurrentSaveRootDirectory, uuid + "oc_rox")