Added FIRE command (throws things and fires arrows!)

Also fixed a manipulator bug (NULL CHECKS, CAL. NULL CHECKS!)
This commit is contained in:
Brian Ricketts 2013-01-21 15:53:02 -06:00
parent feaf8d61c7
commit 0c6fde1912
12 changed files with 262 additions and 150 deletions

View file

@ -86,8 +86,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
/**
* Find items going into the manipulator and input them into an inventory behind this
* manipulator.
* Find items going into the manipulator and input them into an inventory behind this manipulator.
*/
@Override
public void inject()
@ -111,8 +110,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
if (entity.isDead)
continue;
/**
* Try top first, then bottom, then the sides to see if it is possible to insert the
* item into a inventory.
* Try top first, then bottom, then the sides to see if it is possible to insert the item into a inventory.
*/
ItemStack remainingStack = entity.func_92014_d().copy();
@ -182,16 +180,9 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
/*
* @Override public ArrayList getPacketData() { ArrayList list = super.getPacketData();
* list.add(this.isOutput); list.add(this.wattsReceived); return list; }
* @Override public ArrayList getPacketData() { ArrayList list = super.getPacketData(); list.add(this.isOutput); list.add(this.wattsReceived); return list; }
*
* @Override public void handlePacketData(INetworkManager network, int packetType,
* Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { if
* (worldObj.isRemote) { ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
* DataInputStream dis = new DataInputStream(bis); int id, x, y, z; try { id = dis.readInt(); x
* = dis.readInt(); y = dis.readInt(); z = dis.readInt(); NBTTagCompound tag =
* Packet.readNBTTagCompound(dis); readFromNBT(tag); this.wattsReceived = dis.readDouble();
* this.isOutput = dis.readBoolean(); } catch (IOException e) { e.printStackTrace(); } } }
* @Override public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { if (worldObj.isRemote) { ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); DataInputStream dis = new DataInputStream(bis); int id, x, y, z; try { id = dis.readInt(); x = dis.readInt(); y = dis.readInt(); z = dis.readInt(); NBTTagCompound tag = Packet.readNBTTagCompound(dis); readFromNBT(tag); this.wattsReceived = dis.readDouble(); this.isOutput = dis.readBoolean(); } catch (IOException e) { e.printStackTrace(); } } }
*/
/**
@ -248,6 +239,8 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
for (TileEntityChest chest : chests)
{
if (chest != null)
{
for (int i = 0; i < chest.getSizeInventory(); i++)
{
@ -257,6 +250,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
}
}
}
else if (tileEntity instanceof ISidedInventory)
{
ISidedInventory inventory = (ISidedInventory) tileEntity;

View file

@ -131,7 +131,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{
if (!this.commandManager.hasTasks())
{
if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01)
if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01 || Math.abs(this.rotationPitch - CommandReturn.IDLE_ROTATION_PITCH) > 0.01)
{
this.commandManager.addCommand(this, CommandReturn.class);
}
@ -140,16 +140,15 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.commandManager.setCurrentTask(0);
}
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
this.commandManager.onUpdate();
}
this.commandManager.onUpdate();
this.ticksSincePower = 0;
}
else
{
this.ticksSincePower++;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && ticksSincePower < 20)
this.commandManager.onUpdate();
}
for (Entity entity : this.grabbedEntities)
@ -282,7 +281,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
double distance = 1f;
Vector3 delta = new Vector3();
// The delta Y of the hand.
delta.y = Math.sin(Math.toRadians(this.renderPitch)) * distance;
delta.y = Math.sin(Math.toRadians(this.renderPitch)) * distance * 2; //arm bend up in a taller-than-wide arc
// The horizontal delta of the hand.
double dH = Math.cos(Math.toRadians(this.renderPitch)) * distance;
// The delta X and Z.
@ -674,9 +673,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
for (int i = 0; i < found.size(); i++)
{
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && found.get(i).ridingEntity == null) // isn't null, isn't a player, and isn't riding anything
{
return new Object[] { true };
}
{ return new Object[] { true }; }
}
}

View file

@ -33,6 +33,7 @@ public abstract class Command
registerCommand("return", CommandReturn.class);
registerCommand("repeat", CommandRepeat.class);
registerCommand("use", CommandUse.class);
registerCommand("fire", CommandFire.class);
}
public static void registerCommand(String command, Class<? extends Command> commandClass)

View file

@ -11,6 +11,9 @@ public class CommandDrop extends Command
{
super.doTask();
if (this.tileEntity.grabbedEntities.size() == 0)
return false;
// TODO: Animate Armbot to move down and drop all items.
for (Entity entity : this.tileEntity.grabbedEntities)
{
@ -19,6 +22,7 @@ public class CommandDrop extends Command
entity.isDead = false;
entity.worldObj = this.tileEntity.worldObj;
if (entity instanceof EntityItem)
if (!world.isRemote)
world.spawnEntityInWorld(entity); // items don't move right, so we render them manually
this.world.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);
}

View file

@ -0,0 +1,98 @@
package assemblyline.common.machine.command;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import universalelectricity.core.vector.Vector3;
public class CommandFire extends Command
{
private static final float MIN_ACTUAL_PITCH = 0;
private static final float MAX_ACTUAL_PITCH = 100;
private static final float VELOCITY = 2f;
private float actualYaw;
private float actualPitch;
private Vector3 finalVelocity;
@Override
public void onTaskStart()
{
super.onTaskStart();
this.actualYaw = this.tileEntity.rotationYaw;
this.actualPitch = ((MAX_ACTUAL_PITCH - MIN_ACTUAL_PITCH) * (this.tileEntity.rotationPitch / 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);
this.finalVelocity.multiply(VELOCITY);
}
@Override
protected boolean doTask()
{
if (this.finalVelocity == null) // something went wrong
{
this.finalVelocity = new Vector3(0, 0, 0);
}
if (this.tileEntity.grabbedEntities.size() > 0)
{
Entity held = this.tileEntity.grabbedEntities.get(0);
if (held != null)
{
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
if (item.func_92014_d().stackSize > 1)
{
item.func_92014_d().stackSize--;
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
if (!this.world.isRemote)
this.world.removeEntity(held);
}
if (item.func_92014_d().itemID == Item.arrow.itemID)
{
EntityArrow arrow = new EntityArrow(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z);
arrow.motionX = this.finalVelocity.x;
arrow.motionY = this.finalVelocity.y;
arrow.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(arrow);
}
else
{
EntityItem item2 = new EntityItem(world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z, item.func_92014_d());
item2.motionX = this.finalVelocity.x;
item2.motionY = this.finalVelocity.y;
item2.motionZ = this.finalVelocity.z;
if (!this.world.isRemote)
this.world.spawnEntityInWorld(item2);
}
}
else
{
this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[] {}).doTask();
held.motionX = this.finalVelocity.x;
held.motionY = this.finalVelocity.y;
held.motionZ = this.finalVelocity.z;
}
}
}
return false;
}
}

View file

@ -2,10 +2,10 @@ package assemblyline.common.machine.command;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.util.AxisAlignedBB;
import universalelectricity.core.vector.Vector3;
@ -34,6 +34,10 @@ public class CommandGrab extends Command
protected boolean doTask()
{
super.doTask();
if (this.tileEntity.grabbedEntities.size() > 0)
return false;
Vector3 serachPosition = this.tileEntity.getHandPosition();
List<Entity> found = this.world.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(serachPosition.x - radius, serachPosition.y - radius, serachPosition.z - radius, serachPosition.x + radius, serachPosition.y + radius, serachPosition.z + radius));
@ -41,7 +45,7 @@ public class CommandGrab extends Command
{
for (int i = 0; i < found.size(); i++)
{
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && found.get(i).ridingEntity == null) // isn't null, isn't a player, and isn't riding anything
if (found.get(i) != null && !(found.get(i) instanceof EntityPlayer) && !(found.get(i) instanceof EntityArrow) && found.get(i).ridingEntity == null) // isn't null, isn't a player, and isn't riding anything
{
this.tileEntity.grabbedEntities.add(found.get(i));
if (found.get(i) instanceof EntityItem)

View file

@ -6,7 +6,9 @@ import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import assemblyline.common.machine.armbot.TileEntityArmbot;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
public class CommandManager
{
@ -44,24 +46,19 @@ public class CommandManager
task.onTaskStart();
}
//System.out.print(Command.getCommandName(task.getClass()) + "|");
//System.out.println("curTask: " + currentTask);
if (!task.doTask())
{
// End the task and reinitiate it into a new class to make sure it is fresh.
int tempCurrentTask = this.currentTask;
this.currentTask++;
task.onTaskEnd();
this.currentTask++;
if (!(task instanceof CommandRepeat)) //repeat needs to be persistent
{
// End the task and reinitialize it into a new class to make sure it is fresh.
this.tasks.set(tempCurrentTask, this.getNewCommand(task.tileEntity, task.getClass(), task.getArgs()));
}
/*for (Command command : this.tasks)
{
System.out.print(Command.getCommandName(command.getClass()));
System.out.print("; ");
}
System.out.println(this.currentTask);*/
}
else
{
@ -99,8 +96,7 @@ public class CommandManager
}
/**
* Used to register Tasks for a TileEntity, executes onTaskStart for the Task after registering
* it
* Used to register Tasks for a TileEntity, executes onTaskStart for the Task after registering it
*
* @param tileEntity TE instance to register the task for
* @param newCommand Task instance to register
@ -146,7 +142,7 @@ public class CommandManager
public void setCurrentTask(int i)
{
this.currentTask = Math.max(Math.min(i, this.tasks.size()), 0);
this.currentTask = Math.min(i, this.tasks.size());
}
public int getCurrentTask()

View file

@ -12,22 +12,40 @@ public class CommandRepeat extends Command
* The amount of tasks above this task to repeat.
*/
private int tasksToRepeat;
private int numReps;
private int curReps;
private boolean initialized = false;
public void onTaskStart()
{
this.tasksToRepeat = Math.max(this.getIntArg(0), 0);
this.numReps = this.getIntArg(1);
if (numReps == 0)
numReps = -1; // infinite
if (!this.initialized)
{
this.initialized = true;
this.curReps = 0;
}
}
@Override
public void onTaskEnd()
{
if (this.curReps < this.numReps || this.numReps == -1)
{
this.curReps++;
if (this.tasksToRepeat > 0)
{
this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat);
this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat - 1);
return;
}
else
{
this.commandManager.setCurrentTask(0);
this.commandManager.setCurrentTask(-1);
return;
}
}
this.initialized = false;
}
}