Lot of work on armbot task system
Started designing the task system to work with other non-armbot devices. As well fixed up several command, and designed a way for the command to say something is wrong. Will continue to improve this before i actually start on the encoder and armbot. That way there is less changes after recoding both devices.
This commit is contained in:
parent
7d8ba9cdc7
commit
38ed9fdbff
29 changed files with 626 additions and 436 deletions
24
docs/PLC and Displays.txt
Normal file
24
docs/PLC and Displays.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
PLC
|
||||
I know another mod has Programming logic controls(PLCs) however i don't really care. What i'm planning on doing is adding a block that can use the same coding system as the armbot. This way there are even more uses for the flowchart system, and more factory control.
|
||||
|
||||
Idea
|
||||
Basic multi-functional mini computer that can do several different logic tasks. Mainly it will be used to control redstone, power, and other machines. It will not do anything on its own or even have built in sensors. It will however use the same exact commands system as the armbot. This means the armbot system is going to need to be recoded to understand non-armbot machines.
|
||||
|
||||
Looks
|
||||
Little box smaller than a single block. Will have 4 sides for input and one side for power. Will connect to the face of a wall. Will render connections to objects near it.
|
||||
|
||||
Extras
|
||||
Wrench rotation support for both rotation and turning off connection nodes.
|
||||
|
||||
|
||||
Displays
|
||||
Very simple programable display that is fully customizable to display data and control systems.
|
||||
|
||||
Idea
|
||||
The idea is to provide a display that can be designed and programmed by users. Using a system very simular to Visual studios drag and drop GUI builder. Other than that it will use the same coding interface to do its logic. Though its main purpose is to display data and change data values of machines. A very easy use of it will be redstone switch to turn off a machine. Another is to display the machines power needs/uses and item outputs.
|
||||
|
||||
Looks
|
||||
Like a computer monitor that has several different selectable monitors. Very basic versions will be a CC monitor look, and flat panel version. Though there plan is to allow rotation to make it easer to view.
|
||||
|
||||
Extras
|
||||
Selectable rotations both pitch and yaw. As well different colors, models, textures, and designs.
|
|
@ -14,12 +14,12 @@ 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 Set<IDeviceTask> COMMANDS = new HashSet<IDeviceTask>();
|
||||
|
||||
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)
|
||||
public static void registerCommand(IDeviceTask task)
|
||||
{
|
||||
if (!COMMANDS.contains(task))
|
||||
{
|
||||
|
@ -28,9 +28,9 @@ public class ArmbotTaskManager
|
|||
}
|
||||
|
||||
/** returns the first command with the same name */
|
||||
public static IArmbotTask getCommand(String name)
|
||||
public static IDeviceTask getCommand(String name)
|
||||
{
|
||||
for (IArmbotTask command : COMMANDS)
|
||||
for (IDeviceTask command : COMMANDS)
|
||||
{
|
||||
if (command.getMethodName().equalsIgnoreCase(name))
|
||||
{
|
||||
|
@ -41,10 +41,10 @@ public class ArmbotTaskManager
|
|||
}
|
||||
|
||||
/** Gets all commands with the given name though there should only be one */
|
||||
public static List<IArmbotTask> getCommands(String name)
|
||||
public static List<IDeviceTask> getCommands(String name)
|
||||
{
|
||||
List<IArmbotTask> tasks = new ArrayList<IArmbotTask>();
|
||||
for (IArmbotTask command : COMMANDS)
|
||||
List<IDeviceTask> tasks = new ArrayList<IDeviceTask>();
|
||||
for (IDeviceTask command : COMMANDS)
|
||||
{
|
||||
if (command.getMethodName().equalsIgnoreCase(name))
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import universalelectricity.core.vector.Vector2;
|
||||
|
||||
/** Should be used to interact with the armbot and not to create a new armbot */
|
||||
public interface IArmbot extends Cloneable
|
||||
public interface IArmbot extends Cloneable, ILogicDevice
|
||||
{
|
||||
/** Location of the hand, or working location of the object */
|
||||
public universalelectricity.core.vector.Vector3 getHandPos();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package dark.api.al.armbot;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -7,63 +9,65 @@ 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
|
||||
/** Use to construct a basic task that can be used in any device that supports this interface
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IArmbotTask
|
||||
public interface IDeviceTask
|
||||
{
|
||||
/** Gets the position inside the coding display. Set by the user but is general grid aligned by
|
||||
* int values */
|
||||
/** Location in the column and row format. */
|
||||
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
|
||||
/** Method name or rather command name this will be called. Uses 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();
|
||||
|
||||
public Object[] getCurrentParms();
|
||||
|
||||
public void setParms(Object... arguments);
|
||||
/** Passed in from the device 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, ILogicDevice device, IComputerAccess computer, ILuaContext context) throws Exception;
|
||||
|
||||
/** 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) 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 devices program manager. 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);
|
||||
* @return false to stop the task here. */
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice device);
|
||||
|
||||
/** Update the current segment of the task */
|
||||
public ProcessReturn onUpdate();
|
||||
|
||||
/** Called when the task is finish and then cleared */
|
||||
public void terminated();
|
||||
|
||||
/** Read the command from the armbot save. */
|
||||
public IArmbotTask load(NBTTagCompound nbt);
|
||||
public IDeviceTask load(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);
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt);
|
||||
|
||||
/** Reads the progress of the command if it was saved mid process */
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt);
|
||||
|
||||
public TaskType getType();
|
||||
|
||||
/** Can this task function for this machine */
|
||||
public boolean canUseTask(ILogicDevice device);
|
||||
|
||||
/** Hashmap to tell the encoder what params it will use in the encoder */
|
||||
public HashMap<String, Object> getEncoderParms();
|
||||
|
||||
/** Used mainly for display purposes in the encoder */
|
||||
public static enum TaskType
|
||||
{
|
||||
|
@ -71,4 +75,13 @@ public interface IArmbotTask
|
|||
DEFINEDPROCESS(),
|
||||
DECISION()
|
||||
}
|
||||
|
||||
public static enum ProcessReturn
|
||||
{
|
||||
CONTINUE(),
|
||||
DONE(),
|
||||
GENERAL_ERROR(),
|
||||
SYNTAX_ERROR(),
|
||||
ARGUMENT_ERROR();
|
||||
}
|
||||
}
|
8
src/minecraft/dark/api/al/armbot/ILogicDevice.java
Normal file
8
src/minecraft/dark/api/al/armbot/ILogicDevice.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package dark.api.al.armbot;
|
||||
|
||||
public interface ILogicDevice
|
||||
{
|
||||
public IProgram getCurrentProgram();
|
||||
|
||||
public void setCurrentProgram(IProgram program);
|
||||
}
|
32
src/minecraft/dark/api/al/armbot/IMemoryTask.java
Normal file
32
src/minecraft/dark/api/al/armbot/IMemoryTask.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package dark.api.al.armbot;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/** Used by task to tell the program it needs to remember a value outside the task. Should only be
|
||||
* used by task that really need to save values beyond there local values. Cases were this is used
|
||||
* should be is loops, items counts, and run conditions.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IMemoryTask
|
||||
{
|
||||
/** Number of memory locations this needs. One per variable with no set size at the moment.
|
||||
* Though to keep the bit size down the types are limited at the moment. As well return zero to
|
||||
* indicate there is no memory locations. Only called once when the task is run. */
|
||||
public int getMemoryVars();
|
||||
|
||||
/** Called per update to store the changes in memory. If return is null the memory location will
|
||||
* be released. Make sure to do this if the value is no longer needed. Memory is limited to
|
||||
* basic java variables, and will not accept arrays, or collections */
|
||||
public Object getMemory(String name);
|
||||
|
||||
/** All memory locations needed by this task with there names, data types, and starting/current
|
||||
* values. Take care that this is designed to keep data over several program cycles. This is not
|
||||
* used to save local data. As well machines have limited memory of only a few active vars. */
|
||||
public HashMap<String, Object> getMemory();
|
||||
|
||||
/** Any memory location that needs to be saved to the machines hard disk. Should only do this for
|
||||
* information that must be saved. Treat this as real world memory to hard drive saving. As well
|
||||
* if the machine is running between world saves its active memory will be save. However, if it
|
||||
* turns off its active memory will clear. Called as the task is terminated. */
|
||||
public HashMap<String, Object> getSavedData();
|
||||
}
|
|
@ -19,10 +19,10 @@ public interface IProgram
|
|||
public HashMap<String, Object> getDeclairedVarables();
|
||||
|
||||
/** Next task in the set. Its up to the program to increment down the list */
|
||||
public IArmbotTask getNextTask();
|
||||
public IDeviceTask getNextTask();
|
||||
|
||||
/** Gets a task at the given x y location in the program */
|
||||
public IArmbotTask getTaskAt(Vector2 vector2);
|
||||
public IDeviceTask getTaskAt(Vector2 vector2);
|
||||
|
||||
/** Return this program to its starting conditions */
|
||||
public void reset();
|
||||
|
|
|
@ -5,22 +5,22 @@ package dark.api.al.armbot;
|
|||
* and loops.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface ISplitArmbotTask extends IArmbotTask
|
||||
public interface ISplitArmbotTask extends IDeviceTask
|
||||
{
|
||||
/** Point were this task is entered from. Normally is the task above it, and is never used. */
|
||||
public IArmbotTask getEntryPoint();
|
||||
public IDeviceTask getEntryPoint();
|
||||
|
||||
/** There is always only one exit though you can do logic to pick from all your exit points */
|
||||
public IArmbotTask getExitPoint();
|
||||
public IDeviceTask 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);
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task);
|
||||
|
||||
/** Adds a possible exit point to the split off */
|
||||
public void addExitPoint(IArmbotTask task);
|
||||
public void addExitPoint(IDeviceTask task);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package dark.api.al.armbot;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import dark.api.al.armbot.IDeviceTask.ProcessReturn;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
@ -13,9 +15,9 @@ public class ProgramHelper
|
|||
{
|
||||
/** Current Program */
|
||||
protected IProgram program;
|
||||
protected IArmbot bot;
|
||||
protected ILogicDevice bot;
|
||||
/** Current task in program */
|
||||
protected IArmbotTask currentTask;
|
||||
protected IDeviceTask currentTask;
|
||||
/** Do we have a memory to store values */
|
||||
boolean hasMemory = false;
|
||||
boolean hasTaskBeenCalled = false, nextTask = false;
|
||||
|
@ -24,7 +26,7 @@ public class ProgramHelper
|
|||
/** Array of values to remember between commands */
|
||||
protected HashMap<String, Object> taskMemory = new HashMap<String, Object>();
|
||||
|
||||
public ProgramHelper(IArmbot bot)
|
||||
public ProgramHelper(ILogicDevice bot)
|
||||
{
|
||||
this.bot = bot;
|
||||
}
|
||||
|
@ -32,8 +34,9 @@ public class ProgramHelper
|
|||
/** Needs to be called by the armbot per tick.
|
||||
*
|
||||
* @return true if it is doing something */
|
||||
public boolean onUpdate(World world, Vector3 botLocation)
|
||||
public ProcessReturn onUpdate(World world, Vector3 botLocation)
|
||||
{
|
||||
ProcessReturn re = ProcessReturn.DONE;
|
||||
if (program != null)
|
||||
{
|
||||
if (this.currentTask == null || this.nextTask)
|
||||
|
@ -42,21 +45,28 @@ public class ProgramHelper
|
|||
}
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
if (!this.hasTaskBeenCalled && !this.currentTask.onMethodCalled(world, botLocation, bot))
|
||||
if (!this.hasTaskBeenCalled)
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.currentTask.onUpdate())
|
||||
re = this.currentTask.onMethodCalled(world, botLocation, bot);
|
||||
if (re == ProcessReturn.DONE)
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
else if (re != ProcessReturn.CONTINUE)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
re = this.currentTask.onUpdate();
|
||||
if (re == ProcessReturn.DONE)
|
||||
{
|
||||
this.nextTask = true;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return re;
|
||||
}
|
||||
|
||||
public void nextTask()
|
||||
|
|
51
src/minecraft/dark/assembly/common/armbot/TaskArmbot.java
Normal file
51
src/minecraft/dark/assembly/common/armbot/TaskArmbot.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package dark.assembly.common.armbot;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
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.ILogicDevice;
|
||||
|
||||
public abstract class TaskArmbot extends TaskBase
|
||||
{
|
||||
/** Armbot instance */
|
||||
protected IArmbot armbot;
|
||||
|
||||
public TaskArmbot(String name, TaskType tasktype)
|
||||
{
|
||||
super(name, tasktype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
if (armbot instanceof IArmbot)
|
||||
{
|
||||
this.armbot = (IArmbot) armbot;
|
||||
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
return ProcessReturn.GENERAL_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
{
|
||||
super.onCCMethodCalled(world, location, armbot, computer, context);
|
||||
if (armbot instanceof IArmbot)
|
||||
{
|
||||
this.armbot = (IArmbot) armbot;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
{
|
||||
return device instanceof IArmbot;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,68 +1,85 @@
|
|||
package dark.api.al.armbot;
|
||||
package dark.assembly.common.armbot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
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.IArmbotTask.TaskType;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask;
|
||||
import dark.api.al.armbot.IMemoryTask;
|
||||
import dark.api.al.armbot.IProgram;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.core.prefab.helpers.NBTFileLoader;
|
||||
|
||||
/** 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. */
|
||||
public abstract class Command implements IArmbotTask, Cloneable
|
||||
public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
|
||||
{
|
||||
/** Program this is part of. Can be null while stores as a prefab waiting to be copied */
|
||||
protected IProgram program;
|
||||
private String methodName;
|
||||
/** The amount of ticks this command has been running for. */
|
||||
protected int ticks = 0;
|
||||
protected long ticks;
|
||||
|
||||
protected TaskType taskType;
|
||||
|
||||
/** World current working in */
|
||||
protected World worldObj;
|
||||
/** Armbot instance */
|
||||
protected IArmbot armbot;
|
||||
|
||||
/** Armbot location */
|
||||
protected Vector3 armbotPos;
|
||||
/** Position in the coder is also used during loading to place everything together */
|
||||
protected Vector2 pos;
|
||||
|
||||
/** The parameters this command */
|
||||
private Object[] parameters;
|
||||
private HashMap<String, Object> parameters;
|
||||
|
||||
public Command(String name, TaskType tasktype)
|
||||
protected HashMap<String, Object> activeMemory = new HashMap<String, Object>();
|
||||
|
||||
public TaskBase(String name, TaskType tasktype)
|
||||
{
|
||||
this.methodName = name;
|
||||
this.taskType = tasktype;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
this.ticks++;
|
||||
return false;
|
||||
if (ticks++ >= Long.MAX_VALUE - 1)
|
||||
{
|
||||
this.ticks = 0;
|
||||
}
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.armbot = armbot;
|
||||
this.armbotPos = location;
|
||||
if (location != null && armbotPos != null)
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.armbotPos = location;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ProcessReturn.GENERAL_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.armbot = armbot;
|
||||
this.armbotPos = location;
|
||||
|
||||
return null;
|
||||
|
@ -73,27 +90,6 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
{
|
||||
}
|
||||
|
||||
public void setParameters(String[] strings)
|
||||
{
|
||||
this.parameters = strings;
|
||||
}
|
||||
|
||||
public Object[] getArgs()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
/** Some functions to help get parameter arguments. */
|
||||
protected Object getArg(int i)
|
||||
{
|
||||
if (i >= 0 && i < this.parameters.length)
|
||||
{
|
||||
return this.parameters[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2 getPosition()
|
||||
{
|
||||
|
@ -106,20 +102,22 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
this.pos = pos;
|
||||
}
|
||||
|
||||
public ItemStack getItem(String string, int ammount)
|
||||
public ItemStack getItem(Object object, int ammount)
|
||||
{
|
||||
int id = 0;
|
||||
int meta = 32767;
|
||||
if (string.contains(":"))
|
||||
|
||||
if (object instanceof String && ((String) object).contains(":"))
|
||||
{
|
||||
String[] blockID = string.split(":");
|
||||
String[] blockID = ((String) object).split(":");
|
||||
id = Integer.parseInt(blockID[0]);
|
||||
meta = Integer.parseInt(blockID[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
id = UnitHelper.tryToParseInt(string);
|
||||
id = UnitHelper.tryToParseInt(object);
|
||||
}
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
return null;
|
||||
|
@ -131,16 +129,15 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command load(NBTTagCompound nbt)
|
||||
public TaskBase load(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagCompound parmTag = nbt.getCompoundTag("parms");
|
||||
int parms = parmTag.getInteger("parms");
|
||||
if (parms > 0)
|
||||
if (this.getEncoderParms() != null)
|
||||
{
|
||||
Object[] args = new Object[parms];
|
||||
for (int i = 0; i < parms; i++)
|
||||
this.parameters = new HashMap();
|
||||
NBTTagCompound parms = nbt.getCompoundTag("args");
|
||||
for (Entry<String, Object> entry : this.getEncoderParms().entrySet())
|
||||
{
|
||||
args[i] = nbt.getString("parm" + i);
|
||||
this.parameters.put(entry.getKey(), NBTFileLoader.loadObject(parms, entry.getKey()));
|
||||
}
|
||||
}
|
||||
this.pos = new Vector2(nbt.getDouble("xx"), nbt.getDouble("yy"));
|
||||
|
@ -150,17 +147,12 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
{
|
||||
if (this.parameters != null)
|
||||
NBTTagCompound parms = new NBTTagCompound();
|
||||
for (Entry<String, Object> entry : this.parameters.entrySet())
|
||||
{
|
||||
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);
|
||||
NBTFileLoader.saveObject(parms, entry.getKey(), entry.getValue());
|
||||
}
|
||||
nbt.setCompoundTag("args", parms);
|
||||
if (this.pos != null)
|
||||
{
|
||||
nbt.setDouble("xx", pos.x);
|
||||
|
@ -170,16 +162,14 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
}
|
||||
|
||||
@Override
|
||||
public IArmbotTask loadProgress(NBTTagCompound nbt)
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
this.ticks = nbt.getInteger("ticks");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setInteger("ticks", this.ticks);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
|
@ -201,20 +191,6 @@ 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()
|
||||
{
|
||||
|
@ -222,5 +198,36 @@ public abstract class Command implements IArmbotTask, Cloneable
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract Command clone();
|
||||
public abstract TaskBase clone();
|
||||
|
||||
@Override
|
||||
public int getMemoryVars()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMemory(String name)
|
||||
{
|
||||
return this.activeMemory.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getMemory()
|
||||
{
|
||||
return this.activeMemory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getSavedData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getEncoderParms()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@ import cpw.mods.fml.relauncher.Side;
|
|||
import dan200.computer.api.IComputerAccess;
|
||||
import dan200.computer.api.ILuaContext;
|
||||
import dan200.computer.api.IPeripheral;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbot;
|
||||
import dark.assembly.common.AssemblyLine;
|
||||
import dark.assembly.common.armbot.command.CommandDrop;
|
||||
|
|
|
@ -5,19 +5,26 @@ import java.util.ArrayList;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.api.al.armbot.IDeviceTask;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.core.prefab.helpers.ItemWorldHelper;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class CommandBreak extends Command
|
||||
public class CommandBreak extends TaskArmbot
|
||||
{
|
||||
protected int breakTicks = 30;
|
||||
protected boolean keep = false;
|
||||
|
||||
public CommandBreak()
|
||||
{
|
||||
super("break", TaskType.DEFINEDPROCESS);
|
||||
this.breakTicks = 30;
|
||||
}
|
||||
|
||||
public CommandBreak(String name)
|
||||
|
@ -25,19 +32,18 @@ public class CommandBreak extends Command
|
|||
super(name, TaskType.DEFINEDPROCESS);
|
||||
}
|
||||
|
||||
int BREAK_TIME = 30;
|
||||
boolean keep = false;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
Vector3 serachPosition = this.armbot.getHandPos();
|
||||
|
||||
Block block = Block.blocksList[serachPosition.getBlockID(this.worldObj)];
|
||||
|
||||
if (block != null && BREAK_TIME <= this.ticks)
|
||||
this.breakTicks--;
|
||||
if (block != null && breakTicks <= 0)
|
||||
{
|
||||
ArrayList<ItemStack> items = block.getBlockDropped(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(worldObj), 0);
|
||||
|
||||
|
@ -51,16 +57,30 @@ public class CommandBreak extends Command
|
|||
}
|
||||
|
||||
worldObj.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0, 3);
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
/** Notes on break command Beds Break Wrong Multi blocks don't work */
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandBreak();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
this.breakTicks = nbt.getInteger("breakTicks");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt)
|
||||
{
|
||||
nbt.setInteger("breakTicks", this.breakTicks);
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.al.armbot.IDeviceTask;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
||||
public class CommandDrop extends Command
|
||||
public class CommandDrop extends TaskArmbot
|
||||
{
|
||||
public CommandDrop()
|
||||
{
|
||||
|
@ -11,14 +14,14 @@ public class CommandDrop extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
this.armbot.drop("all");
|
||||
this.worldObj.playSound(this.armbotPos.x, this.armbotPos.x, this.armbotPos.x, "random.pop", 0.2F, ((this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
|
||||
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,8 +31,10 @@ public class CommandDrop extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandDrop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import java.util.Random;
|
|||
|
||||
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.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -17,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
public class CommandFire extends Command
|
||||
public class CommandFire extends TaskArmbot
|
||||
{
|
||||
|
||||
private static final float MIN_ACTUAL_PITCH = -80;
|
||||
|
@ -34,7 +36,7 @@ public class CommandFire extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
@ -65,11 +67,11 @@ public class CommandFire extends Command
|
|||
this.finalVelocity.z *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
|
||||
|
||||
this.finalVelocity.scale(velocity);
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
if (this.finalVelocity == null) // something went wrong
|
||||
{
|
||||
|
@ -137,11 +139,11 @@ public class CommandFire extends Command
|
|||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
public TaskBase loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.actualYaw = taskCompound.getFloat("fireYaw");
|
||||
|
@ -177,7 +179,7 @@ public class CommandFire extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandFire();
|
||||
}
|
||||
|
|
|
@ -13,12 +13,14 @@ 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.api.al.armbot.ILogicDevice;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.machine.InvInteractionHelper;
|
||||
import dark.core.prefab.helpers.MathHelper;
|
||||
|
||||
public class CommandGive extends Command
|
||||
public class CommandGive extends TaskArmbot
|
||||
{
|
||||
|
||||
private ItemStack stack;
|
||||
|
@ -30,7 +32,7 @@ public class CommandGive extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
@ -44,12 +46,12 @@ public class CommandGive extends Command
|
|||
stack = this.getItem("" + this.getArg(0), ammount == -1 ? 1 : ammount);
|
||||
}
|
||||
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
|
||||
|
||||
|
@ -64,29 +66,25 @@ public class CommandGive extends Command
|
|||
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.armbotPos, stacks, false);
|
||||
|
||||
Iterator<Object> targetIt = this.armbot.getGrabbedObjects().iterator();
|
||||
boolean flag = true;
|
||||
boolean itemsLeft = false;
|
||||
while (targetIt.hasNext())
|
||||
{
|
||||
Object object = targetIt.next();
|
||||
if (object instanceof ItemStack)
|
||||
{
|
||||
ItemStack insertStack = (ItemStack) object;
|
||||
if (insertStack != null)
|
||||
insertStack = invEx.tryPlaceInPosition(insertStack, new Vector3(targetTile), direction.getOpposite());
|
||||
itemsLeft = insertStack != null;
|
||||
if (insertStack == null || insertStack.stackSize <= 0)
|
||||
{
|
||||
ItemStack original = insertStack.copy();
|
||||
insertStack = invEx.tryPlaceInPosition(insertStack, new Vector3(targetTile), direction.getOpposite());
|
||||
flag = insertStack != null && insertStack.stackSize == original.stackSize;
|
||||
if (insertStack == null || insertStack.stackSize <= 0)
|
||||
{
|
||||
targetIt.remove();
|
||||
break;
|
||||
}
|
||||
targetIt.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
return itemsLeft ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
|
||||
}
|
||||
return false;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,7 +94,7 @@ public class CommandGive extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
public TaskBase loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
|
@ -117,8 +115,15 @@ public class CommandGive extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandGive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,16 +11,18 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
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.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.armbot.GrabDictionary;
|
||||
import dark.assembly.common.machine.belt.TileEntityConveyorBelt;
|
||||
|
||||
/** Used by arms to search for entities in a region
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class CommandGrab extends Command
|
||||
public class CommandGrab extends TaskArmbot
|
||||
{
|
||||
|
||||
public static final float radius = 0.5f;
|
||||
|
@ -38,7 +40,7 @@ public class CommandGrab extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.entityToInclude = Entity.class;
|
||||
|
@ -63,17 +65,17 @@ public class CommandGrab extends Command
|
|||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
if (this.armbot.getGrabbedObjects().size() > 0)
|
||||
{
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
Vector3 serachPosition = this.armbot.getHandPos();
|
||||
|
@ -102,16 +104,16 @@ public class CommandGrab extends Command
|
|||
{
|
||||
belt.ignoreEntity(found.get(i));
|
||||
}
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
public TaskBase loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.child = taskCompound.getBoolean("child");
|
||||
|
@ -146,7 +148,7 @@ public class CommandGrab extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandGrab();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ 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;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
*
|
||||
|
@ -18,7 +19,7 @@ public class CommandHarvest extends CommandBreak
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
this.keep = true;
|
||||
return super.onMethodCalled(world, location, armbot);
|
||||
|
|
|
@ -3,13 +3,14 @@ package dark.assembly.common.armbot.command;
|
|||
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 dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CommandIdle extends Command
|
||||
public class CommandIdle extends TaskBase
|
||||
{
|
||||
|
||||
/** The amount of time in which the machine will idle. */
|
||||
|
@ -23,7 +24,7 @@ public class CommandIdle extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
@ -31,13 +32,13 @@ public class CommandIdle extends Command
|
|||
{
|
||||
this.idleTime = UnitHelper.tryToParseInt("" + this.getArg(0));
|
||||
this.totalIdleTime = this.idleTime;
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
return false;
|
||||
return ProcessReturn.ARGUMENT_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn 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();
|
||||
|
@ -45,14 +46,14 @@ public class CommandIdle extends Command
|
|||
if (this.idleTime > 0)
|
||||
{
|
||||
this.idleTime--;
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
public TaskBase loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.idleTime = taskCompound.getInteger("idleTime");
|
||||
|
@ -76,9 +77,15 @@ public class CommandIdle extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -14,7 +15,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
/** Used by arms to break a specific block in a position.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class CommandPlace extends Command
|
||||
public class CommandPlace extends TaskArmbot
|
||||
{
|
||||
int PLACE_TIME = 30;
|
||||
|
||||
|
@ -25,23 +26,17 @@ public class CommandPlace extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
Vector3 serachPosition = this.tileEntity.getHandPosition();
|
||||
Vector3 serachPosition = this.armbot.getHandPos();
|
||||
|
||||
Block block = Block.blocksList[serachPosition.getBlockID(this.worldObj)];
|
||||
|
||||
if (block == null && ticks >= this.PLACE_TIME)
|
||||
{
|
||||
for (Entity entity : this.tileEntity.getGrabbedEntities())
|
||||
for (Object entity : this.armbot.getGrabbedObjects())
|
||||
{
|
||||
if (entity instanceof EntityItem)
|
||||
{
|
||||
|
@ -53,8 +48,8 @@ public class CommandPlace extends Command
|
|||
{
|
||||
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
|
||||
|
||||
this.tileEntity.drop(entity);
|
||||
return false;
|
||||
this.armbot.getGrabbedObjects().remove(entity);
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
else if (itemStack.getItem() instanceof IPlantable)
|
||||
{
|
||||
|
@ -74,8 +69,8 @@ public class CommandPlace extends Command
|
|||
{
|
||||
Block.blocksList[blockID].onBlockPlacedBy(worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null, itemStack);
|
||||
Block.blocksList[blockID].onPostBlockPlaced(worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata);
|
||||
this.tileEntity.drop(entity);
|
||||
return false;
|
||||
this.armbot.getGrabbedObjects().remove(entity);
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +81,7 @@ public class CommandPlace extends Command
|
|||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,4 +89,10 @@ public class CommandPlace extends Command
|
|||
{
|
||||
return "PLACE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandPlace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
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.
|
||||
*
|
||||
* @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()
|
||||
{
|
||||
this.tasksToRepeat = Math.max(this.getIntArg(0), 0);
|
||||
this.numReps = this.getIntArg(1);
|
||||
if (numReps == 0)
|
||||
numReps = -1; // infinite
|
||||
if (!this.initialized)
|
||||
{
|
||||
this.initialized = true;
|
||||
this.curReps = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd()
|
||||
{
|
||||
if (this.curReps < this.numReps || this.numReps == -1)
|
||||
{
|
||||
this.curReps++;
|
||||
if (this.tasksToRepeat > 0)
|
||||
{
|
||||
this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat - 1);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.commandManager.setCurrentTask(-2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.initialized = taskCompound.getBoolean("repInitialized");
|
||||
this.tasksToRepeat = taskCompound.getInteger("repTasks");
|
||||
this.curReps = taskCompound.getInteger("repCur");
|
||||
this.numReps = taskCompound.getInteger("repGoal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setBoolean("repInitialized", this.initialized);
|
||||
taskCompound.setInteger("repTasks", this.tasksToRepeat);
|
||||
taskCompound.setInteger("repCur", this.curReps);
|
||||
taskCompound.setInteger("repGoal", this.numReps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
int cmdToTest = 0;
|
||||
if (this.tasksToRepeat > 0)
|
||||
{
|
||||
cmdToTest = this.commandManager.getCurrentTask() - this.tasksToRepeat;
|
||||
}
|
||||
if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size())
|
||||
{
|
||||
return this.commandManager.getCommands().get(cmdToTest).toString();
|
||||
}
|
||||
return "REPEAT " + Integer.toString(this.tasksToRepeat) + " " + ((this.numReps > 0) ? Integer.toString(this.numReps) : "");
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
||||
public class CommandReturn extends Command
|
||||
public class CommandReturn extends TaskArmbot
|
||||
{
|
||||
public static final float IDLE_ROTATION_PITCH = 0;
|
||||
public static final float IDLE_ROTATION_YAW = 0;
|
||||
|
@ -16,12 +16,13 @@ public class CommandReturn extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
if (this.rotateToCommand == null)
|
||||
{
|
||||
this.rotateToCommand = (CommandRotateTo) this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[] { "0", "0" });
|
||||
this.rotateToCommand.onStart();
|
||||
this.rotateToCommand = new CommandRotateTo();
|
||||
this.rotateToCommand.setParms(0,0);
|
||||
this.rotateToCommand.onMethodCalled(this.worldObj, this.armbotPos, armbot);
|
||||
}
|
||||
|
||||
return this.rotateToCommand.onUpdate();
|
||||
|
@ -39,4 +40,10 @@ public class CommandReturn extends Command
|
|||
return "RETURN";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandReturn();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Rotates the armbot to a specific direction. If not specified, it will turn right.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class CommandRotateBy extends Command
|
||||
public class CommandRotateBy extends TaskArmbot
|
||||
{
|
||||
|
||||
float targetRotationYaw = 0;
|
||||
float targetRotationPitch = 0;
|
||||
float deltaPitch = 0, deltaYaw = 90;
|
||||
float totalTicks = 0f;
|
||||
double targetRotationYaw = 0;
|
||||
double targetRotationPitch = 0;
|
||||
double deltaPitch = 0, deltaYaw = 90;
|
||||
double totalTicks = 0f;
|
||||
|
||||
private CommandRotateTo rotateToCommand;
|
||||
|
||||
public CommandRotateBy()
|
||||
{
|
||||
|
@ -21,9 +28,9 @@ public class CommandRotateBy extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onStart();
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
this.ticks = 0;
|
||||
|
||||
|
@ -44,55 +51,25 @@ public class CommandRotateBy extends Command
|
|||
}
|
||||
else
|
||||
{
|
||||
this.targetRotationPitch = this.tileEntity.rotationPitch;
|
||||
this.targetRotationPitch = this.armbot.getRotation().y;
|
||||
}
|
||||
|
||||
while (this.targetRotationYaw < 0)
|
||||
this.targetRotationYaw += 360;
|
||||
while (this.targetRotationYaw > 360)
|
||||
this.targetRotationYaw -= 360;
|
||||
while (this.targetRotationPitch < 0)
|
||||
this.targetRotationPitch += 60;
|
||||
while (this.targetRotationPitch > 60)
|
||||
this.targetRotationPitch -= 60;
|
||||
|
||||
float totalTicksYaw = Math.abs(this.targetRotationYaw - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED;
|
||||
float totalTicksPitch = Math.abs(this.targetRotationPitch - this.tileEntity.rotationPitch) / this.tileEntity.ROTATION_SPEED;
|
||||
this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
/*
|
||||
* float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation);
|
||||
*
|
||||
* if (rotationalDifference < ROTATION_SPEED) { this.tileEntity.rotationYaw =
|
||||
* this.targetRotation; } else { if (this.tileEntity.rotationYaw > this.targetRotation) {
|
||||
* this.tileEntity.rotationYaw -= ROTATION_SPEED; } else { this.tileEntity.rotationYaw +=
|
||||
* ROTATION_SPEED; } this.ticks = 0; }
|
||||
*/
|
||||
|
||||
// set the rotation to the target immediately and let the client handle animating it
|
||||
// wait for the client to catch up
|
||||
|
||||
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotationYaw) > 0.001f)
|
||||
this.tileEntity.rotationYaw = this.targetRotationYaw;
|
||||
if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f)
|
||||
this.tileEntity.rotationPitch = this.targetRotationPitch;
|
||||
|
||||
// if (this.ticks < this.totalTicks) { return true; }
|
||||
if (Math.abs(this.tileEntity.actualPitch - this.tileEntity.rotationPitch) > 0.001f)
|
||||
if (this.rotateToCommand == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Math.abs(this.tileEntity.actualYaw - this.tileEntity.rotationYaw) > 0.001f)
|
||||
{
|
||||
return true;
|
||||
this.rotateToCommand = new CommandRotateTo();
|
||||
this.rotateToCommand.setParms(this.targetRotationYaw,this.targetRotationPitch);
|
||||
this.rotateToCommand.onMethodCalled(this.worldObj, this.armbotPos, armbot);
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.rotateToCommand.onUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,9 +4,11 @@ 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.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.core.prefab.helpers.MathHelper;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -14,7 +16,7 @@ import net.minecraft.world.World;
|
|||
/** Rotates the armbot to a specific direction. If not specified, it will turn right.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class CommandRotateTo extends Command
|
||||
public class CommandRotateTo extends TaskArmbot
|
||||
{
|
||||
public CommandRotateTo()
|
||||
{
|
||||
|
@ -24,28 +26,31 @@ public class CommandRotateTo extends Command
|
|||
float targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
|
||||
|
||||
@Override
|
||||
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice device)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot, arguments);
|
||||
super.onMethodCalled(world, location, device);
|
||||
|
||||
if (this.getArg(0) != null)
|
||||
{
|
||||
this.targetRotationYaw = UnitHelper.tryToParseFloat("" + this.getArg(0));
|
||||
this.targetRotationYaw = UnitHelper.tryToParseFloat(this.getArg(0));
|
||||
}else
|
||||
{
|
||||
return ProcessReturn.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (this.getArg(1) != null)
|
||||
{
|
||||
this.targetRotationPitch = UnitHelper.tryToParseFloat("" + this.getArg(1));
|
||||
this.targetRotationPitch = UnitHelper.tryToParseFloat(this.getArg(1));
|
||||
}
|
||||
|
||||
MathHelper.clampAngleTo360(this.targetRotationPitch);
|
||||
MathHelper.clampAngleTo360(this.targetRotationYaw);
|
||||
|
||||
return true;
|
||||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
|
@ -53,7 +58,7 @@ public class CommandRotateTo extends Command
|
|||
this.currentRotationPitch = (float) this.armbot.getRotation().y;
|
||||
this.armbot.moveArmTo(this.targetRotationYaw, this.targetRotationPitch);
|
||||
|
||||
return Math.abs(this.currentRotationPitch - this.targetRotationPitch) > 0.01f && Math.abs(this.currentRotationYaw - this.targetRotationYaw) > 0.01f;
|
||||
return Math.abs(this.currentRotationPitch - this.targetRotationPitch) > 0.01f && Math.abs(this.currentRotationYaw - this.targetRotationYaw) > 0.01f ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +68,7 @@ public class CommandRotateTo extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound taskCompound)
|
||||
public TaskBase loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
|
||||
|
@ -81,7 +86,7 @@ public class CommandRotateTo extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandRotateTo();
|
||||
}
|
||||
|
|
|
@ -6,16 +6,23 @@ import java.util.List;
|
|||
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 dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.assembly.common.machine.InvInteractionHelper;
|
||||
|
||||
public class CommandTake extends Command
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.machine.InvInteractionHelper;
|
||||
import dark.core.prefab.helpers.MathHelper;
|
||||
|
||||
public class CommandTake extends TaskArmbot
|
||||
{
|
||||
|
||||
private ItemStack stack;
|
||||
protected ItemStack stack;
|
||||
protected int ammount = -1;
|
||||
|
||||
public CommandTake()
|
||||
{
|
||||
|
@ -23,76 +30,54 @@ public class CommandTake extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
int id = 0;
|
||||
int meta = 32767;
|
||||
int count = 1;
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
if (this.getArgs().length > 0)
|
||||
{
|
||||
String block = this.getArg(0);
|
||||
if (block.contains(":"))
|
||||
{
|
||||
String[] blockID = block.split(":");
|
||||
id = Integer.parseInt(blockID[0]);
|
||||
meta = Integer.parseInt(blockID[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
id = Integer.parseInt(block);
|
||||
}
|
||||
}
|
||||
if (this.getArgs().length > 1)
|
||||
{
|
||||
count = this.getIntArg(1);
|
||||
}
|
||||
if (id == 0)
|
||||
{
|
||||
stack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack = new ItemStack(id, count, meta);
|
||||
}
|
||||
ammount = UnitHelper.tryToParseInt(this.getArg(1), -1);
|
||||
|
||||
stack = this.getItem(this.getArg(0), ammount == -1 ? 1 : ammount);
|
||||
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onUpdate()
|
||||
public ProcessReturn onUpdate()
|
||||
{
|
||||
TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.worldObj);
|
||||
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
|
||||
|
||||
if (targetTile != null && this.tileEntity.getGrabbedItems().size() <= 0)
|
||||
if (targetTile != null && this.armbot.getGrabbedObjects().size() <= 0)
|
||||
{
|
||||
ForgeDirection direction = this.tileEntity.getFacingDirectionFromAngle();
|
||||
ForgeDirection direction = MathHelper.getFacingDirectionFromAngle(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);
|
||||
this.tileEntity.grabItem(invEx.tryGrabFromPosition(new Vector3(targetTile), direction, this.stack != null ? stack.stackSize : 1));
|
||||
return !(this.tileEntity.getGrabbedItems().size() > 0);
|
||||
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.armbotPos, stacks, false);
|
||||
this.armbot.grab(invEx.tryGrabFromPosition(new Vector3(targetTile), direction, this.stack != null ? stack.stackSize : 1));
|
||||
return this.armbot.getGrabbedObjects().size() > 0 ? ProcessReturn.DONE : ProcessReturn.CONTINUE;
|
||||
|
||||
}
|
||||
return true;
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Take " + (stack != null ? stack.toString() : "1x???@??? ");
|
||||
return super.toString() + " " + (stack != null ? stack.toString() : "1x???@??? ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadProgress(NBTTagCompound taskCompound)
|
||||
public CommandTake load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProgress(NBTTagCompound taskCompound)
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
if (stack != null)
|
||||
|
@ -101,5 +86,12 @@ public class CommandTake extends Command
|
|||
this.stack.writeToNBT(tag);
|
||||
taskCompound.setTag("item", tag);
|
||||
}
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandTake();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import dark.api.al.armbot.Command;
|
||||
import net.minecraft.world.World;
|
||||
import dark.api.al.armbot.IArmbotUseable;
|
||||
import dark.api.al.armbot.IArmbotTask.TaskType;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
||||
public class CommandUse extends Command
|
||||
public class CommandUse extends TaskArmbot
|
||||
{
|
||||
|
||||
private int times;
|
||||
|
@ -19,7 +24,7 @@ public class CommandUse extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
this.times = 0;
|
||||
this.curTimes = 0;
|
||||
|
@ -34,7 +39,7 @@ public class CommandUse extends Command
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean onUpdate()
|
||||
public boolean onUpdate()
|
||||
{
|
||||
Block block = Block.blocksList[this.worldObj.getBlockId(tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ())];
|
||||
TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.worldObj);
|
||||
|
|
|
@ -2,23 +2,24 @@ package dark.assembly.common.armbot.command;
|
|||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.api.al.armbot.IArmbotTask;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask;
|
||||
import dark.api.al.armbot.ISplitArmbotTask;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
||||
public class CommandIF extends Command implements ISplitArmbotTask
|
||||
public class TaskIF extends TaskBase implements ISplitArmbotTask
|
||||
{
|
||||
protected IArmbotTask entryPoint = null;
|
||||
protected IArmbotTask exitTruePoint = null;
|
||||
protected IArmbotTask exitFalsePoint = null;
|
||||
protected IDeviceTask entryPoint = null;
|
||||
protected IDeviceTask exitTruePoint = null;
|
||||
protected IDeviceTask exitFalsePoint = null;
|
||||
protected boolean isTrue = false;
|
||||
|
||||
public CommandIF()
|
||||
public TaskIF()
|
||||
{
|
||||
super("IF", TaskType.DECISION);
|
||||
}
|
||||
|
||||
public CommandIF(IArmbotTask entryPoint, IArmbotTask trueExit, IArmbotTask falseExit)
|
||||
public TaskIF(IDeviceTask entryPoint, IDeviceTask trueExit, IDeviceTask falseExit)
|
||||
{
|
||||
this();
|
||||
this.setEntryPoint(this.entryPoint);
|
||||
|
@ -28,19 +29,19 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command clone()
|
||||
public TaskBase clone()
|
||||
{
|
||||
return new CommandIF(this.entryPoint, this.exitTruePoint, this.exitFalsePoint);
|
||||
return new TaskIF(this.entryPoint, this.exitTruePoint, this.exitFalsePoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArmbotTask getEntryPoint()
|
||||
public IDeviceTask getEntryPoint()
|
||||
{
|
||||
return this.entryPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArmbotTask getExitPoint()
|
||||
public IDeviceTask getExitPoint()
|
||||
{
|
||||
if (this.isTrue)
|
||||
{
|
||||
|
@ -56,21 +57,21 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public ISplitArmbotTask setEntryPoint(IArmbotTask task)
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task)
|
||||
{
|
||||
this.entryPoint = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExitPoint(IArmbotTask task)
|
||||
public void addExitPoint(IDeviceTask task)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command loadProgress(NBTTagCompound nbt)
|
||||
public TaskBase loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
super.loadProgress(nbt);
|
||||
this.entryPoint = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY"))));
|
||||
|
@ -101,4 +102,10 @@ public class CommandIF extends Command implements ISplitArmbotTask
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
103
src/minecraft/dark/assembly/common/armbot/command/TaskLoop.java
Normal file
103
src/minecraft/dark/assembly/common/armbot/command/TaskLoop.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
package dark.assembly.common.armbot.command;
|
||||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.armbot.ILogicDevice;
|
||||
import dark.api.al.armbot.IDeviceTask;
|
||||
import dark.api.al.armbot.IDeviceTask.TaskType;
|
||||
import dark.api.al.armbot.ISplitArmbotTask;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Basic While loop that mainly handles number of repeats.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
||||
{
|
||||
protected int numReps = -1;
|
||||
protected IDeviceTask entry, exit;
|
||||
|
||||
public TaskLoop()
|
||||
{
|
||||
super("repeat", TaskType.DECISION);
|
||||
}
|
||||
|
||||
public TaskLoop(IDeviceTask entry, IDeviceTask exit)
|
||||
{
|
||||
this();
|
||||
this.entry = entry;
|
||||
this.exit = exit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.numReps = UnitHelper.tryToParseInt(this.getArg(0), -1);
|
||||
return ProcessReturn.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getEntryPoint()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getExitPoint()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxExitPoints()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISplitArmbotTask setEntryPoint(IDeviceTask task)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExitPoint(IDeviceTask task)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBase clone()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask loadProgress(NBTTagCompound nbt)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound saveProgress(NBTTagCompound nbt)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dark.api.al.armbot.Command;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
||||
public class TileEntityEncoder extends TileEntityAdvanced implements IPacketReceiver, ISidedInventory
|
||||
{
|
||||
|
@ -169,7 +169,7 @@ public class TileEntityEncoder extends TileEntityAdvanced implements IPacketRece
|
|||
// Split commands that contains parameters
|
||||
String commandName = newCommand.split(" ")[0];
|
||||
|
||||
if (Command.getCommand(commandName) != null)
|
||||
if (TaskBase.getCommand(commandName) != null)
|
||||
tempCmds.add(newCommand);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue