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)

This commit is contained in:
Florian Nücke 2013-12-11 13:25:34 +01:00
parent 9c45f1f823
commit a845ce1be1
3 changed files with 20 additions and 9 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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
// ----------------------------------------------------------------------- //