mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Added safety try-catch to machine loading code, to avoid crashes for unexpected states.
Added callback doc for experience upgrade and chunkloader upgrades.
This commit is contained in:
parent
d24907b7ab
commit
5e268af84b
@ -28,10 +28,10 @@ class UpgradeChunkloader(val owner: Container) extends component.ManagedComponen
|
||||
}
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Callback(doc = """function():boolean -- Gets whether the chunkloader is currently active.""")
|
||||
def isActive(context: Context, args: Arguments): Array[AnyRef] = result(ticket.isDefined)
|
||||
|
||||
@Callback
|
||||
@Callback(doc = """function(enabled:boolean):boolean -- Enables or disables the chunkloader.""")
|
||||
def setActive(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val enabled = args.checkBoolean(0)
|
||||
if (enabled && ticket.isEmpty) {
|
||||
|
@ -39,7 +39,7 @@ class UpgradeExperience extends component.ManagedComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Callback(direct = true, doc = """function():number -- The current level of experience stored in this experience upgrade.""")
|
||||
def level(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val xpNeeded = xpForNextLevel - xpForLevel(level)
|
||||
val xpProgress = math.max(0, experience - xpForLevel(level))
|
||||
|
@ -577,7 +577,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
||||
|
||||
tmp.foreach(fs => fs.load(nbt.getCompoundTag("tmp")))
|
||||
|
||||
if (state.size > 0 && state.top != Machine.State.Stopped && init()) {
|
||||
if (state.size > 0 && state.top != Machine.State.Stopped && init()) try {
|
||||
architecture.load(nbt)
|
||||
|
||||
signals ++= nbt.getTagList("signals").iterator[NBTTagCompound].map(signalNbt => {
|
||||
@ -612,6 +612,11 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
||||
pause(Settings.get.startupDelay)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case t: Throwable =>
|
||||
OpenComputers.log.log(Level.SEVERE, s"""Unexpected error loading a state of computer at (${owner.x}, ${owner.y}, ${owner.z}). """ +
|
||||
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
||||
}
|
||||
else close() // Clean up in case we got a weird state stack.
|
||||
}
|
||||
|
||||
@ -641,7 +646,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
||||
|
||||
tmp.foreach(fs => nbt.setNewCompoundTag("tmp", fs.save))
|
||||
|
||||
if (state.top != Machine.State.Stopped) {
|
||||
if (state.top != Machine.State.Stopped) try {
|
||||
architecture.save(nbt)
|
||||
|
||||
val signalsNbt = new NBTTagList()
|
||||
@ -674,6 +679,11 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
||||
nbt.setLong("cpuTime", cpuTotal)
|
||||
nbt.setInteger("remainingPause", remainingPause)
|
||||
}
|
||||
catch {
|
||||
case t: Throwable =>
|
||||
OpenComputers.log.log(Level.SEVERE, s"""Unexpected error saving a state of computer at (${owner.x}, ${owner.y}, ${owner.z}). """ +
|
||||
s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
Loading…
x
Reference in New Issue
Block a user