More armbot improvements
This commit is contained in:
parent
c83ab74fa7
commit
ae26c2889c
4 changed files with 131 additions and 113 deletions
|
@ -30,13 +30,34 @@ public class RenderArmbot extends TileEntitySpecialRenderer
|
|||
{
|
||||
String cmdText = ((TileEntityArmbot) tileEntity).getCommandDisplayText();
|
||||
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);
|
||||
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, ((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();
|
||||
handPos.subtract(new Vector3(tileEntity));
|
||||
GL11.glPushMatrix();
|
||||
|
|
|
@ -146,25 +146,36 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
this.commandManager.setCurrentTask(0);
|
||||
}
|
||||
}
|
||||
this.commandManager.onUpdate();
|
||||
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
this.displayText = "";
|
||||
Command curCommand = this.getCurrentCommand();
|
||||
if (curCommand != null)
|
||||
{
|
||||
this.displayText = curCommand.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
this.commandManager.onUpdate();
|
||||
|
||||
this.ticksSincePower = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
|
@ -184,53 +195,32 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
}
|
||||
}
|
||||
|
||||
// keep it within 0 - 360 degrees so ROTATE commands work properly
|
||||
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;
|
||||
}
|
||||
|
||||
// System.out.println("Ren: " + this.renderYaw + "; Rot: " + this.rotationYaw);
|
||||
if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f)
|
||||
{
|
||||
float speedYaw;
|
||||
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;
|
||||
else
|
||||
speedYaw = -this.ROTATION_SPEED;
|
||||
}
|
||||
else if (Math.abs(this.renderYaw - this.rotationYaw) > 180)
|
||||
speedYaw = -this.ROTATION_SPEED;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
if (this.renderYaw >= 360)
|
||||
{
|
||||
while (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)
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
speedPitch = this.ROTATION_SPEED;
|
||||
}
|
||||
|
||||
this.renderPitch += speedPitch;
|
||||
|
||||
if (this.renderPitch <= 0)
|
||||
{
|
||||
this.renderPitch = 0;
|
||||
}
|
||||
if (this.renderPitch >= 60)
|
||||
{
|
||||
this.renderPitch = 60;
|
||||
}
|
||||
while (this.renderPitch < 0)
|
||||
this.renderPitch += 60;
|
||||
while (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)
|
||||
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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, new Vector3(this), 50);
|
||||
|
@ -456,6 +450,11 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
this.playerUsing--;
|
||||
}
|
||||
|
||||
public String getCommandDisplayText()
|
||||
{
|
||||
return this.displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
* NBT Data
|
||||
*/
|
||||
|
@ -478,6 +477,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
this.rotationYaw = nbt.getFloat("yaw");
|
||||
this.rotationPitch = nbt.getFloat("pitch");
|
||||
|
||||
if (this.worldObj.isRemote)
|
||||
this.displayText = nbt.getString("cmdText");
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
@ -524,15 +521,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
* NBTTagCompound cmdManager = new NBTTagCompound("cmdManager"); this.commandManager.writeToNBT(cmdManager); nbt.setCompoundTag("cmdManager", cmdManager);
|
||||
*/
|
||||
|
||||
Command curCommand = this.getCurrentCommand();
|
||||
if (curCommand != null)
|
||||
{
|
||||
nbt.setString("cmdText", curCommand.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
nbt.setString("cmdText", "");
|
||||
}
|
||||
nbt.setString("cmdText", this.displayText);
|
||||
|
||||
nbt.setInteger("curTask", this.commandManager.getCurrentTask());
|
||||
|
||||
|
@ -682,7 +671,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
@Override
|
||||
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
|
||||
|
@ -746,7 +735,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
this.addCommand(CommandDrop.class);
|
||||
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.addCommand(CommandReturn.class);
|
||||
|
@ -816,6 +805,20 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
*/
|
||||
public class CommandRotateBy extends Command
|
||||
{
|
||||
float targetRotationYaw = 0;
|
||||
float targetRotationPitch = 0;
|
||||
float deltaPitch = 0, deltaYaw = 90;
|
||||
float totalTicks = 0f;
|
||||
float targetRotationYaw = 0;
|
||||
float targetRotationPitch = 0;
|
||||
float deltaPitch = 0, deltaYaw = 90;
|
||||
float totalTicks = 0f;
|
||||
|
||||
@Override
|
||||
public void onTaskStart()
|
||||
|
@ -34,30 +34,21 @@ public class CommandRotateBy extends Command
|
|||
if (this.getArg(1) != null)
|
||||
{
|
||||
this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1);
|
||||
this.deltaYaw = this.getFloatArg(1);
|
||||
this.deltaPitch = this.getFloatArg(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.targetRotationPitch = this.tileEntity.rotationPitch;
|
||||
}
|
||||
|
||||
while (this.targetRotationYaw >= 360)
|
||||
{
|
||||
this.targetRotationYaw -= 360;
|
||||
}
|
||||
while (this.targetRotationYaw <= -360)
|
||||
{
|
||||
while (this.targetRotationYaw < 0)
|
||||
this.targetRotationYaw += 360;
|
||||
}
|
||||
|
||||
if (this.targetRotationPitch >= 60)
|
||||
{
|
||||
this.targetRotationPitch = 60;
|
||||
}
|
||||
if (this.targetRotationPitch <= 0)
|
||||
{
|
||||
this.targetRotationPitch = 0;
|
||||
}
|
||||
while (this.targetRotationYaw > 360)
|
||||
this.targetRotationYaw -= 360;
|
||||
while (this.targetRotationPitch < 0)
|
||||
this.targetRotationPitch += 60;
|
||||
while (this.targetRotationPitch > 60)
|
||||
this.targetRotationPitch -= 60;
|
||||
|
||||
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;
|
||||
|
@ -71,10 +62,7 @@ public class CommandRotateBy extends Command
|
|||
/*
|
||||
* 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; }
|
||||
* 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
|
||||
|
@ -107,7 +95,7 @@ public class CommandRotateBy extends Command
|
|||
taskCompound.setFloat("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setFloat("rotYaw", this.targetRotationYaw);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -39,8 +39,14 @@ public class CommandRotateTo extends Command
|
|||
this.targetRotationPitch = 0;
|
||||
}
|
||||
|
||||
this.targetRotationYaw = this.targetRotationYaw % 360;
|
||||
this.targetRotationPitch = this.targetRotationPitch % 60;
|
||||
while (this.targetRotationYaw < 0)
|
||||
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 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
|
||||
// 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)
|
||||
this.tileEntity.rotationPitch = this.targetRotationPitch;
|
||||
this.tileEntity.rotationYaw = this.targetRotationYaw;
|
||||
this.tileEntity.rotationPitch = this.targetRotationPitch;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue