diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index fe45447c6..bfcd52137 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -208,7 +208,7 @@ opencomputers { # can reconfigure any CPU to use the Lua 5.3 architecture. This is # not enabled by default for the time being, because it needs some # more stability testing. - enableLua53: false + enableLua53: true # The sizes of the six levels of RAM, in kilobytes. This list must # contain exactly six entries, or it will be ignored. Note that while diff --git a/src/main/resources/assets/opencomputers/doc/en_US/block/capacitor.md b/src/main/resources/assets/opencomputers/doc/en_US/block/capacitor.md index 1d8faf904..5714f1483 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/block/capacitor.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/block/capacitor.md @@ -2,7 +2,7 @@ ![It's over 9000.](oredict:oc:capacitor) -The capacitor stores energy to be used by the network, acting as an energy buffer when needed. Unlike conversion from other mod's energy to OpenComputers' internal energy type (using a [power converter](powerConverter.md) for example), transferring energy inside a single subnetwork is instantaneous. Having an internal energy bugger will be useful for tasks that require a lot of energy, such as [assembling](assembler.md) and/or [charging](charger.md) devices such as [robots](robot.md) or [drones](../item/drone.md). +The capacitor stores energy to be used by the network, acting as an energy buffer when needed. Unlike conversion from other mod's energy to OpenComputers' internal energy type (using a [power converter](powerConverter.md) for example), transferring energy inside a single subnetwork is instantaneous. Having an internal energy buffer will be useful for tasks that require a lot of energy, such as [assembling](assembler.md) and/or [charging](charger.md) devices such as [robots](robot.md) or [drones](../item/drone.md). The storage efficiency of capacitors increases with the number of capacitors in direct contact or in the vicinity. For example, two capacitors directly next to each other will have a higher storage capacity than the sum of two separated capacitors. This adjacency bonus applies for capacitors up to two blocks away, and is reduced as the distance between capacitors increases. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md b/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md index e9fbb87c6..0566ab3c9 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/general/lua.md @@ -2,7 +2,8 @@ The Lua [reference manual](http://www.lua.org/manual/5.2/manual.html) and the [Programming in Lua](http://www.lua.org/pil/) books (first edition is available for free online) are a good place to get started with the basics of Lua and becoming familiar with the basic syntax and standard libraries. [OpenOS](openOS.md) strives to emulate the standard libraries very closely, with a few deviations, such as the mostly missing debug library (for sandboxing reasons). These differences are [documented on the wiki](http://ocdoc.cil.li/api:non-standard-lua-libs). -Non-standard libraries will need to be `require`d in order to use them in a script. For example: +Non-standard libraries will need to be +`require`d in order to use them in a script. For example: `local component = require("component")` `local rs = component.redstone` diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.32.bsd.so b/src/main/resources/assets/opencomputers/lib/lua53/native.32.bsd.so index 0723ba81a..cbb700549 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.32.bsd.so and b/src/main/resources/assets/opencomputers/lib/lua53/native.32.bsd.so differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.32.dll b/src/main/resources/assets/opencomputers/lib/lua53/native.32.dll index b18cb88c8..c805ef7db 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.32.dll and b/src/main/resources/assets/opencomputers/lib/lua53/native.32.dll differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.32.dylib b/src/main/resources/assets/opencomputers/lib/lua53/native.32.dylib index d33d64df1..ec682534a 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.32.dylib and b/src/main/resources/assets/opencomputers/lib/lua53/native.32.dylib differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.32.so b/src/main/resources/assets/opencomputers/lib/lua53/native.32.so index 8ffb882d9..7533865bb 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.32.so and b/src/main/resources/assets/opencomputers/lib/lua53/native.32.so differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.64.bsd.so b/src/main/resources/assets/opencomputers/lib/lua53/native.64.bsd.so index 9dd32d845..6eee93892 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.64.bsd.so and b/src/main/resources/assets/opencomputers/lib/lua53/native.64.bsd.so differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.64.dll b/src/main/resources/assets/opencomputers/lib/lua53/native.64.dll index adcccb210..9c42aff66 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.64.dll and b/src/main/resources/assets/opencomputers/lib/lua53/native.64.dll differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.64.dylib b/src/main/resources/assets/opencomputers/lib/lua53/native.64.dylib index dc00a46bc..78957be97 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.64.dylib and b/src/main/resources/assets/opencomputers/lib/lua53/native.64.dylib differ diff --git a/src/main/resources/assets/opencomputers/lib/lua53/native.64.so b/src/main/resources/assets/opencomputers/lib/lua53/native.64.so index 86cf9ff9c..1dabd59b3 100644 Binary files a/src/main/resources/assets/opencomputers/lib/lua53/native.64.so and b/src/main/resources/assets/opencomputers/lib/lua53/native.64.so differ diff --git a/src/main/scala/li/cil/oc/client/gui/Screen.scala b/src/main/scala/li/cil/oc/client/gui/Screen.scala index d6620f499..8952746d1 100644 --- a/src/main/scala/li/cil/oc/client/gui/Screen.scala +++ b/src/main/scala/li/cil/oc/client/gui/Screen.scala @@ -27,13 +27,11 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha if (hasMouse && Mouse.hasWheel && Mouse.getEventDWheel != 0) { val mouseX = Mouse.getEventX * width / mc.displayWidth val mouseY = height - Mouse.getEventY * height / mc.displayHeight - 1 - val bx = (mouseX - x - bufferMargin) / TextBufferRenderCache.renderer.charRenderWidth.toDouble - val by = (mouseY - y - bufferMargin) / TextBufferRenderCache.renderer.charRenderHeight.toDouble - val bw = buffer.getWidth - val bh = buffer.getHeight - if (bx >= 0 && by >= 0 && bx < bw && by < bh) { - val scroll = math.signum(Mouse.getEventDWheel) - buffer.mouseScroll(bx, by, scroll, null) + toBufferCoordinates(mouseX, mouseY) match { + case Some((bx, by)) => + val scroll = math.signum(Mouse.getEventDWheel) + buffer.mouseScroll(bx, by, scroll, null) + case _ => // Ignore when out of bounds. } } } @@ -60,15 +58,9 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha super.mouseMovedOrUp(mouseX, mouseY, button) if (hasMouse && button >= 0) { if (didDrag) { - val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth - val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight - val bw = buffer.getWidth - val bh = buffer.getHeight - if (bx >= 0 && by >= 0 && bx < bw && by < bh) { - buffer.mouseUp(bx, by, button, null) - } - else { - buffer.mouseUp(-1.0, -1.0, button, null) + toBufferCoordinates(mouseX, mouseY) match { + case Some((bx, by)) => buffer.mouseUp(bx, by, button, null) + case _ => buffer.mouseUp(-1.0, -1.0, button, null) } } didDrag = false @@ -78,21 +70,26 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha } private def clickOrDrag(mouseX: Int, mouseY: Int, button: Int) { - val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth - val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight - val bw = buffer.getWidth - val bh = buffer.getHeight - if (bx >= 0 && by >= 0 && bx < bw && by < bh) { - if (bx.toInt != mx || by.toInt != my) { + toBufferCoordinates(mouseX, mouseY) match { + case Some((bx, by)) if bx.toInt != mx || by.toInt != my => if (mx >= 0 && my >= 0) buffer.mouseDrag(bx, by, button, null) else buffer.mouseDown(bx, by, button, null) didDrag = mx >= 0 && my >= 0 mx = bx.toInt my = by.toInt - } + case _ => } } + private def toBufferCoordinates(mouseX: Int, mouseY: Int): Option[(Double, Double)] = { + val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth + val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight + val bw = buffer.getWidth + val bh = buffer.getHeight + if (bx >= 0 && by >= 0 && bx < bw && by < bh) Some((bx, by)) + else None + } + override def drawScreen(mouseX: Int, mouseY: Int, dt: Float): Unit = { super.drawScreen(mouseX, mouseY, dt) drawBufferLayer() diff --git a/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala b/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala index 1c7ff8d53..3fcd4065a 100644 --- a/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala +++ b/src/main/scala/li/cil/oc/common/asm/ClassTransformer.scala @@ -134,7 +134,8 @@ class ClassTransformer extends IClassTransformer { { val classNode = newClassNode(transformedClass) if (classNode.interfaces.contains("li/cil/oc/api/network/SimpleComponent") && - !classNode.visibleAnnotations.exists(_.desc == "Lli/cil/oc/api/network/SimpleComponent$SkipInjection;")) { + (classNode.visibleAnnotations == null || !classNode.visibleAnnotations. + exists(annotation => annotation != null && annotation.desc == "Lli/cil/oc/api/network/SimpleComponent$SkipInjection;"))) { try { transformedClass = injectEnvironmentImplementation(classNode) log.info(s"Successfully injected component logic into class $name.") diff --git a/src/main/scala/li/cil/oc/common/launch/TransformerLoader.scala b/src/main/scala/li/cil/oc/common/launch/TransformerLoader.scala index cec9eca0a..25b9f7b52 100644 --- a/src/main/scala/li/cil/oc/common/launch/TransformerLoader.scala +++ b/src/main/scala/li/cil/oc/common/launch/TransformerLoader.scala @@ -17,7 +17,7 @@ class TransformerLoader extends DummyModContainer({ val md = new ModMetadata() md.authorList.add("Sangar") md.modId = "OpenComputers|Core" - md.version = "1.0.0" + md.version = "@VERSION@" md.name = "OpenComputers (Core)" md.url = "http://oc.cil.li/" md.description = "OC core mod used for class transformer and as API owner to avoid cyclic dependencies." diff --git a/src/main/scala/li/cil/oc/common/template/Template.scala b/src/main/scala/li/cil/oc/common/template/Template.scala index 45a0f369d..2dcd0cde1 100644 --- a/src/main/scala/li/cil/oc/common/template/Template.scala +++ b/src/main/scala/li/cil/oc/common/template/Template.scala @@ -49,7 +49,7 @@ abstract class Template { val progress = if (!hasCPU) Localization.Assembler.InsertCPU - else if (!hasRAM) Localization.Assembler.InsertRAM + else if (!hasRAM && requiresRAM) Localization.Assembler.InsertRAM else Localization.Assembler.Complexity(complexity, maxComplexity) val warnings = mutable.ArrayBuffer.empty[IChatComponent] diff --git a/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala b/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala index 2daf17a78..d5adec0ce 100644 --- a/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala +++ b/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala @@ -35,6 +35,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.language.existentials +// Note to self: this class is used by ExtraCells (and potentially others), do not rename / drastically change it. trait NetworkControl[AETile >: Null <: TileEntity with IGridProxyable with IActionHost] { def tile: AETile diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala index 81655f760..df3cdd997 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala @@ -12,6 +12,7 @@ import li.cil.oc.common.Slot import li.cil.oc.common.Tier import li.cil.oc.common.item import li.cil.oc.common.item.Delegator +import li.cil.oc.server.machine.luac.NativeLuaArchitecture import net.minecraft.item.ItemStack import scala.collection.convert.WrapAsScala._ @@ -40,7 +41,13 @@ abstract class DriverCPU extends Item with Processor { override def architecture(stack: ItemStack): Class[_ <: Architecture] = { if (stack.hasTagCompound) { - val archClass = stack.getTagCompound.getString(Settings.namespace + "archClass") + val archClass = stack.getTagCompound.getString(Settings.namespace + "archClass") match { + case clazz if clazz == classOf[NativeLuaArchitecture].getName => + // Migrate old saved CPUs to new versions (since the class they refer still + // exists, but is abstract, which would lead to issues). + api.Machine.LuaArchitecture.getName + case clazz => clazz + } if (!archClass.isEmpty) try return Class.forName(archClass).asSubclass(classOf[Architecture]) catch { case t: Throwable => OpenComputers.log.warn("Failed getting class for CPU architecture. Resetting CPU to use the default.", t) diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index d4cff5c12..8bb64559b 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -124,9 +124,12 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach case Some(driver: Processor) if driver.slot(stack) == Slot.CPU => Option(driver.architecture(stack)) match { case Some(clazz) => - if (architecture == null || architecture.getClass != clazz) { + if (architecture == null || architecture.getClass != clazz) try { newArchitecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this) } + catch { + case t: Throwable => OpenComputers.log.warn("Failed instantiating a CPU architecture.", t) + } else { newArchitecture = architecture } diff --git a/src/main/scala/li/cil/oc/server/machine/luac/LuaStateFactory.scala b/src/main/scala/li/cil/oc/server/machine/luac/LuaStateFactory.scala index 79ac20a09..ccb9ac707 100644 --- a/src/main/scala/li/cil/oc/server/machine/luac/LuaStateFactory.scala +++ b/src/main/scala/li/cil/oc/server/machine/luac/LuaStateFactory.scala @@ -57,9 +57,8 @@ object LuaStateFactory { state.openLib(jnlua.LuaState.Library.MATH) state.openLib(jnlua.LuaState.Library.STRING) state.openLib(jnlua.LuaState.Library.TABLE) - // TODO Enable once I update the natives. -// state.openLib(jnlua.LuaState.Library.UTF8) - state.pop(7) + state.openLib(jnlua.LuaState.Library.UTF8) + state.pop(8) } } diff --git a/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala b/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala index ef54c0c57..c72e37b85 100644 --- a/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala +++ b/src/main/scala/li/cil/oc/util/GameTimeFormatter.scala @@ -72,7 +72,7 @@ object GameTimeFormatter { day = yearDay val monthLengths = monthLengthsForYear(year) var month = 0 - while (day > monthLengths(month)) { + while (day >= monthLengths(month)) { day = day - monthLengths(month) month = month + 1 }