Removed Armbot

This commit is contained in:
Robert S 2014-09-07 19:03:55 -04:00
parent a236c4a9a5
commit 518f0474c1
61 changed files with 1 additions and 5351 deletions

View File

@ -8,8 +8,6 @@ import resonant.lib.render.item.GlobalItemRenderer;
import resonantinduction.electrical.battery.RenderBattery;
import resonantinduction.electrical.battery.TileBattery;
import resonantinduction.electrical.charger.RenderCharger;
import resonantinduction.electrical.encoder.TileEncoder;
import resonantinduction.electrical.encoder.gui.GuiEncoderInventory;
import resonantinduction.electrical.laser.gun.RenderMiningLaserGun;
import resonantinduction.electrical.levitator.RenderLevitator;
import resonantinduction.electrical.multimeter.GuiMultimeter;
@ -65,10 +63,6 @@ public class ClientProxy extends CommonProxy
return new GuiMultimeter(player.inventory, (PartMultimeter) part);
}
}
else if (tileEntity instanceof TileEncoder)
{
return new GuiEncoderInventory(player.inventory, (TileEncoder) tileEntity);
}
return null;
}

View File

@ -6,8 +6,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonant.lib.prefab.ProxyBase;
import resonantinduction.electrical.encoder.TileEncoder;
import resonantinduction.electrical.encoder.gui.ContainerEncoder;
import resonantinduction.electrical.multimeter.ContainerMultimeter;
import resonantinduction.electrical.multimeter.PartMultimeter;
import universalelectricity.api.vector.Vector3;
@ -29,10 +27,6 @@ public class CommonProxy extends ProxyBase
return new ContainerMultimeter(player.inventory, ((PartMultimeter) part));
}
}
else if (tileEntity instanceof TileEncoder)
{
return new ContainerEncoder(player.inventory, (TileEncoder) tileEntity);
}
return null;
}

View File

@ -16,8 +16,6 @@ import resonantinduction.core.ResonantInduction;
import resonantinduction.core.Settings;
import resonantinduction.core.TabRI;
import resonantinduction.core.resource.ItemResourcePart;
import resonantinduction.electrical.armbot.BlockArmbot;
import resonantinduction.electrical.armbot.TileArmbot;
import resonantinduction.electrical.battery.BlockBattery;
import resonantinduction.electrical.battery.ItemBlockBattery;
import resonantinduction.electrical.battery.TileBattery;
@ -118,8 +116,7 @@ public class Electrical
itemCharger = contentRegistry.createItem(ItemCharger.class);
blockTesla = contentRegistry.createTile(BlockTesla.class, TileTesla.class);
blockBattery = contentRegistry.createBlock(BlockBattery.class, ItemBlockBattery.class, TileBattery.class);
blockArmbot = contentRegistry.createBlock(BlockArmbot.class, null, TileArmbot.class);
// Transport
itemLevitator = contentRegistry.createItem(ItemLevitator.class);
itemInsulation = contentRegistry.createItem("insulation", ItemResourcePart.class);

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.ForgeDirection;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.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.api.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.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.api.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).translate(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.translate(0.5);
position.translate(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.api.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.getBlockID(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.api.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.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.api.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.ForgeDirection;
import resonant.api.IEntityConveyor;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.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().translate(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.ForgeDirection;
import net.minecraftforge.common.IPlantable;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import universalelectricity.api.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.getBlockID(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.translate(serachPosition, new Vector3(0, -1, 0)).getBlockID(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.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.api.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().getBlockID(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);
}
}

View File

@ -1,81 +0,0 @@
package resonantinduction.electrical.encoder;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import resonant.lib.prefab.block.BlockTile;
import resonantinduction.core.Reference;
import resonantinduction.electrical.Electrical;
import universalelectricity.api.UniversalElectricity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockEncoder extends BlockTile
{
Icon encoder_side;
Icon encoder_top;
Icon encoder_bottom;
public BlockEncoder(int id)
{
super(id, UniversalElectricity.machine);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconReg)
{
this.encoder_side = iconReg.registerIcon(Reference.PREFIX + "encoder_side");
this.encoder_top = iconReg.registerIcon(Reference.PREFIX + "encoder_top");
this.encoder_bottom = iconReg.registerIcon(Reference.PREFIX + "encoder_bottom");
}
/** Returns the block texture based on the side being looked at. Args: side */
@Override
@SideOnly(Side.CLIENT)
public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
{
return getIcon(side, 0);
}
/** Returns the block texture based on the side being looked at. Args: side */
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta)
{
if (side == 1)
{
return this.encoder_top;
}
else if (side == 0)
{
return this.encoder_bottom;
}
return this.encoder_side;
}
/** Called upon block activation (right click on the block.) */
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
if (!world.isRemote)
{
entityPlayer.openGui(Electrical.INSTANCE, 0, world, x, y, z);
}
return true;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEncoder();
}
}

View File

@ -1,6 +0,0 @@
package resonantinduction.electrical.encoder;
public interface IInventoryWatcher
{
public void inventoryChanged();
}

View File

@ -1,99 +0,0 @@
package resonantinduction.electrical.encoder;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import resonantinduction.core.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemDisk extends Item
{
public ItemDisk(int id)
{
super(id);
this.setHasSubtypes(true);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon(Reference.PREFIX + "disk");
}
@Override
public int getItemStackLimit()
{
return 1;
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4)
{
List<String> commands = getCommands(itemStack);
if (commands.size() > 0)
{
if (commands.size() == 1)
list.add(commands.size() + " command");
else
list.add(commands.size() + " commands");
}
else
{
list.add("No commands");
}
}
/** Saves the list of items to filter out inside. */
public static void setCommands(ItemStack itemStack, ArrayList<String> commands)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
NBTTagList nbt = new NBTTagList();
for (int i = 0; i < commands.size(); ++i)
{
if (commands.get(i) != null)
{
NBTTagCompound newCompound = new NBTTagCompound();
newCompound.setString("command", commands.get(i));
nbt.appendTag(newCompound);
}
}
itemStack.getTagCompound().setTag("Commands", nbt);
}
public static ArrayList<String> getCommands(ItemStack itemStack)
{
ArrayList<String> commands = new ArrayList<String>();
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound nbt = itemStack.getTagCompound();
NBTTagList tagList = nbt.getTagList("Commands");
for (int i = 0; i < tagList.tagCount(); ++i)
{
NBTTagCompound curTag = (NBTTagCompound) tagList.tagAt(i);
String cmd = curTag.getString("command");
commands.add(cmd);
}
return commands;
}
}

View File

@ -1,21 +0,0 @@
package resonantinduction.electrical.encoder;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import resonantinduction.electrical.Electrical;
public class SlotDisk extends Slot
{
public SlotDisk(IInventory par1iInventory, int par2, int par3, int par4)
{
super(par1iInventory, par2, par3, par4);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return itemStack.itemID == Electrical.itemDisk.itemID;
}
}

View File

@ -1,42 +0,0 @@
package resonantinduction.electrical.encoder;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotDiskResult extends Slot
{
public SlotDiskResult(IInventory par1iInventory, int par2, int par3, int par4)
{
super(par1iInventory, par2, par3, par4);
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
{
super.onPickupFromSlot(par1EntityPlayer, par2ItemStack);
if (this.inventory.getStackInSlot(0) != null)
{
this.inventory.getStackInSlot(0).stackSize--;
if (this.inventory.getStackInSlot(0).stackSize <= 0)
{
this.inventory.setInventorySlotContents(0, null);
}
}
/*
* if (this.inventory.getStackInSlot(1) != null) {
* this.inventory.getStackInSlot(1).stackSize--; if
* (this.inventory.getStackInSlot(1).stackSize <= 1) {
* this.inventory.setInventorySlotContents(1, null); } }
*/
}
}

View File

@ -1,233 +0,0 @@
package resonantinduction.electrical.encoder;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import resonant.lib.network.IPacketReceiver;
import resonant.lib.network.PacketHandler;
import resonant.lib.prefab.tile.TileExternalInventory;
import resonantinduction.core.ResonantInduction;
import resonantinduction.electrical.armbot.Program;
import resonantinduction.electrical.armbot.task.TaskRotateTo;
import resonantinduction.electrical.encoder.coding.IProgram;
import resonantinduction.electrical.encoder.coding.ITask;
import resonantinduction.electrical.encoder.coding.TaskRegistry;
import universalelectricity.api.vector.Vector2;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
public class TileEncoder extends TileExternalInventory implements ISidedInventory, IPacketReceiver
{
private ItemStack disk;
private IInventoryWatcher watcher;
public static final int PROGRAM_PACKET_ID = 0;
public static final int PROGRAM_CHANGE_PACKET_ID = 1;
public static final int REMOVE_TASK_PACKET_ID = 2;
public static final int NEW_TASK_PACKET_ID = 3;
protected IProgram program;
@Override
public void initiate()
{
super.initiate();
if (!this.worldObj.isRemote)
{
program = new Program();
program.setTaskAt(0, 0, new TaskRotateTo());
}
}
@Override
public void onInventoryChanged()
{
super.onInventoryChanged();
if (watcher != null)
{
watcher.inventoryChanged();
}
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.disk != null)
{
NBTTagCompound diskNBT = new NBTTagCompound();
this.disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
if (diskNBT != null)
{
this.disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
int readInt = data.readInt();
if (readInt == PROGRAM_PACKET_ID)
{
if (data.readBoolean())
{
Program program = new Program();
program.load(PacketHandler.readNBTTagCompound(data));
this.program = program;
}
else
{
this.program = null;
}
}
else if (readInt == PROGRAM_CHANGE_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().setTaskAt(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == NEW_TASK_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().insertTask(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == REMOVE_TASK_PACKET_ID)
{
this.getProgram().setTaskAt(data.readInt(), data.readInt(), null);
this.sendGUIPacket();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
private void sendGUIPacket()
{
// TODO Auto-generated method stub
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
boolean exists = this.program != null;
if (exists)
{
this.program.save(tag);
}
return ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.PROGRAM_PACKET_ID, this, exists, tag);
}
public void removeTask(Vector2 vec)
{
if (vec != null)
{
if (this.worldObj.isRemote)
{
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.REMOVE_TASK_PACKET_ID, this, vec.intX(), vec.intY()));
}
else
{
this.program.setTaskAt(vec.intX(), vec.intY(), null);
}
}
}
public void updateTask(ITask editTask)
{
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, PROGRAM_CHANGE_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.setTaskAt(editTask.getCol(), editTask.getRow(), editTask);
}
}
}
public void insertTask(ITask editTask)
{
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, NEW_TASK_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.insertTask(editTask.getCol(), editTask.getRow(), editTask);
}
}
}
public IProgram getProgram()
{
if (this.program == null)
{
this.program = new Program();
}
return this.program;
}
}

View File

@ -1,17 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import net.minecraft.nbt.NBTTagCompound;
/**
* Used to ID that an item can support saving data to it NBT
*
* @author DarkGuardsman
*/
public interface IDataItem
{
/** Saves the data to the item */
public NBTTagCompound saveData(NBTTagCompound nbt);
/** Gets the data from the item */
public NBTTagCompound getData();
}

View File

@ -1,32 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.List;
import universalelectricity.api.vector.Vector2;
/**
* Task in which it doesn't go right to the next task in the row. In this case the task will store
* the entry point, and exit points. As well handle anything in between. Examples are IF statements
* and loops. Do your logic in the refresh method as it should be called each time a new task is
* selected.
*
* @author DarkGuardsman
*/
public interface ILogicTask extends ITask
{
/**
* There is always only one exit though you can do logic to pick from all your exit points. Exit
* is the next task rather than the exit of the statement. Use #IRedirectTask to force the logic
* back to this task.
*/
public ITask getExitPoint();
public List<Vector2> getExits();
/** Mainly used by the encoder to understand the limit on connections */
public int getMaxExitPoints();
/** Adds a possible exit point to the split off */
public void setExitPoint(int i, ITask task);
}

View File

@ -1,35 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.HashMap;
/**
* Used by task to tell the program it needs to remember a value outside the task. Should only be
* used by task that really need to save values beyond there local values. Cases were this is used
* should be is loops, items counts, and run conditions.
*
* @author DarkGuardsman
*/
public interface IMemorySlot
{
/**
* Called per update to store the changes in memory. If return is null the memory location will
* be released. Make sure to do this if the value is no longer needed. Memory is limited to
* basic java variables, and will not accept arrays, or collections
*/
public Object getMemory(String name);
/**
* All memory locations needed by this task with there names, data types, and starting/current
* values. Take care that this is designed to keep data over several program cycles. This is not
* used to save local data. As well machines have limited memory of only a few active vars.
*/
public HashMap<String, Object> getMemory();
/**
* Any memory location that needs to be saved to the machines hard disk. Should only do this for
* information that must be saved. Treat this as real world memory to hard drive saving. As well
* if the machine is running between world saves its active memory will be save. However, if it
* turns off its active memory will clear. Called as the task is terminated.
*/
public HashMap<String, Object> getSavedData();
}

View File

@ -1,57 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
/**
* Use to construct a basic task that can be used in any device that supports this interface.
*
* @Note - there are several methods that look a like. GetArgs is used to get the programs arguments
* that were set by the encoder. GetEncoderParms should be a constant set of arguments that the
* device can support. GetMemory is a list of variables that the program needs to store outside of
* the task. That way it can save values after the task has been refreshed or even deleted.
*
* @author DarkGuardsman
*/
public interface IProcessTask extends ITask
{
/**
* Passed in from the device to the program manager then here after a Computer craft machine
* calls a this commands method name. {@IPeripheral #callMethod()}
*/
public Object[] onCCMethodCalled(IComputerAccess computer, ILuaContext context) throws Exception;
/**
* Called when the task is being run by the devices program manager. Used mainly to setup the
* task before actually doing the task.
*
* @param world - current world
* @param location - current location
* @param armbot - armbot instance
* @param arguments - arguments for command
* @return false to stop the task here.
*/
public ProcessReturn onMethodCalled();
/** Update the current segment of the task */
public ProcessReturn onUpdate();
/** Called when the task is finish and then cleared */
public void terminated();
public static enum ProcessReturn
{
CONTINUE("Continue", "Running"), DONE("Done", "Done"),
GENERAL_ERROR("General Error", "Error program failure"),
SYNTAX_ERROR("Syntax Error", "Error incorrect syntax"),
ARGUMENT_ERROR("Arument error", "Error incorrect arguments");
public String name, userOutput;
private ProcessReturn(String name, String userOutput)
{
this.name = name;
this.userOutput = userOutput;
}
}
}

View File

@ -1,61 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.HashMap;
import net.minecraft.nbt.NBTTagCompound;
import universalelectricity.api.vector.Vector2;
/**
* Flow chart style program. Each command in the program needs to have a stored location so it can
* be saved and loaded with its correct connections. Though the location only need to be a simple
* Column and row based system.
*
* @author DarkGuardsman
*/
public interface IProgram extends Cloneable
{
/** Called when the program is added to an encoder, machine, or devices. */
public void init(IProgrammableMachine machine);
public IProgrammableMachine getMachine();
/**
* Variables this program has to operate. Is still limited by the actual machine. String is the
* name, Object is the starting value and data type
*/
public HashMap<String, Object> getDeclairedVarables();
/** Next task in the set. Its up to the program to increment down the list */
public ITask getNextTask();
/** Gets a task at the given x y location in the program */
public ITask getTaskAt(int col, int row);
/** Returns the entire program as a map as grid locations and tasks. */
public HashMap<Vector2, ITask> getTaskMap();
/**
* Sets the task at the point overriding what was there. If the task is null remove it and shift
* everything up one
*/
public void setTaskAt(int col, int row, ITask task);
/** Inserts a task at the point. If a task is already there everything should shift down 1 */
public void insertTask(int col, int row, ITask task);
/** Return this program to its starting conditions */
public void reset();
/** Sets the declared variable */
public void setVar(String name, Object object);
/** Gets a declared variable */
public Object getVar(String name);
/** return size in commands high and wide */
public Vector2 getSize();
public NBTTagCompound save(NBTTagCompound nbt);
public void load(NBTTagCompound nbt);
}

View File

@ -1,15 +0,0 @@
package resonantinduction.electrical.encoder.coding;
/**
* IDs that an item can load/save a program
*
* @author Darkguardsman
*/
public interface IProgramItem
{
/** Sets the program into the item */
public void setProgram(IProgram program);
/** Gets the program from the item */
public IProgram getProgram();
}

View File

@ -1,26 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import net.minecraft.world.World;
import resonant.lib.type.Pair;
import universalelectricity.api.vector.Vector3;
/**
* Simple interface too say an object is programmable
*
* @author DarkGuardsman
*/
public interface IProgrammableMachine
{
/** Current program in use */
public IProgram getCurrentProgram();
/** Sets the current program */
public void setCurrentProgram(IProgram program);
/**
* Gets the machine location as a pair containing both the world and xyz vector.
*
* @return try to avoid returning null as every object but a fake one has a location
*/
public Pair<World, Vector3> getLocation();
}

View File

@ -1,14 +0,0 @@
package resonantinduction.electrical.encoder.coding;
/**
* Used to tell the program that this task is used to tell the program were to go next. Used by
* things like LOOP, IF, and GOTO statement's end catches. Not actually used by the statement itself
* other than to help control the flow of the program
*
* @author DarkGuardsman
*/
public interface IRedirectTask extends ILogicTask
{
/** Should we show this in the encoder. Useful if your using a task as part of another task */
public boolean render();
}

View File

@ -1,101 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import resonant.lib.utility.nbt.ISaveObj;
import resonantinduction.core.ArgumentData;
import universalelectricity.api.vector.Vector2;
/** @author DarkGuardsman */
public interface ITask extends Cloneable, ISaveObj
{
/** Called each time the program is loaded or changed */
public void refresh();
/** Called when this task is asked to return to default */
public void reset();
/** Sets the task's program reference letting it know what it is part of */
public void setProgram(IProgram program);
/** Location in the program */
public int getRow();
public int getCol();
/** Sets the tasks position in the program */
public void setPosition(int col, int row);
/**
* Method name or rather command name this will be called. Uses both to ID this command, and do
* basic command structuring.
*/
public String getMethodName();
/** Type of task used mainly for GUI displays */
public TaskType getType();
/** Get an argument by a given name */
public Object getArg(String name);
/** Get all given arguments */
public List<ArgumentData> getArgs();
public void setArg(String arg, Object data);
/** Reads the progress of the command if it was saved mid process */
public ITask loadProgress(NBTTagCompound nbt);
/** Saves the current progress of the current command */
public NBTTagCompound saveProgress(NBTTagCompound nbt);
/**
* Can this task function for this machine. Only do basic checks here as its only used to make
* sure the machine, or task will not crash while running.
*/
public boolean canUseTask(IProgrammableMachine device);
/**
* Used to create a new task from this task. Make sure to return a fresh copy without anything.
* This includes no arguments, progress, variables, etc. As this is used to make new tasks from
* the TaskRegistry
*/
public ITask clone();
/**
* Texture used by encoder's to render the icon for the task. Make sure not to create a new
* instance of the resource location each call. Doing so will cause the client to experience
* increase RAM usage
*/
public ResourceLocation getTextureSheet();
/** Location of the texture in the sheet */
public Vector2 getTextureUV();
/** Passes in a list so that the task can add to the tool tip render */
public void getToolTips(List<String> list);
/** Used mainly for display purposes in the encoder */
public static enum TaskType
{
DATA("Data", 120, 40), DEFINEDPROCESS("Defined Process", 40, 40),
PROCESS("Process", 60, 40), DECISION("Decision", 80, 40), START("Start", 20, 40),
END("End", 100, 40);
public final String name;
public final Vector2 UV;
/**
* This is only loaded when assembly line is installed, and only used as a backup if tasks
* don't return textures
*/
public static final ResourceLocation TEXTURE = new ResourceLocation("al", "textures/gui/gui_coder_icons.png");
private TaskType(String name, int uu, int vv)
{
this.name = name;
this.UV = new Vector2(uu, vv);
}
}
}

View File

@ -1,182 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.HashMap;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import resonantinduction.electrical.encoder.coding.IProcessTask.ProcessReturn;
import universalelectricity.api.vector.Vector3;
/**
* Basic class to handle a machine like programs for any object that uses the IProgramable
* interface. Doesn't actually do much then tell the program to function, and stores the programs
* active run time memory.
*
* @author DarkGuardsman
*/
public class ProgramHelper
{
/** Current Program */
protected IProgram program;
protected IProgrammableMachine bot;
/** Current task in program */
protected ITask currentTask;
/** Do we have a memory to store values */
boolean hasMemory = false;
boolean hasTaskBeenCalled = false, nextTask = false;
/** Max memorySize */
protected int memorySize = 0;
/** Array of values to remember between commands */
protected HashMap<String, Object> taskMemory = new HashMap<String, Object>();
public ProgramHelper(IProgrammableMachine bot)
{
this.bot = bot;
}
/**
* Needs to be called by the armbot per tick.
*
* @return true if it is doing something
*/
public ProcessReturn onUpdate(World world, Vector3 botLocation)
{
ProcessReturn re = ProcessReturn.DONE;
if (program != null)
{
if (this.currentTask == null || this.nextTask)
{
this.nextTask();
}
if (this.currentTask != null)
{
if (!this.hasTaskBeenCalled)
{
this.hasTaskBeenCalled = true;
if (this.currentTask instanceof IProcessTask)
{
re = ((IProcessTask) this.currentTask).onMethodCalled();
if (re == ProcessReturn.DONE)
{
this.nextTask = true;
}
else if (re != ProcessReturn.CONTINUE)
{
return re;
}
}
}
if (this.currentTask instanceof IProcessTask)
{
re = ((IProcessTask) this.currentTask).onUpdate();
if (re == ProcessReturn.DONE)
{
this.nextTask = true;
}
}
else
{
re = ProcessReturn.CONTINUE;
}
return re;
}
}
return re;
}
/** Gets the next task from the program */
public void nextTask()
{
this.hasTaskBeenCalled = false;
this.nextTask = false;
this.currentTask = program.getNextTask();
}
public ProgramHelper setMemoryLimit(int varableLimit)
{
if (varableLimit > 0)
{
this.memorySize = varableLimit;
this.hasMemory = true;
}
else
{
this.taskMemory = null;
}
return this;
}
public ProgramHelper setProgram(IProgram program)
{
this.program = program;
this.onProgramChanged();
return this;
}
public IProgram getProgram()
{
return this.program;
}
public void onProgramChanged()
{
this.taskMemory.clear();
if (this.program != null)
{
HashMap<String, Object> memory = this.program.getDeclairedVarables();
if (memory.size() <= memorySize)
{
// TODO load in memory and throw error stopping machine if there is not enough
}
this.program.init(this.bot);
}
}
/** Gets the memory location */
public Object getMemoryLocation(String var)
{
return this.taskMemory.get(var);
}
/** Sets the memory location at the give spot. */
public boolean setMemoryLocation(String var, Object object)
{
if (var != null)
{
if (this.taskMemory.containsKey(var))
{
if (object == null)
{
this.taskMemory.remove(var);
}
return this.addMemory(var, object);
}
else if (object != null && this.taskMemory.size() < this.memorySize)
{
return this.addMemory(var, object);
}
}
return false;
}
protected boolean addMemory(String var, Object object)
{
// We don't want cheat methods to bypass the variable memory limit
if (!(object instanceof java.util.Arrays && object instanceof java.util.ArrayList && object instanceof java.util.List && object instanceof java.util.Set))
{
return this.taskMemory.put(var, object) != null;
}
return false;
}
public NBTTagCompound save(NBTTagCompound nbt)
{
return nbt;
}
public void load(NBTTagCompound nbt)
{
}
}

View File

@ -1,97 +0,0 @@
package resonantinduction.electrical.encoder.coding;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import resonantinduction.electrical.armbot.IArmbot;
/**
* Used to both register task and fake machines for the encoder to use to create new programs.
*
* @author DarkGuardsman
*/
public class TaskRegistry
{
/**
* A class of all available commands.
*
* String - Command name. Command - The actual command class.
*/
private static final HashMap<String, ITask> COMMANDS = new HashMap();
private static final HashMap<String, IArmbot> SUDO_BOTS = new HashMap<String, IArmbot>();
/** Registers a command and tells armbots that it exists */
public static void registerCommand(ITask task)
{
if (!COMMANDS.containsKey(task.getMethodName()))
{
COMMANDS.put(task.getMethodName(), task);
}
}
public static void registerCommand(String registryName, IProcessTask task)
{
if (!COMMANDS.containsKey(registryName))
{
COMMANDS.put(registryName, task);
}
}
/** returns the first command with the same name */
public static ITask getCommand(String name)
{
for (Entry<String, ITask> command : COMMANDS.entrySet())
{
if (command.getKey().equalsIgnoreCase(name))
{
return command.getValue();
}
}
return null;
}
/** Gets all commands with the given name though there should only be one */
public static List<ITask> getCommands(String name)
{
List<ITask> tasks = new ArrayList<ITask>();
for (Entry<String, ITask> command : COMMANDS.entrySet())
{
if (command.getValue().getMethodName().equalsIgnoreCase(name))
{
tasks.add(command.getValue());
}
}
return tasks;
}
/**
* Don't actually register the real machine. Register a fake version so that a code can use it
* for simulations
*/
public static void registerMachine(String name, IArmbot bot)
{
if (!SUDO_BOTS.containsKey(name))
{
SUDO_BOTS.put(name, bot);
}
}
/**
* Do not edit the return or you will change the behavior of all machine that use this list
*
* @return The list of registered sudo machines for the encoder to check against
*/
public static HashMap<String, IArmbot> getSudoMachines()
{
return SUDO_BOTS;
}
/** Get one of the sudo bots in the hashmap. Make sure to clone before editing */
public static IArmbot getBot(String string)
{
return SUDO_BOTS.get(string);
}
}

View File

@ -1,40 +0,0 @@
package resonantinduction.electrical.encoder.coding.args;
import net.minecraft.util.MathHelper;
import resonantinduction.core.ArgumentData;
import universalelectricity.api.energy.UnitDisplay;
/**
* Used to create argument data for the encoder. Should only be used if the value needs to be
* clearly limited inside the encoder display.
*
* @author DarkGuardsman
*/
public class ArgumentDoubleData extends ArgumentData
{
protected double max, min;
public ArgumentDoubleData(String name, double value, double max, double min)
{
super(name, value);
this.max = max;
this.min = min;
}
@Override
public boolean isValid(Object object)
{
if (super.isValid())
{
double value = MathHelper.parseDoubleWithDefault("" + object, min - 100);
return value != min - 100 && value >= min && value <= max;
}
return false;
}
@Override
public String warning()
{
return "" + UnitDisplay.roundDecimals(min, 2) + " - " + UnitDisplay.roundDecimals(max, 2);
}
}

View File

@ -1,13 +0,0 @@
package resonantinduction.electrical.encoder.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

@ -1,40 +0,0 @@
package resonantinduction.electrical.encoder.coding.args;
import net.minecraft.util.MathHelper;
import resonantinduction.core.ArgumentData;
import universalelectricity.api.energy.UnitDisplay;
/**
* Used to create argument data for the encoder. Should only be used if the value needs to be
* clearly limited inside the encoder display.
*
* @author DarkGuardsman
*/
public class ArgumentFloatData extends ArgumentData
{
protected float max, min;
public ArgumentFloatData(String name, float value, float max, float min)
{
super(name, value);
this.max = max;
this.min = min;
}
@Override
public boolean isValid(Object object)
{
if (super.isValid())
{
float value = (float) MathHelper.parseDoubleWithDefault("" + object, min - 100);
return value != min - 100 && value >= min && value <= max;
}
return false;
}
@Override
public String warning()
{
return "" + UnitDisplay.roundDecimals(min, 2) + " - " + UnitDisplay.roundDecimals(max, 2);
}
}

View File

@ -1,39 +0,0 @@
package resonantinduction.electrical.encoder.coding.args;
import net.minecraft.util.MathHelper;
import resonantinduction.core.ArgumentData;
/**
* Used to create argument data for the encoder. Should only be used if the value needs to be
* clearly limited inside the encoder display.
*
* @author DarkGuardsman
*/
public class ArgumentIntData extends ArgumentData
{
protected int max, min;
public ArgumentIntData(String name, int value, int max, int min)
{
super(name, value);
this.max = max;
this.min = min;
}
@Override
public boolean isValid(Object object)
{
if (super.isValid())
{
int value = MathHelper.parseIntWithDefault("" + object, min - 100);
return value != min - 100 && value >= min && value <= max;
}
return false;
}
@Override
public String warning()
{
return "" + min + " - " + max;
}
}

View File

@ -1,24 +0,0 @@
package resonantinduction.electrical.encoder.coding.args;
import resonantinduction.core.ArgumentData;
/**
* 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

@ -1,23 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import resonant.lib.gui.ContainerBase;
import resonant.lib.prefab.slot.SlotSpecific;
import resonantinduction.electrical.encoder.ItemDisk;
import resonantinduction.electrical.encoder.TileEncoder;
public class ContainerEncoder extends ContainerBase
{
private ItemStack[] containingItems = new ItemStack[1];
private TileEncoder tileEntity;
public ContainerEncoder(InventoryPlayer inventoryPlayer, TileEncoder encoder)
{
super(encoder);
this.tileEntity = encoder;
// Disk
addSlotToContainer(new SlotSpecific(encoder, 0, 80, 24, ItemDisk.class));
addPlayerInventory(inventoryPlayer.player);
}
}

View File

@ -1,35 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import resonant.lib.gui.ContainerDummy;
import resonant.lib.gui.GuiContainerBase;
import resonantinduction.electrical.encoder.TileEncoder;
public class GuiEncoderBase extends GuiContainerBase
{
protected InventoryPlayer player;
protected TileEncoder tileEntity;
public GuiEncoderBase(InventoryPlayer player, TileEncoder tileEntity, Container container)
{
super(container);
this.tileEntity = tileEntity;
this.player = player;
}
public GuiEncoderBase(InventoryPlayer player, TileEncoder tileEntity)
{
this(player, tileEntity, new ContainerDummy(tileEntity));
}
public int getGuiLeft()
{
return guiLeft;
}
public int getGuiTop()
{
return guiTop;
}
}

View File

@ -1,187 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import resonantinduction.core.gui.GuiButtonImage;
import resonantinduction.core.gui.GuiButtonImage.ButtonIcon;
import resonantinduction.electrical.encoder.TileEncoder;
public class GuiEncoderCoder extends GuiEncoderBase
{
private GuiEncoderTaskList taskListGui;
GuiButtonImage left, right, up, down;
GuiButton newTask, newTask2;
String helpMessage = "";
boolean insertingTask = false;
boolean bellow = true;
public GuiEncoderCoder(InventoryPlayer player, TileEncoder tileEntity)
{
super(player, tileEntity);
}
@Override
public void initGui()
{
super.initGui();
this.getTaskListElement(true);
left = new GuiButtonImage(3, containerWidth + 13, containerHeight + 120, ButtonIcon.ARROW_LEFT);
this.buttonList.add(left);
right = new GuiButtonImage(4, containerWidth + 147, containerHeight + 120, ButtonIcon.ARROW_RIGHT);
this.buttonList.add(right);
up = new GuiButtonImage(5, containerWidth + 147, containerHeight + 30, ButtonIcon.ARROW_UP);
this.buttonList.add(up);
down = new GuiButtonImage(6, containerWidth + 147, containerHeight + 100, ButtonIcon.ARROW_DOWN);
this.buttonList.add(down);
newTask = new GuiButton(7, containerWidth + 15, containerHeight + 135, 70, 10, "Insert bellow");
this.buttonList.add(newTask);
newTask2 = new GuiButton(8, containerWidth + 90, containerHeight + 135, 70, 10, "Insert Above");
newTask2.enabled = false; // TODO fix
this.buttonList.add(newTask2);
}
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
if (tileEntity.getProgram() != null)
{
switch (button.id)
{
case 3:
getTaskListElement().scrollSide(-1);
break;
case 4:
getTaskListElement().scrollSide(1);
break;
case 5:
getTaskListElement().scroll(-1);
break;
case 6:
getTaskListElement().scroll(1);
break;
case 7:
this.insertingTask = true;
this.bellow = true;
this.helpMessage = "Click a task to create a new task";
break;
case 8:
this.insertingTask = true;
this.bellow = false;
this.helpMessage = "Click a task to create a new task";
break;
}
}
}
protected GuiEncoderTaskList getTaskListElement(boolean renew)
{
if (taskListGui == null || renew)
{
if (taskListGui != null)
{
taskListGui.xPos = this.containerWidth + 25;
taskListGui.yPos = this.containerHeight + 15;
}
else
{
taskListGui = new GuiEncoderTaskList(this.tileEntity, this, this.containerWidth + 25, this.containerHeight + 15);
}
}
return this.taskListGui;
}
@Override
public void handleMouseInput()
{
super.handleMouseInput();
int wheel = Mouse.getEventDWheel();
if (tileEntity.getProgram() != null)
{
if (wheel > 0)
{
this.getTaskListElement().scroll(-2);
}
else if (wheel < 0)
{
this.getTaskListElement().scroll(2);
}
}
}
@Override
protected void keyTyped(char character, int keycode)
{
if (keycode == Keyboard.KEY_ESCAPE)
{
this.mc.thePlayer.closeScreen();
}
else if (tileEntity.getProgram() != null)
{
if (keycode == Keyboard.KEY_UP) // PAGE UP (no constant)
{
this.getTaskListElement().scroll(-1);
}
else if (keycode == Keyboard.KEY_DOWN) // PAGE DOWN (no constant)
{
this.getTaskListElement().scroll(1);
}
else if (keycode == Keyboard.KEY_LEFT) // PAGE LEFT (no constant)
{
if (this.getTaskListElement().scrollX > -5)
this.getTaskListElement().scrollSide(-1);
}
else if (keycode == Keyboard.KEY_RIGHT) // PAGE RIGHT (no constant)
{
if (this.getTaskListElement().scrollX < tileEntity.getProgram().getSize().intX())
this.getTaskListElement().scrollSide(1);
}
}
}
protected GuiEncoderTaskList getTaskListElement()
{
return this.getTaskListElement(false);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
super.drawGuiContainerBackgroundLayer(f, i, j);
getTaskListElement().drawConsole(this.mc);
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
super.drawGuiContainerForegroundLayer(x, y);
taskListGui.drawGuiContainerForegroundLayer(this.mc, x, y);
if (!this.insertingTask)
{
this.helpMessage = "";
}
this.fontRenderer.drawString(this.helpMessage, (this.xSize / 2 - 82), 150, 4210752);
}
@Override
protected void mouseClicked(int par1, int par2, int par3)
{
super.mouseClicked(par1, par2, par3);
if (par3 == 0)
{
this.taskListGui.mousePressed(par1, par2);
}
}
public TileEncoder getTile()
{
return this.tileEntity;
}
}

View File

@ -1,260 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import resonant.lib.gui.ContainerDummy;
import resonant.lib.gui.GuiContainerBase;
import resonantinduction.core.ArgumentData;
import resonantinduction.core.Reference;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.api.vector.Vector2;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
public class GuiEncoderEditTask extends GuiContainerBase
{
public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.GUI_DIRECTORY + "gui_task_edit.png");
protected GuiEncoderCoder gui;
protected ITask task, editTask;
int ySpacing = 20;
int xStart = 13, yStart = 50;
protected GuiTextField[] argTextBoxes;
int getFocus = -1;
boolean newTask = false;
public GuiEncoderEditTask(GuiEncoderCoder gui, ITask task, boolean newTask)
{
super(new ContainerDummy());
this.newTask = newTask;
this.ySize = 380 / 2;
this.gui = gui;
this.task = task;
this.editTask = task.clone();
NBTTagCompound nbt = new NBTTagCompound();
task.save(nbt);
this.editTask.load(nbt);
}
@Override
public void initGui()
{
super.initGui();
this.drawButtons();
Keyboard.enableRepeatEvents(true);
}
@SuppressWarnings("unchecked")
public void drawButtons()
{
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, (this.width - xSize) / 2 + 13, (this.height - ySize) / 2 + 135, 50, 20, "Save"));
this.buttonList.add(new GuiButton(1, (this.width - xSize) / 2 + 68, (this.height - ySize) / 2 + 135, 50, 20, "Cancel"));
if (!this.newTask)
this.buttonList.add(new GuiButton(2, (this.width - xSize) / 2 + 125, (this.height - ySize) / 2 + 135, 40, 20, "Del"));
if (task.getArgs() != null)
{
this.argTextBoxes = new GuiTextField[task.getArgs().size()];
int i = 0;
for (ArgumentData arg : task.getArgs())
{
this.argTextBoxes[i] = new GuiTextField(this.fontRenderer, (this.width - xSize) / 2 + 60, (this.height - ySize) / 2 + 64 + (i * this.ySpacing), 30, 10);
this.argTextBoxes[i].setMaxStringLength(30);
this.argTextBoxes[i].setVisible(true);
this.argTextBoxes[i].setText("" + arg.getData());
i++;
}
}
}
@Override
public void onGuiClosed()
{
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
}
@Override
protected void keyTyped(char character, int keycode)
{
if (keycode == Keyboard.KEY_ESCAPE)
{
this.mc.thePlayer.closeScreen();
}
else if (keycode == Keyboard.KEY_TAB)
{
if (this.argTextBoxes != null)
{
this.getFocus += 1;
if (this.getFocus >= this.argTextBoxes.length)
{
this.getFocus = 0;
}
}
else
{
this.getFocus = -1;
}
}
else
{
if (this.argTextBoxes != null && this.getFocus > -1 && this.getFocus < this.argTextBoxes.length)
{
if (this.argTextBoxes[this.getFocus] != null)
this.argTextBoxes[this.getFocus].textboxKeyTyped(character, keycode);
}
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3)
{
super.mouseClicked(par1, par2, par3);
this.getFocus = -1;
if (this.argTextBoxes != null)
{
for (int i = 0; i < this.argTextBoxes.length; i++)
{
GuiTextField box = this.argTextBoxes[i];
if (box != null && box.getVisible())
{
box.mouseClicked(par1, par2, par3);
if (box.isFocused())
{
this.getFocus = i;
}
}
}
}
}
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
switch (button.id)
{
case 0:
case 1:
if (button.id == 0)
{
if (this.argTextBoxes != null)
{
int i = 0;
for (ArgumentData arg : task.getArgs())
{
if (this.argTextBoxes[i] != null)
{
if (arg.isValid(this.argTextBoxes[i].getText()))
{
editTask.setArg(arg.getName(), this.argTextBoxes[i].getText());
}
else
{
this.argTextBoxes[i].setText("");
}
}
i++;
}
}
if (!this.newTask)
{
this.gui.getTile().updateTask(this.editTask);
FMLCommonHandler.instance().showGuiScreen(this.gui);
}
else
{
// new GuiMessageBox(this, 1, "Create new Task", "Are you sure?").show();
}
}
else
{
FMLCommonHandler.instance().showGuiScreen(this.gui);
}
break;
case 2:
// new GuiMessageBox(this, 0, "Remove Task", "Are you sure?").show();
break;
}
}
/** Draw the background layer for the GuiContainer (everything behind the items) */
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int containerWidth = (this.width - xSize) / 2;
int containerHeight = (this.height - ySize) / 2;
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, xSize, ySize);
if (this.argTextBoxes != null)
{
for (int i = 0; i < this.argTextBoxes.length; i++)
{
GuiTextField box = this.argTextBoxes[i];
if (box != null)
{
box.drawTextBox();
}
}
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
this.fontRenderer.drawString("Edit Task", (int) (xSize / 2 - 7 * 2.5), 5, 4210752);
this.fontRenderer.drawString("Task: " + "\u00a77" + this.task.getMethodName(), ((xSize / 2) - 70), 20, 4210752);
this.fontRenderer.drawString("----Task Arguments---- ", ((xSize / 2) - 70), 50, 4210752);
int i = 0;
if (task.getArgs() != null)
{
for (ArgumentData arg : task.getArgs())
{
i++;
this.fontRenderer.drawString(arg.getName() + ":", ((xSize / 2) - 70), 45 + (i * this.ySpacing), 4210752);
this.fontRenderer.drawString(arg.warning(), ((xSize / 2) + 11), 45 + (i * this.ySpacing), 4210752);
}
}
else
{
this.fontRenderer.drawString("\u00a77" + " No editable args ", ((xSize / 2) - 70), 70, 4210752);
}
}
public void onMessageBoxClosed(int id, boolean yes)
{
if (id == 0 && yes)
{
this.gui.getTile().removeTask(new Vector2(this.editTask.getCol(), this.editTask.getRow()));
FMLCommonHandler.instance().showGuiScreen(this.gui);
}
if (id == 1)
{
if (yes)
{
this.gui.getTile().insertTask(this.editTask);
FMLCommonHandler.instance().showGuiScreen(this.gui);
}
this.gui.insertingTask = false;
}
}
}

View File

@ -1,19 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import resonantinduction.core.Reference;
import resonantinduction.electrical.encoder.TileEncoder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiEncoderInventory extends GuiEncoderBase
{
public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.GUI_DIRECTORY + "gui_encoder_slot.png");
public GuiEncoderInventory(InventoryPlayer inventoryPlayer, TileEncoder tileEntity)
{
super(inventoryPlayer, tileEntity, new ContainerEncoder(inventoryPlayer, tileEntity));
}
}

View File

@ -1,201 +0,0 @@
package resonantinduction.electrical.encoder.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import resonant.api.IScroll;
import resonantinduction.electrical.armbot.task.TaskEnd;
import resonantinduction.electrical.armbot.task.TaskIdle;
import resonantinduction.electrical.armbot.task.TaskStart;
import resonantinduction.electrical.encoder.TileEncoder;
import resonantinduction.electrical.encoder.coding.IProgram;
import resonantinduction.electrical.encoder.coding.IRedirectTask;
import resonantinduction.electrical.encoder.coding.ITask;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
/**
* Not a gui itself but a component used to display task as a box inside of a gui
*
* @author DarkGuardsman
*/
public class GuiEncoderTaskList extends Gui implements IScroll
{
protected int scrollY = 0, scrollX;
protected TileEntity entity;
/** The string displayed on this control. */
public String displayString;
int xPos, yPos;
int countX = 6, countY = 6;
GuiEncoderCoder coder;
public GuiEncoderTaskList(TileEntity entity, GuiEncoderCoder coder, int x, int y)
{
this.xPos = x;
this.yPos = y;
this.coder = coder;
this.entity = entity;
if (this.getProgram() != null)
{
if (this.getProgram().getSize().intX() < (this.countX / 2))
{
this.scrollX = -2;
}
else
{
this.scrollX = 0;
}
}
else
{
this.scrollX = 0;
this.scrollY = 0;
}
}
public IProgram getProgram()
{
if (entity instanceof TileEncoder)
{
return ((TileEncoder) entity).getProgram();
}
return null;
}
@Override
public void scroll(int amount)
{
this.scrollY += amount;
}
public void scrollSide(int i)
{
this.scrollX += i;
}
@Override
public void setScroll(int length)
{
this.scrollY = length;
}
@Override
public int getScroll()
{
return this.scrollY;
}
public void drawConsole(Minecraft mc)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
for (int colume = 0; colume < countX; colume++)
{
int actualCol = colume + this.scrollX;
for (int row = 0; row < countY; row++)
{
int actualRow = row + this.scrollY - 1;
boolean drawnButton = false;
if (this.getProgram() != null)
{
ITask task = this.getProgram().getTaskAt(actualCol, actualRow);
if (actualRow == -1 && colume + this.scrollX - 1 == -1)
{
task = new TaskStart();
}
else if (actualRow == this.getProgram().getSize().intY() + 1 && colume + this.scrollX - 1 == -1)
{
task = new TaskEnd();
}
if (task != null && (!(task instanceof IRedirectTask) || task instanceof IRedirectTask && ((IRedirectTask) task).render()))
{
drawnButton = true;
FMLClientHandler.instance().getClient().renderEngine.bindTexture(task.getTextureSheet());
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), task.getTextureUV().intX(), task.getTextureUV().intY(), 20, 20);
}
}
if (!drawnButton)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(ITask.TaskType.TEXTURE);
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), 0, 40, 20, 20);
}
}
}
}
protected void drawGuiContainerForegroundLayer(Minecraft mc, int cx, int cy)
{
ITask task = this.getTaskAt(cx, cy);
if (task != null && coder != null)
{
coder.drawTooltip(cx - coder.getGuiLeft(), cy - coder.getGuiTop() + 10, "[" + task.getRow() + "," + task.getCol() + "] " + task.getMethodName());
}
}
public void mousePressed(int cx, int cy)
{
ITask task = this.getTaskAt(cx, cy);
if (task != null)
{
if (this.coder.insertingTask)
{
ITask t = new TaskIdle();
if (this.coder.bellow)
{
if (task instanceof TaskEnd)
{
this.coder.helpMessage = "Can't insert bellow end";
return;
}
t.setPosition(task.getCol(), task.getRow() + 1);
}
else
{
if (task instanceof TaskStart)
{
this.coder.helpMessage = "Can't insert above start";
return;
}
t.setPosition(task.getCol(), task.getRow());
}
FMLCommonHandler.instance().showGuiScreen(new GuiEncoderEditTask(this.coder, t, true));
}
else
{
FMLCommonHandler.instance().showGuiScreen(new GuiEncoderEditTask(this.coder, task, false));
}
}
}
public ITask getTaskAt(int cx, int cz)
{
if (cx >= this.xPos && cz >= this.yPos && cx < this.xPos + (this.countX * 20) + 20 && cz < this.yPos + (this.countX * 20) + 20)
{
int col = ((cx - this.xPos) / 20) + this.scrollX;
int row = ((cz - this.yPos) / 20) + this.scrollY;
if (row == 0 && col == 0)
{
return new TaskStart();
}
else if (row == this.getProgram().getSize().intY() + 2 && col == 0)
{
return new TaskEnd();
}
else if (this.getProgram() != null)
{
return this.getProgram().getTaskAt(col, row - 1);
}
}
return null;
}
}