Cleared out all command and armbot errors

This doesn't mean it works but simple there are no errors from the
editor. I'll still need to spend the next few days check if everything
works. As well i still need to fix and recode the encoder.
This commit is contained in:
DarkGuardsman 2013-10-17 05:34:13 -04:00
parent 83dbce4e13
commit 5cc68a4720
25 changed files with 639 additions and 468 deletions

View file

@ -40,6 +40,9 @@ public interface IArmbot extends Cloneable, ILogicDevice
* @return - true if the bot dropped the item */
public boolean drop(Object object);
/** Same as deleting the object */
public boolean clear(Object object);
/** Object currently held. In some cases this can be a list or array but is suggest to only be
* one object */
public Object getGrabbedObject();

View file

@ -1,19 +1,21 @@
package dark.api.al.coding;
import java.util.HashMap;
/** 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, String[] args);
public boolean onUse(IArmbot armbot, HashMap<String, Object> hashMap);
}

View file

@ -76,7 +76,7 @@ public class ProgramHelper
this.nextTask = false;
}
public ProgramHelper(int varableLimit)
public ProgramHelper setMemory(int varableLimit)
{
if (varableLimit > 0)
{
@ -87,6 +87,7 @@ public class ProgramHelper
{
this.taskMemory = null;
}
return this;
}
public ProgramHelper setProgram(IProgram program)
@ -96,6 +97,11 @@ public class ProgramHelper
return this;
}
public IProgram getProgram()
{
return this.program;
}
public void onProgramChanged()
{
this.taskMemory.clear();

View file

@ -0,0 +1,13 @@
package dark.api.al.coding.args;
import net.minecraft.entity.Entity;
public class ArgumentEntityList extends ArgumentListData<Class< ? extends Entity>>
{
public ArgumentEntityList(String name, Object defaultvalue, Class<? extends Entity>... object)
{
super(name, defaultvalue, object);
}
}

View file

@ -0,0 +1,20 @@
package dark.api.al.coding.args;
/** Used to store lists of data that the user can scroll threw to select one.
*
* @author DarkGuardsman */
public class ArgumentListData<O> extends ArgumentData
{
protected O[] options;
public ArgumentListData(String name, Object defaultvalue, O... object)
{
super(name, defaultvalue);
this.options = object;
}
public O[] getOptions()
{
return options;
}
}

View file

@ -41,7 +41,7 @@ public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
protected World worldObj;
/** Armbot location */
protected Vector3 armbotPos;
protected Vector3 devicePos;
/** Position in the coder is also used during loading to place everything together */
protected Vector2 pos;
@ -69,10 +69,10 @@ public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
if (location != null && armbotPos != null)
if (location != null && devicePos != null)
{
this.worldObj = world;
this.armbotPos = location;
this.devicePos = location;
return ProcessReturn.CONTINUE;
}
@ -83,7 +83,7 @@ public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice armbot, IComputerAccess computer, ILuaContext context) throws Exception
{
this.worldObj = world;
this.armbotPos = location;
this.devicePos = location;
return null;
}

View file

@ -1,7 +1,6 @@
package dark.assembly.common.armbot;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.Entity;
@ -10,7 +9,6 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
@ -28,14 +26,9 @@ import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
import dark.api.al.coding.IArmbot;
import dark.api.al.coding.IProgram;
import dark.api.al.coding.ProgramHelper;
import dark.assembly.common.AssemblyLine;
import dark.assembly.common.armbot.command.CommandDrop;
import dark.assembly.common.armbot.command.CommandFire;
import dark.assembly.common.armbot.command.CommandGrab;
import dark.assembly.common.armbot.command.CommandReturn;
import dark.assembly.common.armbot.command.CommandRotateBy;
import dark.assembly.common.armbot.command.CommandRotateTo;
import dark.assembly.common.armbot.command.CommandUse;
import dark.assembly.common.machine.TileEntityAssembly;
import dark.assembly.common.machine.encoder.ItemDisk;
import dark.core.common.DarkMain;
@ -47,34 +40,28 @@ import dark.core.prefab.machine.BlockMulti;
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IArmbot, IPeripheral
{
protected List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
/** The rotation of the arms. In Degrees. */
protected float rotationPitch = 0;
protected float rotationYaw = 0;
public float actualPitch = 0;
public float actualYaw = 0;
protected final float ROTATION_SPEED = 2.0f;
/** The rotation of the arms. In Degrees. */
protected float rotationPitch = 0, rotationYaw = 0;
protected float actualPitch = 0, actualYaw = 0;
protected boolean hasTask = false;
protected boolean spawnEntity = false;
protected String displayText = "";
/** An entity that the Armbot is grabbed onto. Entity Items are held separately. */
protected final List<Entity> grabbedEntities = new ArrayList<Entity>();
protected final List<ItemStack> grabbedItems = new ArrayList<ItemStack>();
protected Object grabbedObject = null;
/** Client Side Object Storage */
public EntityItem renderEntityItem = null;
protected List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
protected ProgramHelper programHelper;
public TileEntityArmbot()
{
super(.02f);
}
@Override
public void initiate()
{
super.initiate();
programHelper = new ProgramHelper(this).setMemory(20);
}
@Override
@ -83,20 +70,22 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
super.updateEntity();
Vector3 handPosition = this.getHandPos();
for (Entity entity : this.grabbedEntities)
if (this.grabbedObject instanceof Entity)
{
if (entity != null)
if (this.spawnEntity)
{
entity.setPosition(handPosition.x, handPosition.y, handPosition.z);
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
this.worldObj.spawnEntityInWorld((Entity) this.grabbedObject);
this.spawnEntity = false;
}
((Entity) this.grabbedObject).setPosition(handPosition.x, handPosition.y, handPosition.z);
((Entity) this.grabbedObject).motionX = 0;
((Entity) this.grabbedObject).motionY = 0;
((Entity) this.grabbedObject).motionZ = 0;
if (entity instanceof EntityItem)
{
((EntityItem) entity).delayBeforeCanPickup = 20;
((EntityItem) entity).age = 0;
}
if (this.grabbedObject instanceof EntityItem)
{
((EntityItem) this.grabbedObject).delayBeforeCanPickup = 20;
((EntityItem) this.grabbedObject).age = 0;
}
}
@ -117,7 +106,11 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
public void updateLogic()
{
if(this.programHelper == null)
{
this.programHelper = new ProgramHelper(this);
}
this.programHelper.onUpdate(this.worldObj, new Vector3(this));
}
public void updateRotation()
@ -205,8 +198,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
this.rotationPitch = MathHelper.clampAngle(this.rotationPitch, 0, 60);
}
@Override
public String getInvName()
{
@ -224,37 +215,24 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
{
super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
ItemStack disk = null;
if (diskNBT != null)
{
disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
this.rotationYaw = nbt.getFloat("yaw");
this.rotationPitch = nbt.getFloat("pitch");
NBTTagList entities = nbt.getTagList("entities");
this.grabbedEntities.clear();
for (int i = 0; i < entities.tagCount(); i++)
if (nbt.hasKey("grabbedEntity"))
{
NBTTagCompound entityTag = (NBTTagCompound) entities.tagAt(i);
if (entityTag != null)
NBTTagCompound tag = nbt.getCompoundTag("grabbedEntity");
Entity entity = EntityList.createEntityFromNBT(tag, worldObj);
if (entity != null)
{
Entity entity = EntityList.createEntityFromNBT(entityTag, worldObj);
this.grabbedEntities.add(entity);
this.grabbedObject = entity;
}
}
NBTTagList items = nbt.getTagList("items");
this.grabbedItems.clear();
for (int i = 0; i < items.tagCount(); i++)
else if (nbt.hasKey("grabbedItem"))
{
NBTTagCompound itemTag = (NBTTagCompound) items.tagAt(i);
if (itemTag != null)
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("grabbedItem"));
if (stack != null)
{
ItemStack item = ItemStack.loadItemStackFromNBT(itemTag);
this.grabbedItems.add(item);
this.grabbedObject = stack;
}
}
}
@ -268,34 +246,20 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
nbt.setFloat("yaw", this.rotationYaw);
nbt.setFloat("pitch", this.rotationPitch);
NBTTagList entities = new NBTTagList();
for (Entity entity : grabbedEntities)
if (this.grabbedObject instanceof Entity)
{
if (entity != null)
{
NBTTagCompound entityNBT = new NBTTagCompound();
entity.writeToNBT(entityNBT);
entity.writeToNBTOptional(entityNBT);
entities.appendTag(entityNBT);
}
NBTTagCompound entityNBT = new NBTTagCompound();
((Entity) this.grabbedObject).writeToNBT(entityNBT);
((Entity) this.grabbedObject).writeToNBTOptional(entityNBT);
nbt.setCompoundTag("grabbedEntity", entityNBT);
}
else if (this.grabbedObject instanceof ItemStack)
{
NBTTagCompound itemTag = new NBTTagCompound();
((Entity) this.grabbedObject).writeToNBT(itemTag);
nbt.setCompoundTag("grabbedItem", itemTag);
}
nbt.setTag("entities", entities);
NBTTagList items = new NBTTagList();
for (ItemStack itemStack : grabbedItems)
{
if (itemStack != null)
{
NBTTagCompound entityNBT = new NBTTagCompound();
itemStack.writeToNBT(entityNBT);
items.appendTag(entityNBT);
}
}
nbt.setTag("items", items);
}
@Override
@ -430,58 +394,53 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
@Override
public List<Object> getGrabbedObjects()
public Object getGrabbedObject()
{
List<Object> list = new ArrayList<Object>();
list.addAll(this.grabbedEntities);
list.addAll(this.grabbedItems);
return list;
return this.grabbedObject;
}
@Override
public void grab(Object entity)
public boolean grab(Object entity)
{
if (entity instanceof EntityItem)
if (entity instanceof ItemStack)
{
this.grabbedItems.add(((EntityItem) entity).getEntityItem());
this.grabbedObject = entity;
return true;
}
else if (entity instanceof EntityItem)
{
this.grabbedObject = ((EntityItem) entity).getEntityItem();
((EntityItem) entity).setDead();
return true;
}
else if (entity instanceof Entity)
{
this.grabbedEntities.add((Entity) entity);
this.grabbedObject = entity;
return true;
}
return false;
}
@Override
public void drop(Object object)
public boolean drop(Object object)
{
if (object instanceof Entity)
if (object != null)
{
this.grabbedEntities.remove(object);
}
if (object instanceof ItemStack)
{
Vector3 handPosition = this.getHandPos();
ItemWorldHelper.dropItemStack(worldObj, handPosition, (ItemStack) object, false);
this.grabbedItems.remove(object);
}
if (object instanceof String)
{
String string = ((String) object).toLowerCase();
if (string.equalsIgnoreCase("all"))
boolean drop = object instanceof String && ((String) object).equalsIgnoreCase("all");
if (object.equals(this.grabbedObject) || drop)
{
Vector3 handPosition = this.getHandPos();
Iterator<ItemStack> it = this.grabbedItems.iterator();
while (it.hasNext())
if (object instanceof ItemStack && this.grabbedObject instanceof ItemStack)
{
ItemWorldHelper.dropItemStack(worldObj, handPosition, it.next(), false);
Vector3 handPosition = this.getHandPos();
ItemWorldHelper.dropItemStack(worldObj, handPosition, (ItemStack) object, false);
}
this.grabbedEntities.clear();
this.grabbedItems.clear();
this.grabbedObject = null;
return true;
}
}
return false;
}
@Override
@ -554,34 +513,62 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
@Override
public void moveArmTo(float yaw, float pitch)
public boolean moveArmTo(float yaw, float pitch)
{
if (!this.worldObj.isRemote)
{
this.rotationYaw = yaw;
this.rotationPitch = pitch;
return true;
}
return false;
}
@Override
public void moveTo(ForgeDirection direction)
public boolean moveTo(ForgeDirection direction)
{
if (direction == ForgeDirection.SOUTH)
{
this.rotationYaw = 0;
return true;
}
else if (direction == ForgeDirection.EAST)
{
this.rotationYaw = 90;
return true;
}
else if (direction == ForgeDirection.NORTH)
{
this.rotationYaw = 180;
return true;
}
else if (direction == ForgeDirection.WEST)
{
this.rotationYaw = 270;
return true;
}
return false;
}
@Override
public IProgram getCurrentProgram()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void setCurrentProgram(IProgram program)
{
// TODO Auto-generated method stub
}
@Override
public boolean clear(Object object)
{
// TODO Auto-generated method stub
return false;
}
}

View file

@ -19,7 +19,7 @@ public class CommandDrop extends TaskArmbot
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);
this.worldObj.playSound(this.devicePos.x, this.devicePos.x, this.devicePos.x, "random.pop", 0.2F, ((this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
return ProcessReturn.DONE;
}

View file

@ -91,7 +91,7 @@ public class CommandFire extends TaskArmbot
}
if (held != null)
{
this.worldObj.playSound(this.armbotPos.x, this.armbotPos.y, this.armbotPos.z, "random.bow", velocity, 2f - (velocity / 4f), true);
this.worldObj.playSound(this.devicePos.x, this.devicePos.y, this.devicePos.z, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -13,10 +14,10 @@ import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.coding.IArmbot;
import dark.api.al.coding.ILogicDevice;
import dark.assembly.common.armbot.TaskBase;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskArmbot;
import dark.assembly.common.armbot.TaskBase;
import dark.assembly.common.machine.InvInteractionHelper;
import dark.core.prefab.helpers.MathHelper;
@ -29,6 +30,9 @@ public class CommandGive extends TaskArmbot
public CommandGive()
{
super("give", TaskType.DEFINEDPROCESS);
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));
}
@Override
@ -36,14 +40,13 @@ public class CommandGive extends TaskArmbot
{
super.onMethodCalled(world, location, armbot);
if (this.getArgs().length > 1)
{
ammount = UnitHelper.tryToParseInt("" + this.getArg(1));
}
ammount = UnitHelper.tryToParseInt(this.getArg("stackSize"), -1);
int blockID = UnitHelper.tryToParseInt(this.getArg("blockID"), -1);
int blockMeta = UnitHelper.tryToParseInt(this.getArg("blockMeta"), 32767);
if (this.getArgs().length > 0)
if (blockID > 0)
{
stack = this.getItem("" + this.getArg(0), ammount == -1 ? 1 : ammount);
stack = new ItemStack(blockID, ammount <= 0 ? 1 : ammount, blockMeta == -1 ? 32767 : blockMeta);
}
return ProcessReturn.CONTINUE;
@ -55,34 +58,21 @@ public class CommandGive extends TaskArmbot
{
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
if (targetTile != null && this.armbot.getGrabbedObjects().size() > 0)
if (targetTile != null && this.armbot.getGrabbedObject() instanceof ItemStack)
{
ForgeDirection direction = MathHelper.getFacingDirectionFromAngle((float) this.armbot.getRotation().x);
ItemStack itemStack = (ItemStack) this.armbot.getGrabbedObject();
List<ItemStack> stacks = new ArrayList<ItemStack>();
if (this.stack != null)
{
stacks.add(stack);
}
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.armbotPos, stacks, false);
Iterator<Object> targetIt = this.armbot.getGrabbedObjects().iterator();
boolean itemsLeft = false;
while (targetIt.hasNext())
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.devicePos, stacks, false);
ItemStack insertStack = invEx.tryPlaceInPosition(itemStack, new Vector3(targetTile), direction.getOpposite());
if (this.armbot.clear(itemStack))
{
Object object = targetIt.next();
if (object instanceof ItemStack)
{
ItemStack insertStack = (ItemStack) object;
insertStack = invEx.tryPlaceInPosition(insertStack, new Vector3(targetTile), direction.getOpposite());
itemsLeft = insertStack != null;
if (insertStack == null || insertStack.stackSize <= 0)
{
targetIt.remove();
break;
}
}
this.armbot.grab(insertStack);
}
return itemsLeft ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
}
return ProcessReturn.CONTINUE;
}

View file

@ -1,155 +0,0 @@
package dark.assembly.common.armbot.command;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import dark.api.al.coding.IArmbot;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.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 TaskArmbot
{
public static final float radius = 0.5f;
/** If the grab command is specific to one entity this tell whether or not to grab the child
* version of that entity. */
public boolean child = false;
private TileEntityConveyorBelt belt;
/** The item to be collected. */
private Class<? extends Entity> entityToInclude;
public CommandGrab()
{
super("Grab", TaskType.DEFINEDPROCESS);
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
super.onMethodCalled(world, location, armbot);
this.entityToInclude = Entity.class;
if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null)
{
if (this.getArg(0) instanceof String && (((String) this.getArg(0)).equalsIgnoreCase("baby") || ((String) this.getArg(0)).equalsIgnoreCase("child")))
{
child = true;
if (this.getArgs().length > 1 && this.getArgs()[1] != null)
{
this.entityToInclude = GrabDictionary.get(this.getArg(1)).getEntityClass();
}
}
else
{
this.entityToInclude = GrabDictionary.get(this.getArg(0)).getEntityClass();
if (this.getArg(1) instanceof String && (((String) this.getArg(1)).equalsIgnoreCase("baby") || ((String) this.getArg(1)).equalsIgnoreCase("child")))
{
child = true;
}
}
}
return ProcessReturn.CONTINUE;
}
@Override
public ProcessReturn onUpdate()
{
super.onUpdate();
if (this.armbot.getGrabbedObjects().size() > 0)
{
return ProcessReturn.DONE;
}
Vector3 serachPosition = this.armbot.getHandPos();
List<Entity> found = this.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(serachPosition.x - radius, serachPosition.y - radius, serachPosition.z - radius, serachPosition.x + radius, serachPosition.y + radius, serachPosition.z + radius));
TileEntity ent = serachPosition.getTileEntity(worldObj);
Vector3 searchPostion2 = Vector3.add(serachPosition, new Vector3(0, -1, 0));
TileEntity ent2 = searchPostion2.getTileEntity(worldObj);
if (ent instanceof TileEntityConveyorBelt)
{
this.belt = (TileEntityConveyorBelt) ent;
}
else if (ent2 instanceof TileEntityConveyorBelt)
{
this.belt = (TileEntityConveyorBelt) ent2;
}
if (found != null && found.size() > 0)
{
for (int i = 0; i < found.size(); i++)
{
if (found.get(i) != null && !(found.get(i) instanceof EntityArrow) && !(found.get(i) instanceof EntityPlayer) && found.get(i).ridingEntity == null && (!(found.get(i) instanceof EntityAgeable) || (found.get(i) instanceof EntityAgeable && child == ((EntityAgeable) found.get(i)).isChild())))
{
this.armbot.grab(found.get(i));
if (this.belt != null)
{
belt.ignoreEntity(found.get(i));
}
return ProcessReturn.DONE;
}
}
}
return ProcessReturn.CONTINUE;
}
@Override
public TaskBase loadProgress(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.child = taskCompound.getBoolean("child");
this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass();
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setBoolean("child", child);
taskCompound.setString("name", ((this.entityToInclude != null) ? GrabDictionary.get(this.entityToInclude).getName() : ""));
return taskCompound;
}
@Override
public String toString()
{
String baby = "";
String entity = "";
if (this.entityToInclude != null)
{
entity = GrabDictionary.get(this.entityToInclude).getName();
if (this.child)
{
// TODO do check for EntityAgable
baby = "baby ";
}
}
return "GRAB " + baby + entity;
}
@Override
public TaskBase clone()
{
return new CommandGrab();
}
}

View file

@ -0,0 +1,130 @@
package dark.assembly.common.armbot.command;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.args.ArgumentData;
import dark.api.al.coding.args.ArgumentListData;
import dark.assembly.common.armbot.GrabDictionary;
import dark.assembly.common.armbot.TaskBase;
public class CommandGrabEntity extends CommandGrabPrefab
{
/** If the grab command is specific to one entity this tell whether or not to grab the child
* version of that entity. */
public boolean child = false;
/** The item to be collected. */
private Class<? extends Entity> entityToInclude;
@SuppressWarnings("unchecked")
public CommandGrabEntity()
{
super("Grab-Entity");
this.defautlArguments.add(new ArgumentData("child", false));
this.defautlArguments.add(new ArgumentListData("Entity", Entity.class, GrabDictionary.getList().toArray(new Object[1])));
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
super.onMethodCalled(world, location, armbot);
this.entityToInclude = Entity.class;
try
{
if (this.getArg("Entity") instanceof Class)
{
this.entityToInclude = (Class<? extends Entity>) this.getArg("Entity");
}
}
catch (Exception e)
{
}
if(this.getArg("child") instanceof Boolean)
{
this.child = (boolean) this.getArg("child");
}
return ProcessReturn.CONTINUE;
}
@Override
public ProcessReturn onUpdate()
{
super.onUpdate();
if (this.armbot.getGrabbedObject() != null)
{
return ProcessReturn.DONE;
}
List<Entity> found = this.worldObj.getEntitiesWithinAABB(entityToInclude, AxisAlignedBB.getBoundingBox(this.armPos.x - radius, this.armPos.y - radius, this.armPos.z - radius, this.armPos.x + radius, this.armPos.y + radius, this.armPos.z + radius));
if (found != null && found.size() > 0)
{
for (Entity entity : found)
{
if ((entity != null && !(entity instanceof EntityArrow) && !(entity instanceof EntityPlayer) && (!(entity instanceof EntityAgeable) || (entity instanceof EntityAgeable && child == ((EntityAgeable) entity).isChild()))))
{
this.armbot.grab(entity);
if (this.belt != null)
{
belt.ignoreEntity(entity);
}
return ProcessReturn.DONE;
}
}
}
return ProcessReturn.CONTINUE;
}
@Override
public TaskBase load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.child = taskCompound.getBoolean("child");
this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass();
return this;
}
@Override
public NBTTagCompound save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setBoolean("child", child);
taskCompound.setString("name", ((this.entityToInclude != null) ? GrabDictionary.get(this.entityToInclude).getName() : ""));
return taskCompound;
}
@Override
public String toString()
{
String baby = "";
String entity = "";
if (this.entityToInclude != null)
{
entity = GrabDictionary.get(this.entityToInclude).getName();
if (this.child)
{
// TODO do check for EntityAgable
baby = "baby ";
}
}
return "GRAB " + baby + entity;
}
@Override
public TaskBase clone()
{
return new CommandGrabEntity();
}
}

View file

@ -0,0 +1,82 @@
package dark.assembly.common.armbot.command;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskBase;
public class CommandGrabItem extends CommandGrabPrefab
{
ItemStack stack = null;
public CommandGrabItem()
{
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));
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
super.onMethodCalled(world, location, armbot);
int ammount = UnitHelper.tryToParseInt(this.getArg("stackSize"), -1);
int blockID = UnitHelper.tryToParseInt(this.getArg("blockID"), -1);
int blockMeta = UnitHelper.tryToParseInt(this.getArg("blockMeta"), 32767);
if (blockID > 0)
{
stack = new ItemStack(blockID, ammount <= 0 ? 1 : ammount, blockMeta == -1 ? 32767 : blockMeta);
}
return ProcessReturn.CONTINUE;
}
@Override
public ProcessReturn onUpdate()
{
super.onUpdate();
if (this.armbot.getGrabbedObject() != null)
{
return ProcessReturn.DONE;
}
List<EntityItem> found = this.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(this.armPos.x - radius, this.armPos.y - radius, this.armPos.z - radius, this.armPos.x + radius, this.armPos.y + radius, this.armPos.z + radius));
if (found != null && found.size() > 0)
{
for (EntityItem item : found)
{
if (stack == null || item.getEntityItem().isItemEqual(stack))
{
this.armbot.grab(item);
if (this.belt != null)
{
belt.ignoreEntity(item);
}
return ProcessReturn.DONE;
}
}
}
return ProcessReturn.CONTINUE;
}
@Override
public TaskBase clone()
{
return new CommandGrabItem();
}
}

View file

@ -0,0 +1,70 @@
package dark.assembly.common.armbot.command;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import dark.api.al.IBelt;
import dark.api.al.coding.ILogicDevice;
import dark.assembly.common.armbot.GrabDictionary;
import dark.assembly.common.armbot.TaskArmbot;
import dark.assembly.common.armbot.TaskBase;
import dark.assembly.common.machine.belt.TileEntityConveyorBelt;
/** Prefab for grab based commands
*
* @author DarkGuardsman */
public abstract class CommandGrabPrefab extends TaskArmbot
{
public static final float radius = 0.5f;
protected Vector3 armPos;
protected IBelt belt;
public CommandGrabPrefab(String name)
{
super(name, TaskType.DEFINEDPROCESS);
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
ProcessReturn re = super.onMethodCalled(world, location, armbot);
if (re == ProcessReturn.CONTINUE)
{
this.armPos = this.armbot.getHandPos();
TileEntity entity = this.armPos.getTileEntity(this.worldObj);
if (entity == null)
{
entity = this.armPos.clone().translate(new Vector3(ForgeDirection.DOWN)).getTileEntity(this.worldObj);
}
if (entity instanceof IBelt)
{
this.belt = (IBelt) entity;
}
return ProcessReturn.CONTINUE;
}
return re;
}
@Override
public ProcessReturn onUpdate()
{
super.onUpdate();
if (this.armbot.getGrabbedObject() != null)
{
return ProcessReturn.DONE;
}
return ProcessReturn.CONTINUE;
}
}

View file

@ -11,7 +11,6 @@ import dark.api.al.coding.IDeviceTask.TaskType;
* @author Calclavia */
public class CommandHarvest extends CommandBreak
{
private CommandRotateTo rotateToCommand;
public CommandHarvest()
{

View file

@ -6,6 +6,7 @@ import universalelectricity.core.vector.Vector3;
import dark.api.al.coding.IArmbot;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.IDeviceTask.TaskType;
import dark.api.al.coding.args.ArgumentData;
import dark.assembly.common.armbot.TaskBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@ -20,7 +21,7 @@ public class CommandIdle extends TaskBase
public CommandIdle()
{
super("wait", TaskType.DEFINEDPROCESS);
// TODO Auto-generated constructor stub
this.defautlArguments.add(new ArgumentData("idleTime", 20));
}
@Override
@ -28,10 +29,9 @@ public class CommandIdle extends TaskBase
{
super.onMethodCalled(world, location, armbot);
if (UnitHelper.tryToParseInt("" + this.getArg(0)) > 0)
if (UnitHelper.tryToParseInt(this.getArg("idleTime")) > 0)
{
this.idleTime = UnitHelper.tryToParseInt("" + this.getArg(0));
this.totalIdleTime = this.idleTime;
this.totalIdleTime = this.idleTime = UnitHelper.tryToParseInt(this.getArg("idleTime"));
return ProcessReturn.CONTINUE;
}
return ProcessReturn.ARGUMENT_ERROR;
@ -40,15 +40,11 @@ public class CommandIdle extends TaskBase
@Override
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();
if (this.idleTime > 0)
{
this.idleTime--;
return ProcessReturn.CONTINUE;
}
return ProcessReturn.DONE;
}

View file

@ -36,43 +36,45 @@ public class CommandPlace extends TaskArmbot
if (block == null && ticks >= this.PLACE_TIME)
{
for (Object entity : this.armbot.getGrabbedObjects())
Object entity = armbot.getGrabbedObject();
ItemStack itemStack = null;
if (entity instanceof EntityItem)
{
if (entity instanceof EntityItem)
itemStack = ((EntityItem) entity).getEntityItem();
}
if (entity instanceof ItemStack)
{
itemStack = (ItemStack) entity;
}
if (itemStack != null)
{
if (itemStack.getItem() instanceof ItemBlock)
{
ItemStack itemStack = ((EntityItem) entity).getEntityItem();
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
if (itemStack != null)
this.armbot.clear(entity);
return ProcessReturn.DONE;
}
else if (itemStack.getItem() instanceof IPlantable)
{
IPlantable plantable = ((IPlantable) itemStack.getItem());
Block blockBelow = Block.blocksList[Vector3.add(serachPosition, new Vector3(0, -1, 0)).getBlockID(this.worldObj)];
if (blockBelow != null)
{
if (itemStack.getItem() instanceof ItemBlock)
if (blockBelow.canSustainPlant(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), ForgeDirection.UP, plantable))
{
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
int blockID = plantable.getPlantID(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
int blockMetadata = plantable.getPlantMetadata(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
this.armbot.getGrabbedObjects().remove(entity);
return ProcessReturn.DONE;
}
else if (itemStack.getItem() instanceof IPlantable)
{
IPlantable plantable = ((IPlantable) itemStack.getItem());
Block blockBelow = Block.blocksList[Vector3.add(serachPosition, new Vector3(0, -1, 0)).getBlockID(this.worldObj)];
if (blockBelow != null)
if (this.worldObj.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockID, blockMetadata, 3))
{
if (blockBelow.canSustainPlant(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), ForgeDirection.UP, plantable))
if (this.worldObj.getBlockId(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()) == blockID)
{
int blockID = plantable.getPlantID(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
int blockMetadata = plantable.getPlantMetadata(this.worldObj, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
if (this.worldObj.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockID, blockMetadata, 3))
{
if (this.worldObj.getBlockId(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()) == blockID)
{
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.armbot.getGrabbedObjects().remove(entity);
return ProcessReturn.DONE;
}
}
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.armbot.clear(entity);
return ProcessReturn.DONE;
}
}
}

View file

@ -20,9 +20,8 @@ public class CommandReturn extends TaskArmbot
{
if (this.rotateToCommand == null)
{
this.rotateToCommand = new CommandRotateTo();
this.rotateToCommand.setParms(0,0);
this.rotateToCommand.onMethodCalled(this.worldObj, this.armbotPos, armbot);
this.rotateToCommand = new CommandRotateTo(0, 0);
this.rotateToCommand.onMethodCalled(this.worldObj, this.devicePos, armbot);
}
return this.rotateToCommand.onUpdate();

View file

@ -1,30 +1,33 @@
package dark.assembly.common.armbot.command;
import com.builtbroken.common.science.units.UnitHelper;
import universalelectricity.core.vector.Vector3;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.IDeviceTask.ProcessReturn;
import dark.api.al.coding.IDeviceTask.TaskType;
import dark.api.al.coding.args.ArgumentIntData;
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;
/** Rotates the armbot to a specific direction. If not specified, it will turn right.
/** Rotates an armbot by a set amount
*
* @author Calclavia */
* @author DarkGuardsman */
public class CommandRotateBy extends TaskArmbot
{
double targetRotationYaw = 0;
double targetRotationPitch = 0;
double deltaPitch = 0, deltaYaw = 90;
double totalTicks = 0f;
int targetRotationYaw = 0, targetRotationPitch = 0, deltaPitch = 0, deltaYaw = 0;
private CommandRotateTo rotateToCommand;
public CommandRotateBy()
{
super("RotateBy", TaskType.DEFINEDPROCESS);
this.defautlArguments.add(new ArgumentIntData("yaw", 0, 360, 0));
this.defautlArguments.add(new ArgumentIntData("pitch", 0, 360, 0));
}
@Override
@ -32,31 +35,10 @@ public class CommandRotateBy extends TaskArmbot
{
super.onMethodCalled(world, location, armbot);
this.ticks = 0;
this.targetRotationYaw = (int) MathHelper.clampAngleTo360((float) (this.armbot.getRotation().x + UnitHelper.tryToParseInt(this.getArg("yaw"))));
this.targetRotationYaw = (int) MathHelper.clampAngleTo360((float) (this.armbot.getRotation().x + UnitHelper.tryToParseInt(this.getArg("pitch"))));
if (this.getArg(0) != null)
{
this.targetRotationYaw = this.tileEntity.rotationYaw + this.getFloatArg(0);
this.deltaYaw = this.getFloatArg(0);
}
else
{
this.targetRotationYaw = this.tileEntity.rotationYaw + 90;
}
if (this.getArg(1) != null)
{
this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1);
this.deltaPitch = this.getFloatArg(1);
}
else
{
this.targetRotationPitch = this.armbot.getRotation().y;
}
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);
return ProcessReturn.CONTINUE;
}
@Override
@ -64,33 +46,40 @@ public class CommandRotateBy extends TaskArmbot
{
if (this.rotateToCommand == null)
{
this.rotateToCommand = new CommandRotateTo();
this.rotateToCommand.setParms(this.targetRotationYaw,this.targetRotationPitch);
this.rotateToCommand.onMethodCalled(this.worldObj, this.armbotPos, armbot);
this.rotateToCommand = new CommandRotateTo(this.targetRotationYaw, this.targetRotationPitch);
this.rotateToCommand.onMethodCalled(this.worldObj, this.devicePos, armbot);
}
return this.rotateToCommand.onUpdate();
}
@Override
public void loadProgress(NBTTagCompound taskCompound)
public CommandRotateBy load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
this.targetRotationYaw = taskCompound.getFloat("rotYaw");
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
return this;
}
@Override
public void saveProgress(NBTTagCompound taskCompound)
public NBTTagCompound save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
return taskCompound;
}
@Override
public String toString()
{
return "ROTATE " + Float.toString(this.deltaYaw) + " " + Float.toString(this.deltaPitch);
return super.toString() + " " + Float.toString(this.deltaYaw) + " " + Float.toString(this.deltaPitch);
}
@Override
public TaskBase clone()
{
return new CommandRotateBy();
}
}

View file

@ -7,6 +7,7 @@ import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.coding.IArmbot;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.IDeviceTask.TaskType;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskBase;
import dark.assembly.common.armbot.TaskArmbot;
import dark.core.prefab.helpers.MathHelper;
@ -18,35 +19,31 @@ import net.minecraft.world.World;
* @author DarkGuardsman */
public class CommandRotateTo extends TaskArmbot
{
int targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
public CommandRotateTo()
{
super("RotateTo", TaskType.DEFINEDPROCESS);
this.defautlArguments.add(new ArgumentIntData("yaw", 0, 360, 0));
this.defautlArguments.add(new ArgumentIntData("pitch", 0, 360, 0));
}
float targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
public CommandRotateTo(int yaw, int pitch)
{
super("RotateTo", TaskType.DEFINEDPROCESS);
this.defautlArguments.add(new ArgumentIntData("yaw", yaw, 360, 0));
this.defautlArguments.add(new ArgumentIntData("pitch", pitch, 360, 0));
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice device)
{
super.onMethodCalled(world, location, device);
if (this.getArg(0) != null)
{
this.targetRotationYaw = UnitHelper.tryToParseFloat(this.getArg(0));
}else
{
return ProcessReturn.SYNTAX_ERROR;
}
this.targetRotationYaw = (int) MathHelper.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("yaw")));
this.targetRotationPitch = (int) MathHelper.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("pitch")));
if (this.getArg(1) != null)
{
this.targetRotationPitch = UnitHelper.tryToParseFloat(this.getArg(1));
}
MathHelper.clampAngleTo360(this.targetRotationPitch);
MathHelper.clampAngleTo360(this.targetRotationYaw);
return ProcessReturn.DONE;
return ProcessReturn.CONTINUE;
}
@Override
@ -54,11 +51,9 @@ public class CommandRotateTo extends TaskArmbot
{
super.onUpdate();
this.currentRotationYaw = (float) this.armbot.getRotation().x;
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 ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
return Math.abs(this.armbot.getRotation().y - this.targetRotationPitch) > 0 && Math.abs(this.armbot.getRotation().x - this.targetRotationYaw) > 0 ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
}
@Override
@ -68,20 +63,20 @@ public class CommandRotateTo extends TaskArmbot
}
@Override
public TaskBase loadProgress(NBTTagCompound taskCompound)
public CommandRotateTo load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
this.targetRotationYaw = taskCompound.getFloat("rotYaw");
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
public NBTTagCompound save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
return taskCompound;
}

View file

@ -3,6 +3,7 @@ package dark.assembly.common.armbot.command;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -13,6 +14,8 @@ import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.IDeviceTask.ProcessReturn;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskArmbot;
import dark.assembly.common.armbot.TaskBase;
import dark.assembly.common.machine.InvInteractionHelper;
@ -27,6 +30,9 @@ public class CommandTake extends TaskArmbot
public CommandTake()
{
super("Take", TaskType.DEFINEDPROCESS);
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));
}
@Override
@ -34,9 +40,14 @@ public class CommandTake extends TaskArmbot
{
super.onMethodCalled(world, location, armbot);
ammount = UnitHelper.tryToParseInt(this.getArg(1), -1);
ammount = UnitHelper.tryToParseInt(this.getArg("stackSize"), -1);
int blockID = UnitHelper.tryToParseInt(this.getArg("blockID"), -1);
int blockMeta = UnitHelper.tryToParseInt(this.getArg("blockMeta"), 32767);
stack = this.getItem(this.getArg(0), ammount == -1 ? 1 : ammount);
if (blockID > 0)
{
stack = new ItemStack(blockID, ammount <= 0 ? 1 : ammount, blockMeta == -1 ? 32767 : blockMeta);
}
return ProcessReturn.CONTINUE;
}
@ -46,7 +57,7 @@ public class CommandTake extends TaskArmbot
{
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
if (targetTile != null && this.armbot.getGrabbedObjects().size() <= 0)
if (targetTile != null && this.armbot.getGrabbedObject() instanceof ItemStack)
{
ForgeDirection direction = MathHelper.getFacingDirectionFromAngle(this.armbot.getRotation().x);
List<ItemStack> stacks = new ArrayList<ItemStack>();
@ -54,9 +65,9 @@ public class CommandTake extends TaskArmbot
{
stacks.add(stack);
}
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.armbotPos, stacks, false);
InvInteractionHelper invEx = new InvInteractionHelper(this.worldObj, this.devicePos, 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 this.armbot.getGrabbedObject() != null ? ProcessReturn.DONE : ProcessReturn.CONTINUE;
}
return ProcessReturn.CONTINUE;

View file

@ -1,54 +1,53 @@
package dark.assembly.common.armbot.command;
import com.builtbroken.common.science.units.UnitHelper;
import universalelectricity.core.vector.Vector3;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import dark.api.al.coding.IArmbotUseable;
import dark.api.al.coding.IDeviceTask;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.IDeviceTask.ProcessReturn;
import dark.api.al.coding.IDeviceTask.TaskType;
import dark.api.al.coding.args.ArgumentData;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskBase;
import dark.assembly.common.armbot.TaskArmbot;
public class CommandUse extends TaskArmbot
{
private int times;
private int curTimes;
protected int times, curTimes;
public CommandUse()
{
super("use", TaskType.DEFINEDPROCESS);
this.defautlArguments.add(new ArgumentIntData("repeat", 1, Integer.MAX_VALUE, 1));
}
@Override
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
this.times = 0;
super.onMethodCalled(world, location, armbot);
this.curTimes = 0;
if (this.getArgs().length > 0)
{
this.times = this.getIntArg(0);
}
if (this.times <= 0)
this.times = 1;
this.times = UnitHelper.tryToParseInt(this.getArg("repeat"));
return ProcessReturn.CONTINUE;
}
@Override
public boolean onUpdate()
public ProcessReturn 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);
Block block = Block.blocksList[this.armbot.getHandPos().getBlockID(this.worldObj)];
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
if (targetTile != null)
{
if (targetTile instanceof IArmbotUseable)
{
((IArmbotUseable) targetTile).onUse(this.tileEntity, this.getArgs());
((IArmbotUseable) targetTile).onUse(this.armbot, this.getArgs());
}
}
@ -56,7 +55,7 @@ public class CommandUse extends TaskArmbot
{
try
{
boolean f = block.onBlockActivated(this.worldObj, tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ(), null, 0, 0, 0, 0);
boolean f = block.onBlockActivated(this.worldObj, this.armbot.getHandPos().intX(), this.armbot.getHandPos().intY(), this.armbot.getHandPos().intZ(), null, 0, 0, 0, 0);
}
catch (Exception e)
{
@ -70,10 +69,10 @@ public class CommandUse extends TaskArmbot
if (this.curTimes >= this.times)
{
return false;
return ProcessReturn.DONE;
}
return true;
return ProcessReturn.CONTINUE;
}
@Override
@ -83,18 +82,40 @@ public class CommandUse extends TaskArmbot
}
@Override
public void loadProgress(NBTTagCompound taskCompound)
public CommandUse load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.times = taskCompound.getInteger("useTimes");
this.curTimes = taskCompound.getInteger("useCurTimes");
return this;
}
@Override
public void saveProgress(NBTTagCompound taskCompound)
public NBTTagCompound save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setInteger("useTimes", this.times);
taskCompound.setInteger("useCurTimes", this.curTimes);
return taskCompound;
}
@Override
public IDeviceTask loadProgress(NBTTagCompound nbt)
{
this.curTimes = nbt.getInteger("useCurTimes");
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound nbt)
{
nbt.setInteger("useCurTimes", this.curTimes);
return nbt;
}
@Override
public TaskBase clone()
{
return new CommandUse();
}
}

View file

@ -71,7 +71,7 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
}
@Override
public TaskBase loadProgress(NBTTagCompound nbt)
public TaskBase load(NBTTagCompound nbt)
{
super.loadProgress(nbt);
this.entryPoint = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY"))));
@ -81,7 +81,7 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound nbt)
public NBTTagCompound save(NBTTagCompound nbt)
{
super.saveProgress(nbt);
if (this.entryPoint != null)

View file

@ -2,11 +2,13 @@ package dark.assembly.common.armbot.command;
import com.builtbroken.common.science.units.UnitHelper;
import universalelectricity.core.vector.Vector2;
import universalelectricity.core.vector.Vector3;
import dark.api.al.coding.IDeviceTask;
import dark.api.al.coding.ILogicDevice;
import dark.api.al.coding.ISplitArmbotTask;
import dark.api.al.coding.IDeviceTask.TaskType;
import dark.api.al.coding.args.ArgumentIntData;
import dark.assembly.common.armbot.TaskBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@ -22,6 +24,7 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
public TaskLoop()
{
super("repeat", TaskType.DECISION);
this.defautlArguments.add(new ArgumentIntData("loop", 1, Integer.MAX_VALUE, -1));
}
public TaskLoop(IDeviceTask entry, IDeviceTask exit)
@ -35,7 +38,7 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
{
super.onMethodCalled(world, location, armbot);
this.numReps = UnitHelper.tryToParseInt(this.getArg(0), -1);
this.numReps = UnitHelper.tryToParseInt(this.getArg("loop"), 1);
return ProcessReturn.CONTINUE;
}
@ -48,56 +51,63 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
@Override
public IDeviceTask getEntryPoint()
{
// TODO Auto-generated method stub
return null;
return this.entry;
}
@Override
public IDeviceTask getExitPoint()
{
// TODO Auto-generated method stub
return null;
return this.exit;
}
@Override
public int getMaxExitPoints()
{
// TODO Auto-generated method stub
return 0;
return 1;
}
@Override
public ISplitArmbotTask setEntryPoint(IDeviceTask task)
{
// TODO Auto-generated method stub
return null;
this.entry = task;
return this;
}
@Override
public void addExitPoint(IDeviceTask task)
{
// TODO Auto-generated method stub
this.exit = task;
}
@Override
public TaskBase clone()
{
// TODO Auto-generated method stub
return null;
return new TaskLoop();
}
@Override
public IDeviceTask loadProgress(NBTTagCompound nbt)
public TaskBase load(NBTTagCompound nbt)
{
// TODO Auto-generated method stub
return null;
super.loadProgress(nbt);
this.entry = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY"))));
this.exit = this.program.getTaskAt(new Vector2(nbt.getDouble("exitX"), (nbt.getDouble("exitY"))));
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound nbt)
public NBTTagCompound save(NBTTagCompound nbt)
{
// TODO Auto-generated method stub
return null;
super.saveProgress(nbt);
if (this.entry != null)
{
nbt.setDouble("entryX", this.entry.getPosition().x);
nbt.setDouble("entryY", this.entry.getPosition().y);
}
if (this.exit != null)
{
nbt.setDouble("exitX", this.exit.getPosition().x);
nbt.setDouble("exitY", this.exit.getPosition().y);
}
return nbt;
}
}

View file

@ -1,6 +1,7 @@
package dark.assembly.common.imprinter;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@ -387,7 +388,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
/** Tries to let the Armbot craft an item. */
@Override
public boolean onUse(IArmbot armbot, String[] args)
public boolean onUse(IArmbot armbot, HashMap<String, Object> hashMap)
{
this.onInventoryChanged();