From 7e38f9027fb1af07c0fcc490fdb8b8a86da6a14a Mon Sep 17 00:00:00 2001 From: Brian Ricketts Date: Mon, 14 Jan 2013 01:13:28 -0600 Subject: [PATCH] First go at implementing the CC API for the ArmBot --- .../machine/armbot/TileEntityArmbot.java | 105 +++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java index 90d53a1f..e07a94cf 100644 --- a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java +++ b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java @@ -30,8 +30,10 @@ import assemblyline.common.AssemblyLine; import assemblyline.common.machine.TileEntityAssemblyNetwork; import assemblyline.common.machine.command.Command; import assemblyline.common.machine.command.CommandDrop; +import assemblyline.common.machine.command.CommandGrab; import assemblyline.common.machine.command.CommandManager; import assemblyline.common.machine.command.CommandReturn; +import assemblyline.common.machine.command.CommandRotate; import assemblyline.common.machine.encoder.ItemDisk; import com.google.common.io.ByteArrayDataInput; @@ -39,8 +41,10 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.relauncher.Side; +import dan200.computer.api.IComputerAccess; +import dan200.computer.api.IPeripheral; -public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage +public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage, IPeripheral { private final CommandManager commandManager = new CommandManager(); private static final int PACKET_COMMANDS = 128; @@ -466,4 +470,103 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult this.worldObj.setBlockWithNotify(this.xCoord, this.yCoord, this.zCoord, 0); } + @Override + public String getType() + { + return "ArmBot"; + } + + @Override + public String[] getMethodNames() + { + return new String[] { "rotateBy", "rotateTo", "grab", "drop", "reset", "isWorking" }; + } + + @Override + public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception + { + switch (method) + { + case 0: // rotateBy: rotates by a certain amount + { + if (arguments.length > 0) + { + if (arguments[0] instanceof Float) + { + float angle = (Float) arguments[0]; + this.commandManager.addCommand(this, CommandRotate.class, new String[] { Float.toString(angle) }); + } + else + { + throw new IllegalArgumentException("expected number"); + } + } + else + { + throw new IllegalArgumentException("expected number"); + } + break; + } + case 1: // rotateTo: rotates to an absolute angle (0 is idle position, increases clockwise) + { + if (arguments.length > 0) + { + if (arguments[0] instanceof Float) + { + float angle = (Float) arguments[0]; + float diff = angle - this.rotationYaw; + this.commandManager.addCommand(this, CommandRotate.class, new String[] { Float.toString(diff) }); + } + else + { + throw new IllegalArgumentException("expected number"); + } + } + else + { + throw new IllegalArgumentException("expected number"); + } + break; + } + case 2: // grab: grabs an item + { + this.commandManager.addCommand(this, CommandGrab.class); + break; + } + case 3: // drop: drops an item + { + this.commandManager.addCommand(this, CommandDrop.class); + break; + } + case 4: // reset: calls the RETURN command + { + this.commandManager.addCommand(this, CommandReturn.class); + break; + } + case 5: // isWorking: returns whether or not the ArmBot is executing commands + { + return new Object[] { this.commandManager.hasTasks() }; + } + } + return null; + } + + @Override + public boolean canAttachToSide(int side) + { + return side != ForgeDirection.UP.ordinal(); + } + + @Override + public void attach(IComputerAccess computer) + { + + } + + @Override + public void detach(IComputerAccess computer) + { + + } + }