Make disks work on Armbot

This commit is contained in:
Henry Mao 2013-01-10 21:04:20 +08:00
parent f1cd1bf848
commit af74b4230b
10 changed files with 180 additions and 202 deletions

View file

@ -100,81 +100,52 @@ public class ModelArmbot extends ModelBase
{ {
super.render(entity, f, f1, f2, f3, f4, f5); super.render(entity, f, f1, f2, f3, f4, f5);
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity); this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
this.render(f5, null); this.render(f5, entity.rotationYaw, entity.rotationPitch);
} }
public void render(float f5, TileEntityArmbot armBot) public void render(float f5, float rotationYaw, float rotationPitch)
{ {
// set yaw from tileentity /*
if (armBot != null) * armMountRight.setRotationPoint(baseRotation.rotationPointX, armMountRight.rotationPointY,
{ * baseRotation.rotationPointX); armMountLeft.setRotationPoint(baseRotation.rotationPointX,
/*armMountRight.setRotationPoint(baseRotation.rotationPointX, armMountRight.rotationPointY, baseRotation.rotationPointX); * armMountLeft.rotationPointY, baseRotation.rotationPointX);
armMountLeft.setRotationPoint(baseRotation.rotationPointX, armMountLeft.rotationPointY, baseRotation.rotationPointX); * armLower.setRotationPoint(baseRotation.rotationPointX, armLower.rotationPointY,
armLower.setRotationPoint(baseRotation.rotationPointX, armLower.rotationPointY, baseRotation.rotationPointX); * baseRotation.rotationPointX); armUpper.setRotationPoint(baseRotation.rotationPointX,
armUpper.setRotationPoint(baseRotation.rotationPointX, armUpper.rotationPointY, baseRotation.rotationPointX); * armUpper.rotationPointY, baseRotation.rotationPointX);
baseRotation.setRotationPoint(baseRotation.rotationPointX, baseRotation.rotationPointY, baseRotation.rotationPointX); * baseRotation.setRotationPoint(baseRotation.rotationPointX, baseRotation.rotationPointY,
clampBody.setRotationPoint(baseRotation.rotationPointX, clampBody.rotationPointY, baseRotation.rotationPointX); * baseRotation.rotationPointX); clampBody.setRotationPoint(baseRotation.rotationPointX,
clampBody2.setRotationPoint(baseRotation.rotationPointX, clampBody2.rotationPointY, baseRotation.rotationPointX); * clampBody.rotationPointY, baseRotation.rotationPointX);
clampClawLower.setRotationPoint(baseRotation.rotationPointX, clampClawLower.rotationPointY, baseRotation.rotationPointX); * clampBody2.setRotationPoint(baseRotation.rotationPointX, clampBody2.rotationPointY,
clampClawLower2.setRotationPoint(baseRotation.rotationPointX, clampClawLower2.rotationPointY, baseRotation.rotationPointX); * baseRotation.rotationPointX);
* clampClawLower.setRotationPoint(baseRotation.rotationPointX,
* clampClawLower.rotationPointY, baseRotation.rotationPointX);
* clampClawLower2.setRotationPoint(baseRotation.rotationPointX,
* clampClawLower2.rotationPointY, baseRotation.rotationPointX);
*
* armMountRight.rotateAngleY = armBot.rotationYaw; armMountLeft.rotateAngleY =
* armBot.rotationYaw; armLower.rotateAngleY = armBot.rotationYaw; armUpper.rotateAngleY =
* armBot.rotationYaw; baseRotation.rotateAngleY = armBot.rotationYaw;
* clampBody.rotateAngleY = armBot.rotationYaw; clampBody2.rotateAngleY =
* armBot.rotationYaw; clampClawLower.rotateAngleY = armBot.rotationYaw;
* clampClawLower2.rotateAngleY = armBot.rotationYaw;
*/
BaseTop.render(f5);
Base.render(f5);
GL11.glPushMatrix();
GL11.glRotatef(rotationYaw, 0, 1, 0);
armMountRight.render(f5);
armMountLeft.render(f5);
armLower.render(f5);
armUpper.render(f5);
baseRotation.render(f5);
clampBody.render(f5);
clampBody2.render(f5);
clampClawLower.render(f5);
clampClawLower2.render(f5);
GL11.glPopMatrix();
armMountRight.rotateAngleY = armBot.rotationYaw;
armMountLeft.rotateAngleY = armBot.rotationYaw;
armLower.rotateAngleY = armBot.rotationYaw;
armUpper.rotateAngleY = armBot.rotationYaw;
baseRotation.rotateAngleY = armBot.rotationYaw;
clampBody.rotateAngleY = armBot.rotationYaw;
clampBody2.rotateAngleY = armBot.rotationYaw;
clampClawLower.rotateAngleY = armBot.rotationYaw;
clampClawLower2.rotateAngleY = armBot.rotationYaw;*/
BaseTop.render(f5);
Base.render(f5);
GL11.glPushMatrix();
GL11.glRotatef((float) (armBot.rotationYaw * (180f / Math.PI)), 0, 1, 0);
armMountRight.render(f5);
armMountLeft.render(f5);
armLower.render(f5);
armUpper.render(f5);
baseRotation.render(f5);
clampBody.render(f5);
clampBody2.render(f5);
clampClawLower.render(f5);
clampClawLower2.render(f5);
GL11.glPopMatrix();
}
else
{
/*armMountRight.setRotationPoint(0F, 17F, 0F);
setRotation(armMountRight, 0F, 0F, 0F);
armMountLeft.setRotationPoint(0F, 17F, 0F);
setRotation(armMountLeft, 0F, 0F, 0F);
armLower.setRotationPoint(0F, 14F, 0F);
setRotation(armLower, 0.5235988F, 0F, 0F);
armUpper.setRotationPoint(0F, 2F, -7F);
setRotation(armUpper, 2.007129F, 0F, 0F);
baseRotation.setRotationPoint(0F, 17F, 0F);
setRotation(baseRotation, 0F, 0F, 0F);
clampBody.setRotationPoint(0F, 2F, -7F);
setRotation(clampBody, 2.007129F, 0F, 0F);
clampBody2.setRotationPoint(0F, 2F, -7F);
setRotation(clampBody2, 2.007129F, 0F, 0F);
clampClawLower.setRotationPoint(0F, 10F, -23F);
setRotation(clampClawLower, 2.007129F, 0F, 0F);
clampClawLower2.setRotationPoint(0F, 10F, -23F);
setRotation(clampClawLower2, 2.007129F, 0F, 0F);*/
BaseTop.render(f5);
Base.render(f5);
armMountRight.render(f5);
armMountLeft.render(f5);
armLower.render(f5);
armUpper.render(f5);
baseRotation.render(f5);
clampBody.render(f5);
clampBody2.render(f5);
clampClawLower.render(f5);
clampClawLower2.render(f5);
}
} }
private void setRotation(ModelRenderer model, float x, float y, float z) private void setRotation(ModelRenderer model, float x, float y, float z)

View file

@ -71,7 +71,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
GL11.glScalef(0.7f, 0.7f, 0.7f); GL11.glScalef(0.7f, 0.7f, 0.7f);
GL11.glRotatef(180f, 0f, 0f, 1f); GL11.glRotatef(180f, 0f, 0f, 1f);
GL11.glRotatef(-90f, 0f, 1f, 0f); GL11.glRotatef(-90f, 0f, 1f, 0f);
RenderArmbot.MODEL.render(0.0625F, null); RenderArmbot.MODEL.render(0.0625F, 0, 0);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }

View file

@ -23,7 +23,7 @@ public class RenderArmbot extends TileEntitySpecialRenderer
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); MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).rotationYaw, ((TileEntityArmbot) tileEntity).rotationPitch);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }

View file

@ -38,12 +38,12 @@ import cpw.mods.fml.relauncher.Side;
public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IJouleStorage
{ {
private final CommandManager commandManager = new CommandManager();
/** /**
* The items this container contains. * The items this container contains.
*/ */
protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()]; protected ItemStack disk = null;
private CommandManager taskManager = new CommandManager();
public final double WATT_REQUEST = 20; public final double WATT_REQUEST = 20;
@ -52,10 +52,10 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
private int playerUsing = 0; private int playerUsing = 0;
/** /**
* The rotation of the arms. * The rotation of the arms. In Degrees.
*/ */
public float rotationPitch = CommandIdle.IDLE_ROTATION_PITCH; public float rotationPitch = 0;
public float rotationYaw = CommandIdle.IDLE_ROTATION_YAW; public float rotationYaw = 0;
/** /**
* An entity that the armbot is grabbed onto. * An entity that the armbot is grabbed onto.
@ -80,30 +80,57 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
} }
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
this.taskManager.onUpdate();
if (!this.taskManager.hasTasks())
{ {
this.taskManager.addTask(this, new CommandIdle(this)); this.commandManager.onUpdate();
} }
System.out.println("RUNNNIN"); if (this.disk != null)
{
try
{
if (!this.commandManager.hasTasks())
{
List<String> commands = ItemDisk.getCommands(this.disk);
// Give some slight random movement to the armbot. for (String commandString : commands)
if (this.rotationPitch < 0) {
this.rotationPitch += (float) (Math.PI * 2); Class<? extends Command> command = Command.getCommand(commandString);
if (this.rotationPitch >= Math.PI * 2)
this.rotationPitch -= (float) (Math.PI * 2); if (command != null)
if (this.rotationYaw < 0) {
this.rotationYaw += (float) (Math.PI * 2); Command newCommand = command.newInstance();
if (this.rotationYaw >= Math.PI * 2) newCommand.world = this.worldObj;
this.rotationYaw -= (float) (Math.PI * 2); newCommand.tileEntity = this;
newCommand.parameters = new String[5];
newCommand.onTaskStart();
this.commandManager.addTask(this, newCommand);
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
this.commandManager.clearTasks();
}
// Give some slight random movement to the Armbot.
/*
* if (this.rotationPitch < 0) this.rotationPitch += (float) (Math.PI * 2); if
* (this.rotationPitch >= Math.PI * 2) this.rotationPitch -= (float) (Math.PI * 2); if
* (this.rotationYaw < 0) this.rotationYaw += (float) (Math.PI * 2); if
* (this.rotationYaw >= Math.PI * 2) this.rotationYaw -= (float) (Math.PI * 2);
*/
} }
// Simulates smoothness on client side // Simulates smoothness on client side
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{ {
this.taskManager.onUpdate(); this.commandManager.onUpdate();
} }
} }
@ -164,29 +191,29 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override @Override
public ItemStack getStackInSlot(int par1) public ItemStack getStackInSlot(int par1)
{ {
return this.containingItems[par1]; return this.disk;
} }
@Override @Override
public ItemStack decrStackSize(int par1, int par2) public ItemStack decrStackSize(int par1, int par2)
{ {
if (this.containingItems[par1] != null) if (this.disk != null)
{ {
ItemStack var3; ItemStack var3;
if (this.containingItems[par1].stackSize <= par2) if (this.disk.stackSize <= par2)
{ {
var3 = this.containingItems[par1]; var3 = this.disk;
this.containingItems[par1] = null; this.disk = null;
return var3; return var3;
} }
else else
{ {
var3 = this.containingItems[par1].splitStack(par2); var3 = this.disk.splitStack(par2);
if (this.containingItems[par1].stackSize == 0) if (this.disk.stackSize == 0)
{ {
this.containingItems[par1] = null; this.disk = null;
} }
return var3; return var3;
@ -201,10 +228,10 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override @Override
public ItemStack getStackInSlotOnClosing(int par1) public ItemStack getStackInSlotOnClosing(int par1)
{ {
if (this.containingItems[par1] != null) if (this.disk != null)
{ {
ItemStack var2 = this.containingItems[par1]; ItemStack var2 = this.disk;
this.containingItems[par1] = null; this.disk = null;
return var2; return var2;
} }
else else
@ -216,7 +243,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override @Override
public void setInventorySlotContents(int par1, ItemStack par2ItemStack) public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{ {
this.containingItems[par1] = par2ItemStack; this.disk = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{ {
@ -257,21 +284,15 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
super.readFromNBT(nbt); super.readFromNBT(nbt);
NBTTagList var2 = nbt.getTagList("Items"); NBTTagList var2 = nbt.getTagList("Items");
this.containingItems = new ItemStack[this.getSizeInventory()];
for (int var3 = 0; var3 < var2.tagCount(); ++var3) for (int var3 = 0; var3 < var2.tagCount(); ++var3)
{ {
NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3); NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3);
byte var5 = var4.getByte("Slot"); this.disk = ItemStack.loadItemStackFromNBT(var4);
if (var5 >= 0 && var5 < this.containingItems.length)
{
this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4);
}
} }
rotationYaw = nbt.getFloat("yaw"); this.rotationYaw = nbt.getFloat("yaw");
rotationPitch = nbt.getFloat("pitch"); this.rotationPitch = nbt.getFloat("pitch");
} }
/** /**
@ -282,19 +303,17 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
NBTTagList var2 = new NBTTagList(); NBTTagList var2 = new NBTTagList();
for (int var3 = 0; var3 < this.containingItems.length; ++var3)
if (this.disk != null)
{ {
if (this.containingItems[var3] != null) NBTTagCompound var4 = new NBTTagCompound();
{ this.disk.writeToNBT(var4);
NBTTagCompound var4 = new NBTTagCompound(); var2.appendTag(var4);
var4.setByte("Slot", (byte) var3);
this.containingItems[var3].writeToNBT(var4);
var2.appendTag(var4);
}
} }
nbt.setTag("Items", var2); nbt.setTag("Items", var2);
nbt.setFloat("yaw", rotationYaw); nbt.setFloat("yaw", this.rotationYaw);
nbt.setFloat("pitch", rotationPitch); nbt.setFloat("pitch", this.rotationPitch);
} }
@Override @Override
@ -353,18 +372,6 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
@Override @Override
public void onInventoryChanged() public void onInventoryChanged()
{ {
super.onInventoryChanged();
ItemStack disk = this.getStackInSlot(0);
if (disk != null)
{
this.taskManager = new CommandManager();
}
else
{
this.taskManager = new CommandManager();
this.taskManager.addTask(this, new CommandIdle(this));
}
} }
@Override @Override

View file

@ -40,22 +40,15 @@ public abstract class Command
/** /**
* The amount of ticks this command has been running for. * The amount of ticks this command has been running for.
*/ */
protected int ticks; protected int ticks = 0;
protected World world; public World world;
protected TileEntityArmbot tileEntity; public TileEntityArmbot tileEntity;
/** /**
* The parameters this command has, or the properties. Entered by the player in the disk. * The parameters this command has, or the properties. Entered by the player in the disk.
*/ */
protected String[] parameters; public String[] parameters;
public Command(TileEntityArmbot arm, String... parameters)
{
this.tileEntity = arm;
this.world = tileEntity.worldObj;
this.parameters = parameters;
}
/** /**
* Called by the TaskManager to propagate tick updates * Called by the TaskManager to propagate tick updates

View file

@ -25,14 +25,6 @@ public class CommandGrab extends Command
private Entity foundEntity; private Entity foundEntity;
public CommandGrab(TileEntityArmbot arm, Class<? extends Entity> entityToInclude, double radius, float searchSpeed)
{
super(arm);
this.entityToInclude = entityToInclude;
this.radius = radius;
this.searchSpeed = searchSpeed;
}
@Override @Override
protected boolean doTask() protected boolean doTask()
{ {

View file

@ -2,45 +2,14 @@ package assemblyline.common.machine.command;
import assemblyline.common.machine.armbot.TileEntityArmbot; import assemblyline.common.machine.armbot.TileEntityArmbot;
public class CommandIdle extends Command public class CommandIdle extends Command
{ {
public static final float IDLE_ROTATION_PITCH = 0;
public static final float IDLE_ROTATION_YAW = 0;
public CommandIdle(TileEntityArmbot arm)
{
super(arm);
}
protected boolean doTask() protected boolean doTask()
{ {
/**
* Move the arm rotation to idle position if the machine is not idling
*/
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) > 0.001 || Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) > 0.001)
{
if (Math.abs(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) > 0.125)
this.tileEntity.rotationPitch += (IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * 0.05;
else
this.tileEntity.rotationPitch += Math.signum(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) < 0.0125)
this.tileEntity.rotationPitch = IDLE_ROTATION_PITCH;
if (Math.abs(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) > 0.125)
this.tileEntity.rotationYaw += (IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * 0.05;
else
this.tileEntity.rotationYaw += Math.signum(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) < 0.0125)
this.tileEntity.rotationYaw = IDLE_ROTATION_YAW;
return true;
}
/** /**
* Randomly move the arm to simulate life in the arm if the arm is powered * Randomly move the arm to simulate life in the arm if the arm is powered
*/ */
//this.tileEntity.rotationYaw *= 0.98 * this.world.rand.nextFloat(); this.tileEntity.rotationPitch *= 0.98 * this.world.rand.nextFloat();
return false; return false;
} }

View file

@ -25,6 +25,7 @@ public class CommandManager
{ {
Command task; Command task;
Iterator<Command> iter = tasks.iterator(); Iterator<Command> iter = tasks.iterator();
while (iter.hasNext()) while (iter.hasNext())
{ {
task = iter.next(); task = iter.next();
@ -70,9 +71,14 @@ public class CommandManager
{ {
return !tasks.isEmpty(); return !tasks.isEmpty();
} }
public List<Command> getCommands() public List<Command> getCommands()
{ {
return tasks; return tasks;
} }
public void clearTasks()
{
this.tasks.clear();
}
} }

View file

@ -0,0 +1,36 @@
package assemblyline.common.machine.command;
import assemblyline.common.machine.armbot.TileEntityArmbot;
public class CommandReturn extends Command
{
public static final float IDLE_ROTATION_PITCH = 0;
public static final float IDLE_ROTATION_YAW = 0;
protected boolean doTask()
{
/**
* Move the arm rotation to idle position if the machine is not idling
*/
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) > 0.001 || Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) > 0.001)
{
if (Math.abs(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) > 0.125)
this.tileEntity.rotationPitch += (IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * 0.05;
else
this.tileEntity.rotationPitch += Math.signum(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationPitch - IDLE_ROTATION_PITCH) < 0.0125)
this.tileEntity.rotationPitch = IDLE_ROTATION_PITCH;
if (Math.abs(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) > 0.125)
this.tileEntity.rotationYaw += (IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * 0.05;
else
this.tileEntity.rotationYaw += Math.signum(IDLE_ROTATION_YAW - this.tileEntity.rotationYaw) * (0.125 * 0.05);
if (Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) < 0.0125)
this.tileEntity.rotationYaw = IDLE_ROTATION_YAW;
return true;
}
return false;
}
}

View file

@ -13,12 +13,18 @@ import assemblyline.common.machine.armbot.TileEntityArmbot;
*/ */
public class CommandRotate extends Command public class CommandRotate extends Command
{ {
public static final float ROTATION_SPEED = 1f;
float targetRotation = 0; float targetRotation = 0;
public CommandRotate(TileEntityArmbot arm, String...parameters) @Override
public void onTaskStart()
{ {
super(arm, parameters); this.targetRotation = this.tileEntity.rotationYaw + 90;
this.targetRotation = arm.rotationYaw + (float) (Math.PI / 2);
while (this.targetRotation > 360)
{
this.targetRotation -= 360;
}
} }
@Override @Override
@ -26,19 +32,17 @@ public class CommandRotate extends Command
{ {
super.doTask(); super.doTask();
if (this.tileEntity.rotationYaw != this.targetRotation) if (this.tileEntity.rotationYaw > this.targetRotation)
{ {
if (Math.abs(this.targetRotation - this.tileEntity.rotationYaw) > 0.125) this.tileEntity.rotationYaw -= ROTATION_SPEED;
this.tileEntity.rotationYaw += (this.targetRotation - this.tileEntity.rotationYaw) * 0.05; }
else else
this.tileEntity.rotationYaw += Math.signum(this.targetRotation - this.tileEntity.rotationYaw) * (0.125 * 0.05); {
if (Math.abs(this.tileEntity.rotationYaw - this.targetRotation) < 0.0125) this.tileEntity.rotationYaw += ROTATION_SPEED;
this.tileEntity.rotationYaw = this.targetRotation;
return true;
} }
if (ticks < 80)
return true;
return false; if (Math.abs(this.targetRotation - this.tileEntity.rotationYaw) < 0.125) { return false; }
return true;
} }
} }