Worked on command system
This commit is contained in:
parent
d98f77dc7c
commit
7d8ba9cdc7
21 changed files with 284 additions and 112 deletions
|
@ -9,6 +9,7 @@ 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.IArmbotTask.TaskType;
|
||||
|
||||
/** Basic command prefab used by machines like an armbot. You are not required to use this in order
|
||||
* to make armbot commands but it does help. Delete this if you don't plan to use it. */
|
||||
|
@ -20,6 +21,8 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
/** The amount of ticks this command has been running for. */
|
||||
protected int ticks = 0;
|
||||
|
||||
protected TaskType taskType;
|
||||
|
||||
/** World current working in */
|
||||
protected World worldObj;
|
||||
/** Armbot instance */
|
||||
|
@ -32,9 +35,10 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
/** The parameters this command */
|
||||
private Object[] parameters;
|
||||
|
||||
public Command(String name)
|
||||
public Command(String name, TaskType tasktype)
|
||||
{
|
||||
this.methodName = name;
|
||||
this.taskType = tasktype;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,22 +49,20 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.armbot = armbot;
|
||||
this.parameters = arguments;
|
||||
this.armbotPos = location;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context, Object[] arguments) throws Exception
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.armbot = armbot;
|
||||
this.parameters = arguments;
|
||||
this.armbotPos = location;
|
||||
|
||||
return null;
|
||||
|
@ -104,14 +106,6 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
this.ticks = nbt.getInteger("ticks");
|
||||
this.pos = new Vector2(nbt.getDouble("xx"), nbt.getDouble("yy"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItem(String string, int ammount)
|
||||
{
|
||||
int id = 0;
|
||||
|
@ -137,9 +131,36 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
public Command load(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setInteger("ticks", this.ticks);
|
||||
NBTTagCompound parmTag = nbt.getCompoundTag("parms");
|
||||
int parms = parmTag.getInteger("parms");
|
||||
if (parms > 0)
|
||||
{
|
||||
Object[] args = new Object[parms];
|
||||
for (int i = 0; i < parms; i++)
|
||||
{
|
||||
args[i] = nbt.getString("parm" + i);
|
||||
}
|
||||
}
|
||||
this.pos = new Vector2(nbt.getDouble("xx"), nbt.getDouble("yy"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
{
|
||||
if (this.parameters != null)
|
||||
{
|
||||
NBTTagCompound parmTag = new NBTTagCompound();
|
||||
parmTag.setInteger("parms", this.parameters.length);
|
||||
|
||||
for (int i = 0; i < this.parameters.length; i++)
|
||||
{
|
||||
parmTag.setString("parm" + i, "" + this.parameters[i]);
|
||||
}
|
||||
nbt.setCompoundTag("parms", parmTag);
|
||||
}
|
||||
if (this.pos != null)
|
||||
{
|
||||
nbt.setDouble("xx", pos.x);
|
||||
|
@ -148,6 +169,20 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArmbotTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
this.ticks = nbt.getInteger("ticks");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setInteger("ticks", this.ticks);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -166,6 +201,26 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
return this.methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCurrentParms()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParms(Object... arguments)
|
||||
{
|
||||
this.parameters = arguments;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TaskType getType()
|
||||
{
|
||||
return this.taskType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Command clone();
|
||||
}
|
||||
|
|
|
@ -25,34 +25,50 @@ public interface IArmbotTask
|
|||
/** Should be the same as getMethodName() but can be different */
|
||||
public String getCCMethod();
|
||||
|
||||
public Object[] getCurrentParms();
|
||||
|
||||
public void setParms(Object... arguments);
|
||||
|
||||
/** 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(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context, Object[] arguments) throws Exception;
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context) throws Exception;
|
||||
|
||||
/** Update the current segment of the task */
|
||||
public boolean onUpdate();
|
||||
|
||||
/** Called when the task is being run by the armbot. Used mainly to setup the task before actually doing the task.
|
||||
/** Called when the task is being run by the armbot. Used mainly to setup the task before
|
||||
* actually doing the task.
|
||||
*
|
||||
* @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);
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot);
|
||||
|
||||
/** 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);
|
||||
/** Read the command from the armbot save. */
|
||||
public IArmbotTask load(NBTTagCompound nbt);
|
||||
|
||||
/** Writes the command to the armbot save. Mainly only the current task is saved. */
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt);
|
||||
/** Writes the command to the armbot save. Should only be used to save the data used to recreate
|
||||
* a new version of this command */
|
||||
public NBTTagCompound save(NBTTagCompound nbt);
|
||||
|
||||
/** Saves the current progress of the current command */
|
||||
public IArmbotTask loadProgress(NBTTagCompound nbt);
|
||||
|
||||
/** Reads the progress of the command if it was saved mid process */
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt);
|
||||
|
||||
public TaskType getType();
|
||||
|
||||
/** Used mainly for display purposes in the encoder */
|
||||
public static enum TaskType
|
||||
{
|
||||
DATA(), PROCESS(), DECISION()
|
||||
DATA(),
|
||||
DEFINEDPROCESS(),
|
||||
DECISION()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,7 @@ public interface IProgram
|
|||
|
||||
/** Gets a task at the given x y location in the program */
|
||||
public IArmbotTask getTaskAt(Vector2 vector2);
|
||||
|
||||
/** Return this program to its starting conditions */
|
||||
public void reset();
|
||||
}
|
||||
|
|
|
@ -1,25 +1,72 @@
|
|||
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
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/** Basic class to handle a armbot like programs for any object that uses the IArmbot class
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ProgramHandler
|
||||
public class ProgramHelper
|
||||
{
|
||||
/** Current Program */
|
||||
protected IProgram program;
|
||||
protected IArmbot bot;
|
||||
/** Current task in program */
|
||||
protected IArmbotTask currentTask;
|
||||
/** Do we have a memory to store values */
|
||||
boolean hasMemory = false;
|
||||
boolean hasTaskBeenCalled = false, nextTask = 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)
|
||||
public ProgramHelper(IArmbot bot)
|
||||
{
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
/** Needs to be called by the armbot per tick.
|
||||
*
|
||||
* @return true if it is doing something */
|
||||
public boolean onUpdate(World world, Vector3 botLocation)
|
||||
{
|
||||
if (program != null)
|
||||
{
|
||||
if (this.currentTask == null || this.nextTask)
|
||||
{
|
||||
this.nextTask();
|
||||
}
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
if (!this.hasTaskBeenCalled && !this.currentTask.onMethodCalled(world, botLocation, bot))
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.currentTask.onUpdate())
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void nextTask()
|
||||
{
|
||||
this.currentTask = program.getNextTask();
|
||||
this.hasTaskBeenCalled = false;
|
||||
this.nextTask = false;
|
||||
}
|
||||
|
||||
public ProgramHelper(int varableLimit)
|
||||
{
|
||||
if (varableLimit > 0)
|
||||
{
|
||||
|
@ -32,7 +79,7 @@ public class ProgramHandler
|
|||
}
|
||||
}
|
||||
|
||||
public ProgramHandler setProgram(IProgram program)
|
||||
public ProgramHelper setProgram(IProgram program)
|
||||
{
|
||||
this.program = program;
|
||||
this.onProgramChanged();
|
||||
|
@ -47,8 +94,9 @@ public class ProgramHandler
|
|||
HashMap<String, Object> memory = this.program.getDeclairedVarables();
|
||||
if (memory.size() <= memorySize)
|
||||
{
|
||||
|
||||
//TODO load in memory and throw error stopping machine if there is not enough
|
||||
}
|
||||
this.program.init();
|
||||
}
|
||||
}
|
||||
|
|
@ -52,8 +52,8 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
/** The rotation of the arms. In Degrees. */
|
||||
protected float rotationPitch = 0;
|
||||
protected float rotationYaw = 0;
|
||||
protected float actualPitch = 0;
|
||||
protected float actualYaw = 0;
|
||||
public float actualPitch = 0;
|
||||
public float actualYaw = 0;
|
||||
protected final float ROTATION_SPEED = 2.0f;
|
||||
|
||||
protected boolean hasTask = false;
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.item.EntityItem;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.core.prefab.helpers.ItemWorldHelper;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
|
@ -16,12 +17,12 @@ public class CommandBreak extends Command
|
|||
{
|
||||
public CommandBreak()
|
||||
{
|
||||
super("break");
|
||||
super("break", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
public CommandBreak(String name)
|
||||
{
|
||||
super(name);
|
||||
super(name, TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
int BREAK_TIME = 30;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
|
||||
public class CommandDrop extends Command
|
||||
{
|
||||
public CommandDrop()
|
||||
{
|
||||
super("drop");
|
||||
super("drop", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -29,13 +30,13 @@ public class CommandFire extends Command
|
|||
|
||||
public CommandFire()
|
||||
{
|
||||
super("throw");
|
||||
super("throw", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot, arguments);
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
this.velocity = UnitHelper.tryToParseFloat("" + this.getArg(0));
|
||||
if (this.velocity > 2.5f)
|
||||
|
@ -140,9 +141,9 @@ public class CommandFire extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound taskCompound)
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.actualYaw = taskCompound.getFloat("fireYaw");
|
||||
this.actualPitch = taskCompound.getFloat("firePitch");
|
||||
this.velocity = taskCompound.getFloat("fireVelocity");
|
||||
|
@ -154,9 +155,9 @@ public class CommandFire extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setFloat("fireYaw", this.actualYaw);
|
||||
taskCompound.setFloat("firePitch", this.actualPitch);
|
||||
taskCompound.setFloat("fireVelocity", this.velocity);
|
||||
|
|
|
@ -4,17 +4,19 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.assembly.common.machine.InvInteractionHelper;
|
||||
import dark.core.prefab.helpers.MathHelper;
|
||||
|
||||
public class CommandGive extends Command
|
||||
{
|
||||
|
@ -24,13 +26,13 @@ public class CommandGive extends Command
|
|||
|
||||
public CommandGive()
|
||||
{
|
||||
super("give");
|
||||
super("give", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot, arguments);
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
if (this.getArgs().length > 1)
|
||||
{
|
||||
|
@ -53,19 +55,22 @@ public class CommandGive extends Command
|
|||
|
||||
if (targetTile != null && this.armbot.getGrabbedObjects().size() > 0)
|
||||
{
|
||||
ForgeDirection direction = this.tileEntity.getFacingDirectionFromAngle();
|
||||
ForgeDirection direction = MathHelper.getFacingDirectionFromAngle((float) this.armbot.getRotation().x);
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
if (this.stack != null)
|
||||
{
|
||||
stacks.add(stack);
|
||||
}
|
||||
InvInteractionHelper invEx = new InvInteractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false);
|
||||
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.armbotPos, stacks, false);
|
||||
|
||||
Iterator<ItemStack> targetIt = this.tileEntity.getGrabbedItems().iterator();
|
||||
Iterator<Object> targetIt = this.armbot.getGrabbedObjects().iterator();
|
||||
boolean flag = true;
|
||||
while (targetIt.hasNext())
|
||||
{
|
||||
ItemStack insertStack = targetIt.next();
|
||||
Object object = targetIt.next();
|
||||
if (object instanceof ItemStack)
|
||||
{
|
||||
ItemStack insertStack = (ItemStack) object;
|
||||
if (insertStack != null)
|
||||
{
|
||||
ItemStack original = insertStack.copy();
|
||||
|
@ -78,6 +83,7 @@ public class CommandGive extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
return false;
|
||||
|
@ -90,17 +96,17 @@ public class CommandGive extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound taskCompound)
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
if (stack != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.World;
|
|||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.assembly.common.armbot.GrabDictionary;
|
||||
import dark.assembly.common.machine.belt.TileEntityConveyorBelt;
|
||||
|
||||
|
@ -33,13 +34,13 @@ public class CommandGrab extends Command
|
|||
|
||||
public CommandGrab()
|
||||
{
|
||||
super("Grab");
|
||||
super("Grab", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot, arguments);
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.entityToInclude = Entity.class;
|
||||
if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null)
|
||||
{
|
||||
|
@ -110,18 +111,18 @@ public class CommandGrab extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound taskCompound)
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.child = taskCompound.getBoolean("child");
|
||||
this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setBoolean("child", child);
|
||||
taskCompound.setString("name", ((this.entityToInclude != null) ? GrabDictionary.get(this.entityToInclude).getName() : ""));
|
||||
return taskCompound;
|
||||
|
|
|
@ -3,6 +3,7 @@ package dark.assembly.common.armbot.command;
|
|||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
*
|
||||
|
@ -17,9 +18,9 @@ public class CommandHarvest extends CommandBreak
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
this.keep = true;
|
||||
return super.onMethodCalled(world, location, armbot, arguments);
|
||||
return super.onMethodCalled(world, location, armbot);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
|
||||
public CommandIF()
|
||||
{
|
||||
super("IF");
|
||||
super("IF", TaskType.DECISION);
|
||||
}
|
||||
|
||||
public CommandIF(IArmbotTask entryPoint, IArmbotTask trueExit, IArmbotTask falseExit)
|
||||
|
@ -70,9 +70,9 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound nbt)
|
||||
public Command loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
super.loadProgress(nbt);
|
||||
this.entryPoint = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY"))));
|
||||
this.exitFalsePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitFalseX"), (nbt.getDouble("exitFalseY"))));
|
||||
this.exitTruePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitTrueX"), (nbt.getDouble("exitTrueY"))));
|
||||
|
@ -80,9 +80,9 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
super.saveProgress(nbt);
|
||||
if (this.entryPoint != null)
|
||||
{
|
||||
nbt.setDouble("entryX", this.entryPoint.getPosition().x);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -17,14 +18,14 @@ public class CommandIdle extends Command
|
|||
|
||||
public CommandIdle()
|
||||
{
|
||||
super("wait");
|
||||
super("wait", TaskType.DEFINEDPROCESS);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot, arguments);
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
if (UnitHelper.tryToParseInt("" + this.getArg(0)) > 0)
|
||||
{
|
||||
|
@ -51,18 +52,18 @@ public class CommandIdle extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound taskCompound)
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.idleTime = taskCompound.getInteger("idleTime");
|
||||
this.totalIdleTime = taskCompound.getInteger("idleTotal");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setInteger("idleTime", this.idleTime);
|
||||
taskCompound.setInteger("idleTotal", this.totalIdleTime);
|
||||
return taskCompound;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -17,6 +18,12 @@ public class CommandPlace extends Command
|
|||
{
|
||||
int PLACE_TIME = 30;
|
||||
|
||||
public CommandPlace()
|
||||
{
|
||||
super("Place", TaskType.DEFINEDPROCESS);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/** This task resets all previous tasks and does them again in a loop.
|
||||
|
@ -8,12 +9,19 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
* @author Calclavia */
|
||||
public class CommandRepeat extends Command
|
||||
{
|
||||
|
||||
/** The amount of tasks above this task to repeat. */
|
||||
private int tasksToRepeat;
|
||||
private int numReps;
|
||||
private int curReps;
|
||||
private boolean initialized = false;
|
||||
|
||||
public CommandRepeat()
|
||||
{
|
||||
super("repeat", TaskType.DEFINEDPROCESS);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
|
@ -49,9 +57,9 @@ public class CommandRepeat extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound taskCompound)
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.initialized = taskCompound.getBoolean("repInitialized");
|
||||
this.tasksToRepeat = taskCompound.getInteger("repTasks");
|
||||
this.curReps = taskCompound.getInteger("repCur");
|
||||
|
@ -59,9 +67,9 @@ public class CommandRepeat extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound taskCompound)
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setBoolean("repInitialized", this.initialized);
|
||||
taskCompound.setInteger("repTasks", this.tasksToRepeat);
|
||||
taskCompound.setInteger("repCur", this.curReps);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
|
||||
public class CommandReturn extends Command
|
||||
{
|
||||
|
@ -11,7 +12,7 @@ public class CommandReturn extends Command
|
|||
|
||||
public CommandReturn()
|
||||
{
|
||||
super("Return");
|
||||
super("Return", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/** Rotates the armbot to a specific direction. If not specified, it will turn right.
|
||||
|
@ -8,11 +9,17 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
* @author Calclavia */
|
||||
public class CommandRotateBy extends Command
|
||||
{
|
||||
|
||||
float targetRotationYaw = 0;
|
||||
float targetRotationPitch = 0;
|
||||
float deltaPitch = 0, deltaYaw = 90;
|
||||
float totalTicks = 0f;
|
||||
|
||||
public CommandRotateBy()
|
||||
{
|
||||
super("RotateBy", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
|
@ -89,17 +96,17 @@ public class CommandRotateBy extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound taskCompound)
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
|
||||
this.targetRotationYaw = taskCompound.getFloat("rotYaw");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound taskCompound)
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.core.prefab.helpers.MathHelper;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -17,7 +18,7 @@ public class CommandRotateTo extends Command
|
|||
{
|
||||
public CommandRotateTo()
|
||||
{
|
||||
super("RotateTo");
|
||||
super("RotateTo", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
float targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
|
||||
|
@ -62,18 +63,18 @@ public class CommandRotateTo extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command readFromNBT(NBTTagCompound taskCompound)
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
|
||||
this.targetRotationYaw = taskCompound.getFloat("rotYaw");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
|
||||
return taskCompound;
|
||||
|
|
|
@ -9,12 +9,19 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.assembly.common.machine.InvInteractionHelper;
|
||||
|
||||
public class CommandTake extends Command
|
||||
{
|
||||
|
||||
private ItemStack stack;
|
||||
|
||||
public CommandTake()
|
||||
{
|
||||
super("Take", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
|
@ -78,16 +85,16 @@ public class CommandTake extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound taskCompound)
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound taskCompound)
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
if (stack != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
|
|
@ -5,12 +5,19 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotUseable;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
|
||||
public class CommandUse extends Command
|
||||
{
|
||||
|
||||
private int times;
|
||||
private int curTimes;
|
||||
|
||||
public CommandUse()
|
||||
{
|
||||
super("use", TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
|
@ -71,17 +78,17 @@ public class CommandUse extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound taskCompound)
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.readFromNBT(taskCompound);
|
||||
super.loadProgress(taskCompound);
|
||||
this.times = taskCompound.getInteger("useTimes");
|
||||
this.curTimes = taskCompound.getInteger("useCurTimes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound taskCompound)
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.writeToNBT(taskCompound);
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setInteger("useTimes", this.times);
|
||||
taskCompound.setInteger("useCurTimes", this.curTimes);
|
||||
}
|
||||
|
|
|
@ -393,7 +393,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
if (this.imprinterMatrix[craftingOutputSlot] != null)
|
||||
{
|
||||
armbot.grabItem(this.imprinterMatrix[craftingOutputSlot].copy());
|
||||
armbot.grab(this.imprinterMatrix[craftingOutputSlot].copy());
|
||||
this.onPickUpFromSlot(null, 2, this.imprinterMatrix[craftingOutputSlot]);
|
||||
this.imprinterMatrix[craftingOutputSlot] = null;
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue