Most likely broke a few things
Was working on getting edits to task to save when i decided to redo arguments. I have yet to fully test the changes so things might be broken.
This commit is contained in:
parent
fad9b46b4d
commit
c04830ebc4
22 changed files with 174 additions and 191 deletions
|
@ -1,20 +1,23 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
|
||||
/** The IUseable inteface is used by the ArmBot so that it may interact with Tile Entities. onUse
|
||||
* will be called on the block an ArmBot is touching whenever the USE command is run on it.
|
||||
*
|
||||
*
|
||||
* @author Briman0094 */
|
||||
public interface IArmbotUseable
|
||||
{
|
||||
|
||||
/** Called when the ArmBot command "USE" is run. This is called on any IUseable the ArmBot is
|
||||
* touching.
|
||||
*
|
||||
*
|
||||
* @param armbot - The Armbot instance.
|
||||
*
|
||||
*
|
||||
* @return true if the use was completed correctly */
|
||||
public boolean onUse(IArmbot armbot, HashMap<String, Object> hashMap);
|
||||
public boolean onUse(IArmbot armbot, List<ArgumentData> list);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.save.ISaveObj;
|
||||
|
||||
/** @author DarkGuardsman */
|
||||
public interface ITask extends Cloneable
|
||||
public interface ITask extends Cloneable, ISaveObj
|
||||
{
|
||||
/** Called each time the program is loaded or changed */
|
||||
public void refresh();
|
||||
|
@ -35,25 +36,13 @@ public interface ITask extends Cloneable
|
|||
/** Type of task used mainly for GUI displays */
|
||||
public TaskType getType();
|
||||
|
||||
/** ArgumentData used to both restrict and set values into the argument hashmap. As tells the
|
||||
* encoder what varables that the user has access to */
|
||||
public List<ArgumentData> getEncoderParms();
|
||||
|
||||
/** Get an argument by a given name */
|
||||
public Object getArg(String name);
|
||||
|
||||
/** Get all given arguments */
|
||||
public HashMap<String, Object> getArgs();
|
||||
public List<ArgumentData> getArgs();
|
||||
|
||||
/** Get all given arguments */
|
||||
public void setArgs(HashMap<String, Object> args);
|
||||
|
||||
/** Read the command from the armbot save. */
|
||||
public ITask 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);
|
||||
public void setArg(String arg, Object data);
|
||||
|
||||
/** Reads the progress of the command if it was saved mid process */
|
||||
public ITask loadProgress(NBTTagCompound nbt);
|
||||
|
@ -70,8 +59,9 @@ public interface ITask extends Cloneable
|
|||
* the TaskRegistry */
|
||||
public ITask clone();
|
||||
|
||||
/** Texture to be used make sure to use a reference as creating a new one each call with memory
|
||||
* leak the game */
|
||||
/** Texture used by encoder's to render the icon for the task. Make sure not to create a new
|
||||
* instance of the resource location each call. Doing so will cause the client to experience
|
||||
* increase RAM usage */
|
||||
public ResourceLocation getTextureSheet();
|
||||
|
||||
/** Location of the texture in the sheet */
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
package dark.api.al.coding.args;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.save.ISaveObj;
|
||||
import dark.api.save.NBTFileHelper;
|
||||
import dark.api.save.SaveManager;
|
||||
|
||||
/** Used to store arguments in a way that can be easier to read, limit, and understand
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ArgumentData
|
||||
public class ArgumentData implements ISaveObj
|
||||
{
|
||||
protected String name;
|
||||
protected Object storedValue;
|
||||
protected Object currentValue;
|
||||
protected final Object defaultValue;
|
||||
|
||||
public ArgumentData(String name, Object object)
|
||||
public ArgumentData(String name, Object defaultValue)
|
||||
{
|
||||
this.name = name;
|
||||
this.storedValue = object;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/** Sets the value
|
||||
|
@ -21,7 +27,7 @@ public class ArgumentData
|
|||
{
|
||||
if (this.isValid(object))
|
||||
{
|
||||
this.storedValue = object;
|
||||
this.currentValue = object;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -30,7 +36,7 @@ public class ArgumentData
|
|||
/** Gets the value of the stored data */
|
||||
public Object getData()
|
||||
{
|
||||
return this.storedValue;
|
||||
return this.currentValue;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
|
@ -46,8 +52,7 @@ public class ArgumentData
|
|||
/** Is this argument valid. */
|
||||
public boolean isValid()
|
||||
{
|
||||
//Null is invalide since the object is used to understand data types. Without data the encoder can't use the value and will remove it
|
||||
return storedValue != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Used by things like a gui to give a warning such as limits of data this can accept */
|
||||
|
@ -55,4 +60,17 @@ public class ArgumentData
|
|||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
NBTFileHelper.saveObject(nbt, "ObjectData", this.currentValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
this.currentValue = NBTFileHelper.loadObject(nbt, "ObjectData");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dark.api.al.coding.args;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
|
||||
/** Used to create argument data for the encoder. Should only be used if the value needs to be
|
||||
|
@ -20,7 +21,12 @@ public class ArgumentDoubleData extends ArgumentData
|
|||
@Override
|
||||
public boolean isValid(Object object)
|
||||
{
|
||||
return super.isValid() && object instanceof Double && ((Double) object) >= min && ((Double) object) <= max;
|
||||
if (super.isValid())
|
||||
{
|
||||
double value = MathHelper.parseDoubleWithDefault("" + object, min - 100);
|
||||
return value != min - 100 && value >= min && value <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dark.api.al.coding.args;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
|
||||
/** Used to create argument data for the encoder. Should only be used if the value needs to be
|
||||
|
@ -20,7 +21,12 @@ public class ArgumentFloatData extends ArgumentData
|
|||
@Override
|
||||
public boolean isValid(Object object)
|
||||
{
|
||||
return super.isValid() && object instanceof Float && ((Float) object) >= min && ((Float) object) <= max;
|
||||
if (super.isValid())
|
||||
{
|
||||
float value = (float) MathHelper.parseDoubleWithDefault("" + object, min - 100);
|
||||
return value != min - 100 && value >= min && value <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package dark.api.al.coding.args;
|
||||
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/** Used to create argument data for the encoder. Should only be used if the value needs to be
|
||||
* clearly limited inside the encoder display.
|
||||
|
@ -20,7 +20,12 @@ public class ArgumentIntData extends ArgumentData
|
|||
@Override
|
||||
public boolean isValid(Object object)
|
||||
{
|
||||
return super.isValid() && object instanceof Integer && ((Integer) object) >= min && ((Integer) object) <= max;
|
||||
if (super.isValid())
|
||||
{
|
||||
int value = MathHelper.parseIntWithDefault("" + object, min - 100);
|
||||
return value != min - 100 && value >= min && value <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -207,11 +207,7 @@ public class Program implements IProgram
|
|||
{
|
||||
if (this.currentTask != null)
|
||||
{
|
||||
NBTTagCompound tag = this.currentTask.save(new NBTTagCompound());
|
||||
this.currentTask = TaskRegistry.getCommand(this.currentTask.getMethodName()).clone();
|
||||
this.currentTask.load(tag);
|
||||
this.setTaskAt(this.currentTask.getCol(), this.currentTask.getRow(), this.currentTask);
|
||||
this.currentTask = null;
|
||||
this.currentTask.reset();
|
||||
}
|
||||
this.currentPos = new Vector2(0, 0);
|
||||
}
|
||||
|
@ -247,7 +243,8 @@ public class Program implements IProgram
|
|||
for (Entry<Vector2, ITask> entry : this.tasks.entrySet())
|
||||
{
|
||||
entry.getValue().setPosition(entry.getKey().intX(), entry.getKey().intY());
|
||||
NBTTagCompound task = entry.getValue().save(new NBTTagCompound());
|
||||
NBTTagCompound task = new NBTTagCompound();
|
||||
entry.getValue().save(task);
|
||||
if (this.currentTask != null && entry.getKey().equals(new Vector2(this.currentTask.getCol(), this.currentTask.getRow())))
|
||||
{
|
||||
task.setBoolean("currentTask", true);
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.Map.Entry;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import dark.api.al.coding.IMemorySlot;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.IProgrammableMachine;
|
||||
import dark.api.al.coding.ITask;
|
||||
|
@ -16,7 +15,7 @@ import dark.api.al.coding.args.ArgumentData;
|
|||
import dark.api.save.NBTFileHelper;
|
||||
|
||||
/** @author DarkGuardsman */
|
||||
public abstract class TaskBase implements ITask, IMemorySlot
|
||||
public abstract class TaskBase implements ITask
|
||||
{
|
||||
/** Program this is part of. Can be null while stores as a prefab waiting to be copied */
|
||||
protected IProgram program;
|
||||
|
@ -32,9 +31,7 @@ public abstract class TaskBase implements ITask, IMemorySlot
|
|||
protected Vector2 UV;
|
||||
|
||||
/** The parameters this command */
|
||||
protected HashMap<String, Object> aruguments = new HashMap<String, Object>();
|
||||
protected List<ArgumentData> defautlArguments = new ArrayList<ArgumentData>();
|
||||
protected HashMap<String, Object> activeMemory = new HashMap<String, Object>();
|
||||
protected List<ArgumentData> args = new ArrayList<ArgumentData>();
|
||||
|
||||
public TaskBase(String name, TaskType tasktype)
|
||||
{
|
||||
|
@ -52,25 +49,7 @@ public abstract class TaskBase implements ITask, IMemorySlot
|
|||
@Override
|
||||
public void reset()
|
||||
{
|
||||
this.activeMemory.clear();
|
||||
}
|
||||
|
||||
@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
|
||||
|
@ -113,91 +92,78 @@ public abstract class TaskBase implements ITask, IMemorySlot
|
|||
@Override
|
||||
public Object getArg(String name)
|
||||
{
|
||||
if (this.getArgs().containsKey(name))
|
||||
if (this.getArgs() != null)
|
||||
{
|
||||
return this.getArgs().get(name);
|
||||
for (ArgumentData arg : this.getArgs())
|
||||
{
|
||||
if (arg.getName().equalsIgnoreCase(name))
|
||||
{
|
||||
return arg.getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArg(String argName, Object obj)
|
||||
{
|
||||
if (this.getArgs() != null && this.getArgs().containsKey(argName))
|
||||
if (this.getArgs() != null)
|
||||
{
|
||||
this.getArgs().put(argName, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArgs(HashMap<String, Object> args)
|
||||
{
|
||||
if (this.aruguments == null)
|
||||
{
|
||||
this.aruguments = new HashMap();
|
||||
}
|
||||
this.aruguments = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getArgs()
|
||||
{
|
||||
if (this.aruguments == null)
|
||||
{
|
||||
this.aruguments = new HashMap();
|
||||
if (this.defautlArguments != null && !this.defautlArguments.isEmpty())
|
||||
for (ArgumentData arg : this.getArgs())
|
||||
{
|
||||
for (ArgumentData obj : this.defautlArguments)
|
||||
if (arg.getName().equalsIgnoreCase(argName))
|
||||
{
|
||||
this.aruguments.put(obj.getName(), obj.getData());
|
||||
arg.setData(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.aruguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArgumentData> getEncoderParms()
|
||||
public List<ArgumentData> getArgs()
|
||||
{
|
||||
return this.defautlArguments;
|
||||
return this.args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract TaskBase clone();
|
||||
|
||||
@Override
|
||||
public TaskBase load(NBTTagCompound nbt)
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
this.col = nbt.getInteger("col");
|
||||
this.row = nbt.getInteger("row");
|
||||
if (this.getEncoderParms() != null)
|
||||
System.out.println("\nLoading task data");
|
||||
if (this.getArgs() != null)
|
||||
{
|
||||
this.aruguments = new HashMap();
|
||||
NBTTagCompound parms = nbt.getCompoundTag("args");
|
||||
for (ArgumentData arg : this.getEncoderParms())
|
||||
for (ArgumentData arg : this.getArgs())
|
||||
{
|
||||
System.out.println("Loading data for " + arg.getName());
|
||||
Object obj = NBTFileHelper.loadObject(parms, arg.getName());
|
||||
if (arg.isValid(obj))
|
||||
{
|
||||
this.aruguments.put(arg.getName(), obj);
|
||||
System.out.println("data is valid " + obj.toString());
|
||||
arg.setData(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
|
||||
System.out.println("\nSaving task data");
|
||||
nbt.setInteger("col", this.col);
|
||||
nbt.setInteger("row", this.row);
|
||||
NBTTagCompound parms = new NBTTagCompound();
|
||||
for (Entry<String, Object> entry : this.aruguments.entrySet())
|
||||
for (ArgumentData arg : this.getArgs())
|
||||
{
|
||||
NBTFileHelper.saveObject(parms, entry.getKey(), entry.getValue());
|
||||
NBTFileHelper.saveObject(parms, arg.getName(), arg.getData());
|
||||
}
|
||||
nbt.setCompoundTag("args", parms);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TaskFire extends TaskBaseArmbot
|
|||
public TaskFire()
|
||||
{
|
||||
super("throw");
|
||||
this.defautlArguments.add(new ArgumentFloatData("velocity", 1.0f, 2.5f, 1.0f));
|
||||
this.args.add(new ArgumentFloatData("velocity", 1.0f, 2.5f, 1.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,15 +85,14 @@ public class TaskGOTO extends TaskBase implements IRedirectTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskGOTO load(NBTTagCompound nbt)
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.loadProgress(nbt);
|
||||
this.taskPos = new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY")));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.saveProgress(nbt);
|
||||
if (this.task != null)
|
||||
|
@ -101,7 +100,6 @@ public class TaskGOTO extends TaskBase implements IRedirectTask
|
|||
nbt.setDouble("entryX", this.task.getCol());
|
||||
nbt.setDouble("entryY", this.task.getRow());
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,9 +30,9 @@ public class TaskGive extends TaskBaseArmbot
|
|||
public TaskGive()
|
||||
{
|
||||
super("give");
|
||||
this.defautlArguments.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
this.args.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.args.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.args.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
this.UV = new Vector2(60, 80);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class TaskGrabEntity extends TaskGrabPrefab
|
|||
public TaskGrabEntity()
|
||||
{
|
||||
super("Grab-Entity");
|
||||
this.defautlArguments.add(new ArgumentData("child", false));
|
||||
this.args.add(new ArgumentData("child", false));
|
||||
//this.defautlArguments.add(new ArgumentListData<Class<? extends Entity>>("Entity", Entity.class, (Class<? extends Entity>[]) EntityDictionary.getList().toArray(new Object[1])));
|
||||
}
|
||||
|
||||
|
@ -91,21 +91,19 @@ public class TaskGrabEntity extends TaskGrabPrefab
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskBaseProcess load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.child = taskCompound.getBoolean("child");
|
||||
this.entityToInclude = EntityDictionary.get(taskCompound.getString("name"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setBoolean("child", child);
|
||||
taskCompound.setString("name", ((this.entityToInclude != null) ? EntityDictionary.get(this.entityToInclude) : ""));
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,9 +20,9 @@ public class TaskGrabItem extends TaskGrabPrefab
|
|||
public TaskGrabItem()
|
||||
{
|
||||
super("Grab-Item");
|
||||
this.defautlArguments.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
this.args.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.args.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.args.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,8 +21,8 @@ public class TaskIF extends TaskBaseLogic
|
|||
public TaskIF()
|
||||
{
|
||||
super("IF");
|
||||
this.defautlArguments.add(new ArgumentData("check", "statement"));
|
||||
this.defautlArguments.add(new ArgumentData("compare", "statement"));
|
||||
this.args.add(new ArgumentData("check", "statement"));
|
||||
this.args.add(new ArgumentData("compare", "statement"));
|
||||
this.UV = new Vector2(0, 120);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class TaskIdle extends TaskBaseProcess
|
|||
public TaskIdle()
|
||||
{
|
||||
super("wait");
|
||||
this.defautlArguments.add(new ArgumentData("idleTime", 20));
|
||||
this.args.add(new ArgumentData("idleTime", 20));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,19 +52,17 @@ public class TaskIdle extends TaskBaseProcess
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskBaseProcess load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.load(taskCompound);
|
||||
this.totalIdleTime = taskCompound.getInteger("idleTotal");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("idleTotal", this.totalIdleTime);
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,8 +26,8 @@ public class TaskRotateBy extends TaskBaseArmbot
|
|||
public TaskRotateBy()
|
||||
{
|
||||
super("RotateBy");
|
||||
this.defautlArguments.add(new ArgumentIntData("yaw", 0, 360, 0));
|
||||
this.defautlArguments.add(new ArgumentIntData("pitch", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("yaw", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("pitch", 0, 360, 0));
|
||||
this.UV = new Vector2(80, 80);
|
||||
}
|
||||
|
||||
|
@ -58,21 +58,21 @@ public class TaskRotateBy extends TaskBaseArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskRotateBy load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
|
||||
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
|
||||
return taskCompound;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,8 +23,8 @@ public class TaskRotateTo extends TaskBaseArmbot
|
|||
public TaskRotateTo()
|
||||
{
|
||||
super("RotateTo");
|
||||
this.defautlArguments.add(new ArgumentIntData("yaw", 0, 360, 0));
|
||||
this.defautlArguments.add(new ArgumentIntData("pitch", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("yaw", 0, 360, 0));
|
||||
this.args.add(new ArgumentIntData("pitch", 0, 360, 0));
|
||||
this.UV = new Vector2(100, 80);
|
||||
}
|
||||
|
||||
|
@ -70,21 +70,19 @@ public class TaskRotateTo extends TaskBaseArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskRotateTo load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.load(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
|
||||
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,9 +29,9 @@ public class TaskTake extends TaskBaseArmbot
|
|||
public TaskTake()
|
||||
{
|
||||
super("Take");
|
||||
this.defautlArguments.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.defautlArguments.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
this.args.add(new ArgumentIntData("blockID", -1, Block.blocksList.length - 1, -1));
|
||||
this.args.add(new ArgumentIntData("blockMeta", -1, 15, -1));
|
||||
this.args.add(new ArgumentIntData("stackSize", -1, 64, -1));
|
||||
this.UV = new Vector2(40, 80);
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,15 @@ public class TaskTake extends TaskBaseArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskTake load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.load(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.save(taskCompound);
|
||||
if (stack != null)
|
||||
|
@ -103,7 +103,7 @@ public class TaskTake extends TaskBaseArmbot
|
|||
this.stack.writeToNBT(tag);
|
||||
taskCompound.setTag("item", tag);
|
||||
}
|
||||
return taskCompound;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,7 @@ public class TaskUse extends TaskBaseArmbot
|
|||
public TaskUse()
|
||||
{
|
||||
super("use");
|
||||
this.defautlArguments.add(new ArgumentIntData("repeat", 1, Integer.MAX_VALUE, 1));
|
||||
this.args.add(new ArgumentIntData("repeat", 1, Integer.MAX_VALUE, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,21 +87,17 @@ public class TaskUse extends TaskBaseArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public TaskUse load(NBTTagCompound taskCompound)
|
||||
public void load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.load(taskCompound);
|
||||
this.times = taskCompound.getInteger("useTimes");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
public void save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("useTimes", this.times);
|
||||
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package dark.assembly.client.gui;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
@ -38,7 +39,9 @@ public class GuiEditTask extends GuiBase implements IMessageBoxDialog
|
|||
this.gui = gui;
|
||||
this.task = task;
|
||||
this.editTask = task.clone();
|
||||
this.editTask.load(task.save(new NBTTagCompound()));
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
task.save(nbt);
|
||||
this.editTask.load(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,26 +63,17 @@ public class GuiEditTask extends GuiBase implements IMessageBoxDialog
|
|||
|
||||
this.buttonList.add(new GuiButton(2, (this.width - this.guiSize.intX()) / 2 + 125, (this.height - this.guiSize.intY()) / 2 + 135, 40, 20, "Del"));
|
||||
|
||||
HashMap<String, Object> args = task.getArgs();
|
||||
List<ArgumentData> eArgs = task.getEncoderParms();
|
||||
|
||||
if (eArgs != null && !eArgs.isEmpty())
|
||||
if (task.getArgs() != null)
|
||||
{
|
||||
this.argTextBoxes = new GuiTextField[eArgs.size()];
|
||||
for (int i = 0; i < this.argTextBoxes.length; i++)
|
||||
this.argTextBoxes = new GuiTextField[task.getArgs().size()];
|
||||
int i = 0;
|
||||
for (ArgumentData arg : task.getArgs())
|
||||
{
|
||||
ArgumentData arg = eArgs.get(i);
|
||||
this.argTextBoxes[i] = new GuiTextField(this.fontRenderer, (this.width - this.guiSize.intX()) / 2 + 60, (this.height - this.guiSize.intY()) / 2 + 64 + (i * this.ySpacing), 30, 10);
|
||||
this.argTextBoxes[i].setMaxStringLength(30);
|
||||
this.argTextBoxes[i].setVisible(true);
|
||||
if (args.containsKey(arg.getName()))
|
||||
{
|
||||
this.argTextBoxes[i].setText("" + args.get(arg.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.argTextBoxes[i].setText("" + arg.getData());
|
||||
}
|
||||
this.argTextBoxes[i].setText("" + arg.getData());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +151,24 @@ public class GuiEditTask extends GuiBase implements IMessageBoxDialog
|
|||
|
||||
if (button.id == 0)
|
||||
{
|
||||
if (this.argTextBoxes != null)
|
||||
{
|
||||
int i = 0;
|
||||
for (ArgumentData arg : task.getArgs())
|
||||
{
|
||||
if (this.argTextBoxes[i] != null)
|
||||
{
|
||||
if (arg.isValid(this.argTextBoxes[i].getText()))
|
||||
{
|
||||
editTask.setArg(arg.getName(), this.argTextBoxes[i].getText());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.argTextBoxes[i].setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.gui.getTile().updateTask(this.editTask);
|
||||
}
|
||||
FMLCommonHandler.instance().showGuiScreen(this.gui);
|
||||
|
@ -198,17 +210,15 @@ public class GuiEditTask extends GuiBase implements IMessageBoxDialog
|
|||
this.fontRenderer.drawString("Task: " + "\u00a77" + this.task.getMethodName(), (int) ((this.guiSize.intX() / 2) - 70), 20, 4210752);
|
||||
this.fontRenderer.drawString("----Task Arguments---- ", (int) ((this.guiSize.intX() / 2) - 70), 50, 4210752);
|
||||
|
||||
HashMap<String, Object> args = task.getArgs();
|
||||
List<ArgumentData> eArgs = task.getEncoderParms();
|
||||
|
||||
if (eArgs != null && !eArgs.isEmpty())
|
||||
int i = 0;
|
||||
if (task.getArgs() != null)
|
||||
{
|
||||
int i = 0;
|
||||
for (ArgumentData arg : eArgs)
|
||||
for (ArgumentData arg : task.getArgs())
|
||||
{
|
||||
i++;
|
||||
this.fontRenderer.drawString(arg.getName() + ":", (int) ((this.guiSize.intX() / 2) - 70), 45 + (i * this.ySpacing), 4210752);
|
||||
this.fontRenderer.drawString(arg.warning(), (int) ((this.guiSize.intX() / 2) + 11), 45 + (i * this.ySpacing), 4210752);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package dark.assembly.imprinter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -27,6 +27,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IArmbotUseable;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.events.AutoCraftEvent;
|
||||
import dark.core.common.DarkMain;
|
||||
import dark.core.helpers.AutoCraftingManager;
|
||||
|
@ -192,7 +193,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
}
|
||||
|
||||
/** Construct an InventoryCrafting Matrix on the fly.
|
||||
*
|
||||
*
|
||||
* @return */
|
||||
public InventoryCrafting getCraftingMatrix()
|
||||
{
|
||||
|
@ -389,7 +390,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
|
|||
|
||||
/** Tries to let the Armbot craft an item. */
|
||||
@Override
|
||||
public boolean onUse(IArmbot armbot, HashMap<String, Object> hashMap)
|
||||
public boolean onUse(IArmbot armbot, List<ArgumentData> data)
|
||||
{
|
||||
this.onInventoryChanged();
|
||||
|
||||
|
|
|
@ -52,16 +52,6 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
{
|
||||
program = new Program();
|
||||
program.setTaskAt(0, 0, new TaskRotateTo());
|
||||
program.setTaskAt(0, 1, new TaskDrop());
|
||||
program.setTaskAt(0, 2, new TaskRotateTo());
|
||||
program.setTaskAt(0, 3, new TaskGrabItem());
|
||||
program.setTaskAt(0, 4, new TaskIF());
|
||||
program.setTaskAt(0, 5, new TaskRotateTo());
|
||||
program.setTaskAt(0, 6, new TaskGive());
|
||||
|
||||
program.setTaskAt(1, 4, new TaskRotateTo());
|
||||
program.setTaskAt(1, 5, new TaskGive());
|
||||
program.setTaskAt(1, 6, new TaskGOTO(0, 6));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,18 +144,18 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
{
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_CHANGE_PACKET_ID))
|
||||
{
|
||||
|
||||
System.out.println("Update task packet");
|
||||
ITask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
task.setPosition(dis.readInt(), dis.readInt());
|
||||
task.load(PacketManager.readNBTTagCompound(dis));
|
||||
this.program.setTaskAt(task.getCol(), task.getRow(), task);
|
||||
task.load(PacketHandler.instance().readNBTTagCompound(dis));
|
||||
this.getProgram().setTaskAt(task.getCol(), task.getRow(), task);
|
||||
this.sendGUIPacket();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (id.equalsIgnoreCase(TileEntityEncoder.REMOVE_TASK_PACKET_ID))
|
||||
{
|
||||
this.program.setTaskAt(dis.readInt(), dis.readInt(), null);
|
||||
this.getProgram().setTaskAt(dis.readInt(), dis.readInt(), null);
|
||||
this.sendGUIPacket();
|
||||
return true;
|
||||
}
|
||||
|
@ -220,11 +210,14 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
|
||||
public void updateTask(ITask editTask)
|
||||
{
|
||||
|
||||
if (editTask != null)
|
||||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, TileEntityEncoder.PROGRAM_CHANGE_PACKET_ID, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), editTask.save(new NBTTagCompound())));
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
editTask.save(nbt);
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, TileEntityEncoder.PROGRAM_CHANGE_PACKET_ID, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue