diff --git a/src/minecraft/assemblyline/client/render/RenderArmbot.java b/src/minecraft/assemblyline/client/render/RenderArmbot.java index fa7cd5c9..6666e388 100644 --- a/src/minecraft/assemblyline/client/render/RenderArmbot.java +++ b/src/minecraft/assemblyline/client/render/RenderArmbot.java @@ -1,10 +1,15 @@ package assemblyline.client.render; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; import assemblyline.client.model.ModelArmbot; import assemblyline.common.AssemblyLine; import assemblyline.common.machine.armbot.TileEntityArmbot; @@ -23,7 +28,23 @@ public class RenderArmbot extends TileEntitySpecialRenderer 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).rotationYaw, ((TileEntityArmbot) tileEntity).rotationPitch); + MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).renderYaw, ((TileEntityArmbot) tileEntity).renderPitch); + Vector3 handPos = ((TileEntityArmbot) tileEntity).getHandPosition(); + handPos.subtract(new Vector3(tileEntity)); + GL11.glPushMatrix(); + GL11.glRotatef(180, 0, 0, 1); + for (Entity entity : ((TileEntityArmbot) tileEntity).grabbedEntities) + { + if (entity != null && entity instanceof EntityItem) //items don't move right, so we render them manually + { + Render render = RenderManager.instance.getEntityRenderObject(entity); + if (render != null) + { + render.doRender(entity, -handPos.x + 0.5f, handPos.y - 1.5f, -handPos.z + 0.5f, 0, 0); + } + } + } + GL11.glPopMatrix(); GL11.glPopMatrix(); } } diff --git a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java index e70cfc78..b6dd55a6 100644 --- a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java +++ b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java @@ -10,11 +10,13 @@ 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; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; @@ -54,22 +56,19 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult * The items this container contains. */ protected ItemStack disk = null; - public final double WATT_REQUEST = 20; - public double wattsReceived = 0; - private int playerUsing = 0; - private int computersAttached = 0; - /** * The rotation of the arms. In Degrees. */ public float rotationPitch = 0; public float rotationYaw = 0; - + public float renderPitch = 0; + public float renderYaw = 0; private int ticksSincePower = 0; + public final float ROTATION_SPEED = 1.3f; /** * An entity that the armbot is grabbed onto. @@ -86,25 +85,60 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult @Override public void onUpdate() { + Vector3 handPosition = this.getHandPosition(); if (this.isRunning()) { - Vector3 handPosition = this.getHandPosition(); - - /** - * Break the block if the hand hits a solid block. - */ - Block block = Block.blocksList[handPosition.getBlockID(this.worldObj)]; - - if (block != null) + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { - if (Block.isNormalCube(block.blockID)) - { - block.dropBlockAsItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, handPosition.getBlockMetadata(this.worldObj), 0); - handPosition.setBlockWithNotify(this.worldObj, 0); - } - } + /** + * Break the block if the hand hits a solid block. + */ + Block block = Block.blocksList[handPosition.getBlockID(this.worldObj)]; - for (Entity entity : this.grabbedEntities) + if (block != null) + { + if (Block.isNormalCube(block.blockID)) + { + block.dropBlockAsItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, handPosition.getBlockMetadata(this.worldObj), 0); + handPosition.setBlockWithNotify(this.worldObj, 0); + } + } + + if (this.disk == null && this.computersAttached == 0) + { + this.commandManager.clear(); + if (this.grabbedEntities.size() > 0) + { + this.commandManager.addCommand(this, CommandDrop.class); + } + else + { + if (!this.commandManager.hasTasks()) + { + if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01) + { + this.commandManager.addCommand(this, CommandReturn.class); + } + } + } + + this.commandManager.setCurrentTask(0); + } + + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) + this.commandManager.onUpdate(); + + } + this.ticksSincePower = 0; + } + else + { + this.ticksSincePower++; + } + + for (Entity entity : this.grabbedEntities) + { + if (entity != null) { entity.setPosition(handPosition.x, handPosition.y, handPosition.z); entity.motionX = 0; @@ -117,54 +151,46 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult ((EntityItem) entity).age = 0; } } - - if (this.disk == null && this.computersAttached == 0) - { - if (this.grabbedEntities.size() > 0) - { - this.commandManager.addCommand(this, CommandDrop.class); - } - else - { - if (!this.commandManager.hasTasks()) - { - if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01) - { - this.commandManager.addCommand(this, CommandReturn.class); - } - } - } - - this.commandManager.setCurrentTask(0); - } - - this.commandManager.onUpdate(); - - // keep it within 0 - 360 degrees so ROTATE commands work properly - if (this.rotationPitch <= -360) - { - this.rotationPitch += 360; - } - if (this.rotationPitch >= 360) - { - this.rotationPitch -= 360; - } - if (this.rotationYaw <= -360) - { - this.rotationYaw += 360; - } - if (this.rotationYaw >= 360) - { - this.rotationYaw -= 360; - } - - this.ticksSincePower = 0; } - else + + // keep it within 0 - 360 degrees so ROTATE commands work properly + if (this.rotationPitch <= -360) { - this.ticksSincePower++; - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && ticksSincePower <= 20) - this.commandManager.onUpdate(); + this.rotationPitch += 360; + } + if (this.rotationPitch >= 360) + { + this.rotationPitch -= 360; + } + if (this.rotationYaw <= -360) + { + this.rotationYaw += 360; + } + if (this.rotationYaw >= 360) + { + this.rotationYaw -= 360; + } + + if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f) + { + float speed; + if (this.renderYaw > this.rotationYaw) + speed = -this.ROTATION_SPEED; + else + speed = this.ROTATION_SPEED; + // System.out.println("Speed: " + speed); + // System.out.println("Yaw: [" + this.rotationYaw + ", " + this.renderYaw + "]"); + this.renderYaw += speed; + if (this.ticks % 5 == 0) //sound is 0.5 seconds long (20 ticks/second) + Minecraft.getMinecraft().sndManager.playSound("assemblyline.conveyor", this.xCoord, this.yCoord, this.zCoord, 2f, 1.7f); + if (Math.abs(this.renderYaw - this.rotationYaw) < this.ROTATION_SPEED + 0.1f) + { + this.renderYaw = this.rotationYaw; + } + if (Math.abs(this.renderYaw - this.rotationYaw) > 720f) // something's wrong! + { + this.renderYaw = this.rotationYaw; + } } if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 20 == 0) @@ -184,12 +210,12 @@ 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.rotationPitch)) * distance; + delta.y = Math.sin(Math.toRadians(this.renderPitch)) * distance; // The horizontal delta of the hand. - double dH = Math.cos(Math.toRadians(this.rotationPitch)) * distance; + double dH = Math.cos(Math.toRadians(this.renderPitch)) * distance; // The delta X and Z. - delta.x = Math.sin(Math.toRadians(-this.rotationYaw)) * dH; - delta.z = Math.cos(Math.toRadians(-this.rotationYaw)) * dH; + delta.x = Math.sin(Math.toRadians(-this.renderYaw)) * dH; + delta.z = Math.cos(Math.toRadians(-this.renderYaw)) * dH; position.add(delta); return position; } @@ -355,6 +381,18 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult this.rotationYaw = nbt.getFloat("yaw"); this.rotationPitch = nbt.getFloat("pitch"); this.commandManager.setCurrentTask(nbt.getInteger("currentTask")); + + NBTTagList entities = nbt.getTagList("entities"); + this.grabbedEntities.clear(); + for (int i = 0; i < entities.tagCount(); i++) + { + NBTTagCompound entityTag = (NBTTagCompound) entities.tagAt(i); + if (entityTag != null) + { + Entity entity = EntityList.createEntityFromNBT(entityTag, worldObj); + this.grabbedEntities.add(entity); + } + } } /** @@ -376,6 +414,20 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult nbt.setFloat("yaw", this.rotationYaw); nbt.setFloat("pitch", this.rotationPitch); nbt.setInteger("currentTask", this.commandManager.getCurrentTask()); + + NBTTagList entities = new NBTTagList(); + for (Entity entity : grabbedEntities) + { + if (entity != null) + { + NBTTagCompound entityNBT = new NBTTagCompound(); + entity.writeToNBT(entityNBT); + entity.addEntityID(entityNBT); + entities.appendTag(entityNBT); + } + } + + nbt.setTag("entities", entities); } @Override @@ -460,10 +512,6 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult } } } - else - { - this.commandManager.clear(); - } } @Override @@ -533,7 +581,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult double angle = (Double) arguments[0]; double diff = angle - this.rotationYaw; this.commandManager.addCommand(this, CommandRotate.class, new String[] { Double.toString(diff) }); - while (this.commandManager.hasTasks()); + while (this.commandManager.hasTasks()) + ; } catch (Exception ex) { diff --git a/src/minecraft/assemblyline/common/machine/command/CommandDrop.java b/src/minecraft/assemblyline/common/machine/command/CommandDrop.java index 7cb46d4c..b799ec78 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandDrop.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandDrop.java @@ -1,5 +1,8 @@ package assemblyline.common.machine.command; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; public class CommandDrop extends Command { @@ -9,6 +12,17 @@ public class CommandDrop extends Command super.doTask(); // TODO: Animate Armbot to move down and drop all items. + for (Entity entity : this.tileEntity.grabbedEntities) + { + if (entity != null) + { + entity.isDead = false; + entity.worldObj = this.tileEntity.worldObj; + if (entity instanceof EntityItem) + world.spawnEntityInWorld(entity); //items don't move right, so we render them manually + Minecraft.getMinecraft().sndManager.playSound("random.pop", this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F); + } + } this.tileEntity.grabbedEntities.clear(); return false; } diff --git a/src/minecraft/assemblyline/common/machine/command/CommandGrab.java b/src/minecraft/assemblyline/common/machine/command/CommandGrab.java index 524c9e13..74259467 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandGrab.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandGrab.java @@ -2,7 +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.util.AxisAlignedBB; import universalelectricity.core.vector.Vector3; @@ -36,8 +39,28 @@ public class CommandGrab extends Command if (found != null && found.size() > 0) { - this.tileEntity.grabbedEntities.add(found.get(0)); - return false; + 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 + { + this.tileEntity.grabbedEntities.add(found.get(i)); + if (found.get(i) instanceof EntityItem) + this.tileEntity.worldObj.removeEntity(found.get(i)); //items don't move right, so we render them manually + Minecraft.getMinecraft().sndManager.playSound("random.pop", this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F); + found.get(i).isDead = false; + /*if (found.get(i).riddenByEntity != null) + { + found.get(i).riddenByEntity.ridingEntity = null; + found.get(i).riddenByEntity = null; + } + if (found.get(i).ridingEntity != null) + { + found.get(i).ridingEntity.riddenByEntity = null; + found.get(i).ridingEntity = null; + }*/ + return false; + } + } } /** * Move the robotic arm around and emulate an item search. Then initiate a collect task. diff --git a/src/minecraft/assemblyline/common/machine/command/CommandReturn.java b/src/minecraft/assemblyline/common/machine/command/CommandReturn.java index 0036f504..2223747c 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandReturn.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandReturn.java @@ -1,17 +1,24 @@ package assemblyline.common.machine.command; -public class CommandReturn extends Command +public class CommandReturn extends CommandRotate { public static final float IDLE_ROTATION_PITCH = 0; public static final float IDLE_ROTATION_YAW = 0; - + @Override + public void onTaskStart() + { + this.targetRotation = IDLE_ROTATION_YAW; + this.totalTicks = Math.abs(this.targetRotation - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED; + } + + /*@Override 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.01 || Math.abs(this.tileEntity.rotationYaw - IDLE_ROTATION_YAW) > 0.01) { if (Math.abs(IDLE_ROTATION_PITCH - this.tileEntity.rotationPitch) > 0.125) @@ -31,6 +38,6 @@ public class CommandReturn extends Command } return false; - } + }*/ } diff --git a/src/minecraft/assemblyline/common/machine/command/CommandRotate.java b/src/minecraft/assemblyline/common/machine/command/CommandRotate.java index 9d729dfa..7c1e5449 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandRotate.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandRotate.java @@ -8,8 +8,8 @@ package assemblyline.common.machine.command; */ public class CommandRotate extends Command { - public static final float ROTATION_SPEED = 1.3f; float targetRotation = 0; + float totalTicks = 0f; @Override public void onTaskStart() @@ -33,13 +33,15 @@ public class CommandRotate extends Command { this.targetRotation += 360; } + + this.totalTicks = Math.abs(this.targetRotation - this.tileEntity.rotationYaw) / this.tileEntity.ROTATION_SPEED; } @Override protected boolean doTask() { super.doTask(); - float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation); + /*float rotationalDifference = Math.abs(this.tileEntity.rotationYaw - this.targetRotation); if (rotationalDifference < ROTATION_SPEED) { @@ -56,9 +58,14 @@ public class CommandRotate extends Command this.tileEntity.rotationYaw += ROTATION_SPEED; } this.ticks = 0; - } + }*/ + + //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.targetRotation) > 0.001f) + this.tileEntity.rotationYaw = this.targetRotation; - if (this.ticks < 10) + if (this.ticks < this.totalTicks) { return true; }