From a845ce1be1435f9eb6472c66455ff2b589420437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 11 Dec 2013 13:25:34 +0100 Subject: [PATCH] made the "response" port when sending messages to computercraft optional (it'll default to -1, an invalid port number); fixed a deadlock when consuming power in computers for the first time (lazy vals lock `this` when initializing... kinda makes sense in hindsight) --- li/cil/oc/common/block/Screen.scala | 7 ++++++- li/cil/oc/common/tileentity/Adapter.scala | 20 +++++++++++++------- li/cil/oc/server/component/Computer.scala | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/li/cil/oc/common/block/Screen.scala b/li/cil/oc/common/block/Screen.scala index a118fd8de..491d14434 100644 --- a/li/cil/oc/common/block/Screen.scala +++ b/li/cil/oc/common/block/Screen.scala @@ -285,7 +285,12 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate { if (!player.isSneaking) { world.getBlockTileEntity(x, y, z) match { case screen: tileentity.Screen if screen.hasKeyboard => - player.openGui(OpenComputers, GuiType.Screen.id, world, x, y, z) + // Yep, this GUI is actually purely client side. We could skip this + // if, but it is clearer this way (to trigger it from the server we + // would have to give screens a "container", which we do not want). + if (world.isRemote) { + player.openGui(OpenComputers, GuiType.Screen.id, world, x, y, z) + } true case screen: tileentity.Screen if screen.tier > 0 && side == screen.facing => screen.click(player, hitX, hitY, hitZ) diff --git a/li/cil/oc/common/tileentity/Adapter.scala b/li/cil/oc/common/tileentity/Adapter.scala index 81e4f9c32..5681f6a67 100644 --- a/li/cil/oc/common/tileentity/Adapter.scala +++ b/li/cil/oc/common/tileentity/Adapter.scala @@ -94,18 +94,24 @@ class Adapter extends Environment with IPeripheral { if (Loader.isModLoaded("ComputerCraft")) { if (message.name == "network.message") message.data match { case Array(port: Integer, answerPort: java.lang.Double, args@_*) => - for (computer <- computers.map(_.asInstanceOf[IComputerAccess])) { - if (openPorts(computer).contains(port)) - computer.queueEvent("modem_message", Array(Seq(computer.getAttachmentName, Int.box(port), Int.box(answerPort.toInt)) ++ args.map { - case x: Array[Byte] => new String(x, "UTF-8") - case x => x - }: _*)) - } + queueMessage(port, answerPort.toInt, args) + case Array(port: Integer, args@_*) => + queueMessage(port, -1, args) case _ => } } } + private def queueMessage(port: Int, answerPort: Int, args: Seq[AnyRef]) { + for (computer <- computers.map(_.asInstanceOf[IComputerAccess])) { + if (openPorts(computer).contains(port)) + computer.queueEvent("modem_message", Array(Seq(computer.getAttachmentName, Int.box(port), Int.box(answerPort)) ++ args.map { + case x: Array[Byte] => new String(x, "UTF-8") + case x => x + }: _*)) + } + } + // ----------------------------------------------------------------------- // override def readFromNBT(nbt: NBTTagCompound) { diff --git a/li/cil/oc/server/component/Computer.scala b/li/cil/oc/server/component/Computer.scala index 7d6e8f7f6..4ba62f9d3 100644 --- a/li/cil/oc/server/component/Computer.scala +++ b/li/cil/oc/server/component/Computer.scala @@ -92,7 +92,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con def isRobot = false - private lazy val cost = (if (isRobot) Settings.get.robotCost else Settings.get.computerCost) * Settings.get.tickFrequency + private val cost = (if (isRobot) Settings.get.robotCost else Settings.get.computerCost) * Settings.get.tickFrequency // ----------------------------------------------------------------------- //