Cleared up some errors from changes

This commit is contained in:
DarkGuardsman 2013-10-15 14:58:29 -04:00
parent 1c1d8721a2
commit d98f77dc7c
14 changed files with 379 additions and 628 deletions

View file

@ -1,5 +1,8 @@
package dark.api.al.armbot;
import com.builtbroken.common.science.units.UnitHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector2;
@ -109,6 +112,30 @@ public abstract class Command implements IArmbotTask, Cloneable
return this;
}
public ItemStack getItem(String string, int ammount)
{
int id = 0;
int meta = 32767;
if (string.contains(":"))
{
String[] blockID = string.split(":");
id = Integer.parseInt(blockID[0]);
meta = Integer.parseInt(blockID[1]);
}
else
{
id = UnitHelper.tryToParseInt(string);
}
if (id == 0)
{
return null;
}
else
{
return new ItemStack(id, ammount, meta);
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{

View file

@ -2,19 +2,14 @@ package dark.api.al.armbot;
import java.util.List;
import universalelectricity.core.vector.Vector2;
import com.builtbroken.common.Vector3;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector2;
/** Should be used to interact with the armbot and not to create a new armbot */
public interface IArmbot extends Cloneable
{
/** Location of the hand, or working location of the object */
public Vector3 getHandPos();
public universalelectricity.core.vector.Vector3 getHandPos();
/** Gets the rotation as a Vector2 (X - Yaw, Y - pitch) */
public Vector2 getRotation();
@ -23,7 +18,7 @@ public interface IArmbot extends Cloneable
public void setRotation(float yaw, float pitch);
/** Asks the armbot to move its arm to the rotation */
public void moveTo(float yaw, float pitch);
public void moveArmTo(float yaw, float pitch);
/** Asks the armbot to move to the facing direction */
public void moveTo(ForgeDirection direction);
@ -31,7 +26,7 @@ public interface IArmbot extends Cloneable
/** Adds an entity to the Armbot's grab list. Entity or ItemStack */
public void grab(Object entity);
/**Drops an object. Does except strings with "All" resulting in dropping everything */
/** Drops an object. Does except strings with "All" resulting in dropping everything */
public void drop(Object object);
/** List of object held by the armbot */

View file

@ -29,10 +29,10 @@ public interface IArmbotTask
* machine calls a this commands method name. {@IPeripheral #callMethod()} */
public Object[] onCCMethodCalled(World world, Vector3 location, IArmbot armbot, IComputerAccess computer, ILuaContext context, Object[] arguments) throws Exception;
/** Update the current part of the command */
/** Update the current segment of the task */
public boolean onUpdate();
/** Called when the task is being run by the armbot
/** Called when the task is being run by the armbot. Used mainly to setup the task before actually doing the task.
*
* @param world - current world
* @param location - current location
@ -53,6 +53,6 @@ public interface IArmbotTask
/** Used mainly for display purposes in the encoder */
public static enum TaskType
{
DATA(), PROCESS(), DECISION()
}
}

View file

@ -15,6 +15,7 @@ import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector2;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper;
@ -47,23 +48,21 @@ import dark.core.prefab.machine.BlockMulti;
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IArmbot, IPeripheral
{
private final CommandManager commandManager = new CommandManager();
private int computersAttached = 0;
private List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
protected List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
/** The rotation of the arms. In Degrees. */
public float rotationPitch = 0;
public float rotationYaw = 0;
public float actualPitch = 0;
public float actualYaw = 0;
public final float ROTATION_SPEED = 2.0f;
protected float rotationPitch = 0;
protected float rotationYaw = 0;
protected float actualPitch = 0;
protected float actualYaw = 0;
protected final float ROTATION_SPEED = 2.0f;
private String displayText = "";
protected boolean hasTask = false;
public boolean isProvidingPower = false;
protected String displayText = "";
/** An entity that the Armbot is grabbed onto. Entity Items are held separately. */
private final List<Entity> grabbedEntities = new ArrayList<Entity>();
private final List<ItemStack> grabbedItems = new ArrayList<ItemStack>();
protected final List<Entity> grabbedEntities = new ArrayList<Entity>();
protected final List<ItemStack> grabbedItems = new ArrayList<ItemStack>();
/** Client Side Object Storage */
public EntityItem renderEntityItem = null;
@ -77,18 +76,13 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
public void initiate()
{
super.initiate();
if (!this.commandManager.hasTasks())
{
this.onInventoryChanged();
}
}
@Override
//TODO separate out functions of this method to make it easier to read and work with
public void updateEntity()
{
super.updateEntity();
Vector3 handPosition = this.getHandPosition();
Vector3 handPosition = this.getHandPos();
for (Entity entity : this.grabbedEntities)
{
@ -111,61 +105,24 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
{
if (!this.worldObj.isRemote)
{
if (this.disk == null && this.computersAttached == 0)
float preYaw = this.rotationYaw, prePitch = this.rotationPitch;
this.updateLogic();
if (this.rotationYaw != preYaw || this.rotationPitch != prePitch)
{
this.commandManager.clear();
if (this.grabbedEntities.size() > 0 || this.grabbedItems.size() > 0)
{
this.addCommand(CommandDrop.class);
}
else
{
if (!this.commandManager.hasTasks())
{
if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01 || Math.abs(this.rotationPitch - CommandReturn.IDLE_ROTATION_PITCH) > 0.01)
{
this.addCommand(CommandReturn.class);
}
}
}
this.commandManager.setCurrentTask(0);
this.sendRotationPacket();
}
}
if (!this.worldObj.isRemote)
{
this.commandManager.onUpdate();
}
}
else
{
this.updateRotation();
}
}
if (!this.worldObj.isRemote)
{
if (!this.commandManager.hasTasks())
{
this.displayText = "";
}
else
{
try
{
Command curCommand = this.commandManager.getCommands().get(this.commandManager.getCurrentTask());
if (curCommand != null)
{
this.displayText = curCommand.toString();
}
}
catch (Exception ex)
{
}
}
}
public void updateLogic()
{
// System.out.println("Ren: " + this.renderYaw + "; Rot: " +
// this.rotationYaw);
}
public void updateRotation()
{
if (Math.abs(this.actualYaw - this.rotationYaw) > 0.001f)
{
float speedYaw;
@ -247,45 +204,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
this.rotationYaw = MathHelper.clampAngleTo360(this.rotationYaw);
this.rotationPitch = MathHelper.clampAngle(this.rotationPitch, 0, 60);
//TODO reduce this to an event based system were it only updates the client when something changes
if (!this.worldObj.isRemote && this.ticks % 20 == 0)
{
this.sendRotationPacket();
}
}
public Command getCurrentCommand()
{
if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size())
{
return this.commandManager.getCommands().get(this.commandManager.getCurrentTask());
}
return null;
}
/** @return The current hand position of the armbot. */
public Vector3 getHandPosition()
{
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;
}
@ -296,8 +214,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
return TranslationHelper.getLocal("tile.armbot.name");
}
public String getCommandDisplayText()
{
return this.displayText;
@ -319,8 +235,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
this.rotationYaw = nbt.getFloat("yaw");
this.rotationPitch = nbt.getFloat("pitch");
this.commandManager.setCurrentTask(nbt.getInteger("curTask"));
NBTTagList entities = nbt.getTagList("entities");
this.grabbedEntities.clear();
for (int i = 0; i < entities.tagCount(); i++)
@ -355,8 +269,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
nbt.setFloat("yaw", this.rotationYaw);
nbt.setFloat("pitch", this.rotationPitch);
nbt.setInteger("curTask", this.commandManager.getCurrentTask());
NBTTagList entities = new NBTTagList();
for (Entity entity : grabbedEntities)
@ -460,24 +372,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
return false;
}
public void addCommand(Class<? extends Command> command)
{
this.commandManager.addCommand(this, command);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
PacketHandler.instance().sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50);
}
}
public void addCommand(Class<? extends Command> command, String[] parameters)
{
this.commandManager.addCommand(this, command, parameters);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
PacketHandler.instance().sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50);
}
}
@Override
public void onCreate(Vector3 placedPosition)
{
@ -509,163 +403,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch (method)
{
case 0: // rotateBy: rotates by a certain amount
{
if (arguments.length > 0)
{
try
// try to cast to Float
{
double yaw = (Double) arguments[0];
double pitch = (Double) arguments[1];
this.addCommand(CommandRotateBy.class, new String[] { Double.toString(yaw), Double.toString(pitch) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
throw new IllegalArgumentException("expected number");
}
break;
}
case 1:
{
// rotateTo: rotates to a specific rotation
if (arguments.length > 0)
{
try
{// try to cast to Float
double yaw = (Double) arguments[0];
double pitch = (Double) arguments[1];
this.addCommand(CommandRotateTo.class, new String[] { Double.toString(yaw), Double.toString(pitch) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
throw new IllegalArgumentException("expected number");
}
break;
}
case 2:
{
// grab: grabs an item
this.addCommand(CommandGrab.class);
break;
}
case 3:
{
// drop: drops an item
this.addCommand(CommandDrop.class);
break;
}
case 4:
{
// reset: equivalent to calling .clear() then .return()
this.commandManager.clear();
this.addCommand(CommandReturn.class);
break;
}
case 5:
{
// isWorking: returns whether or not the ArmBot is executing
// commands
return new Object[] { this.commandManager.hasTasks() };
}
case 6:
{
// touchingEntity: returns whether or not the ArmBot is touching an
// entity it is
// able to pick up
Vector3 serachPosition = this.getHandPosition();
List<Entity> found = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(serachPosition.x - 0.5f, serachPosition.y - 0.5f, serachPosition.z - 0.5f, serachPosition.x + 0.5f, serachPosition.y + 0.5f, serachPosition.z + 0.5f));
if (found != null && found.size() > 0)
{
for (int i = 0; i < found.size(); i++)
{
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && found.get(i).ridingEntity == null)
{
return new Object[] { true };
}
}
}
return new Object[] { false };
}
case 7:
{
if (arguments.length > 0)
{
try
{
// try to cast to Float
int times = (Integer) arguments[0];
this.addCommand(CommandUse.class, new String[] { Integer.toString(times) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
this.addCommand(CommandUse.class);
}
break;
}
case 8: // fire: think "flying pig"
{
if (arguments.length > 0)
{
try
{
// try to cast to Float
float strength = (float) ((double) ((Double) arguments[0]));
this.addCommand(CommandFire.class, new String[] { Float.toString(strength) });
}
catch (Exception ex)
{
ex.printStackTrace();
throw new IllegalArgumentException("expected number");
}
}
else
{
this.addCommand(CommandFire.class);
}
break;
}
case 9:
{
// return: returns to home position
this.addCommand(CommandReturn.class);
break;
}
case 10:
{
// clear: clears commands
this.commandManager.clear();
break;
}
case 11:
{
// isHolding: returns whether or not it is holding something
return new Object[] { this.grabbedEntities.size() > 0 };
}
}
return null;
}
@ -678,7 +415,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
@Override
public void attach(IComputerAccess computer)
{
computersAttached++;
synchronized (connectedComputers)
{
connectedComputers.add(computer);
@ -688,7 +424,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
@Override
public void detach(IComputerAccess computer)
{
computersAttached--;
synchronized (connectedComputers)
{
connectedComputers.remove(computer);
@ -696,37 +431,28 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
@Override
public List<Entity> getGrabbedEntities()
public List<Object> getGrabbedObjects()
{
return this.grabbedEntities;
List<Object> list = new ArrayList<Object>();
list.addAll(this.grabbedEntities);
list.addAll(this.grabbedItems);
return list;
}
@Override
public List<ItemStack> getGrabbedItems()
{
return this.grabbedItems;
}
@Override
public void grabEntity(Entity entity)
public void grab(Object entity)
{
if (entity instanceof EntityItem)
{
this.grabItem(((EntityItem) entity).getEntityItem());
entity.setDead();
this.grabbedItems.add(((EntityItem) entity).getEntityItem());
((EntityItem) entity).setDead();
}
else
else if (entity instanceof Entity)
{
this.grabbedEntities.add(entity);
this.grabbedEntities.add((Entity) entity);
}
}
@Override
public void grabItem(ItemStack itemStack)
{
this.grabbedItems.add(itemStack);
}
@Override
public void drop(Object object)
{
@ -736,7 +462,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
if (object instanceof ItemStack)
{
Vector3 handPosition = this.getHandPosition();
Vector3 handPosition = this.getHandPos();
ItemWorldHelper.dropItemStack(worldObj, handPosition, (ItemStack) object, false);
this.grabbedItems.remove(object);
}
@ -745,7 +471,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
String string = ((String) object).toLowerCase();
if (string.equalsIgnoreCase("all"))
{
Vector3 handPosition = this.getHandPosition();
Vector3 handPosition = this.getHandPos();
Iterator<ItemStack> it = this.grabbedItems.iterator();
while (it.hasNext())
@ -759,36 +485,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
}
/** called by the block when another checks it too see if it is providing power to a direction */
public boolean isProvidingPowerSide(ForgeDirection dir)
{
return this.isProvidingPower && dir.getOpposite() == this.getFacingDirectionFromAngle();
}
/** gets the facing direction using the yaw angle */
public ForgeDirection getFacingDirectionFromAngle()
{
float angle = net.minecraft.util.MathHelper.wrapAngleTo180_float(this.rotationYaw);
if (angle >= -45 && angle <= 45)
{
return ForgeDirection.SOUTH;
}
else if (angle >= 45 && angle <= 135)
{
return ForgeDirection.WEST;
}
else if (angle >= 135 && angle <= -135)
{
return ForgeDirection.NORTH;
}
else
{
return ForgeDirection.EAST;
}
}
@Override
public boolean canConnect(ForgeDirection direction)
{
@ -804,7 +500,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
@Override
public double getWattLoad()
{
if (this.getCurrentCommand() != null)
if (this.hasTask)
{
return .4;//400w
}
@ -816,4 +512,77 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
{
return itemstack != null && itemstack.itemID == AssemblyLine.recipeLoader.itemDisk.itemID;
}
@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(float yaw, float pitch)
{
if (!this.worldObj.isRemote)
{
this.actualYaw = yaw;
this.actualPitch = pitch;
}
}
@Override
public void moveArmTo(float yaw, float pitch)
{
if (!this.worldObj.isRemote)
{
this.rotationYaw = yaw;
this.rotationPitch = pitch;
}
}
@Override
public void moveTo(ForgeDirection direction)
{
if (direction == ForgeDirection.SOUTH)
{
this.rotationYaw = 0;
}
else if (direction == ForgeDirection.EAST)
{
this.rotationYaw = 90;
}
else if (direction == ForgeDirection.NORTH)
{
this.rotationYaw = 180;
}
else if (direction == ForgeDirection.WEST)
{
this.rotationYaw = 270;
}
}
}

View file

@ -10,21 +10,29 @@ import dark.api.al.armbot.Command;
import dark.core.prefab.helpers.ItemWorldHelper;
/** Used by arms to break a specific block in a position.
*
*
* @author Calclavia */
public class CommandBreak extends Command
{
private CommandRotateTo rotateToCommand;
public CommandBreak()
{
super("break");
}
public CommandBreak(String name)
{
super(name);
}
int BREAK_TIME = 30;
boolean keep = false;
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
super.onUpdate();
Vector3 serachPosition = this.tileEntity.getHandPosition();
Vector3 serachPosition = this.armbot.getHandPos();
Block block = Block.blocksList[serachPosition.getBlockID(this.worldObj)];
@ -38,7 +46,7 @@ public class CommandBreak extends Command
}
else
{
this.tileEntity.grabEntity(new EntityItem(this.worldObj, serachPosition.intX() + 0.5D, serachPosition.intY() + 0.5D, serachPosition.intZ() + 0.5D, items.get(0)));
this.armbot.grab(new EntityItem(this.worldObj, serachPosition.intX() + 0.5D, serachPosition.intY() + 0.5D, serachPosition.intZ() + 0.5D, items.get(0)));
}
worldObj.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0, 3);
@ -50,8 +58,8 @@ public class CommandBreak extends Command
}
@Override
public String toString()
public Command clone()
{
return "BREAK";
return new CommandBreak();
}
}

View file

@ -4,13 +4,18 @@ import dark.api.al.armbot.Command;
public class CommandDrop extends Command
{
public CommandDrop()
{
super("drop");
}
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
super.onUpdate();
this.tileEntity.drop("all");
this.worldObj.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
this.armbot.drop("all");
this.worldObj.playSound(this.armbotPos.x, this.armbotPos.x, this.armbotPos.x, "random.pop", 0.2F, ((this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
return false;
}
@ -20,4 +25,10 @@ public class CommandDrop extends Command
{
return "DROP";
}
@Override
public Command clone()
{
return new CommandDrop();
}
}

View file

@ -2,7 +2,10 @@ package dark.assembly.common.armbot.command;
import java.util.Random;
import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbot;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@ -10,10 +13,12 @@ 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 universalelectricity.core.vector.Vector3;
public class CommandFire extends Command
{
private static final float MIN_ACTUAL_PITCH = -80;
private static final float MAX_ACTUAL_PITCH = 80;
@ -22,19 +27,24 @@ public class CommandFire extends Command
private float velocity;
private Vector3 finalVelocity;
@Override
public void onStart()
public CommandFire()
{
super.onStart();
super("throw");
}
this.velocity = this.getFloatArg(0);
@Override
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
super.onMethodCalled(world, location, armbot, arguments);
this.velocity = UnitHelper.tryToParseFloat("" + this.getArg(0));
if (this.velocity > 2.5f)
this.velocity = 2.5f;
if (this.velocity < 0.125f)
this.velocity = 1f;
this.actualYaw = this.tileEntity.rotationYaw;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * (this.tileEntity.rotationPitch / 60f)) + MIN_ACTUAL_PITCH;
this.actualYaw = (float) this.armbot.getRotation().x;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * ((float) this.armbot.getRotation().y / 60f)) + MIN_ACTUAL_PITCH;
double x, y, z;
double yaw, pitch;
@ -53,22 +63,31 @@ public class CommandFire extends Command
this.finalVelocity.y *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.z *= (1f - (1f / 200f)) + (random.nextFloat() * (1f / 100f));
this.finalVelocity.multiply(velocity);
this.finalVelocity.scale(velocity);
return true;
}
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
if (this.finalVelocity == null) // something went wrong
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (this.tileEntity.getGrabbedEntities().size() > 0)
if (this.armbot.getGrabbedObjects().size() > 0)
{
Entity held = this.tileEntity.getGrabbedEntities().get(0);
Entity held = null;
for (Object obj : this.armbot.getGrabbedObjects())
{
if (obj instanceof Entity)
{
held = (Entity) obj;
break;
}
}
if (held != null)
{
this.worldObj.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.bow", velocity, 2f - (velocity / 4f), true);
this.worldObj.playSound(this.armbotPos.x, this.armbotPos.y, this.armbotPos.z, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
@ -82,13 +101,15 @@ public class CommandFire extends Command
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).onUpdate();
this.armbot.drop("all");
if (!this.worldObj.isRemote)
{
this.worldObj.removeEntity(held);
}
}
if (item.getEntityItem().itemID == Item.arrow.itemID)
{
EntityArrow arrow = new EntityArrow(worldObj, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z);
EntityArrow arrow = new EntityArrow(worldObj, this.armbot.getHandPos().x, this.armbot.getHandPos().y, this.armbot.getHandPos().z);
arrow.motionX = this.finalVelocity.x;
arrow.motionY = this.finalVelocity.y;
arrow.motionZ = this.finalVelocity.z;
@ -97,7 +118,7 @@ public class CommandFire extends Command
}
else
{
EntityItem item2 = new EntityItem(worldObj, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z, thrown);
EntityItem item2 = new EntityItem(worldObj, this.armbot.getHandPos().x, this.armbot.getHandPos().y, this.armbot.getHandPos().z, thrown);
item2.motionX = this.finalVelocity.x;
item2.motionY = this.finalVelocity.y;
item2.motionZ = this.finalVelocity.z;
@ -107,7 +128,7 @@ public class CommandFire extends Command
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).onUpdate();
this.armbot.drop("all");
held.motionX = this.finalVelocity.x;
held.motionY = this.finalVelocity.y;
held.motionZ = this.finalVelocity.z;
@ -119,7 +140,7 @@ public class CommandFire extends Command
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
public Command readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.actualYaw = taskCompound.getFloat("fireYaw");
@ -129,10 +150,11 @@ public class CommandFire extends Command
this.finalVelocity.x = taskCompound.getDouble("fireVectorX");
this.finalVelocity.y = taskCompound.getDouble("fireVectorY");
this.finalVelocity.z = taskCompound.getDouble("fireVectorZ");
return this;
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setFloat("fireYaw", this.actualYaw);
@ -144,11 +166,18 @@ public class CommandFire extends Command
taskCompound.setDouble("fireVectorY", this.finalVelocity.y);
taskCompound.setDouble("fireVectorZ", this.finalVelocity.z);
}
return taskCompound;
}
@Override
public String toString()
{
return "FIRE " + Float.toString(this.velocity);
return super.toString() + " " + Float.toString(this.velocity);
}
@Override
public Command clone()
{
return new CommandFire();
}
}

View file

@ -4,59 +4,54 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.builtbroken.common.science.units.UnitHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbot;
import dark.assembly.common.machine.InvInteractionHelper;
public class CommandGive extends Command
{
private ItemStack stack;
private int ammount = -1;
@Override
public void onStart()
public CommandGive()
{
int id = 0;
int meta = 32767;
if (this.getArgs().length > 0)
{
String block = this.getArg(0);
if (block.contains(":"))
{
String[] blockID = block.split(":");
id = Integer.parseInt(blockID[0]);
meta = Integer.parseInt(blockID[1]);
}
else
{
id = Integer.parseInt(block);
}
}
if (this.getArgs().length > 1)
{
ammount = this.getIntArg(1);
}
if (id == 0)
{
stack = null;
}
else
{
stack = new ItemStack(id, ammount == -1 ? 1 : ammount, meta);
}
super("give");
}
@Override
protected boolean onUpdate()
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.worldObj);
super.onMethodCalled(world, location, armbot, arguments);
if (targetTile != null && this.tileEntity.getGrabbedItems().size() > 0)
if (this.getArgs().length > 1)
{
ammount = UnitHelper.tryToParseInt("" + this.getArg(1));
}
if (this.getArgs().length > 0)
{
stack = this.getItem("" + this.getArg(0), ammount == -1 ? 1 : ammount);
}
return true;
}
@Override
public boolean onUpdate()
{
TileEntity targetTile = this.armbot.getHandPos().getTileEntity(this.worldObj);
if (targetTile != null && this.armbot.getGrabbedObjects().size() > 0)
{
ForgeDirection direction = this.tileEntity.getFacingDirectionFromAngle();
List<ItemStack> stacks = new ArrayList<ItemStack>();
@ -85,24 +80,25 @@ public class CommandGive extends Command
}
return flag;
}
return true;
return false;
}
@Override
public String toString()
{
return "give " + (stack != null ? stack.toString() : "1x???@???");
return super.toString() + " " + (stack != null ? stack.toString() : "1x???@???");
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
public Command readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
return this;
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
if (stack != null)
@ -111,5 +107,12 @@ public class CommandGive extends Command
this.stack.writeToNBT(tag);
taskCompound.setTag("item", tag);
}
return taskCompound;
}
@Override
public Command clone()
{
return new CommandGive();
}
}

View file

@ -9,13 +9,15 @@ import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbot;
import dark.assembly.common.armbot.GrabDictionary;
import dark.assembly.common.machine.belt.TileEntityConveyorBelt;
/** Used by arms to search for entities in a region
*
*
* @author Calclavia */
public class CommandGrab extends Command
{
@ -29,15 +31,20 @@ public class CommandGrab extends Command
/** The item to be collected. */
private Class<? extends Entity> entityToInclude;
@Override
public void onStart()
public CommandGrab()
{
super.onStart();
super("Grab");
}
@Override
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
super.onMethodCalled(world, location, armbot, arguments);
this.entityToInclude = Entity.class;
if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null)
{
if (this.getArg(0).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child"))
if (this.getArg(0) instanceof String && (((String) this.getArg(0)).equalsIgnoreCase("baby") || ((String) this.getArg(0)).equalsIgnoreCase("child")))
{
child = true;
if (this.getArgs().length > 1 && this.getArgs()[1] != null)
@ -48,26 +55,27 @@ public class CommandGrab extends Command
else
{
this.entityToInclude = GrabDictionary.get(this.getArg(0)).getEntityClass();
if (this.getArgs().length > 1 && this.getArgs()[1] != null && (this.getArg(1).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child")))
if (this.getArg(1) instanceof String && (((String) this.getArg(1)).equalsIgnoreCase("baby") || ((String) this.getArg(1)).equalsIgnoreCase("child")))
{
child = true;
}
}
}
return true;
}
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
super.onUpdate();
if (this.tileEntity.getGrabbedEntities().size() > 0)
if (this.armbot.getGrabbedObjects().size() > 0)
{
return false;
}
Vector3 serachPosition = this.tileEntity.getHandPosition();
Vector3 serachPosition = this.armbot.getHandPos();
List<Entity> found = this.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(serachPosition.x - radius, serachPosition.y - radius, serachPosition.z - radius, serachPosition.x + radius, serachPosition.y + radius, serachPosition.z + radius));
TileEntity ent = serachPosition.getTileEntity(worldObj);
@ -88,8 +96,7 @@ public class CommandGrab extends Command
{
if (found.get(i) != null && !(found.get(i) instanceof EntityArrow) && !(found.get(i) instanceof EntityPlayer) && found.get(i).ridingEntity == null && (!(found.get(i) instanceof EntityAgeable) || (found.get(i) instanceof EntityAgeable && child == ((EntityAgeable) found.get(i)).isChild())))
{
this.tileEntity.grabEntity(found.get(i));
this.worldObj.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
this.armbot.grab(found.get(i));
if (this.belt != null)
{
belt.ignoreEntity(found.get(i));
@ -103,19 +110,21 @@ public class CommandGrab extends Command
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
public Command readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.child = taskCompound.getBoolean("child");
this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass();
return this;
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setBoolean("child", child);
taskCompound.setString("name", ((this.entityToInclude != null) ? GrabDictionary.get(this.entityToInclude).getName() : ""));
return taskCompound;
}
@Override
@ -134,4 +143,10 @@ public class CommandGrab extends Command
}
return "GRAB " + baby + entity;
}
@Override
public Command clone()
{
return new CommandGrab();
}
}

View file

@ -1,21 +1,25 @@
package dark.assembly.common.armbot.command;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import dark.api.al.armbot.IArmbot;
/** Used by arms to break a specific block in a position.
*
*
* @author Calclavia */
public class CommandHarvest extends CommandBreak
{
private CommandRotateTo rotateToCommand;
@Override
public void onStart()
public CommandHarvest()
{
this.keep = true;
super("Harvest");
}
@Override
public String toString()
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
return "HARVEST";
this.keep = true;
return super.onMethodCalled(world, location, armbot, arguments);
}
}

View file

@ -1,28 +1,42 @@
package dark.assembly.common.armbot.command;
import com.builtbroken.common.science.units.UnitHelper;
import universalelectricity.core.vector.Vector3;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbot;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class CommandIdle extends Command
{
/** The amount of time in which the machine will idle. */
public int idleTime = 80;
private int totalIdleTime = 80;
@Override
public void onStart()
public CommandIdle()
{
super.onStart();
if (this.getIntArg(0) > 0)
{
this.idleTime = this.getIntArg(0);
this.totalIdleTime = this.idleTime;
}
super("wait");
// TODO Auto-generated constructor stub
}
@Override
protected boolean onUpdate()
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
super.onMethodCalled(world, location, armbot, arguments);
if (UnitHelper.tryToParseInt("" + this.getArg(0)) > 0)
{
this.idleTime = UnitHelper.tryToParseInt("" + this.getArg(0));
this.totalIdleTime = this.idleTime;
return true;
}
return false;
}
@Override
public boolean onUpdate()
{
/** Randomly move the arm to simulate life in the arm if the arm is powered */
// this.tileEntity.rotationPitch *= 0.98 * this.world.rand.nextFloat();
@ -37,25 +51,33 @@ public class CommandIdle extends Command
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
public Command readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.idleTime = taskCompound.getInteger("idleTime");
this.totalIdleTime = taskCompound.getInteger("idleTotal");
return this;
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setInteger("idleTime", this.idleTime);
taskCompound.setInteger("idleTotal", this.totalIdleTime);
return taskCompound;
}
@Override
public String toString()
{
return "IDLE " + Integer.toString(this.totalIdleTime);
return super.toString() + " " + Integer.toString(this.totalIdleTime);
}
@Override
public Command clone()
{
return new CommandIdle();
}
}

View file

@ -1,110 +0,0 @@
package dark.assembly.common.armbot.command;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import dark.api.al.armbot.Command;
import dark.core.prefab.helpers.ItemWorldHelper;
public class CommandPowerTo extends Command
{
private int duration;
private int ticksRan;
@Override
public void onStart()
{
this.duration = 0;
this.ticksRan = 0;
if (this.getArgs().length > 0)
{
this.duration = this.getIntArg(0);
}
if (this.duration <= 30)
{
this.duration = 30;
}
}
@Override
protected boolean onUpdate()
{
super.onUpdate();
if (this.tileEntity.isProvidingPower && this.ticksRan >= duration)
{
powerBlock(false);
return false;
}
else if (this.tileEntity.isProvidingPower)
{
Vector3 loc = this.tileEntity.getHandPosition();
worldObj.spawnParticle("smoke", loc.x, loc.y, loc.z, 0.0D, 0.0D, 0.0D);
worldObj.spawnParticle("flame", loc.x, loc.y, loc.z, 0.0D, 0.0D, 0.0D);
}
Block block = Block.blocksList[this.worldObj.getBlockId(tileEntity.getHandPosition().intX(), tileEntity.getHandPosition().intY(), tileEntity.getHandPosition().intZ())];
TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.worldObj);
if (this.tileEntity.getGrabbedItems().size() > 0)
{
List<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.add(new ItemStack(Block.torchRedstoneActive, 1, 0));
stacks.add(new ItemStack(Block.torchRedstoneIdle, 1, 0));
if (ItemWorldHelper.filterItems(this.tileEntity.getGrabbedItems(), stacks).size() > 0)
{
this.powerBlock(true);
}
}
this.ticksRan++;
return true;
}
public void powerBlock(boolean on)
{
if (!on)
{
this.tileEntity.isProvidingPower = false;
}
else
{
this.tileEntity.isProvidingPower = true;
}
int id = this.tileEntity.worldObj.getBlockId(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord);
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
this.worldObj.notifyBlocksOfNeighborChange(this.tileEntity.xCoord + dir.offsetX, this.tileEntity.yCoord + dir.offsetY, this.tileEntity.zCoord + dir.offsetZ, id);
}
}
@Override
public String toString()
{
return "POWERTO " + Integer.toString(this.duration);
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.duration = taskCompound.getInteger("useTimes");
this.ticksRan = taskCompound.getInteger("useCurTimes");
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setInteger("useTimes", this.duration);
taskCompound.setInteger("useCurTimes", this.ticksRan);
}
}

View file

@ -9,28 +9,27 @@ public class CommandReturn extends Command
private CommandRotateTo rotateToCommand;
@Override
public void onStart()
public CommandReturn()
{
this.rotateToCommand = (CommandRotateTo) this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[] { "0", "0" });
this.rotateToCommand.onStart();
super("Return");
}
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
if (this.rotateToCommand == null)
{
this.onStart();
this.rotateToCommand = (CommandRotateTo) this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[] { "0", "0" });
this.rotateToCommand.onStart();
}
return this.rotateToCommand.onUpdate();
}
@Override
public void onEnd()
public void terminated()
{
this.rotateToCommand.onEnd();
this.rotateToCommand.terminated();
}
@Override

View file

@ -1,108 +1,87 @@
package dark.assembly.common.armbot.command;
import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.science.units.UnitHelper;
import dark.api.al.armbot.Command;
import dark.api.al.armbot.IArmbot;
import dark.core.prefab.helpers.MathHelper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
/** Rotates the armbot to a specific direction. If not specified, it will turn right.
*
* @author Calclavia */
*
* @author DarkGuardsman */
public class CommandRotateTo extends Command
{
float targetRotationYaw = 0;
float targetRotationPitch = 0;
int totalTicks = 0;
public CommandRotateTo()
{
super("RotateTo");
}
float targetRotationYaw = 0, targetRotationPitch = 0, currentRotationYaw, currentRotationPitch;
@Override
public void onStart()
public boolean onMethodCalled(World world, Vector3 location, IArmbot armbot, Object[] arguments)
{
super.onStart();
this.ticks = 0;
this.totalTicks = 0;
super.onMethodCalled(world, location, armbot, arguments);
if (this.getArg(0) != null)
{
this.targetRotationYaw = this.getFloatArg(0);
}
else
{
this.targetRotationYaw = 0;
this.targetRotationYaw = UnitHelper.tryToParseFloat("" + this.getArg(0));
}
if (this.getArg(1) != null)
{
this.targetRotationPitch = this.getFloatArg(1);
}
else
{
this.targetRotationPitch = 0;
this.targetRotationPitch = UnitHelper.tryToParseFloat("" + this.getArg(1));
}
while (this.targetRotationYaw < 0)
this.targetRotationYaw += 360;
while (this.targetRotationYaw > 360)
this.targetRotationYaw -= 360;
while (this.targetRotationPitch < -60)
this.targetRotationPitch += 60;
while (this.targetRotationPitch > 60)
this.targetRotationPitch -= 60;
MathHelper.clampAngleTo360(this.targetRotationPitch);
MathHelper.clampAngleTo360(this.targetRotationYaw);
int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.actualYaw) / this.tileEntity.ROTATION_SPEED);
int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.actualPitch) / this.tileEntity.ROTATION_SPEED);
this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch);
return true;
}
@Override
protected boolean onUpdate()
public boolean onUpdate()
{
super.onUpdate();
/*
* float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation);
*
* if (rotationalDifference < ROTATION_SPEED) { this.tileEntity.rotationYaw =
* this.targetRotation; } else { if (this.tileEntity.rotationYaw > this.targetRotation) {
* this.tileEntity.rotationYaw -= ROTATION_SPEED; } else { this.tileEntity.rotationYaw +=
* ROTATION_SPEED; } this.ticks = 0; }
*/
// set the rotation to the target immediately and let the client handle animating it
// wait for the client to catch up
this.currentRotationYaw = (float) this.armbot.getRotation().x;
this.currentRotationPitch = (float) this.armbot.getRotation().y;
this.armbot.moveArmTo(this.targetRotationYaw, this.targetRotationPitch);
this.tileEntity.rotationYaw = this.targetRotationYaw;
this.tileEntity.rotationPitch = this.targetRotationPitch;
// if (this.ticks < this.totalTicks) { return true; }
if (Math.abs(this.tileEntity.actualPitch - this.tileEntity.rotationPitch) > 0.001f)
{
return true;
}
if (Math.abs(this.tileEntity.actualYaw - this.tileEntity.rotationYaw) > 0.001f)
{
return true;
}
return false;
return Math.abs(this.currentRotationPitch - this.targetRotationPitch) > 0.01f && Math.abs(this.currentRotationYaw - this.targetRotationYaw) > 0.01f;
}
@Override
public String toString()
{
return "ROTATETO " + Float.toString(this.targetRotationYaw) + " " + Float.toString(this.targetRotationPitch);
return super.toString() + " " + Float.toString(this.targetRotationYaw) + " " + Float.toString(this.targetRotationPitch);
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
public Command readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.targetRotationPitch = taskCompound.getFloat("rotPitch");
this.targetRotationYaw = taskCompound.getFloat("rotYaw");
return this;
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
public NBTTagCompound writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
return taskCompound;
}
@Override
public Command clone()
{
return new CommandRotateTo();
}
}