Removed Armbot

This commit is contained in:
Calclavia 2014-07-14 17:33:01 -04:00
parent fb9c712a41
commit 0fddcd5989
30 changed files with 0 additions and 3335 deletions

View file

@ -1,104 +0,0 @@
package resonantinduction.electrical.armbot;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import resonant.core.ResonantEngine;
import resonant.lib.multiblock.IBlockActivate;
import resonant.lib.multiblock.IMultiBlock;
import resonant.lib.prefab.block.BlockTile;
import resonant.lib.render.block.BlockRenderingHandler;
import universalelectricity.api.UniversalElectricity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** A stationary robotic claw used to do simple coded tasks in the world
*
* @author Darkguardsman */
public class BlockArmbot extends BlockTile
{
public BlockArmbot(int id)
{
super(id, UniversalElectricity.machine);
}
@Override
public boolean canBlockStay(World world, int x, int y, int z)
{
return world.getBlockMaterial(x, y - 1, z).isSolid();
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IMultiBlock)
{
ResonantEngine.blockMulti.createMultiBlockStructure((IMultiBlock) tileEntity);
}
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IBlockActivate)
{
return ((IBlockActivate) tileEntity).onActivated(player);
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileArmbot)
{
((TileArmbot) tileEntity).dropHeldObject();
ResonantEngine.blockMulti.destroyMultiBlockStructure((TileArmbot) tileEntity);
}
this.dropBlockAsItem_do(world, x, y, z, new ItemStack(this));
super.breakBlock(world, x, y, z, par5, par6);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
return new ItemStack(this);
}
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileArmbot();
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return BlockRenderingHandler.ID;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
}

View file

@ -1,55 +0,0 @@
package resonantinduction.electrical.armbot;
import net.minecraftforge.common.util.ForgeDirection;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import universalelectricity.api.vector.Vector2;
import universalelectricity.core.transform.vector.Vector3;
/** Should be used to interact with the armbot and not to create a new armbot */
public interface IArmbot extends Cloneable, IProgrammableMachine
{
/** Location of the hand, or working location of the object */
public Vector3 getHandPos();
/** Gets the rotation as a Vector2 (X - Yaw, Y - pitch) */
public Vector2 getRotation();
/** Forces the rotation to the two angles */
public void setRotation(int yaw, int pitch);
/**
* Ask the armbot to rotate to face the given direction. Some bots may not support all angles
*
* @return true if the bot will comply. May return false if it can't
*/
public boolean moveArmTo(int yaw, int pitch);
/**
* Ask the armbot to rotate to face the given direction. Some bots may not support up and down
*
* @param direction - direction
* @return true if the bot will comply. May return false if it can't
*/
public boolean moveTo(ForgeDirection direction);
/**
* Object currently held. In some cases this can be a list or array but is suggest to only be
* one object
*/
public Object getHeldObject();
/**
* Adds an entity to the Armbot's grab list. Entity or ItemStack
*
* @entity - object to grab, can be anything though is suggest to be an entity or itemstack
* @return - true if the bot has grabbed the object
*/
public boolean grabObject(Object entity);
/** Drops the current held object. Use getGrabbedObject to make sure this is the object to drop. */
public boolean dropHeldObject();
/** Same as deleting the object */
public boolean clear(Object object);
}

View file

@ -1,26 +0,0 @@
package resonantinduction.electrical.armbot;
import java.util.List;
import resonantinduction.core.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, List<ArgumentData> list);
}

View file

@ -1,197 +0,0 @@
package resonantinduction.electrical.armbot;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelArmbot extends ModelBase
{
// fields
ModelRenderer baseTop;
ModelRenderer base;
ModelRenderer armMountRight;
ModelRenderer armMountLeft;
ModelRenderer armLower;
ModelRenderer armLower2;
ModelRenderer armLower3;
ModelRenderer armUpper;
ModelRenderer baseRotation;
ModelRenderer clampBody;
ModelRenderer clampBody2;
ModelRenderer clampClawLower;
ModelRenderer clampClawLower2;
ModelRenderer clampClawLower3;
public ModelArmbot()
{
textureWidth = 128;
textureHeight = 128;
baseTop = new ModelRenderer(this, 0, 94);
baseTop.addBox(-6F, 0F, -6F, 12, 3, 12);
baseTop.setRotationPoint(0F, 18F, 0F);
baseTop.setTextureSize(64, 32);
baseTop.mirror = true;
setRotation(baseTop, 0F, 0F, 0F);
base = new ModelRenderer(this, 0, 109);
base.addBox(-8F, 0F, -8F, 16, 3, 16);
base.setRotationPoint(0F, 21F, 0F);
base.setTextureSize(64, 32);
base.mirror = true;
setRotation(base, 0F, 0F, 0F);
armMountRight = new ModelRenderer(this, 24, 85);
armMountRight.addBox(-3.8F, -5F, -2F, 4, 5, 4);
armMountRight.setRotationPoint(0F, 17F, 0F);
armMountRight.setTextureSize(128, 128);
armMountRight.mirror = true;
setRotation(armMountRight, 0F, 0F, 0F);
armMountLeft = new ModelRenderer(this, 0, 85);
armMountLeft.addBox(2F, -5F, -2F, 2, 5, 4);
armMountLeft.setRotationPoint(0F, 17F, 0F);
armMountLeft.setTextureSize(64, 32);
armMountLeft.mirror = true;
setRotation(armMountLeft, 0F, 0F, 0F);
armLower = new ModelRenderer(this, 116, 0);
armLower.addBox(0.3F, -15F, -1.5F, 2, 16, 4);
armLower.setRotationPoint(0F, 14F, 0F);
armLower.setTextureSize(64, 32);
armLower.mirror = true;
setRotation(armLower, 0.5235988F, 0F, 0F);
armLower2 = new ModelRenderer(this, 104, 0);
armLower2.addBox(-2.3F, -15F, -1.5F, 2, 16, 4);
armLower2.setRotationPoint(0F, 14F, 0F);
armLower2.setTextureSize(64, 32);
armLower2.mirror = true;
setRotation(armLower2, 0.5235988F, 0F, 0F);
armLower3 = new ModelRenderer(this, 92, 0);
armLower3.addBox(-1F, -14F, -2F, 2, 14, 4);
armLower3.setRotationPoint(0F, 14F, 0F);
armLower3.setTextureSize(64, 32);
armLower3.mirror = true;
setRotation(armLower3, 0.5235988F, 0F, 0F);
armUpper = new ModelRenderer(this, 0, 70);
armUpper.addBox(-1F, -10F, -1.5F, 2, 12, 3);
armUpper.setRotationPoint(0F, 2F, -7F);
armUpper.setTextureSize(64, 32);
armUpper.mirror = true;
setRotation(armUpper, 2.513274F, 0F, 0F);
baseRotation = new ModelRenderer(this, 0, 60);
baseRotation.addBox(-4.5F, 0F, -4.5F, 9, 1, 9);
baseRotation.setRotationPoint(0F, 17F, 0F);
baseRotation.setTextureSize(64, 32);
baseRotation.mirror = true;
setRotation(baseRotation, 0F, 0F, 0F);
clampBody = new ModelRenderer(this, 0, 7);
clampBody.addBox(-1.5F, -12F, -2.5F, 3, 2, 5);
clampBody.setRotationPoint(0F, 2F, -7F);
clampBody.setTextureSize(64, 32);
clampBody.mirror = true;
setRotation(clampBody, 2.513274F, 0F, 0F);
clampBody2 = new ModelRenderer(this, 0, 56);
clampBody2.addBox(-1F, -14F, -1F, 2, 2, 2);
clampBody2.setRotationPoint(0F, 2F, -7F);
clampBody2.setTextureSize(64, 32);
clampBody2.mirror = true;
setRotation(clampBody2, 2.513274F, 0F, 0F);
clampClawLower = new ModelRenderer(this, 0, 25);
clampClawLower.addBox(-1F, -4F, -1F, 2, 5, 1);
clampClawLower.setRotationPoint(0F, 13F, -15F);
clampClawLower.setTextureSize(64, 32);
clampClawLower.mirror = true;
setRotation(clampClawLower, 2.9147F, 0F, 0F);
clampClawLower2 = new ModelRenderer(this, 0, 31);
clampClawLower2.addBox(-1.2F, -3.5F, 0F, 1, 6, 1);
clampClawLower2.setRotationPoint(0F, 14F, -16F);
clampClawLower2.setTextureSize(64, 32);
clampClawLower2.mirror = true;
setRotation(clampClawLower2, 2.897247F, 0F, 0F);
clampClawLower3 = new ModelRenderer(this, 0, 0);
clampClawLower3.addBox(0.2F, -3.5F, 0F, 1, 6, 1);
clampClawLower3.setRotationPoint(0F, 14F, -16F);
clampClawLower3.setTextureSize(64, 32);
clampClawLower3.mirror = true;
setRotation(clampClawLower3, 2.897247F, 0F, 0F);
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
this.render(f5, entity.rotationYaw, entity.rotationPitch);
}
public void render(float f5, float rotationYaw, float rotationPitch)
{
/*
* armMountRight.setRotationPoint(baseRotation.rotationPointX, armMountRight.rotationPointY,
* baseRotation.rotationPointX); armMountLeft.setRotationPoint(baseRotation.rotationPointX,
* armMountLeft.rotationPointY, baseRotation.rotationPointX);
* armLower.setRotationPoint(baseRotation.rotationPointX, armLower.rotationPointY,
* baseRotation.rotationPointX); armUpper.setRotationPoint(baseRotation.rotationPointX,
* armUpper.rotationPointY, baseRotation.rotationPointX);
* baseRotation.setRotationPoint(baseRotation.rotationPointX, baseRotation.rotationPointY,
* baseRotation.rotationPointX); clampBody.setRotationPoint(baseRotation.rotationPointX,
* clampBody.rotationPointY, baseRotation.rotationPointX);
* clampBody2.setRotationPoint(baseRotation.rotationPointX, clampBody2.rotationPointY,
* baseRotation.rotationPointX);
* clampClawLower.setRotationPoint(baseRotation.rotationPointX,
* clampClawLower.rotationPointY, baseRotation.rotationPointX);
* clampClawLower2.setRotationPoint(baseRotation.rotationPointX,
* clampClawLower2.rotationPointY, baseRotation.rotationPointX);
* armMountRight.rotateAngleY = armBot.rotationYaw; armMountLeft.rotateAngleY =
* armBot.rotationYaw; armLower.rotateAngleY = armBot.rotationYaw; armUpper.rotateAngleY =
* armBot.rotationYaw; baseRotation.rotateAngleY = armBot.rotationYaw;
* clampBody.rotateAngleY = armBot.rotationYaw; clampBody2.rotateAngleY =
* armBot.rotationYaw; clampClawLower.rotateAngleY = armBot.rotationYaw;
* clampClawLower2.rotateAngleY = armBot.rotationYaw;
*/
baseTop.render(f5);
base.render(f5);
GL11.glPushMatrix();
GL11.glRotatef(rotationYaw, 0, 1, 0);
{
armMountRight.render(f5);
armMountLeft.render(f5);
baseRotation.render(f5);
}
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glRotatef(rotationYaw, 0, 1, 0);
GL11.glTranslatef(0f, 0.9f, 0f);
GL11.glRotatef(-rotationPitch, 1, 0, 0);
GL11.glTranslatef(0f, -0.9f, 0f);
{
armLower.render(f5);
GL11.glPushMatrix();
GL11.glTranslatef(0f, 0.1f, -0.35f);
GL11.glRotatef(-rotationPitch, 1, 0, 0);
GL11.glTranslatef(0f, -0.05f, 0.35f);
{
armUpper.render(f5);
clampBody.render(f5);
clampBody2.render(f5);
clampClawLower.render(f5);
clampClawLower2.render(f5);
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -1,355 +0,0 @@
package resonantinduction.electrical.armbot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import resonant.lib.utility.nbt.NBTUtility;
import resonantinduction.electrical.encoder.coding.ILogicTask;
import resonantinduction.electrical.encoder.coding.IProgram;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import resonantinduction.electrical.encoder.coding.ITask;
import resonantinduction.electrical.encoder.coding.TaskRegistry;
import universalelectricity.api.vector.Vector2;
public class Program implements IProgram
{
protected Vector2 currentPos = new Vector2(0, 0);
protected ITask currentTask;
protected IProgrammableMachine machine;
protected HashMap<Vector2, ITask> tasks = new HashMap();
protected HashMap<String, Object> varables = new HashMap();
protected int width = 0, hight = 0;
boolean editing = false;
@Override
public void init(IProgrammableMachine machine)
{
this.machine = machine;
int w = 0;
int h = 0;
List<Vector2> removeList = new ArrayList<Vector2>();
for (Entry<Vector2, ITask> entry : this.tasks.entrySet())
{
if (entry.getValue() != null)
{
entry.getValue().setProgram(this);
if (entry.getValue().getCol() > w)
{
w = entry.getValue().getCol();
}
if (entry.getValue().getRow() > h)
{
h = entry.getValue().getRow();
}
}
else
{
// Should be rare that one of the slots would be null
removeList.add(entry.getKey());
}
}
for (Vector2 vec : removeList)
{
this.tasks.remove(vec);
}
this.width = w;
this.hight = h;
}
@Override
public IProgrammableMachine getMachine()
{
return this.machine;
}
@Override
public HashMap<String, Object> getDeclairedVarables()
{
return varables;
}
@Override
public ITask getNextTask()
{
if (this.currentTask != null)
{
this.currentTask.reset();
}
this.currentTask = this.getTaskAt(currentPos.intX(), currentPos.intY());
this.currentPos.add(new Vector2(0, 1));
if (this.currentTask != null)
{
this.currentTask.refresh();
}
if (this.currentTask instanceof ILogicTask)
{
if (((ILogicTask) this.currentTask).getExitPoint() != null)
{
this.currentTask = ((ILogicTask) this.currentTask).getExitPoint();
this.currentPos = new Vector2(this.currentTask.getCol(), this.currentTask.getRow() + 1);
}
}
return this.currentTask;
}
@Override
public ITask getTaskAt(int col, int row)
{
return this.tasks.get(new Vector2(col, row));
}
@Override
public HashMap<Vector2, ITask> getTaskMap()
{
return this.tasks;
}
@Override
public void setTaskAt(int col, int row, ITask task)
{
if (!this.editing)
{
if (task != null)
{
task.setPosition(col, row);
if (task.getCol() > this.width)
{
this.width = task.getCol();
}
if (task.getRow() > this.hight)
{
this.hight = task.getRow();
}
this.tasks.put(new Vector2(col, row), task);
}
else if (this.tasks.containsKey(new Vector2(col, row)))
{
this.tasks.remove(new Vector2(col, row));
if (col == this.hight && !this.isThereATaskInRow(this.hight))
{
this.hight--;
}
else if (!this.isThereATaskInRow(col))
{
this.moveAll(col, true);
}
}
}
}
public boolean isThereATaskInRow(int row)
{
int colume = 0;
for (int x = 0; x <= this.width; x++)
{
if (this.getTaskAt(colume, row) != null)
{
return true;
}
colume++;
}
return false;
}
public boolean isThereATaskInColume(int colume)
{
int row = 0;
for (int y = 0; y <= this.width; y++)
{
if (this.getTaskAt(row, colume) != null)
{
return true;
}
row++;
}
return false;
}
/**
* Move all tasks at the row and in the direction given.
*
* @param row - row number or Y value of the position from the task
* @param up - true will move all the tasks up one, false will move all the tasks down one
*/
public void moveAll(int row, boolean up)
{
if (!this.editing)
{
this.editing = true;
List<ITask> moveList = new ArrayList<ITask>();
final int move = up ? -1 : 1;
Vector2 targetPos;
ITask tagetTask;
/* Gather all task and remove them so they can be re-added wither there new positions */
for (int x = 0; x <= this.width; x++)
{
for (int y = row; y <= this.hight; y++)
{
targetPos = new Vector2(x, y);
tagetTask = this.getTaskAt(x, y);
if (tagetTask != null)
{
// Add the task to the move list
moveList.add(tagetTask);
// Removes the task
this.tasks.remove(targetPos);
}
}
}
/* Update all the task locations */
for (ITask moveTask : moveList)
{
this.setTaskAt(moveTask.getCol(), moveTask.getRow() + move, moveTask);
}
this.editing = false;
}
}
@Override
public void insertTask(int col, int row, ITask task)
{
if (task != null && !this.editing)
{
if (this.getTaskAt(col, row) != null)
{
this.moveAll(row, false);
this.setTaskAt(col, row, task);
}
else
{
this.setTaskAt(col, row, task);
}
}
}
@Override
public void reset()
{
if (this.currentTask != null)
{
this.currentTask.reset();
}
this.currentPos = new Vector2(0, 0);
}
@Override
public void setVar(String name, Object object)
{
if (name != null)
{
if (object != null)
{
this.varables.put(name, object);
}
else
{
this.varables.remove(name);
}
}
}
@Override
public Object getVar(String name)
{
return this.varables.get(name);
}
@Override
public NBTTagCompound save(NBTTagCompound nbt)
{
// Save process list
NBTTagList taskList = new NBTTagList();
for (Entry<Vector2, ITask> entry : this.tasks.entrySet())
{
entry.getValue().setPosition(entry.getKey().intX(), entry.getKey().intY());
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);
entry.getValue().saveProgress(task);
}
task.setString("methodName", entry.getValue().getMethodName());
taskList.appendTag(task);
}
nbt.setTag("tasks", taskList);
// save varables
taskList = new NBTTagList();
for (Entry<String, Object> var : this.varables.entrySet())
{
taskList.appendTag(NBTUtility.saveObject(var.getKey(), var.getValue()));
}
nbt.setTag("vars", taskList);
return nbt;
}
@Override
public void load(NBTTagCompound nbt)
{
// Load process list
NBTTagList taskList = nbt.getTagList("tasks");
for (int s = 0; s < taskList.tagCount(); ++s)
{
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
if (tag.hasKey("methodName"))
{
ITask task = TaskRegistry.getCommand(tag.getString("methodName"));
if (task != null)
{
task = task.clone();
if (task != null)
{
task.load(tag);
if (tag.getBoolean("currentTask"))
{
this.currentTask = task;
task.loadProgress(tag);
this.currentPos = new Vector2(task.getCol(), task.getRow());
}
this.tasks.put(new Vector2(task.getCol(), task.getRow()), task);
if (task.getCol() > this.width)
{
this.width = task.getCol();
}
if (task.getRow() > this.hight)
{
this.hight = task.getRow();
}
}
}
else
{
System.out.println("[CoreMachine]Error: failed to load task " + tag.getString("methodName"));
}
}
}
taskList = nbt.getTagList("vars");
for (int s = 0; s < taskList.tagCount(); ++s)
{
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
this.varables.put(tag.getName(), NBTUtility.loadObject(tag, tag.getName()));
}
}
@Override
public Program clone()
{
Program program = new Program();
program.load(this.save(new NBTTagCompound()));
program.reset();
return program;
}
@Override
public Vector2 getSize()
{
return new Vector2(this.width, this.hight);
}
}

View file

@ -1,96 +0,0 @@
package resonantinduction.electrical.armbot;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonant.api.items.ISimpleItemRenderer;
import resonant.lib.render.RenderUtility;
import resonantinduction.core.Reference;
import universalelectricity.core.transform.vector.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderArmbot extends TileEntitySpecialRenderer implements ISimpleItemRenderer
{
public static final ModelArmbot MODEL = new ModelArmbot();
public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "armbot.png");
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
{
if (tileEntity instanceof TileArmbot)
{
String cmdText = ((TileArmbot) tileEntity).getCommandDisplayText();
if (cmdText != null && !cmdText.isEmpty())
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null)
{
if (objectPosition.blockX == tileEntity.xCoord && (objectPosition.blockY == tileEntity.yCoord || objectPosition.blockY == tileEntity.yCoord + 1) && objectPosition.blockZ == tileEntity.zCoord)
{
RenderUtility.renderFloatingText(cmdText, new Vector3(x, y, z).add(0.5), 0xFFFFFF);
}
}
}
bindTexture(TEXTURE);
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
MODEL.render(0.0625f, (float) ((TileArmbot) tileEntity).getRotation().x, (float) ((TileArmbot) tileEntity).getRotation().y);
GL11.glPopMatrix();
Vector3 handPosition = ((TileArmbot) tileEntity).getDeltaHandPosition();
handPosition.add(0.5);
handPosition.add(new Vector3(x, y, z));
RenderItem renderItem = ((RenderItem) RenderManager.instance.getEntityClassRenderObject(EntityItem.class));
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
// Items don't move right, so we render them manually. Client side this can only be one
// object so the bot should return its preferred render item client side
if (((TileArmbot) tileEntity).getHeldObject() instanceof ItemStack)
{
ItemStack itemStack = (ItemStack) ((TileArmbot) tileEntity).getHeldObject();
if (((TileArmbot) tileEntity).renderEntityItem == null)
{
((TileArmbot) tileEntity).renderEntityItem = new EntityItem(tileEntity.worldObj, 0, 0, 0, itemStack);
}
else if (!itemStack.isItemEqual(((TileArmbot) tileEntity).renderEntityItem.getEntityItem()))
{
((TileArmbot) tileEntity).renderEntityItem = new EntityItem(tileEntity.worldObj, 0, 0, 0, itemStack);
}
renderItem.doRenderItem(((TileArmbot) tileEntity).renderEntityItem, handPosition.x, handPosition.y, handPosition.z, 0, f);
}
}
}
@Override
public void renderInventoryItem(ItemStack itemStack)
{
GL11.glPushMatrix();
FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderArmbot.TEXTURE);
GL11.glTranslatef(0.5f, 1.3f, 0.5f);
GL11.glRotatef(180f, 0f, 0f, 1f);
GL11.glScalef(0.8f, 0.8f, 0.8f);
RenderArmbot.MODEL.render(0.0625F, 0, 0);
GL11.glPopMatrix();
}
}

View file

@ -1,206 +0,0 @@
package resonantinduction.electrical.armbot;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import resonant.lib.utility.nbt.NBTUtility;
import resonantinduction.core.ArgumentData;
import resonantinduction.electrical.encoder.coding.IProgram;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.api.vector.Vector2;
/** @author DarkGuardsman */
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;
protected String methodName;
/** The amount of ticks this command has been running for. */
protected long ticks;
protected TaskType taskType;
protected int col;
protected int row;
protected Vector2 UV;
/** The parameters this command */
protected List<ArgumentData> args = new ArrayList<ArgumentData>();
public TaskBase(String name, TaskType tasktype)
{
this.methodName = name;
this.taskType = tasktype;
this.UV = this.taskType.UV;
}
@Override
public void refresh()
{
}
@Override
public void reset()
{
}
@Override
public void setProgram(IProgram program)
{
this.program = program;
}
@Override
public int getCol()
{
return this.col;
}
@Override
public int getRow()
{
return this.row;
}
@Override
public void setPosition(int col, int row)
{
this.col = col;
this.row = row;
}
@Override
public String getMethodName()
{
return this.methodName;
}
@Override
public TaskType getType()
{
return this.taskType;
}
@Override
public Object getArg(String name)
{
if (this.getArgs() != null)
{
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)
{
for (ArgumentData arg : this.getArgs())
{
if (arg.getName().equalsIgnoreCase(argName))
{
arg.setData(obj);
break;
}
}
}
}
@Override
public List<ArgumentData> getArgs()
{
return this.args;
}
@Override
public abstract TaskBase clone();
@Override
public void load(NBTTagCompound nbt)
{
this.col = nbt.getInteger("col");
this.row = nbt.getInteger("row");
if (this.getArgs() != null)
{
NBTTagCompound parms = nbt.getCompoundTag("args");
for (ArgumentData arg : this.getArgs())
{
Object obj = NBTUtility.loadObject(parms, arg.getName());
if (arg.isValid(obj))
{
arg.setData(obj);
}
}
}
}
@Override
public void save(NBTTagCompound nbt)
{
nbt.setInteger("col", this.col);
nbt.setInteger("row", this.row);
NBTTagCompound parms = new NBTTagCompound();
for (ArgumentData arg : this.getArgs())
{
NBTUtility.saveObject(parms, arg.getName(), arg.getData());
}
nbt.setCompoundTag("args", parms);
}
@Override
public ITask loadProgress(NBTTagCompound nbt)
{
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound nbt)
{
return nbt;
}
@Override
public boolean canUseTask(IProgrammableMachine device)
{
// TODO Auto-generated method stub
return false;
}
@Override
public String toString()
{
return "Task[" + this.methodName + "]:";
}
@Override
public ResourceLocation getTextureSheet()
{
return ITask.TaskType.TEXTURE;
}
@Override
public Vector2 getTextureUV()
{
return this.UV;
}
@Override
public void getToolTips(List<String> list)
{
list.add(this.getMethodName());
}
}

View file

@ -1,39 +0,0 @@
package resonantinduction.electrical.armbot;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
public abstract class TaskBaseArmbot extends TaskBaseProcess
{
public TaskBaseArmbot(String name)
{
super(name);
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE && this.program.getMachine() instanceof IArmbot)
{
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE && this.program.getMachine() instanceof IArmbot)
{
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public boolean canUseTask(IProgrammableMachine device)
{
return device instanceof IArmbot;
}
}

View file

@ -1,12 +0,0 @@
package resonantinduction.electrical.armbot;
import resonantinduction.electrical.encoder.coding.ILogicTask;
/** @author DarkGuardsman */
public abstract class TaskBaseLogic extends TaskBase implements ILogicTask
{
public TaskBaseLogic(String name)
{
super(name, TaskType.DECISION);
}
}

View file

@ -1,82 +0,0 @@
package resonantinduction.electrical.armbot;
import net.minecraft.item.ItemStack;
import resonant.lib.science.units.UnitHelper;
import resonantinduction.electrical.encoder.coding.IProcessTask;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
/**
* 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 TaskBaseProcess extends TaskBase implements IProcessTask
{
public TaskBaseProcess(String name)
{
super(name, TaskType.DEFINEDPROCESS);
this.ticks = 0;
}
@Override
public ProcessReturn onMethodCalled()
{
if (this.program != null && this.program.getMachine() != null)
{
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (ticks++ >= Long.MAX_VALUE - 1)
{
this.ticks = 0;
}
if (this.program != null && this.program.getMachine() != null)
{
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public Object[] onCCMethodCalled(IComputerAccess computer, ILuaContext context) throws Exception
{
return null;
}
@Override
public void terminated()
{
}
public ItemStack getItem(Object object, int ammount)
{
int id = 0;
int meta = 32767;
if (object instanceof String && ((String) object).contains(":"))
{
String[] blockID = ((String) object).split(":");
id = Integer.parseInt(blockID[0]);
meta = Integer.parseInt(blockID[1]);
}
else
{
id = UnitHelper.tryToParseInt(object);
}
if (id == 0)
{
return null;
}
else
{
return new ItemStack(id, ammount, meta);
}
}
}

View file

@ -1,498 +0,0 @@
package resonantinduction.electrical.armbot;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
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.network.packet.Packet;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.multiblock.IMultiBlock;
import resonant.lib.network.IPacketReceiverWithID;
import resonant.lib.network.PacketHandler;
import resonant.lib.prefab.tile.TileElectrical;
import resonant.lib.type.Pair;
import resonant.lib.utility.MathUtility;
import resonant.lib.utility.inventory.InventoryUtility;
import resonantinduction.core.ResonantInduction;
import resonantinduction.electrical.armbot.task.TaskDrop;
import resonantinduction.electrical.armbot.task.TaskGOTO;
import resonantinduction.electrical.armbot.task.TaskGrabItem;
import resonantinduction.electrical.armbot.task.TaskReturn;
import resonantinduction.electrical.armbot.task.TaskRotateTo;
import resonantinduction.electrical.encoder.coding.IProgram;
import resonantinduction.electrical.encoder.coding.ProgramHelper;
import universalelectricity.api.energy.EnergyStorageHandler;
import universalelectricity.api.vector.Vector2;
import universalelectricity.core.transform.vector.Vector3;
import com.google.common.io.ByteArrayDataInput;
public class TileArmbot extends TileElectrical implements IMultiBlock, IArmbot, IPacketReceiverWithID
{
protected int ROTATION_SPEED = 6;
/** The rotation of the arms. In Degrees. */
protected int targetPitch = 0, targetYaw = 0;
protected int actualPitch = 0, actualYaw = 0;
protected boolean spawnEntity = false;
protected String displayText = "";
/** An entity that the Armbot is grabbed onto. Entity Items are held separately. */
protected Object grabbedObject = null;
/** Helper class that does all the logic for the armbot's program */
protected ProgramHelper programHelper;
/** Cached location of the armbot to feed to program tasks */
protected Pair<World, Vector3> location;
/** Var used by the armbot renderer */
public EntityItem renderEntityItem;
/**
* Used client side only for render.
*/
private boolean functioning;
public static final int ARMBOT_PACKET_ID = 3;
public static final int ROTATION_PACKET_ID = 4;
public TileArmbot()
{
energy = new EnergyStorageHandler(5000, 1000);
programHelper = new ProgramHelper(this).setMemoryLimit(20);
Program program = new Program();
program.setTaskAt(0, 0, new TaskDrop());
program.setTaskAt(0, 1, new TaskRotateTo(180, 0));
program.setTaskAt(0, 2, new TaskGrabItem());
program.setTaskAt(0, 3, new TaskReturn());
program.setTaskAt(0, 4, new TaskGOTO(0, 0));
programHelper.setProgram(program);
}
/************************************ Armbot logic update methods *************************************/
@Override
public void updateEntity()
{
super.updateEntity();
Vector3 handPosition = this.getHandPos();
if (this.location == null || !this.location.left().equals(this.worldObj) || this.xCoord != this.location.right().intX() || this.yCoord != this.location.right().intY() || this.zCoord != this.location.right().intZ())
{
this.location = new Pair<World, Vector3>(this.worldObj, new Vector3(this));
}
if (this.grabbedObject instanceof Entity)
{
if (this.spawnEntity)
{
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 (this.grabbedObject instanceof EntityItem)
{
((EntityItem) this.grabbedObject).delayBeforeCanPickup = 20;
((EntityItem) this.grabbedObject).age = 0;
}
}
if (energy.checkExtract())
{
float preYaw = this.targetYaw, prePitch = this.targetPitch;
if (!this.worldObj.isRemote && this.ticks % 5 == 0)
{
this.programHelper.onUpdate(this.worldObj, new Vector3(this));
if (this.targetYaw != preYaw || this.targetPitch != prePitch)
{
PacketHandler.sendPacketToClients(this.getDescriptionPacket(), worldObj, new Vector3(this).add(new Vector3(.5f, 1f, .5f)), 64);
}
}
this.updateRotation();
energy.extractEnergy();
}
}
public void updateRotation()
{
// Clamp target angles
this.targetYaw = (int) MathUtility.clampAngleTo360(this.targetYaw);
if (this.targetPitch < 0)
this.targetPitch = 0;
if (this.targetPitch > 60)
this.targetPitch = 60;
// Handle change in yaw rotation
if (Math.abs(this.actualYaw - this.targetYaw) > 1)
{
float speedYaw;
if (this.actualYaw > this.targetYaw)
{
if (Math.abs(this.actualYaw - this.targetYaw) >= 180)
{
speedYaw = this.ROTATION_SPEED;
}
else
{
speedYaw = -this.ROTATION_SPEED;
}
}
else
{
if (Math.abs(this.actualYaw - this.targetYaw) >= 180)
{
speedYaw = -this.ROTATION_SPEED;
}
else
{
speedYaw = this.ROTATION_SPEED;
}
}
this.actualYaw += speedYaw;
if (Math.abs(this.actualYaw - this.targetYaw) < this.ROTATION_SPEED)
{
this.actualYaw = this.targetYaw;
}
this.playRotationSound();
}
// Handle change in pitch rotation
if (Math.abs(this.actualPitch - this.targetPitch) > 1)
{
if (this.actualPitch > this.targetPitch)
{
this.actualPitch -= this.ROTATION_SPEED;
}
else
{
this.actualPitch += this.ROTATION_SPEED;
}
if (Math.abs(this.actualPitch - this.targetPitch) < this.ROTATION_SPEED)
{
this.actualPitch = this.targetPitch;
}
this.playRotationSound();
}
// Clamp actual angles angles
this.actualYaw = (int) MathUtility.clampAngleTo360(this.actualYaw);
if (this.actualPitch < 0)
this.actualPitch = 0;
if (this.actualPitch > 60)
this.actualPitch = 60;
}
public void playRotationSound()
{
if (this.ticks % 5 == 0 && this.worldObj.isRemote)
{
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 2f, 2.5f, true);
}
}
public String getCommandDisplayText()
{
return this.displayText;
}
/************************************ Save and load code *************************************/
/** NBT Data */
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.targetYaw = nbt.getInteger("armYaw");
this.targetPitch = nbt.getInteger("armPitch");
this.actualYaw = nbt.getInteger("armYawActual");
this.actualPitch = nbt.getInteger("armPitchActual");
if (nbt.hasKey("grabbedEntity"))
{
NBTTagCompound tag = nbt.getCompoundTag("grabbedEntity");
Entity entity = EntityList.createEntityFromNBT(tag, worldObj);
if (entity != null)
{
this.grabbedObject = entity;
this.spawnEntity = true;
}
}
else if (nbt.hasKey("grabbedItem"))
{
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("grabbedItem"));
if (stack != null)
{
this.grabbedObject = stack;
}
}
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("armYaw", this.targetYaw);
nbt.setInteger("armPitch", this.targetPitch);
nbt.setInteger("armYawActual", this.actualYaw);
nbt.setInteger("armPitchActual", this.actualPitch);
if (this.grabbedObject instanceof Entity)
{
NBTTagCompound entityNBT = new NBTTagCompound();
((Entity) this.grabbedObject).writeToNBT(entityNBT);
((Entity) this.grabbedObject).writeToNBTOptional(entityNBT);
nbt.setCompoundTag("grabbedEntity", entityNBT);
}
else if (this.grabbedObject instanceof ItemStack)
{
nbt.setCompoundTag("grabbedItem", ((ItemStack) this.grabbedObject).writeToNBT(new NBTTagCompound()));
}
}
/************************************ Network Packet code *************************************/
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacket(this, "armbot", energy.checkExtract(), this.targetYaw, this.targetPitch, this.actualYaw, this.actualPitch);
}
public void sendGrabItemToClient()
{
if (this.grabbedObject instanceof ItemStack)
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, "armbotItem", true, ((ItemStack) this.grabbedObject).writeToNBT(new NBTTagCompound())), worldObj, new Vector3(this), 64);
}
else
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, "armbotItem", false), worldObj, new Vector3(this), 64);
}
}
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (this.worldObj.isRemote)
{
if (id == ARMBOT_PACKET_ID)
{
this.functioning = data.readBoolean();
this.targetYaw = data.readInt();
this.targetPitch = data.readInt();
this.actualYaw = data.readInt();
this.actualPitch = data.readInt();
return true;
}
else if (id == ROTATION_PACKET_ID)
{
if (data.readBoolean())
{
this.grabbedObject = ItemStack.loadItemStackFromNBT(PacketHandler.readNBTTagCompound(data));
}
else
{
this.grabbedObject = null;
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
/************************************ Multi Block code *************************************/
@Override
public Vector3[] getMultiBlockVectors()
{
return new Vector3[] { new Vector3(0, 1, 0) };
}
/************************************ Armbot API methods *************************************/
@Override
public Object getHeldObject()
{
return this.grabbedObject;
}
@Override
public boolean grabObject(Object entity)
{
if (this.getHeldObject() == null)
{
if (entity instanceof ItemStack)
{
this.grabbedObject = entity;
this.sendGrabItemToClient();
return true;
}
else if (entity instanceof EntityItem)
{
this.grabbedObject = ((EntityItem) entity).getEntityItem();
((EntityItem) entity).setDead();
this.sendGrabItemToClient();
return true;
}
else if (entity instanceof Entity)
{
this.grabbedObject = entity;
return true;
}
}
return false;
}
@Override
public boolean dropHeldObject()
{
if (this.getHeldObject() != null)
{
if (this.getHeldObject() instanceof ItemStack)
{
Vector3 handPosition = this.getHandPos();
InventoryUtility.dropItemStack(worldObj, handPosition, (ItemStack) this.getHeldObject());
}
this.grabbedObject = null;
this.sendGrabItemToClient();
return true;
}
return false;
}
@Override
public Vector3 getHandPos()
{
Vector3 position = new Vector3(this);
position.add(0.5);
position.add(this.getDeltaHandPosition());
return position;
}
public Vector3 getDeltaHandPosition()
{
// The distance of the position relative to the main position.
double distance = 1f;
Vector3 delta = new Vector3();
// The delta Y of the hand.
delta.y = Math.sin(Math.toRadians(this.actualPitch)) * distance * 2;
// The horizontal delta of the hand.
double dH = Math.cos(Math.toRadians(this.actualPitch)) * distance;
// The delta X and Z.
delta.x = Math.sin(Math.toRadians(-this.actualYaw)) * dH;
delta.z = Math.cos(Math.toRadians(-this.actualYaw)) * dH;
return delta;
}
@Override
public Vector2 getRotation()
{
return new Vector2(this.actualYaw, this.actualPitch);
}
@Override
public void setRotation(int yaw, int pitch)
{
if (!this.worldObj.isRemote)
{
this.actualYaw = yaw;
this.actualPitch = pitch;
}
}
@Override
public boolean moveArmTo(int yaw, int pitch)
{
if (!this.worldObj.isRemote)
{
this.targetYaw = yaw;
this.targetPitch = pitch;
return true;
}
return false;
}
@Override
public boolean moveTo(ForgeDirection direction)
{
if (direction == ForgeDirection.SOUTH)
{
this.targetYaw = 0;
return true;
}
else if (direction == ForgeDirection.EAST)
{
this.targetYaw = 90;
return true;
}
else if (direction == ForgeDirection.NORTH)
{
this.targetYaw = 180;
return true;
}
else if (direction == ForgeDirection.WEST)
{
this.targetYaw = 270;
return true;
}
return false;
}
@Override
public IProgram getCurrentProgram()
{
if (this.programHelper == null)
{
this.programHelper = new ProgramHelper(this);
}
if (this.programHelper != null)
{
return this.programHelper.getProgram();
}
return null;
}
@Override
public void setCurrentProgram(IProgram program)
{
if (this.programHelper == null)
{
this.programHelper = new ProgramHelper(this);
}
if (this.programHelper != null)
{
this.programHelper.setProgram(program);
}
}
@Override
public boolean clear(Object object)
{
if (this.grabbedObject != null && this.grabbedObject.equals(object))
{
this.grabbedObject = null;
return true;
}
return false;
}
@Override
public Pair<World, Vector3> getLocation()
{
return this.location;
}
}

View file

@ -1,91 +0,0 @@
package resonantinduction.electrical.armbot.task;
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 net.minecraft.world.World;
import resonant.lib.type.Pair;
import resonant.lib.utility.inventory.InventoryUtility;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.core.transform.vector.Vector3;
/**
* Used by arms to break a specific block in a position.
*
* @author Calclavia
*/
public class TaskBreak extends TaskBaseArmbot
{
protected int breakTicks = 30;
protected boolean keep = false;
public TaskBreak()
{
this("break");
}
public TaskBreak(String name)
{
super(name);
this.breakTicks = 30;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
Vector3 serachPosition = ((IArmbot) this.program.getMachine()).getHandPos();
Pair<World, Vector3> location = this.program.getMachine().getLocation();
Block block = Block.blocksList[serachPosition.getBlock(location.left())];
this.breakTicks--;
if (block != null && breakTicks <= 0)
{
ArrayList<ItemStack> items = block.getBlockDropped(location.left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(location.left()), 0);
if (!this.keep || items.size() > 1)
{
InventoryUtility.dropBlockAsItem(location.left(), serachPosition);
}
else
{
((IArmbot) this.program.getMachine()).grabObject(new EntityItem(location.left(), serachPosition.intX() + 0.5D, serachPosition.intY() + 0.5D, serachPosition.intZ() + 0.5D, items.get(0)));
}
location.left().setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0, 3);
return ProcessReturn.DONE;
}
}
/** Notes on break command Beds Break Wrong Multi blocks don't work */
return ProcessReturn.GENERAL_ERROR;
}
@Override
public TaskBaseProcess clone()
{
return new TaskBreak();
}
@Override
public ITask loadProgress(NBTTagCompound nbt)
{
this.breakTicks = nbt.getInteger("breakTicks");
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound nbt)
{
nbt.setInteger("breakTicks", this.breakTicks);
return nbt;
}
}

View file

@ -1,32 +0,0 @@
package resonantinduction.electrical.armbot.task;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import universalelectricity.api.vector.Vector2;
public class TaskDrop extends TaskBaseArmbot
{
public TaskDrop()
{
super("drop");
this.UV = new Vector2(20, 80);
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
((IArmbot) this.program.getMachine()).dropHeldObject();
}
return ProcessReturn.DONE;
}
@Override
public TaskBaseProcess clone()
{
return new TaskDrop();
}
}

View file

@ -1,18 +0,0 @@
package resonantinduction.electrical.armbot.task;
import resonantinduction.electrical.armbot.TaskBase;
/** @author DarkGuardsman */
public class TaskEnd extends TaskBase
{
public TaskEnd()
{
super("end", TaskType.END);
}
@Override
public TaskBase clone()
{
return new TaskEnd();
}
}

View file

@ -1,197 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import resonant.lib.science.units.UnitHelper;
import resonant.lib.type.Pair;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentFloatData;
import universalelectricity.core.transform.vector.Vector3;
public class TaskFire extends TaskBaseArmbot
{
private static final float MIN_ACTUAL_PITCH = -80;
private static final float MAX_ACTUAL_PITCH = 80;
private float actualYaw;
private float actualPitch;
private float velocity;
private Vector3 finalVelocity;
public TaskFire()
{
super("throw");
this.args.add(new ArgumentFloatData("velocity", 1.0f, 2.5f, 1.0f));
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
this.velocity = UnitHelper.tryToParseFloat(this.getArg("velocity"));
if (this.velocity > 2.5f)
{
this.velocity = 2.5f;
}
if (this.velocity < 0.125f)
{
this.velocity = 1f;
}
this.actualYaw = (float) ((IArmbot) this.program.getMachine()).getRotation().x;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * ((float) ((IArmbot) this.program.getMachine()).getRotation().y / 60f)) + MIN_ACTUAL_PITCH;
double x, y, z;
double yaw, pitch;
yaw = Math.toRadians(actualYaw);
pitch = Math.toRadians(actualPitch);
// yaw = actualYaw;
// pitch = actualPitch;
x = -Math.sin(yaw) * Math.cos(pitch);
y = Math.sin(pitch);
z = Math.cos(yaw) * Math.cos(pitch);
this.finalVelocity = new Vector3(x, y, z);
Random random = new Random(System.currentTimeMillis());
this.finalVelocity.x *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.y *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.z *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.scale(velocity);
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
if (this.finalVelocity == null) // something went wrong
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (((IArmbot) this.program.getMachine()).getHeldObject() != null)
{
Entity held = null;
Object obj = ((IArmbot) this.program.getMachine()).getHeldObject();
Pair<World, Vector3> location = this.program.getMachine().getLocation();
if (obj instanceof Entity)
{
held = (Entity) obj;
}
if (held != null)
{
location.left().playSound(location.right().x, location.right().y, location.right().z, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
ItemStack stack = item.getEntityItem();
ItemStack thrown = stack.copy();
thrown.stackSize = 1;
if (item.getEntityItem().stackSize > 0)
{
stack.stackSize--;
item.setEntityItemStack(stack);
}
else
{
((IArmbot) this.program.getMachine()).dropHeldObject();
if (!location.left().isRemote)
{
location.left().removeEntity(held);
}
}
if (item.getEntityItem().itemID == Item.arrow.itemID)
{
EntityArrow arrow = new EntityArrow(location.left(), ((IArmbot) this.program.getMachine()).getHandPos().x, ((IArmbot) this.program.getMachine()).getHandPos().y, ((IArmbot) this.program.getMachine()).getHandPos().z);
arrow.motionX = this.finalVelocity.x;
arrow.motionY = this.finalVelocity.y;
arrow.motionZ = this.finalVelocity.z;
if (!location.left().isRemote)
{
location.left().spawnEntityInWorld(arrow);
}
}
else
{
EntityItem item2 = new EntityItem(location.left(), ((IArmbot) this.program.getMachine()).getHandPos().x, ((IArmbot) this.program.getMachine()).getHandPos().y, ((IArmbot) this.program.getMachine()).getHandPos().z, thrown);
item2.motionX = this.finalVelocity.x;
item2.motionY = this.finalVelocity.y;
item2.motionZ = this.finalVelocity.z;
if (!location.left().isRemote)
{
location.left().spawnEntityInWorld(item2);
}
}
}
else
{
((IArmbot) this.program.getMachine()).dropHeldObject();
held.motionX = this.finalVelocity.x;
held.motionY = this.finalVelocity.y;
held.motionZ = this.finalVelocity.z;
}
}
}
return ProcessReturn.DONE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public TaskBaseProcess loadProgress(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.actualYaw = taskCompound.getFloat("fireYaw");
this.actualPitch = taskCompound.getFloat("firePitch");
this.velocity = taskCompound.getFloat("fireVelocity");
this.finalVelocity = new Vector3();
this.finalVelocity.x = taskCompound.getDouble("fireVectorX");
this.finalVelocity.y = taskCompound.getDouble("fireVectorY");
this.finalVelocity.z = taskCompound.getDouble("fireVectorZ");
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setFloat("fireYaw", this.actualYaw);
taskCompound.setFloat("firePitch", this.actualPitch);
taskCompound.setFloat("fireVelocity", this.velocity);
if (this.finalVelocity != null)
{
taskCompound.setDouble("fireVectorX", this.finalVelocity.x);
taskCompound.setDouble("fireVectorY", this.finalVelocity.y);
taskCompound.setDouble("fireVectorZ", this.finalVelocity.z);
}
return taskCompound;
}
@Override
public String toString()
{
return super.toString() + " " + Float.toString(this.velocity);
}
@Override
public TaskBaseProcess clone()
{
return new TaskFire();
}
}

View file

@ -1,118 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.electrical.armbot.TaskBase;
import resonantinduction.electrical.encoder.coding.IRedirectTask;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.api.vector.Vector2;
/** @author DarkGuardsman */
public class TaskGOTO extends TaskBase implements IRedirectTask
{
protected ITask task;
protected Vector2 taskPos;
protected boolean render = true;
protected List<Vector2> exits = new ArrayList<Vector2>();
public TaskGOTO()
{
super("GoTo", TaskType.DECISION);
}
public TaskGOTO(int x, int y)
{
this();
this.taskPos = new Vector2(x, y);
}
public TaskGOTO(boolean render)
{
this();
this.render = render;
}
@Override
public ITask getExitPoint()
{
return task;
}
@Override
public void refresh()
{
super.refresh();
if (task == null && taskPos != null)
{
this.task = this.program.getTaskAt(taskPos.intX(), taskPos.intY());
}
this.exits.clear();
if (this.task != null)
{
this.exits.add(new Vector2(this.task.getCol(), this.task.getRow()));
}
}
@Override
public void setExitPoint(int i, ITask task)
{
if (i == 0)
{
this.task = task;
}
}
public void setExitPoint(int i, Vector2 vector2)
{
if (i == 0)
{
this.taskPos = vector2;
}
}
@Override
public int getMaxExitPoints()
{
return 1;
}
@Override
public boolean render()
{
return this.render;
}
@Override
public void load(NBTTagCompound nbt)
{
super.loadProgress(nbt);
this.taskPos = new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY")));
}
@Override
public void save(NBTTagCompound nbt)
{
super.saveProgress(nbt);
if (this.task != null)
{
nbt.setDouble("entryX", this.task.getCol());
nbt.setDouble("entryY", this.task.getRow());
}
}
@Override
public TaskBase clone()
{
return new TaskGOTO();
}
@Override
public List<Vector2> getExits()
{
// TODO Auto-generated method stub
return exits;
}
}

View file

@ -1,116 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.science.units.UnitHelper;
import resonant.lib.utility.MathUtility;
import resonant.lib.utility.inventory.InternalInventoryHandler;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import universalelectricity.core.transform.vector.Vector3;
public class TaskGive extends TaskBaseArmbot
{
private ItemStack stack;
private int ammount = -1;
public TaskGive()
{
super("give");
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);
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
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;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
TileEntity targetTile = ((IArmbot) this.program.getMachine()).getHandPos().getTileEntity(this.program.getMachine().getLocation().left());
if (targetTile != null && ((IArmbot) this.program.getMachine()).getHeldObject() instanceof ItemStack)
{
ForgeDirection direction = MathUtility.getFacingDirectionFromAngle((float) ((IArmbot) this.program.getMachine()).getRotation().x);
ItemStack itemStack = (ItemStack) ((IArmbot) this.program.getMachine()).getHeldObject();
Set<ItemStack> stacks = new HashSet<ItemStack>();
if (this.stack != null)
{
stacks.add(stack);
}
InternalInventoryHandler invEx = new InternalInventoryHandler(this.program.getMachine().getLocation().left(), this.program.getMachine().getLocation().right(), stacks, false);
ItemStack insertStack = invEx.tryPlaceInPosition(itemStack, new Vector3(targetTile), direction.getOpposite());
if (((IArmbot) this.program.getMachine()).clear(itemStack))
{
((IArmbot) this.program.getMachine()).grabObject(insertStack);
}
}
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public String toString()
{
return super.toString() + " " + (stack != null ? stack.toString() : "1x???@???");
}
@Override
public TaskBaseProcess loadProgress(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
if (stack != null)
{
NBTTagCompound tag = new NBTTagCompound();
this.stack.writeToNBT(tag);
taskCompound.setTag("item", tag);
}
return taskCompound;
}
@Override
public TaskBaseProcess clone()
{
return new TaskGive();
}
}

View file

@ -1,135 +0,0 @@
package resonantinduction.electrical.armbot.task;
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 resonant.api.ai.EntitySettings;
import resonantinduction.core.ArgumentData;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
public class TaskGrabEntity extends TaskGrabPrefab
{
/**
* 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 TaskGrabEntity()
{
super("Grab-Entity");
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])));
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
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;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
if (((IArmbot) this.program.getMachine()).getHeldObject() != null)
{
return ProcessReturn.DONE;
}
@SuppressWarnings("unchecked")
List<Entity> found = this.program.getMachine().getLocation().left().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()))))
{
((IArmbot) this.program.getMachine()).grabObject(entity);
if (this.belt != null)
{
belt.ignoreEntity(entity);
}
return ProcessReturn.DONE;
}
}
}
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.child = taskCompound.getBoolean("child");
this.entityToInclude = EntitySettings.get(taskCompound.getString("name"));
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setBoolean("child", child);
taskCompound.setString("name", ((this.entityToInclude != null) ? EntitySettings.get(this.entityToInclude) : ""));
}
@Override
public String toString()
{
String baby = "";
String entity = "";
if (this.entityToInclude != null)
{
entity = EntitySettings.get(this.entityToInclude);
if (this.child)
{
// TODO do check for EntityAgable
baby = "baby ";
}
}
return "GRAB " + baby + entity;
}
@Override
public TaskBaseProcess clone()
{
return new TaskGrabEntity();
}
}

View file

@ -1,83 +0,0 @@
package resonantinduction.electrical.armbot.task;
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 resonant.lib.science.units.UnitHelper;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
public class TaskGrabItem extends TaskGrabPrefab
{
ItemStack stack = null;
public TaskGrabItem()
{
super("Grab-Item");
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
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
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;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
if (((IArmbot) this.program.getMachine()).getHeldObject() != null)
{
return ProcessReturn.DONE;
}
List<EntityItem> found = this.program.getMachine().getLocation().left().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))
{
if (((IArmbot) this.program.getMachine()).grabObject(item))
{
if (this.belt != null)
{
belt.ignoreEntity(item);
}
return ProcessReturn.DONE;
}
}
}
}
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public TaskBaseProcess clone()
{
return new TaskGrabItem();
}
}

View file

@ -1,61 +0,0 @@
package resonantinduction.electrical.armbot.task;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.api.IEntityConveyor;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import universalelectricity.api.vector.Vector2;
import universalelectricity.core.transform.vector.Vector3;
/**
* Prefab for grab based commands
*
* @author DarkGuardsman
*/
public abstract class TaskGrabPrefab extends TaskBaseArmbot
{
public static final float radius = 0.5f;
protected Vector3 armPos;
protected IEntityConveyor belt;
public TaskGrabPrefab(String name)
{
super(name);
this.UV = new Vector2(0, 80);
}
@Override
public ProcessReturn onMethodCalled()
{
ProcessReturn re = super.onMethodCalled();
if (re == ProcessReturn.CONTINUE)
{
this.armPos = ((IArmbot) this.program.getMachine()).getHandPos();
TileEntity entity = this.armPos.getTileEntity(this.program.getMachine().getLocation().left());
if (entity == null)
{
entity = this.armPos.clone().add(new Vector3(ForgeDirection.DOWN)).getTileEntity(this.program.getMachine().getLocation().left());
}
if (entity instanceof IEntityConveyor)
{
this.belt = (IEntityConveyor) entity;
}
return ProcessReturn.CONTINUE;
}
return re;
}
@Override
public ProcessReturn onUpdate()
{
super.onUpdate();
if (((IArmbot) this.program.getMachine()).getHeldObject() != null)
{
return ProcessReturn.DONE;
}
return ProcessReturn.CONTINUE;
}
}

View file

@ -1,22 +0,0 @@
package resonantinduction.electrical.armbot.task;
/**
* Used by arms to break a specific block in a position.
*
* @author DarkGuardsman
*/
public class TaskHarvest extends TaskBreak
{
public TaskHarvest()
{
super("Harvest");
}
@Override
public ProcessReturn onMethodCalled()
{
this.keep = true;
return super.onMethodCalled();
}
}

View file

@ -1,102 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.ArrayList;
import java.util.List;
import resonantinduction.core.ArgumentData;
import resonantinduction.electrical.armbot.TaskBaseLogic;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.api.vector.Vector2;
/** @author DarkGuardsman */
public class TaskIF extends TaskBaseLogic
{
protected ITask exitTruePoint = null;
protected ITask exitFalsePoint = null;
protected List<Vector2> exits = new ArrayList<Vector2>();
protected boolean isTrue = false;
public TaskIF()
{
super("IF");
this.args.add(new ArgumentData("check", "statement"));
this.args.add(new ArgumentData("compare", "statement"));
this.UV = new Vector2(0, 120);
}
public TaskIF(ITask trueExit, ITask falseExit)
{
this();
this.exitTruePoint = trueExit;
this.exitFalsePoint = falseExit;
}
@Override
public void refresh()
{
super.refresh();
if (this.getArg("check") != null && this.getArg("compare") != null)
{
this.isTrue = this.getArg("check").equals(this.getArg("compare"));
}
if (exitTruePoint == null)
{
exitTruePoint = this.program.getTaskAt(this.getCol() + 1, this.getRow());
}
if (exitFalsePoint == null)
{
exitFalsePoint = this.program.getTaskAt(this.getCol(), this.getRow() + 1);
;
}
}
@Override
public TaskIF clone()
{
return new TaskIF();
}
@Override
public ITask getExitPoint()
{
if (this.isTrue)
{
return this.exitTruePoint;
}
return this.exitFalsePoint;
}
@Override
public int getMaxExitPoints()
{
return 2;
}
@Override
public void setExitPoint(int i, ITask task)
{
if (i == 0)
{
this.exitFalsePoint = task;
}
else if (i == 1)
{
this.exitTruePoint = task;
}
}
@Override
public boolean canUseTask(IProgrammableMachine device)
{
return true;
}
@Override
public List<Vector2> getExits()
{
return this.exits;
}
}

View file

@ -1,107 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import resonant.lib.science.units.UnitHelper;
import resonantinduction.core.ArgumentData;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
public class TaskIdle extends TaskBaseProcess
{
/** The amount of time in which the machine will idle. */
public int idleTime = 80;
private int totalIdleTime = 80;
public TaskIdle()
{
super("wait");
this.args.add(new ArgumentData("idleTime", 20));
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
if (UnitHelper.tryToParseInt(this.getArg("idleTime")) > 0)
{
this.totalIdleTime = this.idleTime = UnitHelper.tryToParseInt(this.getArg("idleTime"));
return ProcessReturn.CONTINUE;
}
return ProcessReturn.ARGUMENT_ERROR;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (this.idleTime > 0)
{
this.idleTime--;
return ProcessReturn.CONTINUE;
}
return ProcessReturn.DONE;
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.load(taskCompound);
this.totalIdleTime = taskCompound.getInteger("idleTotal");
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.save(taskCompound);
taskCompound.setInteger("idleTotal", this.totalIdleTime);
}
@Override
public TaskBaseProcess loadProgress(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.idleTime = taskCompound.getInteger("idleTime");
return this;
}
@Override
public NBTTagCompound saveProgress(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setInteger("idleTime", this.idleTime);
return taskCompound;
}
@Override
public String toString()
{
return super.toString() + " " + Integer.toString(this.totalIdleTime);
}
@Override
public TaskBaseProcess clone()
{
return new TaskIdle();
}
@Override
public boolean canUseTask(IProgrammableMachine device)
{
return true;
}
@Override
public void getToolTips(List<String> list)
{
super.getToolTips(list);
list.add(" Wait: " + this.totalIdleTime);
}
}

View file

@ -1,102 +0,0 @@
package resonantinduction.electrical.armbot.task;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.common.IPlantable;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import universalelectricity.core.transform.vector.Vector3;
/**
* Used by arms to break a specific block in a position.
*
* @author Calclavia
*/
public class TaskPlace extends TaskBaseArmbot
{
int PLACE_TIME = 30;
public TaskPlace()
{
super("Place");
// TODO Auto-generated constructor stub
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
Vector3 serachPosition = ((IArmbot) this.program.getMachine()).getHandPos();
Block block = Block.blocksList[serachPosition.getBlock(this.program.getMachine().getLocation().left())];
if (block == null && ticks >= this.PLACE_TIME)
{
Object entity = ((IArmbot) this.program.getMachine()).getHeldObject();
ItemStack itemStack = null;
if (entity instanceof EntityItem)
{
itemStack = ((EntityItem) entity).getEntityItem();
}
if (entity instanceof ItemStack)
{
itemStack = (ItemStack) entity;
}
if (itemStack != null)
{
if (itemStack.getItem() instanceof ItemBlock)
{
((ItemBlock) itemStack.getItem()).placeBlockAt(itemStack, null, this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage());
((IArmbot) this.program.getMachine()).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)).getBlock(this.program.getMachine().getLocation().left())];
if (blockBelow != null)
{
if (blockBelow.canSustainPlant(this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), ForgeDirection.UP, plantable))
{
int blockID = plantable.getPlantID(this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
int blockMetadata = plantable.getPlantMetadata(this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ());
if (this.program.getMachine().getLocation().left().setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockID, blockMetadata, 3))
{
if (this.program.getMachine().getLocation().left().getBlockId(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()) == blockID)
{
Block.blocksList[blockID].onBlockPlacedBy(this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null, itemStack);
Block.blocksList[blockID].onPostBlockPlaced(this.program.getMachine().getLocation().left(), serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata);
((IArmbot) this.program.getMachine()).clear(entity);
return ProcessReturn.DONE;
}
}
}
}
}
}
}
return ProcessReturn.DONE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public String toString()
{
return "PLACE";
}
@Override
public TaskBaseProcess clone()
{
return new TaskPlace();
}
}

View file

@ -1,18 +0,0 @@
package resonantinduction.electrical.armbot.task;
import resonantinduction.electrical.armbot.TaskBaseProcess;
public class TaskReturn extends TaskRotateTo
{
public TaskReturn()
{
super("Return", 0, 0);
}
@Override
public TaskBaseProcess clone()
{
return new TaskReturn();
}
}

View file

@ -1,101 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import resonant.lib.science.units.UnitHelper;
import resonant.lib.utility.MathUtility;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
/**
* Rotates an armbot by a set amount
*
* @author DarkGuardsman
*/
public class TaskRotateBy extends TaskBaseArmbot
{
int targetRotationYaw = 0, targetRotationPitch = 0, deltaPitch = 0, deltaYaw = 0;
private TaskRotateTo rotateToCommand;
public TaskRotateBy(int yaw, int pitch)
{
super("RotateBy");
this.args.add(new ArgumentIntData("yaw", yaw, 360, 0));
this.args.add(new ArgumentIntData("pitch", pitch, 360, 0));
this.UV = new Vector2(80, 80);
}
public TaskRotateBy()
{
this(0, 0);
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
this.targetRotationYaw = (int) MathUtility.clampAngleTo360((float) (((IArmbot) this.program.getMachine()).getRotation().x + UnitHelper.tryToParseInt(this.getArg("yaw"))));
this.targetRotationPitch = (int) MathUtility.clampAngleTo360((float) (((IArmbot) this.program.getMachine()).getRotation().x + UnitHelper.tryToParseInt(this.getArg("pitch"))));
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (this.rotateToCommand == null)
{
this.rotateToCommand = new TaskRotateTo(this.targetRotationYaw, this.targetRotationPitch);
this.rotateToCommand.setProgram(this.program);
this.rotateToCommand.onMethodCalled();
}
return this.rotateToCommand.onUpdate();
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.loadProgress(taskCompound);
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.saveProgress(taskCompound);
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
}
@Override
public String toString()
{
return super.toString() + " Yaw:" + Integer.toString(this.targetRotationYaw) + " Pitch:" + Integer.toString(this.targetRotationPitch);
}
@Override
public TaskBaseProcess clone()
{
return new TaskRotateBy();
}
@Override
public void getToolTips(List<String> list)
{
super.getToolTips(list);
list.add(" Yaw: " + this.targetRotationYaw);
list.add(" Pitch: " + this.targetRotationPitch);
}
}

View file

@ -1,99 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import resonant.lib.science.units.UnitHelper;
import resonant.lib.utility.MathUtility;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
/**
* Rotates the armbot to a specific direction.
*
* @author DarkGuardsman
*/
public class TaskRotateTo extends TaskBaseArmbot
{
int targetRotationYaw = 0, targetRotationPitch = 0;
public TaskRotateTo()
{
this(0, 0);
}
public TaskRotateTo(int yaw, int pitch)
{
this("RotateTo", yaw, pitch);
}
public TaskRotateTo(String string, int yaw, int pitch)
{
super(string);
this.args.add(new ArgumentIntData("yaw", yaw, 360, 0));
this.args.add(new ArgumentIntData("pitch", pitch, 360, 0));
this.UV = new Vector2(100, 80);
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
this.targetRotationYaw = (int) MathUtility.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("yaw")));
this.targetRotationPitch = (int) MathUtility.clampAngleTo360(UnitHelper.tryToParseInt(this.getArg("pitch")));
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
((IArmbot) this.program.getMachine()).moveArmTo(this.targetRotationYaw, this.targetRotationPitch);
return ((IArmbot) this.program.getMachine()).getRotation().intX() != this.targetRotationYaw || ((IArmbot) this.program.getMachine()).getRotation().intY() != this.targetRotationPitch ? ProcessReturn.CONTINUE : ProcessReturn.DONE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public String toString()
{
return super.toString() + " Yaw:" + Integer.toString(this.targetRotationYaw) + " Pitch:" + Integer.toString(this.targetRotationPitch);
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.load(taskCompound);
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.save(taskCompound);
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
}
@Override
public TaskBaseProcess clone()
{
return new TaskRotateTo();
}
@Override
public void getToolTips(List<String> list)
{
super.getToolTips(list);
list.add(" Yaw: " + this.targetRotationYaw);
list.add(" Pitch: " + this.targetRotationPitch);
}
}

View file

@ -1,24 +0,0 @@
package resonantinduction.electrical.armbot.task;
import resonantinduction.electrical.armbot.TaskBase;
/**
* Fake task as the player can not create, edit, or do anything with this task. Its only used to
* allow the gui to render the task as an actual task instance
*
* @author DarkGaurdsman
*/
public class TaskStart extends TaskBase
{
public TaskStart()
{
super("Start", TaskType.START);
}
@Override
public TaskBase clone()
{
return new TaskStart();
}
}

View file

@ -1,112 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.science.units.UnitHelper;
import resonant.lib.utility.MathUtility;
import resonant.lib.utility.inventory.InternalInventoryHandler;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import universalelectricity.core.transform.vector.Vector3;
public class TaskTake extends TaskBaseArmbot
{
protected ItemStack stack;
protected int ammount = -1;
public TaskTake()
{
super("Take");
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);
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
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;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
TileEntity targetTile = ((IArmbot) this.program.getMachine()).getHandPos().getTileEntity(this.program.getMachine().getLocation().left());
if (targetTile != null && ((IArmbot) this.program.getMachine()).getHeldObject() instanceof ItemStack)
{
ForgeDirection direction = MathUtility.getFacingDirectionFromAngle(((IArmbot) this.program.getMachine()).getRotation().x);
Set<ItemStack> stacks = new HashSet<ItemStack>();
if (this.stack != null)
{
stacks.add(stack);
}
InternalInventoryHandler invEx = new InternalInventoryHandler(this.program.getMachine().getLocation().left(), this.program.getMachine().getLocation().right(), stacks, false);
((IArmbot) this.program.getMachine()).grabObject(invEx.tryGrabFromPosition(new Vector3(targetTile), direction, this.stack != null ? stack.stackSize : 1));
return ((IArmbot) this.program.getMachine()).getHeldObject() != null ? ProcessReturn.DONE : ProcessReturn.CONTINUE;
}
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public String toString()
{
return super.toString() + " " + (stack != null ? stack.toString() : "1x???@??? ");
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.load(taskCompound);
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.save(taskCompound);
if (stack != null)
{
NBTTagCompound tag = new NBTTagCompound();
this.stack.writeToNBT(tag);
taskCompound.setTag("item", tag);
}
}
@Override
public TaskBaseProcess clone()
{
return new TaskTake();
}
}

View file

@ -1,127 +0,0 @@
package resonantinduction.electrical.armbot.task;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import resonant.lib.science.units.UnitHelper;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.IArmbotUseable;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.IProcessTask;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
public class TaskUse extends TaskBaseArmbot
{
protected int times, curTimes;
public TaskUse()
{
super("use");
this.args.add(new ArgumentIntData("repeat", 1, Integer.MAX_VALUE, 1));
}
@Override
public ProcessReturn onMethodCalled()
{
if (super.onMethodCalled() == ProcessReturn.CONTINUE)
{
this.curTimes = 0;
this.times = UnitHelper.tryToParseInt(this.getArg("repeat"));
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public ProcessReturn onUpdate()
{
if (super.onUpdate() == ProcessReturn.CONTINUE)
{
Block block = Block.blocksList[((IArmbot) this.program.getMachine()).getHandPos().getBlock(this.program.getMachine().getLocation().left())];
TileEntity targetTile = ((IArmbot) this.program.getMachine()).getHandPos().getTileEntity(this.program.getMachine().getLocation().left());
if (targetTile != null)
{
if (targetTile instanceof IArmbotUseable)
{
((IArmbotUseable) targetTile).onUse(((IArmbot) this.program.getMachine()), this.getArgs());
}
}
else if (block != null)
{
try
{
boolean f = block.onBlockActivated(this.program.getMachine().getLocation().left(), ((IArmbot) this.program.getMachine()).getHandPos().intX(), ((IArmbot) this.program.getMachine()).getHandPos().intY(), ((IArmbot) this.program.getMachine()).getHandPos().intZ(), null, 0, 0, 0, 0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
this.curTimes++;
if (this.curTimes >= this.times)
{
return ProcessReturn.DONE;
}
return ProcessReturn.CONTINUE;
}
return ProcessReturn.GENERAL_ERROR;
}
@Override
public String toString()
{
return "USE " + Integer.toString(this.times);
}
@Override
public void load(NBTTagCompound taskCompound)
{
super.load(taskCompound);
this.times = taskCompound.getInteger("useTimes");
}
@Override
public void save(NBTTagCompound taskCompound)
{
super.save(taskCompound);
taskCompound.setInteger("useTimes", this.times);
}
@Override
public IProcessTask 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 TaskBaseProcess clone()
{
return new TaskUse();
}
@Override
public void getToolTips(List<String> list)
{
super.getToolTips(list);
list.add(" Repeat: " + this.times);
}
}