From b2220d4d5f186ecc15d7801b8dd7b5c44c0c9f3f Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Tue, 15 Oct 2013 11:14:45 -0400 Subject: [PATCH] Starting on flowchart coder This is going to be a very long ride of BS and sleepless nights. Too top it off i shouldn't be starting this during midterms. Not that i ever study anyways. --- docs/grafcet.gif | Bin 0 -> 6180 bytes .../dark/{assembly/api => api/al}/IBelt.java | 2 +- .../api => api/al}/ICraneConnectable.java | 2 +- .../api => api/al}/ICraneStructure.java | 2 +- .../{assembly/api => api/al}/IFilterable.java | 2 +- .../api => api/al}/IManipulator.java | 2 +- .../dark/api/al/armbot/ArmbotTaskManager.java | 80 +++++++ .../api => api/al/armbot}/IArmbot.java | 8 +- .../dark/api/al/armbot/IArmbotTask.java | 52 +++++ .../api => api/al/armbot}/IArmbotUseable.java | 3 +- .../dark/api/al/armbot/IProgram.java | 15 ++ .../dark/api/al/armbot/ISplitArmbotTask.java | 26 +++ .../dark/api/al/armbot/ProgramHandler.java | 92 ++++++++ .../dark/assembly/common/armbot/Command.java | 134 +++++++++++ .../armbot/{command => }/GrabDictionary.java | 2 +- .../dark/assembly/common/armbot/Program.java | 6 + .../common/armbot/TileEntityArmbot.java | 143 +----------- .../common/armbot/command/Command.java | 177 --------------- .../common/armbot/command/CommandBreak.java | 5 +- .../common/armbot/command/CommandDrop.java | 6 +- .../common/armbot/command/CommandFire.java | 12 +- .../common/armbot/command/CommandGive.java | 5 +- .../common/armbot/command/CommandGrab.java | 10 +- .../common/armbot/command/CommandHarvest.java | 2 +- .../common/armbot/command/CommandIF.java | 71 ++++++ .../common/armbot/command/CommandIdle.java | 7 +- .../common/armbot/command/CommandManager.java | 213 ------------------ .../common/armbot/command/CommandPlace.java | 9 +- .../common/armbot/command/CommandPowerTo.java | 7 +- .../common/armbot/command/CommandRepeat.java | 5 +- .../common/armbot/command/CommandReturn.java | 16 +- .../armbot/command/CommandRotateBy.java | 9 +- .../armbot/command/CommandRotateTo.java | 9 +- .../common/armbot/command/CommandTake.java | 5 +- .../common/armbot/command/CommandUse.java | 7 +- .../common/imprinter/TileEntityImprinter.java | 4 +- .../imprinter/prefab/BlockImprintable.java | 2 +- .../prefab/TileEntityFilterable.java | 2 +- .../common/machine/TileEntityManipulator.java | 2 +- .../common/machine/TileEntityRejector.java | 2 +- .../machine/belt/TileEntityConveyorBelt.java | 2 +- .../machine/encoder/TileEntityEncoder.java | 2 +- 42 files changed, 567 insertions(+), 595 deletions(-) create mode 100644 docs/grafcet.gif rename src/minecraft/dark/{assembly/api => api/al}/IBelt.java (94%) rename src/minecraft/dark/{assembly/api => api/al}/ICraneConnectable.java (84%) rename src/minecraft/dark/{assembly/api => api/al}/ICraneStructure.java (70%) rename src/minecraft/dark/{assembly/api => api/al}/IFilterable.java (89%) rename src/minecraft/dark/{assembly/api => api/al}/IManipulator.java (91%) create mode 100644 src/minecraft/dark/api/al/armbot/ArmbotTaskManager.java rename src/minecraft/dark/{assembly/api => api/al/armbot}/IArmbot.java (88%) create mode 100644 src/minecraft/dark/api/al/armbot/IArmbotTask.java rename src/minecraft/dark/{assembly/api => api/al/armbot}/IArmbotUseable.java (94%) create mode 100644 src/minecraft/dark/api/al/armbot/IProgram.java create mode 100644 src/minecraft/dark/api/al/armbot/ISplitArmbotTask.java create mode 100644 src/minecraft/dark/api/al/armbot/ProgramHandler.java create mode 100644 src/minecraft/dark/assembly/common/armbot/Command.java rename src/minecraft/dark/assembly/common/armbot/{command => }/GrabDictionary.java (98%) create mode 100644 src/minecraft/dark/assembly/common/armbot/Program.java delete mode 100644 src/minecraft/dark/assembly/common/armbot/command/Command.java create mode 100644 src/minecraft/dark/assembly/common/armbot/command/CommandIF.java delete mode 100644 src/minecraft/dark/assembly/common/armbot/command/CommandManager.java diff --git a/docs/grafcet.gif b/docs/grafcet.gif new file mode 100644 index 0000000000000000000000000000000000000000..b11cf48ef3669496bfe994a31595495d40181b05 GIT binary patch literal 6180 zcmZWt1z6Nyvt9!gkS>u>5u`(wE`>!JR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mI?n^3j$P@FD=Xh`6W&25r z9Z}6>JG2x=G9A9tdMbNy<^K`T8xJ!&LqRo@GPUyt;z# zJ;p2s@z$cQn*AZ$$3L2?on>k=L=%YVMcJ&2bEW@SHYb^H43&q}@SHTPIW$#PPVCf+ z!yPl)R*xA^>FR9J>9H^gss~G}sas|S3npPv z%K}x;lL%54IYZs(g)3f)Outd{ZYws8*`^*3qZw_cq0EtY)>W z^&%a9ys_elDpHGQ9$ESB?XhF>SueaB&+yio>IYapk8x2

(q+5q3W5CD&3P60dZ7 zVA^4>6BVF6(WJR)iq6)`Tq#NvG^>twD9Q2h&Qh+cat}zb)jn{V@(8-V(k#wq^G!0E z?s`*G-RiVRG86rvVgAphkYcBylCvYH#rTRe*V^-A5wFdu^iq;!BVV6G=y+iW?V^a^ zz@pRgj>5R3*2&f^nl)>W;#uQQ^~|luqt}Z19$&M06UB8edD`c?ZD{0_R3DGPm+Filf+lxgOoPNO^j*tB%rlEx5uTGRMkR zDD=mC@STT4CEjtU>)o^Q0>-#B8USzq|9afvWzN_fk( zDTriL)iAo;JoCeyQUtyFfnk3_mw7NCB}PLD;-yy~H&m^U=4lif4>nY9PU1)j5nYw( zNR8`eaJWzH?xMcWl{;$mF8j;9y97@$O`_VX!G-_@0pEK0%59cjF}kFMLHJNpl@sht9`t9Hh3u*oF)F;Z-MPI6I=39bJDeY$K+_x9v6>9U0oBYm?e~1h0nY0HD z5fg_^?U{Gmt_lUyixz!Li(@hAwjVvfwB3gWTthfl&b=3t50RTcsak2uH~I{((?1*t zsxVvZwxeSL|>Yry5}#8)5h-EDtIK*KL< zU3RZ6gp^gi$aq(gaBHxAjy@_3UkvN(=7CW`bOl&Tw!IH$^Wvry$>v@^K*Yga4f&2 COMMANDS = new HashSet(); + + private static final HashMap SUDO_BOTS = new HashMap(); + + /** Registers a command and tells armbots that it exists */ + public static void registerCommand(IArmbotTask task) + { + if (!COMMANDS.contains(task)) + { + COMMANDS.add(task); + } + } + + /** returns the first command with the same name */ + public static IArmbotTask getCommand(String name) + { + for (IArmbotTask command : COMMANDS) + { + if (command.getMethodName().equalsIgnoreCase(name)) + { + return command; + } + } + return null; + } + + /** Gets all commands with the given name though there should only be one */ + public static List getCommands(String name) + { + List tasks = new ArrayList(); + for (IArmbotTask command : COMMANDS) + { + if (command.getMethodName().equalsIgnoreCase(name)) + { + tasks.add(command); + } + } + return tasks; + } + + /** Don't actually register the real machine. Register a fake version so that a code can use it + * for simulations */ + public static void registerMachine(String name, IArmbot bot) + { + if (!SUDO_BOTS.containsKey(name)) + { + SUDO_BOTS.put(name, bot); + } + } + + /** Do not edit the return or you will change the behavior of all machine that use this list + * + * @return The list of registered sudo machines for the encoder to check against */ + public static HashMap getSudoMachines() + { + return SUDO_BOTS; + } + + /** Get one of the sudo bots in the hashmap. Make sure to clone before editing */ + public static IArmbot getBot(String string) + { + return SUDO_BOTS.get(string); + } +} diff --git a/src/minecraft/dark/assembly/api/IArmbot.java b/src/minecraft/dark/api/al/armbot/IArmbot.java similarity index 88% rename from src/minecraft/dark/assembly/api/IArmbot.java rename to src/minecraft/dark/api/al/armbot/IArmbot.java index fb7ad97ca..687dd7690 100644 --- a/src/minecraft/dark/assembly/api/IArmbot.java +++ b/src/minecraft/dark/api/al/armbot/IArmbot.java @@ -1,4 +1,4 @@ -package dark.assembly.api; +package dark.api.al.armbot; import java.util.List; @@ -6,7 +6,7 @@ import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; /** Should be used to interact with the armbot and not to create a new armbot */ -public interface IArmbot +public interface IArmbot extends Cloneable { /** Adds an entity to the Armbot's grab list. */ public void grabEntity(Entity entity); @@ -14,9 +14,9 @@ public interface IArmbot public void grabItem(ItemStack itemStack); /** Drops the given object - * + * * @param object - Entity or ItemStack - * + * * String "All" should cause the armbot to drop all items */ public void drop(Object object); diff --git a/src/minecraft/dark/api/al/armbot/IArmbotTask.java b/src/minecraft/dark/api/al/armbot/IArmbotTask.java new file mode 100644 index 000000000..169cefb4d --- /dev/null +++ b/src/minecraft/dark/api/al/armbot/IArmbotTask.java @@ -0,0 +1,52 @@ +package dark.api.al.armbot; + +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import dan200.computer.api.IComputerAccess; +import dan200.computer.api.ILuaContext; + +/** Basic armbot command use to tell the armbot how to function + * + * @author DarkGuardsman */ +public interface IArmbotTask +{ + /** Gets the position inside the coding display. Set by the user but is general grid aligned by + * int values */ + public Vector2 getPosition(); + + public void setPosition(Vector2 pos); + + /** Method name or rather command name this will be called. Use both to ID this command, and do + * basic command structuring. */ + public String getMethodName(); + + /** Should be the same as getMethodName() but can be different */ + public String getCCMethod(); + + /** Passed in from both the armbot to the program manager then here after a Computer craft + * machine calls a this commands method name. {@IPeripheral #callMethod()} */ + public Object[] onCCMethodCalled(IComputerAccess computer, ILuaContext context, Object[] arguments) throws Exception; + + /** Update the current part of the command */ + public boolean onUpdate(); + + /** Called when the task is being run by the armbot + * + * @param world - current world + * @param location - current location + * @param armbot - armbot instance + * @param arguments - arguments for command + * @return should task be continued */ + public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments); + + /** Called when the task is finish and then cleared */ + public void terminated(); + + /** Read the command from the armbot save. Mainly only the current task is saved. */ + public IArmbotTask readFromNBT(NBTTagCompound nbt); + + /** Writes the command to the armbot save. Mainly only the current task is saved. */ + public NBTTagCompound writeToNBT(NBTTagCompound nbt); +} diff --git a/src/minecraft/dark/assembly/api/IArmbotUseable.java b/src/minecraft/dark/api/al/armbot/IArmbotUseable.java similarity index 94% rename from src/minecraft/dark/assembly/api/IArmbotUseable.java rename to src/minecraft/dark/api/al/armbot/IArmbotUseable.java index f461805d5..91f558c30 100644 --- a/src/minecraft/dark/assembly/api/IArmbotUseable.java +++ b/src/minecraft/dark/api/al/armbot/IArmbotUseable.java @@ -1,4 +1,5 @@ -package dark.assembly.api; +package dark.api.al.armbot; + /** The IUseable inteface is used by the ArmBot so that it may interact with Tile Entities. onUse * will be called on the block an ArmBot is touching whenever the USE command is run on it. diff --git a/src/minecraft/dark/api/al/armbot/IProgram.java b/src/minecraft/dark/api/al/armbot/IProgram.java new file mode 100644 index 000000000..953fb43f9 --- /dev/null +++ b/src/minecraft/dark/api/al/armbot/IProgram.java @@ -0,0 +1,15 @@ +package dark.api.al.armbot; + +import java.util.HashMap; + +public interface IProgram +{ + /** Called when the program is added to an encoder, machine, or devices. + * memory values. */ + public void init(); + + /** Variables this program has to operate. Is still limited by the actual machine */ + public HashMap getDeclairedVarables(); + + public IArmbotTask getNextTask(); +} diff --git a/src/minecraft/dark/api/al/armbot/ISplitArmbotTask.java b/src/minecraft/dark/api/al/armbot/ISplitArmbotTask.java new file mode 100644 index 000000000..1e06a051c --- /dev/null +++ b/src/minecraft/dark/api/al/armbot/ISplitArmbotTask.java @@ -0,0 +1,26 @@ +package dark.api.al.armbot; + +/** Task in which it doesn't go right to the next task in the row. In this case the task will store + * the entry point, and exit points. As well handle anything in between. Examples are IF statements + * and loops. + * + * @author DarkGuardsman */ +public interface ISplitArmbotTask extends IArmbotTask +{ + /** Point were this task is entered from. Normally is the task above it, and is never used. */ + public IArmbotTask getEntryPoint(); + + /** There is always only one exit though you can do logic to pick from all your exit points */ + public IArmbotTask getExitPoint(); + + /** Mainly used by the coder to understand the limit on connections */ + public int getMaxExitPoints(); + + /** Set by the coder, or when this is clone, to say what task was before this. */ + public ISplitArmbotTask setEntryPoint(IArmbotTask task); + + /** Adds a possible exit point to the split off */ + public void addExitPoint(IArmbotTask task); + + +} diff --git a/src/minecraft/dark/api/al/armbot/ProgramHandler.java b/src/minecraft/dark/api/al/armbot/ProgramHandler.java new file mode 100644 index 000000000..6dce37c53 --- /dev/null +++ b/src/minecraft/dark/api/al/armbot/ProgramHandler.java @@ -0,0 +1,92 @@ +package dark.api.al.armbot; + +import java.util.Arrays; +import java.util.HashMap; + +/** Basic class to handle a armbot like program for any object that uses the IArmbot class + * + * @author DarkGuardsman */ +public class ProgramHandler +{ + /** Current Program */ + protected IProgram program; + /** Current task in program */ + protected IArmbotTask currentTask; + /** Do we have a memory to store values */ + boolean hasMemory = false; + /**Max memorySize */ + protected int memorySize = 0; + /** Array of values to remember between commands */ + protected HashMap taskMemory = new HashMap(); + + public ProgramHandler(int varableLimit) + { + if (varableLimit > 0) + { + this.memorySize = varableLimit; + this.hasMemory = true; + } + else + { + this.taskMemory = null; + } + } + + public ProgramHandler setProgram(IProgram program) + { + this.program = program; + this.onProgramChanged(); + return this; + } + + public void onProgramChanged() + { + this.taskMemory.clear(); + if (this.program != null) + { + HashMap memory = this.program.getDeclairedVarables(); + if(memory.size() <= memorySize) + { + + } + } + } + + /** Gets the memory location */ + public Object getMemoryLocation(String var) + { + return this.taskMemory.get(var); + } + + /** Sets the memory location at the give spot. */ + public boolean setMemoryLocation(String var, Object object) + { + if (var != null) + { + if (this.taskMemory.containsKey(var)) + { + if (object == null) + { + this.taskMemory.remove(var); + } + return this.addMemory(var, object); + + } + else if (object != null && this.taskMemory.size() < this.memorySize) + { + return this.addMemory(var, object); + } + } + return false; + } + + protected boolean addMemory(String var, Object object) + { + //We don't want cheat methods to bypass the variable memory limit + if (!(object instanceof java.util.Arrays && object instanceof java.util.ArrayList && object instanceof java.util.List && object instanceof java.util.Set)) + { + return this.taskMemory.put(var, object) != null; + } + return false; + } +} diff --git a/src/minecraft/dark/assembly/common/armbot/Command.java b/src/minecraft/dark/assembly/common/armbot/Command.java new file mode 100644 index 000000000..db3235b71 --- /dev/null +++ b/src/minecraft/dark/assembly/common/armbot/Command.java @@ -0,0 +1,134 @@ +package dark.assembly.common.armbot; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector2; +import universalelectricity.core.vector.Vector3; +import dan200.computer.api.IComputerAccess; +import dan200.computer.api.ILuaContext; +import dark.api.al.armbot.IArmbot; +import dark.api.al.armbot.IArmbotTask; + +/** An AI Commands that is used by TileEntities with AI. + * + * @author Calclavia */ +public abstract class Command implements IArmbotTask, Cloneable +{ + private String methodName; + /** The amount of ticks this command has been running for. */ + protected int ticks = 0; + + protected World world; + protected IArmbot armbot; + protected Vector2 pos; + + /** The parameters this command has, or the properties. Entered by the player in the disk. + * Parameters are entered like a Java function. idle(20) = Idles for 20 seconds. */ + private String[] parameters; + + public Command(String name) + { + this.methodName = name; + } + + @Override + public Vector2 getPosition() + { + return pos; + } + + @Override + public void setPosition(Vector2 pos) + { + this.pos = pos; + } + + @Override + public boolean onUpdate() + { + this.ticks++; + return false; + } + + @Override + public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments) + { + this.world = world; + + return false; + } + + @Override + public Object[] onCCMethodCalled(IComputerAccess computer, ILuaContext context, Object[] arguments) throws Exception + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void terminated() + { + } + + public void setParameters(String[] strings) + { + this.parameters = strings; + } + + public String[] getArgs() + { + return this.parameters; + } + + /** Some functions to help get parameter arguments. */ + protected String getArg(int i) + { + if (i >= 0 && i < this.parameters.length) + { + return this.parameters[i]; + } + + return null; + } + + @Override + public Command readFromNBT(NBTTagCompound nbt) + { + this.ticks = nbt.getInteger("ticks"); + this.pos = new Vector2(nbt.getDouble("xx"),nbt.getDouble("yy")); + return this; + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { + nbt.setInteger("ticks", this.ticks); + if (this.pos != null) + { + nbt.setDouble("xx", pos.x); + nbt.setDouble("yy", pos.y); + } + return nbt; + } + + @Override + public String toString() + { + return "COMMAND[" + super.toString() + "]:" + this.methodName; + } + + @Override + public String getMethodName() + { + return this.methodName; + } + + @Override + public String getCCMethod() + { + return this.methodName; + } + + @Override + public abstract Command clone(); +} diff --git a/src/minecraft/dark/assembly/common/armbot/command/GrabDictionary.java b/src/minecraft/dark/assembly/common/armbot/GrabDictionary.java similarity index 98% rename from src/minecraft/dark/assembly/common/armbot/command/GrabDictionary.java rename to src/minecraft/dark/assembly/common/armbot/GrabDictionary.java index 8d9095b25..3c25bca6a 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/GrabDictionary.java +++ b/src/minecraft/dark/assembly/common/armbot/GrabDictionary.java @@ -1,4 +1,4 @@ -package dark.assembly.common.armbot.command; +package dark.assembly.common.armbot; import java.util.ArrayList; import java.util.List; diff --git a/src/minecraft/dark/assembly/common/armbot/Program.java b/src/minecraft/dark/assembly/common/armbot/Program.java new file mode 100644 index 000000000..420e71c63 --- /dev/null +++ b/src/minecraft/dark/assembly/common/armbot/Program.java @@ -0,0 +1,6 @@ +package dark.assembly.common.armbot; + +public class Program +{ + +} diff --git a/src/minecraft/dark/assembly/common/armbot/TileEntityArmbot.java b/src/minecraft/dark/assembly/common/armbot/TileEntityArmbot.java index e7d94d789..9a5e2c257 100644 --- a/src/minecraft/dark/assembly/common/armbot/TileEntityArmbot.java +++ b/src/minecraft/dark/assembly/common/armbot/TileEntityArmbot.java @@ -26,13 +26,11 @@ import cpw.mods.fml.relauncher.Side; import dan200.computer.api.IComputerAccess; import dan200.computer.api.ILuaContext; import dan200.computer.api.IPeripheral; -import dark.assembly.api.IArmbot; +import dark.api.al.armbot.IArmbot; import dark.assembly.common.AssemblyLine; -import dark.assembly.common.armbot.command.Command; import dark.assembly.common.armbot.command.CommandDrop; import dark.assembly.common.armbot.command.CommandFire; import dark.assembly.common.armbot.command.CommandGrab; -import dark.assembly.common.armbot.command.CommandManager; import dark.assembly.common.armbot.command.CommandReturn; import dark.assembly.common.armbot.command.CommandRotateBy; import dark.assembly.common.armbot.command.CommandRotateTo; @@ -49,8 +47,6 @@ import dark.core.prefab.machine.BlockMulti; public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IArmbot, IPeripheral { private final CommandManager commandManager = new CommandManager(); - /** The items this container contains. */ - protected ItemStack disk = null; private int computersAttached = 0; private List connectedComputers = new ArrayList(); /** The rotation of the arms. In Degrees. */ @@ -232,7 +228,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, this.rotationPitch = MathHelper.clampAngle(this.rotationPitch, 0, 60); - if (this.ticks % 4 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) + if (this.ticks % 4 == 0 && this.worldObj.isRemote) { this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 2f, 2.5f, true); } @@ -291,12 +287,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, return delta; } - /** Inventory */ - @Override - public int getSizeInventory() - { - return 1; - } + @Override public String getInvName() @@ -304,71 +295,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, return TranslationHelper.getLocal("tile.armbot.name"); } - /** Inventory functions. */ - @Override - public ItemStack getStackInSlot(int par1) - { - return this.disk; - } - @Override - public ItemStack decrStackSize(int par1, int par2) - { - if (this.disk != null) - { - ItemStack var3; - - if (this.disk.stackSize <= par2) - { - var3 = this.disk; - this.disk = null; - return var3; - } - else - { - var3 = this.disk.splitStack(par2); - - if (this.disk.stackSize == 0) - { - this.disk = null; - } - - return var3; - } - } - else - { - return null; - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.disk != null) - { - ItemStack var2 = this.disk; - this.disk = null; - return var2; - } - else - { - return null; - } - } - - @Override - public void setInventorySlotContents(int par1, ItemStack par2ItemStack) - { - this.disk = par2ItemStack; - this.onInventoryChanged(); - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } public String getCommandDisplayText() { @@ -382,27 +309,15 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, super.readFromNBT(nbt); NBTTagCompound diskNBT = nbt.getCompoundTag("disk"); - + ItemStack disk = null; if (diskNBT != null) { - this.disk = ItemStack.loadItemStackFromNBT(diskNBT); - } - else - { - this.disk = null; + disk = ItemStack.loadItemStackFromNBT(diskNBT); } this.rotationYaw = nbt.getFloat("yaw"); this.rotationPitch = nbt.getFloat("pitch"); - if (this.worldObj != null) - { - if (this.worldObj.isRemote) - { - this.displayText = nbt.getString("cmdText"); - } - } - this.commandManager.setCurrentTask(nbt.getInteger("curTask")); NBTTagList entities = nbt.getTagList("entities"); @@ -436,19 +351,9 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, { super.writeToNBT(nbt); - NBTTagCompound diskNBT = new NBTTagCompound(); - - if (this.disk != null) - { - this.disk.writeToNBT(diskNBT); - } - - nbt.setTag("disk", diskNBT); nbt.setFloat("yaw", this.rotationYaw); nbt.setFloat("pitch", this.rotationPitch); - nbt.setString("cmdText", this.displayText); - nbt.setInteger("curTask", this.commandManager.getCurrentTask()); NBTTagList entities = new NBTTagList(); @@ -554,44 +459,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, return false; } - @Override - public void onInventoryChanged() - { - this.commandManager.clear(); - - if (this.disk != null) - { - List commands = ItemDisk.getCommands(this.disk); - - for (String commandString : commands) - { - String commandName = commandString.split(" ")[0]; - - Class command = Command.getCommand(commandName); - - if (command != null) - { - List commandParameters = new ArrayList(); - - for (String param : commandString.split(" ")) - { - if (!param.equals(commandName)) - { - commandParameters.add(param); - } - } - - this.addCommand(command, commandParameters.toArray(new String[0])); - } - } - } - else - { - this.addCommand(Command.getCommand("DROP")); - this.addCommand(Command.getCommand("RETURN")); - } - } - public void addCommand(Class command) { this.commandManager.addCommand(this, command); diff --git a/src/minecraft/dark/assembly/common/armbot/command/Command.java b/src/minecraft/dark/assembly/common/armbot/command/Command.java deleted file mode 100644 index 6c9b23074..000000000 --- a/src/minecraft/dark/assembly/common/armbot/command/Command.java +++ /dev/null @@ -1,177 +0,0 @@ -package dark.assembly.common.armbot.command; - -import java.util.HashMap; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; -import dark.assembly.common.armbot.TileEntityArmbot; - -/** An AI Commands that is used by TileEntities with AI. - * - * @author Calclavia */ -public abstract class Command -{ - /** A class of all available commands. - * - * String - Command name. Command - The actual command class. */ - private static final HashMap COMMANDS = new HashMap(); - private static final HashMap REVERSE_LOOKUP = new HashMap(); - - static - { - registerCommand("idle", CommandIdle.class); - registerCommand("grab", CommandGrab.class); - registerCommand("drop", CommandDrop.class); - registerCommand("rotate", CommandRotateBy.class); - registerCommand("rotateto", CommandRotateTo.class); - registerCommand("return", CommandReturn.class); - registerCommand("repeat", CommandRepeat.class); - registerCommand("use", CommandUse.class); - registerCommand("powerto", CommandPowerTo.class); - registerCommand("fire", CommandFire.class); - registerCommand("break", CommandBreak.class); - registerCommand("place", CommandPlace.class); - registerCommand("harvest", CommandHarvest.class); - registerCommand("take", CommandTake.class); - registerCommand("give", CommandGive.class); - } - - public static void registerCommand(String command, Class commandClass) - { - COMMANDS.put(command, commandClass); - REVERSE_LOOKUP.put(commandClass, command); - } - - public static Class getCommand(String command) - { - return COMMANDS.get(command.toLowerCase()); - } - - public static String getCommandName(Class command) - { - return REVERSE_LOOKUP.get(command); - } - - /** The amount of ticks this command has been running for. */ - protected int ticks = 0; - - public World world; - public TileEntityArmbot tileEntity; - public CommandManager commandManager; - - /** The parameters this command has, or the properties. Entered by the player in the disk. - * Parameters are entered like a Java function. idle(20) = Idles for 20 seconds. */ - private String[] parameters; - - /** Called by the TaskManager to propagate tick updates - * - * @param ticks The amount of ticks this task has been running - * @return false if the task is finished and can be continued, true otherwise */ - protected boolean doTask() - { - this.ticks++; - return false; - } - - public void onTaskStart() - { - } - - public void onTaskEnd() - { - } - - /** @return The tick interval of this task. 0 means it will receive no update ticks. */ - public int getTickInterval() - { - return 1; - } - - public void setParameters(String[] strings) - { - this.parameters = strings; - } - - public String[] getArgs() - { - return this.parameters; - } - - /** Some functions to help get parameter arguments. */ - protected String getArg(int i) - { - if (i >= 0 && i < this.parameters.length) - { - return this.parameters[i]; - } - - return null; - } - - protected int getIntArg(int i) - { - if (getArg(i) != null) - { - try - { - return Integer.parseInt(getArg(i)); - } - catch (Exception e) - { - - } - } - - return 0; - } - - protected Double getDoubleArg(int i) - { - if (getArg(i) != null) - { - try - { - return Double.parseDouble(getArg(i)); - } - catch (Exception e) - { - - } - } - - return 0.0; - } - - protected Float getFloatArg(int i) - { - if (getArg(i) != null) - { - try - { - return Float.parseFloat(getArg(i)); - } - catch (Exception e) - { - - } - } - - return 0.0f; - } - - public void readFromNBT(NBTTagCompound taskCompound) - { - this.ticks = taskCompound.getInteger("ticks"); - } - - public void writeToNBT(NBTTagCompound taskCompound) - { - taskCompound.setInteger("ticks", this.ticks); - } - - @Override - public String toString() - { - return "COMMAND"; - } -} diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandBreak.java b/src/minecraft/dark/assembly/common/armbot/command/CommandBreak.java index 85e9af6bd..afcba60da 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandBreak.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandBreak.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import universalelectricity.core.vector.Vector3; +import dark.assembly.common.armbot.Command; import dark.core.prefab.helpers.ItemWorldHelper; /** Used by arms to break a specific block in a position. @@ -19,9 +20,9 @@ public class CommandBreak extends Command boolean keep = false; @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); Vector3 serachPosition = this.tileEntity.getHandPosition(); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandDrop.java b/src/minecraft/dark/assembly/common/armbot/command/CommandDrop.java index 2a3ed4afe..6cff2e8ed 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandDrop.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandDrop.java @@ -1,11 +1,13 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; + public class CommandDrop extends Command { @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); this.tileEntity.drop("all"); this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandFire.java b/src/minecraft/dark/assembly/common/armbot/command/CommandFire.java index 3dc009a0c..c0c81dedf 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandFire.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandFire.java @@ -2,6 +2,8 @@ package dark.assembly.common.armbot.command; import java.util.Random; +import dark.assembly.common.armbot.Command; + import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.projectile.EntityArrow; @@ -21,9 +23,9 @@ public class CommandFire extends Command private Vector3 finalVelocity; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); this.velocity = this.getFloatArg(0); if (this.velocity > 2.5f) @@ -55,7 +57,7 @@ public class CommandFire extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { if (this.finalVelocity == null) // something went wrong { @@ -80,7 +82,7 @@ public class CommandFire extends Command } else { - this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask(); + this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).onUpdate(); if (!this.world.isRemote) this.world.removeEntity(held); } @@ -105,7 +107,7 @@ public class CommandFire extends Command } else { - this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask(); + this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).onUpdate(); held.motionX = this.finalVelocity.x; held.motionY = this.finalVelocity.y; held.motionZ = this.finalVelocity.z; diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandGive.java b/src/minecraft/dark/assembly/common/armbot/command/CommandGive.java index 8c3ae5445..0ccbf5194 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandGive.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandGive.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; +import dark.assembly.common.armbot.Command; import dark.assembly.common.machine.InvInteractionHelper; public class CommandGive extends Command @@ -17,7 +18,7 @@ public class CommandGive extends Command private int ammount = -1; @Override - public void onTaskStart() + public void onStart() { int id = 0; int meta = 32767; @@ -51,7 +52,7 @@ public class CommandGive extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandGrab.java b/src/minecraft/dark/assembly/common/armbot/command/CommandGrab.java index 1ed1dc669..ae433d821 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandGrab.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandGrab.java @@ -10,6 +10,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import universalelectricity.core.vector.Vector3; +import dark.assembly.common.armbot.Command; +import dark.assembly.common.armbot.GrabDictionary; import dark.assembly.common.machine.belt.TileEntityConveyorBelt; /** Used by arms to search for entities in a region @@ -28,9 +30,9 @@ public class CommandGrab extends Command private Class entityToInclude; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); this.entityToInclude = Entity.class; if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null) { @@ -56,9 +58,9 @@ public class CommandGrab extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); if (this.tileEntity.getGrabbedEntities().size() > 0) { diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandHarvest.java b/src/minecraft/dark/assembly/common/armbot/command/CommandHarvest.java index 8c65e2ca2..4def9be34 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandHarvest.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandHarvest.java @@ -8,7 +8,7 @@ public class CommandHarvest extends CommandBreak private CommandRotateTo rotateToCommand; @Override - public void onTaskStart() + public void onStart() { this.keep = true; } diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java b/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java new file mode 100644 index 000000000..5821f8a9b --- /dev/null +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java @@ -0,0 +1,71 @@ +package dark.assembly.common.armbot.command; + +import universalelectricity.core.vector.Vector2; +import dark.api.al.armbot.IArmbotTask; +import dark.api.al.armbot.ISplitArmbotTask; +import dark.assembly.common.armbot.Command; + +public class CommandIF extends Command implements ISplitArmbotTask +{ + protected IArmbotTask entryPoint = null; + protected IArmbotTask exitTruePoint = null; + protected IArmbotTask exitFalsePoint = null; + protected boolean isTrue = false; + + public CommandIF() + { + super("IF"); + } + + public CommandIF(IArmbotTask entryPoint, IArmbotTask left, IArmbotTask right) + { + this(); + this.setEntryPoint(this.entryPoint); + + } + + @Override + public Command clone() + { + return new CommandIF(this.entryPoint, this.exitTruePoint, this.exitFalsePoint); + } + + @Override + public IArmbotTask getEntryPoint() + { + return this.entryPoint; + } + + @Override + public IArmbotTask getExitPoint() + { + if(this.isTrue) + { + return this.exitTruePoint; + } + return this.exitFalsePoint; + } + + @Override + public int getMaxExitPoints() + { + return 2; + } + + @Override + public ISplitArmbotTask setEntryPoint(IArmbotTask task) + { + this.entryPoint = task; + return this; + } + + @Override + public void addExitPoint(IArmbotTask task) + { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandIdle.java b/src/minecraft/dark/assembly/common/armbot/command/CommandIdle.java index 5b7c318d6..22d9a545d 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandIdle.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandIdle.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; import net.minecraft.nbt.NBTTagCompound; public class CommandIdle extends Command @@ -9,9 +10,9 @@ public class CommandIdle extends Command private int totalIdleTime = 80; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); if (this.getIntArg(0) > 0) { @@ -21,7 +22,7 @@ public class CommandIdle extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { /** Randomly move the arm to simulate life in the arm if the arm is powered */ // this.tileEntity.rotationPitch *= 0.98 * this.world.rand.nextFloat(); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandManager.java b/src/minecraft/dark/assembly/common/armbot/command/CommandManager.java deleted file mode 100644 index dfa74792c..000000000 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandManager.java +++ /dev/null @@ -1,213 +0,0 @@ -package dark.assembly.common.armbot.command; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import cpw.mods.fml.common.FMLLog; -import dark.assembly.common.armbot.TileEntityArmbot; - -public class CommandManager -{ - private final List tasks = new ArrayList(); - - private int ticks = 0; - private int currentTask = 0; - private int lastTask = -1; - - /** Must be called every tick by a tileEntity. */ - public void onUpdate() - { - /** Loop through each task and do them. */ - try - { - if (this.tasks.size() > 0) - { - if (this.currentTask < this.tasks.size()) - { - if (this.currentTask < 0) - { - this.currentTask = 0; - this.lastTask = -1; - } - - Command task = this.tasks.get(this.currentTask); - - if (this.currentTask != this.lastTask) - { - this.lastTask = this.currentTask; - task.onTaskStart(); - } - - if (!task.doTask()) - { - int tempCurrentTask = this.currentTask; - task.onTaskEnd(); - this.currentTask++; - - // Repeat needs to be persistent - if (!(task instanceof CommandRepeat)) - { - // End the task and reinitialize it into a new class to make sure it is - // fresh. - this.tasks.set(tempCurrentTask, this.getNewCommand(task.tileEntity, task.getClass(), task.getArgs())); - } - } - } - else - { - this.clear(); - } - } - } - catch (Exception e) - { - FMLLog.severe("Failed to execute task in Assembly Line."); - e.printStackTrace(); - } - - this.ticks++; - } - - public Command getNewCommand(TileEntityArmbot tileEntity, Class commandClass, String[] parameters) - { - try - { - Command newCommand = commandClass.newInstance(); - newCommand.world = tileEntity.worldObj; - newCommand.tileEntity = tileEntity; - newCommand.commandManager = this; - newCommand.setParameters(parameters); - return newCommand; - } - catch (Exception e) - { - FMLLog.severe("Failed to add command"); - e.printStackTrace(); - } - - return null; - } - - /** Used to register Tasks for a TileEntity, executes onTaskStart for the Task after registering - * it - * - * @param tileEntity TE instance to register the task for - * @param newCommand Task instance to register */ - public void addCommand(TileEntityArmbot tileEntity, Class commandClass, String[] parameters) - { - Command newCommand = this.getNewCommand(tileEntity, commandClass, parameters); - - if (newCommand != null) - { - this.tasks.add(newCommand); - } - } - - public void addCommand(TileEntityArmbot tileEntity, Class task) - { - this.addCommand(tileEntity, task, new String[0]); - } - - /** @return true when there are tasks registered, false otherwise */ - public boolean hasTasks() - { - return tasks.size() > 0; - } - - public List getCommands() - { - return tasks; - } - - /** Resets the command manager. */ - public void clear() - { - this.tasks.clear(); - this.currentTask = 0; - this.lastTask = -1; - this.ticks = 0; - } - - public void setCurrentTask(int i) - { - this.currentTask = Math.min(i, this.tasks.size()); - } - - public int getCurrentTask() - { - return this.currentTask; - } - - public void readFromNBT(TileEntityArmbot tileEntity, NBTTagCompound nbt) - { - this.currentTask = nbt.getInteger("curTasks"); - this.lastTask = nbt.getInteger("lastTask"); - this.ticks = nbt.getInteger("ticks"); - if (nbt.getInteger("numTasks") > 0) - { - NBTTagList taskList = nbt.getTagList("commands"); - for (int i = 0; i < taskList.tagCount(); i++) - { - NBTTagCompound cmdTag = (NBTTagCompound) taskList.tagAt(i); - try - { - Class cmdClass = Class.forName(cmdTag.getString("commandClass")); - ArrayList pars = new ArrayList(); - if (cmdTag.getInteger("numParameters") > 0) - { - NBTTagList parameters = cmdTag.getTagList("parameters"); - for (int ii = 0; ii < parameters.tagCount(); ii++) - { - pars.add(((NBTTagString) parameters.tagAt(ii)).data); - } - } - Command cmd = getNewCommand(tileEntity, cmdClass, pars.toArray(new String[] {})); - cmd.readFromNBT((NBTTagCompound) cmdTag.getTag("customData")); - } - catch (ClassNotFoundException e) - { - System.out.println("Error loading CommandManger: "); - e.printStackTrace(); - } - } - } - } - - public void writeToNBT(NBTTagCompound nbt) - { - nbt.setInteger("numTasks", this.tasks.size()); - if (this.tasks.size() > 0) - { - NBTTagList taskList = new NBTTagList("tasks"); - for (int i = 0; i < this.tasks.size(); i++) - { - NBTTagCompound taskCompound = new NBTTagCompound("taskCompound"); - String cmdName = this.tasks.get(i).getClass().getName(); - if (cmdName != null && !cmdName.isEmpty()) - taskCompound.setString("commandClass", cmdName); - if (this.tasks.get(i).getArgs().length > 0) - { - NBTTagList parameters = new NBTTagList("parameters"); - for (String par : this.tasks.get(i).getArgs()) - { - if (par != null && !par.isEmpty()) - parameters.appendTag(new NBTTagString("parameter", par)); - } - taskCompound.setTag("parameters", parameters); - } - taskCompound.setInteger("numParameters", this.tasks.get(i).getArgs().length); - NBTTagCompound customData = new NBTTagCompound("customData"); - this.tasks.get(i).writeToNBT(customData); - taskCompound.setCompoundTag("customData", customData); - taskList.appendTag(taskCompound); - } - nbt.setTag("commands", taskList); - } - nbt.setInteger("curTask", this.currentTask); - nbt.setInteger("lastTask", this.lastTask); - nbt.setInteger("ticks", this.ticks); - } -} diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandPlace.java b/src/minecraft/dark/assembly/common/armbot/command/CommandPlace.java index b455e2224..3a26bfad1 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandPlace.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandPlace.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; @@ -17,15 +18,15 @@ public class CommandPlace extends Command int PLACE_TIME = 30; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); } @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); Vector3 serachPosition = this.tileEntity.getHandPosition(); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandPowerTo.java b/src/minecraft/dark/assembly/common/armbot/command/CommandPowerTo.java index 50e37ff3a..ff34d58bd 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandPowerTo.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandPowerTo.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; +import dark.assembly.common.armbot.Command; import dark.core.prefab.helpers.ItemWorldHelper; public class CommandPowerTo extends Command @@ -17,7 +18,7 @@ public class CommandPowerTo extends Command private int ticksRan; @Override - public void onTaskStart() + public void onStart() { this.duration = 0; this.ticksRan = 0; @@ -34,9 +35,9 @@ public class CommandPowerTo extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); if (this.tileEntity.isProvidingPower && this.ticksRan >= duration) { powerBlock(false); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandRepeat.java b/src/minecraft/dark/assembly/common/armbot/command/CommandRepeat.java index 02bd173d9..54776a33b 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandRepeat.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandRepeat.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; import net.minecraft.nbt.NBTTagCompound; /** This task resets all previous tasks and does them again in a loop. @@ -14,7 +15,7 @@ public class CommandRepeat extends Command private boolean initialized = false; @Override - public void onTaskStart() + public void onStart() { this.tasksToRepeat = Math.max(this.getIntArg(0), 0); this.numReps = this.getIntArg(1); @@ -28,7 +29,7 @@ public class CommandRepeat extends Command } @Override - public void onTaskEnd() + public void onEnd() { if (this.curReps < this.numReps || this.numReps == -1) { diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandReturn.java b/src/minecraft/dark/assembly/common/armbot/command/CommandReturn.java index ea2c4613c..5bda7ca12 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandReturn.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandReturn.java @@ -1,5 +1,7 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; + public class CommandReturn extends Command { public static final float IDLE_ROTATION_PITCH = 0; @@ -8,27 +10,27 @@ public class CommandReturn extends Command private CommandRotateTo rotateToCommand; @Override - public void onTaskStart() + public void onStart() { this.rotateToCommand = (CommandRotateTo) this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[] { "0", "0" }); - this.rotateToCommand.onTaskStart(); + this.rotateToCommand.onStart(); } @Override - protected boolean doTask() + protected boolean onUpdate() { if (this.rotateToCommand == null) { - this.onTaskStart(); + this.onStart(); } - return this.rotateToCommand.doTask(); + return this.rotateToCommand.onUpdate(); } @Override - public void onTaskEnd() + public void onEnd() { - this.rotateToCommand.onTaskEnd(); + this.rotateToCommand.onEnd(); } @Override diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandRotateBy.java b/src/minecraft/dark/assembly/common/armbot/command/CommandRotateBy.java index 3d2b994de..f52dfacf4 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandRotateBy.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandRotateBy.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; import net.minecraft.nbt.NBTTagCompound; /** Rotates the armbot to a specific direction. If not specified, it will turn right. @@ -13,9 +14,9 @@ public class CommandRotateBy extends Command float totalTicks = 0f; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); this.ticks = 0; @@ -54,9 +55,9 @@ public class CommandRotateBy extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); /* * float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation); * diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandRotateTo.java b/src/minecraft/dark/assembly/common/armbot/command/CommandRotateTo.java index e77301dde..cb90f4c16 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandRotateTo.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandRotateTo.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import dark.assembly.common.armbot.Command; import net.minecraft.nbt.NBTTagCompound; /** Rotates the armbot to a specific direction. If not specified, it will turn right. @@ -12,9 +13,9 @@ public class CommandRotateTo extends Command int totalTicks = 0; @Override - public void onTaskStart() + public void onStart() { - super.onTaskStart(); + super.onStart(); this.ticks = 0; this.totalTicks = 0; @@ -52,9 +53,9 @@ public class CommandRotateTo extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { - super.doTask(); + super.onUpdate(); /* * float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation); * diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandTake.java b/src/minecraft/dark/assembly/common/armbot/command/CommandTake.java index 43ab4f441..8fa24bea2 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandTake.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandTake.java @@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; +import dark.assembly.common.armbot.Command; import dark.assembly.common.machine.InvInteractionHelper; public class CommandTake extends Command @@ -15,7 +16,7 @@ public class CommandTake extends Command private ItemStack stack; @Override - public void onTaskStart() + public void onStart() { int id = 0; int meta = 32767; @@ -50,7 +51,7 @@ public class CommandTake extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world); diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandUse.java b/src/minecraft/dark/assembly/common/armbot/command/CommandUse.java index a840ca305..ec66b6803 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandUse.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandUse.java @@ -3,7 +3,8 @@ package dark.assembly.common.armbot.command; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import dark.assembly.api.IArmbotUseable; +import dark.api.al.armbot.IArmbotUseable; +import dark.assembly.common.armbot.Command; public class CommandUse extends Command { @@ -11,7 +12,7 @@ public class CommandUse extends Command private int curTimes; @Override - public void onTaskStart() + public void onStart() { this.times = 0; this.curTimes = 0; @@ -26,7 +27,7 @@ public class CommandUse extends Command } @Override - protected boolean doTask() + protected boolean onUpdate() { Block block = Block.blocksList[this.world.getBlockId(tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ())]; TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world); diff --git a/src/minecraft/dark/assembly/common/imprinter/TileEntityImprinter.java b/src/minecraft/dark/assembly/common/imprinter/TileEntityImprinter.java index d983b2180..a51525b09 100644 --- a/src/minecraft/dark/assembly/common/imprinter/TileEntityImprinter.java +++ b/src/minecraft/dark/assembly/common/imprinter/TileEntityImprinter.java @@ -24,8 +24,8 @@ import universalelectricity.prefab.tile.TileEntityAdvanced; import com.builtbroken.common.Pair; import com.google.common.io.ByteArrayDataInput; -import dark.assembly.api.IArmbot; -import dark.assembly.api.IArmbotUseable; +import dark.api.al.armbot.IArmbot; +import dark.api.al.armbot.IArmbotUseable; import dark.core.common.DarkMain; import dark.core.network.PacketHandler; import dark.core.prefab.helpers.AutoCraftingManager; diff --git a/src/minecraft/dark/assembly/common/imprinter/prefab/BlockImprintable.java b/src/minecraft/dark/assembly/common/imprinter/prefab/BlockImprintable.java index cf8adb7d1..4d16dad8e 100644 --- a/src/minecraft/dark/assembly/common/imprinter/prefab/BlockImprintable.java +++ b/src/minecraft/dark/assembly/common/imprinter/prefab/BlockImprintable.java @@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import dark.assembly.api.IFilterable; +import dark.api.al.IFilterable; import dark.assembly.common.imprinter.ItemImprinter; import dark.assembly.common.machine.BlockAssembly; import dark.core.registration.ModObjectRegistry.BlockBuildData; diff --git a/src/minecraft/dark/assembly/common/imprinter/prefab/TileEntityFilterable.java b/src/minecraft/dark/assembly/common/imprinter/prefab/TileEntityFilterable.java index 991000f9c..fff9bfe3b 100644 --- a/src/minecraft/dark/assembly/common/imprinter/prefab/TileEntityFilterable.java +++ b/src/minecraft/dark/assembly/common/imprinter/prefab/TileEntityFilterable.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import universalelectricity.prefab.tile.IRotatable; -import dark.assembly.api.IFilterable; +import dark.api.al.IFilterable; import dark.assembly.common.imprinter.ItemImprinter; import dark.assembly.common.machine.TileEntityAssembly; diff --git a/src/minecraft/dark/assembly/common/machine/TileEntityManipulator.java b/src/minecraft/dark/assembly/common/machine/TileEntityManipulator.java index 93e91e567..05418854a 100644 --- a/src/minecraft/dark/assembly/common/machine/TileEntityManipulator.java +++ b/src/minecraft/dark/assembly/common/machine/TileEntityManipulator.java @@ -14,7 +14,7 @@ import universalelectricity.prefab.tile.IRotatable; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.Player; -import dark.assembly.api.IManipulator; +import dark.api.al.IManipulator; import dark.assembly.common.imprinter.ItemImprinter; import dark.assembly.common.imprinter.prefab.TileEntityFilterable; import dark.core.network.PacketHandler; diff --git a/src/minecraft/dark/assembly/common/machine/TileEntityRejector.java b/src/minecraft/dark/assembly/common/machine/TileEntityRejector.java index 0690964a1..d0aaff8f8 100644 --- a/src/minecraft/dark/assembly/common/machine/TileEntityRejector.java +++ b/src/minecraft/dark/assembly/common/machine/TileEntityRejector.java @@ -14,7 +14,7 @@ import universalelectricity.core.vector.Vector3; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.Player; -import dark.assembly.api.IBelt; +import dark.api.al.IBelt; import dark.assembly.common.imprinter.prefab.TileEntityFilterable; import dark.core.network.PacketHandler; diff --git a/src/minecraft/dark/assembly/common/machine/belt/TileEntityConveyorBelt.java b/src/minecraft/dark/assembly/common/machine/belt/TileEntityConveyorBelt.java index bbb89de44..cdff227f5 100644 --- a/src/minecraft/dark/assembly/common/machine/belt/TileEntityConveyorBelt.java +++ b/src/minecraft/dark/assembly/common/machine/belt/TileEntityConveyorBelt.java @@ -16,7 +16,7 @@ import universalelectricity.prefab.tile.IRotatable; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.Player; -import dark.assembly.api.IBelt; +import dark.api.al.IBelt; import dark.assembly.common.AssemblyLine; import dark.assembly.common.machine.TileEntityAssembly; import dark.core.common.DarkMain; diff --git a/src/minecraft/dark/assembly/common/machine/encoder/TileEntityEncoder.java b/src/minecraft/dark/assembly/common/machine/encoder/TileEntityEncoder.java index 5afa130a0..4c97a4be5 100644 --- a/src/minecraft/dark/assembly/common/machine/encoder/TileEntityEncoder.java +++ b/src/minecraft/dark/assembly/common/machine/encoder/TileEntityEncoder.java @@ -15,7 +15,7 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -import dark.assembly.common.armbot.command.Command; +import dark.assembly.common.armbot.Command; public class TileEntityEncoder extends TileEntityAdvanced implements IPacketReceiver, ISidedInventory {