mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 01:10:19 -04:00
prepping for more api->java
This commit is contained in:
parent
c231f61ab5
commit
24228a225a
@ -101,7 +101,7 @@ trait Network {
|
|||||||
* @param address the address of the node to get.
|
* @param address the address of the node to get.
|
||||||
* @return the node with that address.
|
* @return the node with that address.
|
||||||
*/
|
*/
|
||||||
def node(address: String): Option[Node]
|
def node(address: String): Node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of all addressed nodes in this network.
|
* The list of all addressed nodes in this network.
|
||||||
@ -174,7 +174,7 @@ trait Network {
|
|||||||
* @return the result of the message being handled, if any.
|
* @return the result of the message being handled, if any.
|
||||||
* @throws IllegalArgumentException if the source node is not in this network.
|
* @throws IllegalArgumentException if the source node is not in this network.
|
||||||
*/
|
*/
|
||||||
def sendToAddress(source: Node, target: String, name: String, data: AnyRef*): Option[Array[AnyRef]]
|
def sendToAddress(source: Node, target: String, name: String, data: AnyRef*): Array[AnyRef]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to all addressed, visible neighbors of the source node.
|
* Sends a message to all addressed, visible neighbors of the source node.
|
||||||
@ -195,7 +195,7 @@ trait Network {
|
|||||||
* @throws IllegalArgumentException if the source node is not in this network.
|
* @throws IllegalArgumentException if the source node is not in this network.
|
||||||
* @see `neighbors`
|
* @see `neighbors`
|
||||||
*/
|
*/
|
||||||
def sendToNeighbors(source: Node, name: String, data: AnyRef*): Option[Array[AnyRef]]
|
def sendToNeighbors(source: Node, name: String, data: AnyRef*): Array[AnyRef]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to all addressed nodes visible to the source node.
|
* Sends a message to all addressed nodes visible to the source node.
|
||||||
@ -214,7 +214,7 @@ trait Network {
|
|||||||
* @throws IllegalArgumentException if the source node is not in this network.
|
* @throws IllegalArgumentException if the source node is not in this network.
|
||||||
* @see `nodes`
|
* @see `nodes`
|
||||||
*/
|
*/
|
||||||
def sendToVisible(source: Node, name: String, data: AnyRef*): Option[Array[AnyRef]]
|
def sendToVisible(source: Node, name: String, data: AnyRef*): Array[AnyRef]
|
||||||
}
|
}
|
||||||
|
|
||||||
object Network extends NetworkAPI {
|
object Network extends NetworkAPI {
|
||||||
|
@ -89,11 +89,11 @@ trait Component extends Node {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message) orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
if (message.name == "computer.started" && canBeSeenBy(message.source))
|
if (message.name == "computer.started" && canBeSeenBy(message.source))
|
||||||
network.get.sendToAddress(this, message.source.address.get, "computer.signal", "component_added")
|
Some(network.get.sendToAddress(this, message.source.address.get, "computer.signal", "component_added"))
|
||||||
else None
|
else None
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -97,13 +97,13 @@ trait Node extends Persistable {
|
|||||||
* @param message the message to handle.
|
* @param message the message to handle.
|
||||||
* @return the result of the message being handled, if any.
|
* @return the result of the message being handled, if any.
|
||||||
*/
|
*/
|
||||||
def receive(message: Message): Option[Array[AnyRef]] = {
|
def receive(message: Message): Array[AnyRef] = {
|
||||||
if (message.source == this) message.name match {
|
if (message.source == this) message.name match {
|
||||||
case "system.connect" => onConnect()
|
case "system.connect" => onConnect()
|
||||||
case "system.disconnect" => onDisconnect()
|
case "system.disconnect" => onDisconnect()
|
||||||
case _ => // Ignore.
|
case _ => // Ignore.
|
||||||
}
|
}
|
||||||
None
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,7 @@ trait Provider extends Node {
|
|||||||
|
|
||||||
var energyStorageList = mutable.Set[EnergyStorage]()
|
var energyStorageList = mutable.Set[EnergyStorage]()
|
||||||
|
|
||||||
override def receive(message: Message): Option[Array[AnyRef]] = super.receive(message) orElse {
|
override def receive(message: Message): Array[AnyRef] = Option(super.receive(message)).orElse {
|
||||||
if (message.source != this) {
|
if (message.source != this) {
|
||||||
message.name match {
|
message.name match {
|
||||||
case "system.connect" => {
|
case "system.connect" => {
|
||||||
@ -33,7 +33,7 @@ trait Provider extends Node {
|
|||||||
case distributor: Provider =>
|
case distributor: Provider =>
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
message.cancel()
|
message.cancel()
|
||||||
return result(this)
|
return Array(this)
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ trait Provider extends Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override protected def onConnect() {
|
override protected def onConnect() {
|
||||||
//check if other distributors already are in the network
|
//check if other distributors already are in the network
|
||||||
@ -161,7 +161,7 @@ trait Provider extends Node {
|
|||||||
|
|
||||||
def searchMain() {
|
def searchMain() {
|
||||||
network.foreach(_.sendToVisible(this, "power.find") match {
|
network.foreach(_.sendToVisible(this, "power.find") match {
|
||||||
case Some(Array(powerDistributor: Provider)) => {
|
case Array(powerDistributor: Provider) => {
|
||||||
println("found other distri")
|
println("found other distri")
|
||||||
isActive = false
|
isActive = false
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ trait Receiver extends Node {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message) orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.name match {
|
message.name match {
|
||||||
case "system.connect" => {
|
case "system.connect" => {
|
||||||
message.source match {
|
message.source match {
|
||||||
@ -56,7 +56,7 @@ trait Receiver extends Node {
|
|||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override protected def onDisconnect() {
|
override protected def onDisconnect() {
|
||||||
super.onDisconnect()
|
super.onDisconnect()
|
||||||
|
@ -69,7 +69,7 @@ object Screen {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(w: Integer, h: Integer) if message.name == "screen.resolution=" =>
|
case Array(w: Integer, h: Integer) if message.name == "screen.resolution=" =>
|
||||||
result(instance.resolution = (w, h))
|
result(instance.resolution = (w, h))
|
||||||
@ -88,7 +88,7 @@ object Screen {
|
|||||||
instance.copy(x, y, w, h, tx, ty); result(true)
|
instance.copy(x, y, w, h, tx, ty); result(true)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class Adapter extends Rotatable with Node with IPeripheral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message) orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(port: Integer, answerPort: java.lang.Double, data: AnyRef) if message.name == "network.message" =>
|
case Array(port: Integer, answerPort: java.lang.Double, data: AnyRef) if message.name == "network.message" =>
|
||||||
for ((computer, ports) <- openPorts) if (ports.contains(port)) {
|
for ((computer, ports) <- openPorts) if (ports.contains(port)) {
|
||||||
@ -37,7 +37,7 @@ class Adapter extends Rotatable with Node with IPeripheral {
|
|||||||
case _ => // Ignore.
|
case _ => // Ignore.
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override protected def onConnect() {
|
override protected def onConnect() {
|
||||||
super.onConnect()
|
super.onConnect()
|
||||||
|
@ -20,14 +20,13 @@ class DiskDrive extends Rotatable with Component with ComponentInventory {
|
|||||||
|
|
||||||
override def canUpdate = false
|
override def canUpdate = false
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message) orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
components(0) match {
|
components(0) match {
|
||||||
case Some(node) if node.address.isDefined =>
|
case Some(node) if node.address.isDefined => Option(node.receive(message))
|
||||||
node.receive(message)
|
|
||||||
case _ if message.name.startsWith("fs.") => result(Unit, "no disk")
|
case _ if message.name.startsWith("fs.") => result(Unit, "no disk")
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class Keyboard extends Rotatable with Component {
|
|||||||
super.writeToNBT(nbt)
|
super.writeToNBT(nbt)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(p: Player, char: Character, code: Integer) if message.name == "keyboard.keyDown" =>
|
case Array(p: Player, char: Character, code: Integer) if message.name == "keyboard.keyDown" =>
|
||||||
if (isUseableByPlayer(p))
|
if (isUseableByPlayer(p))
|
||||||
@ -38,7 +38,7 @@ class Keyboard extends Rotatable with Component {
|
|||||||
case _ => // Ignore.
|
case _ => // Ignore.
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
def isUseableByPlayer(p: Player) = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
|
def isUseableByPlayer(p: Player) = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
|
||||||
p.asInstanceOf[EntityPlayer].getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64
|
p.asInstanceOf[EntityPlayer].getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64
|
||||||
|
@ -2,7 +2,6 @@ package li.cil.oc.server.component
|
|||||||
|
|
||||||
import li.cil.oc.Config
|
import li.cil.oc.Config
|
||||||
import li.cil.oc.api.network.{Component, Message, Visibility}
|
import li.cil.oc.api.network.{Component, Message, Visibility}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
|
||||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
import net.minecraft.tileentity.TileEntityCommandBlock
|
||||||
|
|
||||||
class CommandBlock(entity: TileEntityCommandBlock) extends Component {
|
class CommandBlock(entity: TileEntityCommandBlock) extends Component {
|
||||||
@ -12,7 +11,7 @@ class CommandBlock(entity: TileEntityCommandBlock) extends Component {
|
|||||||
|
|
||||||
componentVisibility = visibility
|
componentVisibility = visibility
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array() if message.name == "command.value" =>
|
case Array() if message.name == "command.value" =>
|
||||||
result(entity.getCommand)
|
result(entity.getCommand)
|
||||||
@ -29,5 +28,5 @@ class CommandBlock(entity: TileEntityCommandBlock) extends Component {
|
|||||||
result(entity.executeCommandOnPowered(entity.worldObj) != 0)
|
result(entity.executeCommandOnPowered(entity.worldObj) != 0)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.get
|
||||||
}
|
}
|
||||||
|
@ -597,17 +597,17 @@ class Computer(val owner: Computer.Environment) extends Persistable with Runnabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
def send(target: String, name: String, args: AnyRef*) =
|
def send(target: String, name: String, args: AnyRef*) =
|
||||||
owner.network.fold(None: Option[Array[AnyRef]])(network => {
|
owner.network.fold(null: Array[AnyRef])(network => {
|
||||||
network.node(target) match {
|
Option(network.node(target)) match {
|
||||||
case Some(node: Component) if node.canBeSeenBy(this.owner) =>
|
case Some(node: Component) if node.canBeSeenBy(this.owner) =>
|
||||||
network.sendToAddress(owner, target, name, args: _*)
|
network.sendToAddress(owner, target, name, args: _*)
|
||||||
case _ => Some(Array(Unit, "invalid address"))
|
case _ => Array(Unit, "invalid address")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
lua.pushScalaFunction(lua =>
|
lua.pushScalaFunction(lua =>
|
||||||
send(lua.checkString(1), lua.checkString(2), parseArguments(lua, 3): _*) match {
|
send(lua.checkString(1), lua.checkString(2), parseArguments(lua, 3): _*) match {
|
||||||
case Some(Array(results@_*)) =>
|
case Array(results@_*) =>
|
||||||
results.foreach(pushResult(lua, _))
|
results.foreach(pushResult(lua, _))
|
||||||
results.length
|
results.length
|
||||||
case _ => 0
|
case _ => 0
|
||||||
@ -615,7 +615,7 @@ class Computer(val owner: Computer.Environment) extends Persistable with Runnabl
|
|||||||
lua.setGlobal("sendToAddress")
|
lua.setGlobal("sendToAddress")
|
||||||
|
|
||||||
lua.pushScalaFunction(lua => {
|
lua.pushScalaFunction(lua => {
|
||||||
owner.network.fold(None: Option[Node])(_.node(lua.checkString(1))) match {
|
Option(owner.network.fold(null: Node)(_.node(lua.checkString(1)))) match {
|
||||||
case Some(node: Component) if node.canBeSeenBy(this.owner) =>
|
case Some(node: Component) if node.canBeSeenBy(this.owner) =>
|
||||||
lua.pushString(node.name)
|
lua.pushString(node.name)
|
||||||
1
|
1
|
||||||
@ -904,7 +904,7 @@ object Computer {
|
|||||||
|
|
||||||
override val visibility = Visibility.Network
|
override val visibility = Visibility.Network
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array() if message.name == "system.disconnect" && computer.isRunning =>
|
case Array() if message.name == "system.disconnect" && computer.isRunning =>
|
||||||
message.source match {
|
message.source match {
|
||||||
@ -935,7 +935,7 @@ object Computer {
|
|||||||
result(computer.isRunning)
|
result(computer.isRunning)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override protected def onConnect() {
|
override protected def onConnect() {
|
||||||
super.onConnect()
|
super.onConnect()
|
||||||
|
@ -18,7 +18,7 @@ class FileSystem(val fileSystem: api.fs.FileSystem) extends Component {
|
|||||||
|
|
||||||
componentVisibility = visibility
|
componentVisibility = visibility
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
try {
|
try {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array() if message.name == "system.disconnect" && owners.contains(message.source.address.get) =>
|
case Array() if message.name == "system.disconnect" && owners.contains(message.source.address.get) =>
|
||||||
@ -157,7 +157,7 @@ class FileSystem(val fileSystem: api.fs.FileSystem) extends Component {
|
|||||||
case e: IOException =>
|
case e: IOException =>
|
||||||
result(Unit, e.toString)
|
result(Unit, e.toString)
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
private def clean(path: Array[Byte]) = {
|
private def clean(path: Array[Byte]) = {
|
||||||
val result = com.google.common.io.Files.simplifyPath(new String(path, "UTF-8"))
|
val result = com.google.common.io.Files.simplifyPath(new String(path, "UTF-8"))
|
||||||
|
@ -15,11 +15,11 @@ class GraphicsCard(val maxResolution: (Int, Int)) extends Component {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(address: Array[Byte]) if message.name == "gpu.bind" =>
|
case Array(address: Array[Byte]) if message.name == "gpu.bind" =>
|
||||||
network.fold(None: Option[Array[AnyRef]])(network => {
|
network.fold(None: Option[Array[AnyRef]])(network => {
|
||||||
network.node(new String(address, "UTF-8")) match {
|
Option(network.node(new String(address, "UTF-8"))) match {
|
||||||
case None => result(Unit, "invalid address")
|
case None => result(Unit, "invalid address")
|
||||||
case Some(node: component.Screen.Environment) =>
|
case Some(node: component.Screen.Environment) =>
|
||||||
screen = node.address
|
screen = node.address
|
||||||
@ -53,7 +53,7 @@ class GraphicsCard(val maxResolution: (Int, Int)) extends Component {
|
|||||||
trySend("screen.copy", Int.box(x.toInt - 1), Int.box(y.toInt - 1), Int.box(w.toInt), Int.box(h.toInt), Int.box(tx.toInt), Int.box(ty.toInt))
|
trySend("screen.copy", Int.box(x.toInt - 1), Int.box(y.toInt - 1), Int.box(w.toInt), Int.box(h.toInt), Int.box(tx.toInt), Int.box(ty.toInt))
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override protected def onDisconnect() = {
|
override protected def onDisconnect() = {
|
||||||
super.onDisconnect()
|
super.onDisconnect()
|
||||||
@ -78,7 +78,7 @@ class GraphicsCard(val maxResolution: (Int, Int)) extends Component {
|
|||||||
screen match {
|
screen match {
|
||||||
case None => result(Unit, "no screen")
|
case None => result(Unit, "no screen")
|
||||||
case Some(screenAddress) => network.fold(None: Option[Array[AnyRef]])(net => {
|
case Some(screenAddress) => network.fold(None: Option[Array[AnyRef]])(net => {
|
||||||
net.sendToAddress(this, screenAddress, name, data: _*)
|
Option(net.sendToAddress(this, screenAddress, name, data: _*))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ class NetworkCard extends Component {
|
|||||||
|
|
||||||
componentVisibility = Visibility.Neighbors
|
componentVisibility = Visibility.Neighbors
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array() if message.name == "computer.stopped" =>
|
case Array() if message.name == "computer.stopped" =>
|
||||||
if (network.get.neighbors(message.source).exists(_ == this))
|
if (network.get.neighbors(message.source).exists(_ == this))
|
||||||
@ -47,7 +47,7 @@ class NetworkCard extends Component {
|
|||||||
None
|
None
|
||||||
case _ => None // Ignore.
|
case _ => None // Ignore.
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
override def readFromNBT(nbt: NBTTagCompound) {
|
override def readFromNBT(nbt: NBTTagCompound) {
|
||||||
super.readFromNBT(nbt)
|
super.readFromNBT(nbt)
|
||||||
|
@ -58,7 +58,7 @@ trait Redstone extends Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(side: ForgeDirection) if message.name == "redstone.input" && side != ForgeDirection.UNKNOWN =>
|
case Array(side: ForgeDirection) if message.name == "redstone.input" && side != ForgeDirection.UNKNOWN =>
|
||||||
result(_input(side.ordinal()))
|
result(_input(side.ordinal()))
|
||||||
@ -69,7 +69,7 @@ trait Redstone extends Node {
|
|||||||
result(true)
|
result(true)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@ -10,18 +10,18 @@ class RedstoneCard extends Component {
|
|||||||
|
|
||||||
componentVisibility = visibility
|
componentVisibility = visibility
|
||||||
|
|
||||||
override def receive(message: Message) = super.receive(message).orElse {
|
override def receive(message: Message) = Option(super.receive(message)).orElse {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(side: java.lang.Double) if message.name == "redstone.input" =>
|
case Array(side: java.lang.Double) if message.name == "redstone.input" =>
|
||||||
network.get.sendToAddress(this, message.source.address.get,
|
Option(network.get.sendToAddress(this, message.source.address.get,
|
||||||
"redstone.input", ForgeDirection.getOrientation(side.toInt))
|
"redstone.input", ForgeDirection.getOrientation(side.toInt)))
|
||||||
case Array(side: java.lang.Double) if message.name == "redstone.output" =>
|
case Array(side: java.lang.Double) if message.name == "redstone.output" =>
|
||||||
network.get.sendToAddress(this, message.source.address.get,
|
Option(network.get.sendToAddress(this, message.source.address.get,
|
||||||
"redstone.output", ForgeDirection.getOrientation(side.toInt))
|
"redstone.output", ForgeDirection.getOrientation(side.toInt)))
|
||||||
case Array(side: java.lang.Double, value: java.lang.Double) if message.name == "redstone.output=" =>
|
case Array(side: java.lang.Double, value: java.lang.Double) if message.name == "redstone.output=" =>
|
||||||
network.get.sendToAddress(this, message.source.address.get,
|
Option(network.get.sendToAddress(this, message.source.address.get,
|
||||||
"redstone.output=", ForgeDirection.getOrientation(side.toInt), Int.box(value.toInt))
|
"redstone.output=", ForgeDirection.getOrientation(side.toInt), Int.box(value.toInt)))
|
||||||
case _ => None // Ignore.
|
case _ => None // Ignore.
|
||||||
}
|
}
|
||||||
}
|
}.orNull
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,8 @@ class Network private(private val addressedNodes: mutable.Map[String, Network.No
|
|||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def node(address: String) = addressedNodes.get(address) match {
|
override def node(address: String) = addressedNodes.get(address) match {
|
||||||
case Some(node) => Some(node.data)
|
case Some(node) => node.data
|
||||||
case _ => None
|
case _ => null
|
||||||
}
|
}
|
||||||
|
|
||||||
override def nodes = addressedNodes.values.map(_.data)
|
override def nodes = addressedNodes.values.map(_.data)
|
||||||
@ -145,8 +145,8 @@ class Network private(private val addressedNodes: mutable.Map[String, Network.No
|
|||||||
case Some(node) if node.data.visibility == Visibility.Network ||
|
case Some(node) if node.data.visibility == Visibility.Network ||
|
||||||
(node.data.visibility == Visibility.Neighbors && neighbors(node.data).exists(_ == source)) =>
|
(node.data.visibility == Visibility.Neighbors && neighbors(node.data).exists(_ == source)) =>
|
||||||
send(new Network.Message(source, name, Array(data: _*)), Iterable(node.data))
|
send(new Network.Message(source, name, Array(data: _*)), Iterable(node.data))
|
||||||
case _ => None
|
case _ => null
|
||||||
} else None
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
override def sendToNeighbors(source: api.network.Node, name: String, data: AnyRef*) = {
|
override def sendToNeighbors(source: api.network.Node, name: String, data: AnyRef*) = {
|
||||||
@ -154,7 +154,7 @@ class Network private(private val addressedNodes: mutable.Map[String, Network.No
|
|||||||
throw new IllegalArgumentException("Source node must be in this network.")
|
throw new IllegalArgumentException("Source node must be in this network.")
|
||||||
if (source.address.isDefined)
|
if (source.address.isDefined)
|
||||||
send(new Network.Message(source, name, Array(data: _*)), neighbors(source).filter(_.visibility != Visibility.None))
|
send(new Network.Message(source, name, Array(data: _*)), neighbors(source).filter(_.visibility != Visibility.None))
|
||||||
else None
|
else null
|
||||||
}
|
}
|
||||||
|
|
||||||
override def sendToVisible(source: api.network.Node, name: String, data: AnyRef*) = {
|
override def sendToVisible(source: api.network.Node, name: String, data: AnyRef*) = {
|
||||||
@ -162,7 +162,7 @@ class Network private(private val addressedNodes: mutable.Map[String, Network.No
|
|||||||
throw new IllegalArgumentException("Source node must be in this network.")
|
throw new IllegalArgumentException("Source node must be in this network.")
|
||||||
if (source.address.isDefined)
|
if (source.address.isDefined)
|
||||||
send(new Network.Message(source, name, Array(data: _*)), nodes(source))
|
send(new Network.Message(source, name, Array(data: _*)), nodes(source))
|
||||||
else None
|
else null
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
@ -279,19 +279,21 @@ class Network private(private val addressedNodes: mutable.Map[String, Network.No
|
|||||||
//println("receive(" + message.name + "(" + message.data.mkString(", ") + "): " + message.source.address.get + ":" + message.source.name + " -> " + target.address.get + ":" + target.name + ")")
|
//println("receive(" + message.name + "(" + message.data.mkString(", ") + "): " + message.source.address.get + ":" + message.source.name + " -> " + target.address.get + ":" + target.name + ")")
|
||||||
target.receive(message)
|
target.receive(message)
|
||||||
} catch {
|
} catch {
|
||||||
case e: Throwable => OpenComputers.log.log(Level.WARNING, "Error in message handler", e); None
|
case e: Throwable =>
|
||||||
|
OpenComputers.log.log(Level.WARNING, "Error in message handler", e)
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
message match {
|
message match {
|
||||||
case _@(Network.ConnectMessage(_) | Network.DisconnectMessage(_)) =>
|
case _@(Network.ConnectMessage(_) | Network.DisconnectMessage(_)) =>
|
||||||
targets.foreach(protectedSend)
|
targets.foreach(protectedSend)
|
||||||
None
|
null
|
||||||
case _ =>
|
case _ =>
|
||||||
var result = None: Option[Array[AnyRef]]
|
var result = null: Array[AnyRef]
|
||||||
val iterator = targets.iterator
|
val iterator = targets.iterator
|
||||||
while (!message.isCanceled && iterator.hasNext)
|
while (!message.isCanceled && iterator.hasNext)
|
||||||
protectedSend(iterator.next()) match {
|
protectedSend(iterator.next()) match {
|
||||||
case None => // Ignore.
|
case null => // Ignore.
|
||||||
case r => result = r
|
case r => result = r
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user