Skip to content

Commit 10e2db7

Browse files
committedSep 15, 2016
First concept of nanomachine commands.
1 parent 917befc commit 10e2db7

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
 

Diff for: ‎src/main/java/li/cil/oc/api/nanomachines/Behavior.java

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package li.cil.oc.api.nanomachines;
22

3+
import li.cil.oc.api.machine.Arguments;
4+
35
/**
46
* Implemented by single behaviors.
57
* <p/>
@@ -49,4 +51,10 @@ public interface Behavior {
4951
* Called each tick while this behavior is active.
5052
*/
5153
void update();
54+
55+
/**
56+
* Calls the nanomachine behavior using the <tt>call</tt> command.
57+
* The returned values will be passed as the response message.
58+
*/
59+
Object[] call(Arguments args);
5260
}

Diff for: ‎src/main/java/li/cil/oc/api/prefab/AbstractBehavior.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package li.cil.oc.api.prefab;
22

3+
import li.cil.oc.api.machine.Arguments;
34
import li.cil.oc.api.nanomachines.Behavior;
45
import li.cil.oc.api.nanomachines.DisableReason;
56
import net.minecraft.entity.player.EntityPlayer;
@@ -49,4 +50,9 @@ public void onDisable(DisableReason reason) {
4950
@Override
5051
public void update() {
5152
}
53+
54+
@Override
55+
public Object[] call(Arguments args) {
56+
return new Object[0];
57+
}
5258
}

Diff for: ‎src/main/scala/li/cil/oc/common/nanomachines/ControllerImpl.scala

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import li.cil.oc.api.network.WirelessEndpoint
1616
import li.cil.oc.common.item.data.NanomachineData
1717
import li.cil.oc.integration.util.DamageSourceWithRandomCause
1818
import li.cil.oc.server.PacketSender
19+
import li.cil.oc.server.machine.ArgumentsImpl
1920
import li.cil.oc.util.BlockPosition
2021
import li.cil.oc.util.ExtendedNBT._
2122
import li.cil.oc.util.InventoryUtils
@@ -139,6 +140,20 @@ class ControllerImpl(val player: EntityPlayer) extends Controller with WirelessE
139140
val joined = "{" + names.map(_.replace(',', '_').replace('"', '_')).mkString(",") + "}"
140141
respond(sender, "effects", joined)
141142
}
143+
case Array("call", index: java.lang.Number, data @ _*) =>
144+
try {
145+
var response: Array[AnyRef] = null
146+
configuration.synchronized(
147+
response = configuration.behaviors(index.intValue - 1).behavior.call(new ArgumentsImpl(data))
148+
)
149+
respond(sender, Array(Array("call", new Integer(index.intValue)), response).flatten)
150+
}
151+
catch {
152+
case e: Exception =>
153+
respond(sender, "call", "error", e.getMessage)
154+
case _: Throwable =>
155+
respond(sender, "call", "error")
156+
}
142157
case _ => // Ignore.
143158
}
144159
case _ => // Not for us.

0 commit comments

Comments
 (0)