More armbot improvements

This commit is contained in:
Brian Ricketts 2013-01-26 19:38:20 -06:00
parent c83ab74fa7
commit ae26c2889c
4 changed files with 131 additions and 113 deletions

View file

@ -30,13 +30,34 @@ public class RenderArmbot extends TileEntitySpecialRenderer
{ {
String cmdText = ((TileEntityArmbot) tileEntity).getCommandDisplayText(); String cmdText = ((TileEntityArmbot) tileEntity).getCommandDisplayText();
if (cmdText != null && !cmdText.isEmpty()) if (cmdText != null && !cmdText.isEmpty())
RenderHelper.renderFloatingText(cmdText, (float) x + 0.5f, ((float) y) + 0.25f, (float) z + 0.5f, 0xFFFFFF); {
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)
{
RenderHelper.renderFloatingText(cmdText, (float) x + 0.5f, ((float) y) + 0.25f, (float) z + 0.5f, 0xFFFFFF);
}
}
}
this.bindTextureByName(AssemblyLine.TEXTURE_PATH + TEXTURE); this.bindTextureByName(AssemblyLine.TEXTURE_PATH + TEXTURE);
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F); GL11.glScalef(1.0F, -1F, -1F);
MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).renderYaw, ((TileEntityArmbot) tileEntity).renderPitch); MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).renderYaw, ((TileEntityArmbot) tileEntity).renderPitch);
//debug render
/*GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1f, 1f, 1f, 0.25f);
MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).rotationYaw, ((TileEntityArmbot) tileEntity).rotationPitch);
GL11.glColor4f(1f, 1f, 1f, 1f);*/
Vector3 handPos = ((TileEntityArmbot) tileEntity).getHandPosition(); Vector3 handPos = ((TileEntityArmbot) tileEntity).getHandPosition();
handPos.subtract(new Vector3(tileEntity)); handPos.subtract(new Vector3(tileEntity));
GL11.glPushMatrix(); GL11.glPushMatrix();

View file

@ -146,25 +146,36 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.commandManager.setCurrentTask(0); this.commandManager.setCurrentTask(0);
} }
} }
this.commandManager.onUpdate(); if (!this.worldObj.isRemote)
this.commandManager.onUpdate();
if (this.worldObj.isRemote)
{
this.displayText = "";
Command curCommand = this.getCurrentCommand();
if (curCommand != null)
{
this.displayText = curCommand.toString();
}
}
this.ticksSincePower = 0; this.ticksSincePower = 0;
} }
else else
{ {
this.ticksSincePower++; this.ticksSincePower++;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && ticksSincePower < 20) }
this.commandManager.onUpdate();
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)
{
}
}
} }
for (Entity entity : this.grabbedEntities) for (Entity entity : this.grabbedEntities)
@ -184,53 +195,32 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
} }
} }
// keep it within 0 - 360 degrees so ROTATE commands work properly // System.out.println("Ren: " + this.renderYaw + "; Rot: " + this.rotationYaw);
if (this.rotationPitch < 0)
{
this.rotationPitch = 0;
}
if (this.rotationPitch > 135)
{
this.rotationPitch = 135;
}
if (this.rotationYaw <= -360)
{
this.rotationYaw += 360;
}
if (this.rotationYaw >= 360)
{
this.rotationYaw -= 360;
}
if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f) if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f)
{ {
float speedYaw; float speedYaw;
if (this.renderYaw > this.rotationYaw) if (this.renderYaw > this.rotationYaw)
{ {
if (Math.abs(this.renderYaw - this.rotationYaw) > 180) if (Math.abs(this.renderYaw - this.rotationYaw) >= 180)
speedYaw = this.ROTATION_SPEED; speedYaw = this.ROTATION_SPEED;
else else
speedYaw = -this.ROTATION_SPEED; speedYaw = -this.ROTATION_SPEED;
} }
else if (Math.abs(this.renderYaw - this.rotationYaw) > 180)
speedYaw = -this.ROTATION_SPEED;
else else
speedYaw = this.ROTATION_SPEED; {
if (Math.abs(this.renderYaw - this.rotationYaw) >= 180)
speedYaw = -this.ROTATION_SPEED;
else
speedYaw = this.ROTATION_SPEED;
}
this.renderYaw += speedYaw; 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) // keep it within 0 - 360 degrees so ROTATE commands work properly
{ while (this.renderYaw < 0)
this.renderYaw += 360; this.renderYaw += 360;
} while (this.renderYaw > 360)
if (this.renderYaw >= 360)
{
this.renderYaw -= 360; this.renderYaw -= 360;
}
if (this.ticks % 5 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) // sound is 0.25 seconds long (20 ticks/second) if (this.ticks % 5 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) // sound is 0.25 seconds long (20 ticks/second)
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 2f, 1.7f, true); this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 2f, 1.7f, true);
@ -239,9 +229,10 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{ {
this.renderYaw = this.rotationYaw; this.renderYaw = this.rotationYaw;
} }
if (Math.abs(this.renderYaw - this.rotationYaw) > 720f) // something's wrong!
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)))
{ {
this.renderYaw = this.rotationYaw; e.rotationYaw = this.renderYaw;
} }
} }
@ -250,26 +241,19 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
float speedPitch; float speedPitch;
if (this.renderPitch > this.rotationPitch) if (this.renderPitch > this.rotationPitch)
{ {
if (Math.abs(this.renderPitch - this.rotationPitch) > 180)
speedPitch = this.ROTATION_SPEED;
else
speedPitch = -this.ROTATION_SPEED;
}
else if (Math.abs(this.renderPitch - this.rotationPitch) > 180)
speedPitch = -this.ROTATION_SPEED; speedPitch = -this.ROTATION_SPEED;
}
else else
{
speedPitch = this.ROTATION_SPEED; speedPitch = this.ROTATION_SPEED;
}
this.renderPitch += speedPitch; this.renderPitch += speedPitch;
if (this.renderPitch <= 0) while (this.renderPitch < 0)
{ this.renderPitch += 60;
this.renderPitch = 0; while (this.renderPitch > 60)
} this.renderPitch -= 60;
if (this.renderPitch >= 60)
{
this.renderPitch = 60;
}
if (this.ticks % 4 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) // sound is 0.25 seconds long (20 ticks/second) if (this.ticks % 4 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) // sound is 0.25 seconds long (20 ticks/second)
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 2f, 2.5f, true); this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 2f, 2.5f, true);
@ -278,12 +262,22 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{ {
this.renderPitch = this.rotationPitch; this.renderPitch = this.rotationPitch;
} }
if (Math.abs(this.renderPitch - this.rotationPitch) > 270f) // something's wrong!
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)))
{ {
this.renderPitch = this.rotationPitch; e.rotationPitch = this.renderPitch;
} }
} }
while (this.rotationYaw < 0)
this.rotationYaw += 360;
while (this.rotationYaw > 360)
this.rotationYaw -= 360;
while (this.rotationPitch < 0)
this.rotationPitch += 60;
while (this.rotationPitch > 60)
this.rotationPitch -= 60;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 20 == 0) if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 20 == 0)
{ {
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50); PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50);
@ -456,6 +450,11 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.playerUsing--; this.playerUsing--;
} }
public String getCommandDisplayText()
{
return this.displayText;
}
/** /**
* NBT Data * NBT Data
*/ */
@ -478,6 +477,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.rotationYaw = nbt.getFloat("yaw"); this.rotationYaw = nbt.getFloat("yaw");
this.rotationPitch = nbt.getFloat("pitch"); this.rotationPitch = nbt.getFloat("pitch");
if (this.worldObj.isRemote)
this.displayText = nbt.getString("cmdText");
/* /*
* NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager"); this.commandManager.readFromNBT(this, cmdManager); * NBTTagCompound cmdManager = nbt.getCompoundTag("cmdManager"); this.commandManager.readFromNBT(this, cmdManager);
*/ */
@ -496,11 +498,6 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
} }
} }
public String getCommandDisplayText()
{
return displayText;
}
/** /**
* Writes a tile entity to NBT. * Writes a tile entity to NBT.
*/ */
@ -524,15 +521,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager"); this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager); * NBTTagCompound cmdManager = new NBTTagCompound("cmdManager"); this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
*/ */
Command curCommand = this.getCurrentCommand(); nbt.setString("cmdText", this.displayText);
if (curCommand != null)
{
nbt.setString("cmdText", curCommand.toString());
}
else
{
nbt.setString("cmdText", "");
}
nbt.setInteger("curTask", this.commandManager.getCurrentTask()); nbt.setInteger("curTask", this.commandManager.getCurrentTask());
@ -682,7 +671,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override @Override
public String[] getMethodNames() public String[] getMethodNames()
{ {
return new String[] { "rotateBy", "rotateTo", "grab", "drop", "reset", "isWorking", "touchingEntity", "use", "fire" }; return new String[] { "rotateBy", "rotateTo", "grab", "drop", "reset", "isWorking", "touchingEntity", "use", "fire", "return", "clear", "isHolding" };
} }
@Override @Override
@ -746,7 +735,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
this.addCommand(CommandDrop.class); this.addCommand(CommandDrop.class);
break; break;
} }
case 4: // reset: clears the queue and calls the RETURN command case 4: // reset: equivalent to calling .clear() then .return()
{ {
this.commandManager.clear(); this.commandManager.clear();
this.addCommand(CommandReturn.class); this.addCommand(CommandReturn.class);
@ -816,6 +805,20 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
} }
break; 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; return null;
} }

View file

@ -9,10 +9,10 @@ import net.minecraft.nbt.NBTTagCompound;
*/ */
public class CommandRotateBy extends Command public class CommandRotateBy extends Command
{ {
float targetRotationYaw = 0; float targetRotationYaw = 0;
float targetRotationPitch = 0; float targetRotationPitch = 0;
float deltaPitch = 0, deltaYaw = 90; float deltaPitch = 0, deltaYaw = 90;
float totalTicks = 0f; float totalTicks = 0f;
@Override @Override
public void onTaskStart() public void onTaskStart()
@ -34,30 +34,21 @@ public class CommandRotateBy extends Command
if (this.getArg(1) != null) if (this.getArg(1) != null)
{ {
this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1); this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1);
this.deltaYaw = this.getFloatArg(1); this.deltaPitch = this.getFloatArg(1);
} }
else else
{ {
this.targetRotationPitch = this.tileEntity.rotationPitch; this.targetRotationPitch = this.tileEntity.rotationPitch;
} }
while (this.targetRotationYaw >= 360) while (this.targetRotationYaw < 0)
{
this.targetRotationYaw -= 360;
}
while (this.targetRotationYaw <= -360)
{
this.targetRotationYaw += 360; this.targetRotationYaw += 360;
} while (this.targetRotationYaw > 360)
this.targetRotationYaw -= 360;
if (this.targetRotationPitch >= 60) while (this.targetRotationPitch < 0)
{ this.targetRotationPitch += 60;
this.targetRotationPitch = 60; while (this.targetRotationPitch > 60)
} this.targetRotationPitch -= 60;
if (this.targetRotationPitch <= 0)
{
this.targetRotationPitch = 0;
}
float totalTicksYaw = Math.abs(this.targetRotationYaw - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED; float totalTicksYaw = Math.abs(this.targetRotationYaw - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED;
float totalTicksPitch = Math.abs(this.targetRotationPitch - this.tileEntity.rotationPitch) / this.tileEntity.ROTATION_SPEED; float totalTicksPitch = Math.abs(this.targetRotationPitch - this.tileEntity.rotationPitch) / this.tileEntity.ROTATION_SPEED;
@ -71,10 +62,7 @@ public class CommandRotateBy extends Command
/* /*
* float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation); * float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation);
* *
* if (rotationalDifference < ROTATION_SPEED) { this.tileEntity.rotationYaw = * 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; }
* 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 // set the rotation to the target immediately and let the client handle animating it
@ -107,7 +95,7 @@ public class CommandRotateBy extends Command
taskCompound.setFloat("rotPitch", this.targetRotationPitch); taskCompound.setFloat("rotPitch", this.targetRotationPitch);
taskCompound.setFloat("rotYaw", this.targetRotationYaw); taskCompound.setFloat("rotYaw", this.targetRotationYaw);
} }
@Override @Override
public String toString() public String toString()
{ {

View file

@ -39,8 +39,14 @@ public class CommandRotateTo extends Command
this.targetRotationPitch = 0; this.targetRotationPitch = 0;
} }
this.targetRotationYaw = this.targetRotationYaw % 360; while (this.targetRotationYaw < 0)
this.targetRotationPitch = this.targetRotationPitch % 60; this.targetRotationYaw += 360;
while (this.targetRotationYaw > 360)
this.targetRotationYaw -= 360;
while (this.targetRotationPitch < 0)
this.targetRotationPitch += 60;
while (this.targetRotationPitch > 60)
this.targetRotationPitch -= 60;
int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.renderYaw) / this.tileEntity.ROTATION_SPEED); int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.renderYaw) / this.tileEntity.ROTATION_SPEED);
int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.renderPitch) / this.tileEntity.ROTATION_SPEED); int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.renderPitch) / this.tileEntity.ROTATION_SPEED);
@ -60,12 +66,12 @@ public class CommandRotateTo extends Command
// set the rotation to the target immediately and let the client handle animating it // set the rotation to the target immediately and let the client handle animating it
// wait for the client to catch up // wait for the client to catch up
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotationYaw) > 0.001f) this.tileEntity.rotationYaw = this.targetRotationYaw;
this.tileEntity.rotationYaw = this.targetRotationYaw; this.tileEntity.rotationPitch = this.targetRotationPitch;
if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f)
this.tileEntity.rotationPitch = this.targetRotationPitch;
if (this.ticks < this.totalTicks) { return true; } if (this.ticks < this.totalTicks) { return true; }
if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f) { return true; }
if (Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f) { return true; }
return false; return false;
} }