Improvements to FIRE command and ArmBot in general

Fixed dupe bug
This commit is contained in:
Brian Ricketts 2013-01-21 19:47:06 -06:00
parent 2e1adab358
commit d7b90682f8
8 changed files with 137 additions and 108 deletions

View file

@ -1,6 +1,7 @@
package assemblyline.client.render;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
@ -37,10 +38,12 @@ public class RenderArmbot extends TileEntitySpecialRenderer
{
if (entity != null && entity instanceof EntityItem) //items don't move right, so we render them manually
{
Render render = RenderManager.instance.getEntityRenderObject(entity);
EntityItem item = (EntityItem) entity;
item.age = 0;
RenderItem render = (RenderItem) RenderManager.instance.getEntityRenderObject(entity);
if (render != null)
{
render.doRender(entity, -handPos.x + 0.5f, handPos.y - 1.5f, -handPos.z + 0.5f, 0, 0);
render.doRender(item, -handPos.x + 0.5f, handPos.y - 1.5f, -handPos.z + 0.5f, 0, 0);
}
}
}

View file

@ -8,7 +8,6 @@ import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
@ -169,11 +168,11 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
}
// keep it within 0 - 360 degrees so ROTATE commands work properly
if (this.rotationPitch <= 0)
if (this.rotationPitch < 0)
{
this.rotationPitch = 0;
}
if (this.rotationPitch >= 135)
if (this.rotationPitch > 135)
{
this.rotationPitch = 135;
}
@ -202,6 +201,10 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
speedYaw = this.ROTATION_SPEED;
this.renderYaw += speedYaw;
for (Entity e : (ArrayList<Entity>) this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord + 2, this.zCoord, this.xCoord + 1, this.yCoord + 3, this.zCoord + 1)))
{
e.rotationYaw += speedYaw;
}
if (this.renderYaw <= -360)
{

View file

@ -276,19 +276,21 @@ public class BlockConveyorBelt extends BlockMachine
entity.motionZ = direction.offsetZ * maxSpeed;
entity.motionX = 0;
}
entity.motionY += 0.0125f;
if (entity instanceof EntityItem)
{
if (direction.offsetX != 0)
{
double difference = (z + 0.5) - entity.posZ;
entity.motionZ += difference * 0.06;
entity.motionZ += difference * 0.1;
// entity.posZ = z + 0.5;
}
else if (direction.offsetZ != 0)
{
double difference = (x + 0.5) - entity.posX;
entity.motionX += difference * 0.06;
entity.motionX += difference * 0.1;
// /entity.posX = x + 0.5;
}

View file

@ -120,7 +120,7 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
if (this.isRunning())
{
if (this.ticks % 10 == 0 && this.worldObj.isRemote && this.worldObj.getBlockId(xCoord - 1, yCoord, zCoord) != AssemblyLine.blockConveyorBelt.blockID && this.worldObj.getBlockId(xCoord, yCoord, zCoord - 1) != AssemblyLine.blockConveyorBelt.blockID) // sound is 0.5 seconds long (20 ticks/second)
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 0.125f, 0.3f, true);
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 0.5f, 0.3f, true);
this.wheelRotation += 40;

View file

@ -1,98 +1,117 @@
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;
}
}
package assemblyline.common.machine.command;
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 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;
private float actualYaw;
private float actualPitch;
private float velocity;
private Vector3 finalVelocity;
@Override
public void onTaskStart()
{
super.onTaskStart();
velocity = this.getFloatArg(0);
if (velocity > 2.5f)
velocity = 2.5f;
if (velocity < 0.125f)
velocity = 1f;
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);
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.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)
{
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.bow", velocity, 2f - (velocity / 4f), true);
if (held instanceof EntityItem)
{
EntityItem item = (EntityItem) held;
ItemStack stack = item.func_92014_d();
ItemStack thrown = stack.copy();
thrown.stackSize = 1;
if (item.func_92014_d().stackSize > 0)
{
stack.stackSize--;
item.func_92013_a(stack);
}
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, thrown);
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

@ -23,7 +23,7 @@ public class CommandIdle extends Command
/**
* Randomly move the arm to simulate life in the arm if the arm is powered
*/
this.tileEntity.rotationPitch *= 0.98 * this.world.rand.nextFloat();
//this.tileEntity.rotationPitch *= 0.98 * this.world.rand.nextFloat();
if (this.idleTime > 0)
{

View file

@ -46,7 +46,8 @@ public class CommandManager
task.onTaskStart();
}
//System.out.println("curTask: " + currentTask);
//if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
//System.out.println("curTask: " + this.currentTask + ": " + this.tasks.get(this.currentTask).toString().substring(this.tasks.get(this.currentTask).toString().lastIndexOf('.') + 1));
if (!task.doTask())
{

View file

@ -85,6 +85,7 @@ public class CommandRotate extends Command
//set the rotation to the target immediately and let the client handle animating it
//wait for the client to catch up
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotationYaw) > 0.001f)
this.tileEntity.rotationYaw = this.targetRotationYaw;
if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f)