mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
Moved hacky variable to SaveHandler, which totally makes it not a hack anymore.
Seriously though, the alternatives I see would not be better in the least, since passing that state along would be completely unnecessary in 99% of the cases, but would break *everything*. Literally. All. The. Things. So this one's here to stay.
This commit is contained in:
parent
db36d01032
commit
a95fa2049e
@ -9,8 +9,8 @@ import cpw.mods.fml.common.eventhandler.EventPriority
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api.network.EnvironmentHost
|
||||
import li.cil.oc.api.machine.MachineHost
|
||||
import li.cil.oc.api.network.EnvironmentHost
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import net.minecraft.nbt.CompressedStreamTools
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
@ -32,6 +32,16 @@ object SaveHandler {
|
||||
|
||||
private val TimeToHoldOntoOldSaves = 60 * 1000
|
||||
|
||||
// THIS IS A MASSIVE HACK OF THE UGLIEST KINDS.
|
||||
// But it works, and the alternative would be to change the Persistable
|
||||
// interface to pass along this state to *everything that gets saved ever*,
|
||||
// which in 99% of the cases it doesn't need to know. So yes, this is fugly,
|
||||
// but the "clean" solution would be no less fugly.
|
||||
// Why is this even required? To avoid flushing file systems to disk and
|
||||
// avoid persisting machine states when sending description packets to clients,
|
||||
// which takes a lot of time and is completely unnecessary in those cases.
|
||||
var savingForClients = false
|
||||
|
||||
val saveData = mutable.Map.empty[Int, mutable.Map[ChunkCoordIntPair, mutable.Map[String, Array[Byte]]]]
|
||||
|
||||
def savePath = new io.File(DimensionManager.getCurrentSaveRootDirectory, Settings.savePath)
|
||||
|
@ -5,7 +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.common.SaveHandler
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import li.cil.oc.util.SideTracker
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
@ -90,14 +90,15 @@ trait TileEntity extends net.minecraft.tileentity.TileEntity {
|
||||
override def getDescriptionPacket = {
|
||||
val nbt = new NBTTagCompound()
|
||||
|
||||
FileSystem.savingForClients = true
|
||||
// See comment on savingForClients variable.
|
||||
SaveHandler.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
|
||||
SaveHandler.savingForClients = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ 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.common.SaveHandler
|
||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
@ -287,7 +287,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option
|
||||
label.save(nbt)
|
||||
}
|
||||
|
||||
if (!FileSystem.savingForClients) {
|
||||
if (!SaveHandler.savingForClients) {
|
||||
val ownersNbt = new NBTTagList()
|
||||
for ((address, handles) <- owners) {
|
||||
val ownerNbt = new NBTTagCompound()
|
||||
|
@ -22,8 +22,6 @@ 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")
|
||||
|
@ -730,7 +730,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
||||
override def save(nbt: NBTTagCompound): Unit = Machine.this.synchronized(state.synchronized {
|
||||
assert(!isExecuting) // Lock on 'this' should guarantee this.
|
||||
|
||||
if (FileSystem.savingForClients) {
|
||||
if (SaveHandler.savingForClients) {
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user