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.
This commit is contained in:
DarkGuardsman 2013-10-15 11:14:45 -04:00
parent 7b4ad06449
commit b2220d4d5f
42 changed files with 567 additions and 595 deletions

BIN
docs/grafcet.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -1,4 +1,4 @@
package dark.assembly.api;
package dark.api.al;
import java.util.List;

View file

@ -1,4 +1,4 @@
package dark.assembly.api;
package dark.api.al;
import net.minecraftforge.common.ForgeDirection;

View file

@ -1,4 +1,4 @@
package dark.assembly.api;
package dark.api.al;
public interface ICraneStructure extends ICraneConnectable
{

View file

@ -1,4 +1,4 @@
package dark.assembly.api;
package dark.api.al;
import net.minecraft.item.ItemStack;

View file

@ -1,4 +1,4 @@
package dark.assembly.api;
package dark.api.al;
/** Interface applied to the manipulator.
*

View file

@ -0,0 +1,80 @@
package dark.api.al.armbot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** Used to both register task and fake machines for the encoder to use to create new programs.
*
* @author DarkGuardsman */
public class ArmbotTaskManager
{
/** A class of all available commands.
*
* String - Command name. Command - The actual command class. */
private static final Set<IArmbotTask> COMMANDS = new HashSet<IArmbotTask>();
private static final HashMap<String, IArmbot> SUDO_BOTS = new HashMap<String, IArmbot>();
/** 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<IArmbotTask> getCommands(String name)
{
List<IArmbotTask> tasks = new ArrayList<IArmbotTask>();
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<String, IArmbot> 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);
}
}

View file

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

View file

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

View file

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

View file

@ -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<String, Object> getDeclairedVarables();
public IArmbotTask getNextTask();
}

View file

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

View file

@ -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<String, Object> taskMemory = new HashMap<String, Object>();
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<String, Object> 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;
}
}

View file

@ -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();
}

View file

@ -1,4 +1,4 @@
package dark.assembly.common.armbot.command;
package dark.assembly.common.armbot;
import java.util.ArrayList;
import java.util.List;

View file

@ -0,0 +1,6 @@
package dark.assembly.common.armbot;
public class Program
{
}

View file

@ -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<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
/** 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<String> commands = ItemDisk.getCommands(this.disk);
for (String commandString : commands)
{
String commandName = commandString.split(" ")[0];
Class<? extends Command> command = Command.getCommand(commandName);
if (command != null)
{
List<String> commandParameters = new ArrayList<String>();
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<? extends Command> command)
{
this.commandManager.addCommand(this, command);

View file

@ -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<String, Class> COMMANDS = new HashMap<String, Class>();
private static final HashMap<Class, String> REVERSE_LOOKUP = new HashMap<Class, String>();
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<? extends Command> commandClass)
{
COMMANDS.put(command, commandClass);
REVERSE_LOOKUP.put(commandClass, command);
}
public static Class<? extends Command> getCommand(String command)
{
return COMMANDS.get(command.toLowerCase());
}
public static String getCommandName(Class<? extends Command> 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";
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -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<? extends Entity> 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)
{

View file

@ -8,7 +8,7 @@ public class CommandHarvest extends CommandBreak
private CommandRotateTo rotateToCommand;
@Override
public void onTaskStart()
public void onStart()
{
this.keep = true;
}

View file

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

View file

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

View file

@ -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<Command> tasks = new ArrayList<Command>();
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<? extends Command> 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<? extends Command> commandClass, String[] parameters)
{
Command newCommand = this.getNewCommand(tileEntity, commandClass, parameters);
if (newCommand != null)
{
this.tasks.add(newCommand);
}
}
public void addCommand(TileEntityArmbot tileEntity, Class<? extends Command> 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<Command> 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<String> pars = new ArrayList<String>();
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);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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