added lumberjack animation, for #1869

This commit is contained in:
SpaceToad 2014-06-09 00:56:58 +02:00
parent 253c398f12
commit 0d978677de
4 changed files with 94 additions and 3 deletions

View file

@ -8,6 +8,8 @@
*/
package buildcraft.core.render;
import java.util.Date;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
@ -63,8 +65,41 @@ public class RenderRobot extends Render implements IItemRenderer {
if (robot.itemInUse != null) {
GL11.glPushMatrix();
GL11.glRotatef(robot.worldObj.getTotalWorldTime() % 45 + 90, 1, 0, 0);
doRenderItemAtHand(robot, robot.itemInUse);
GL11.glRotatef((float) (-robot.itemAngle1 / (2 * Math.PI) * 360) + 180, 0, 1, 0);
GL11.glRotatef((float) (robot.itemAngle2 / (2 * Math.PI) * 360), 0, 0, 1);
if (robot.itemActive) {
long newDate = new Date().getTime();
robot.itemActiveStage = (robot.itemActiveStage + (newDate - robot.lastUpdateTime) / 10) % 45;
GL11.glRotatef(robot.itemActiveStage, 0, 0, 1);
robot.lastUpdateTime = newDate;
}
GL11.glTranslatef(-0.4F, 0, 0);
GL11.glRotatef(-45F + 180F, 0, 1, 0);
GL11.glScalef(0.8F, 0.8F, 0.8F);
ItemStack itemstack1 = robot.itemInUse;
if (itemstack1.getItem().requiresMultipleRenderPasses()) {
for (int k = 0; k < itemstack1.getItem().getRenderPasses(itemstack1.getItemDamage()); ++k) {
int i = itemstack1.getItem().getColorFromItemStack(itemstack1, k);
float f12 = (i >> 16 & 255) / 255.0F;
float f4 = (i >> 8 & 255) / 255.0F;
float f5 = (i & 255) / 255.0F;
GL11.glColor4f(f12, f4, f5, 1.0F);
this.renderManager.itemRenderer.renderItem(robot, itemstack1, k);
}
} else {
int k = itemstack1.getItem().getColorFromItemStack(itemstack1, 0);
float f11 = (k >> 16 & 255) / 255.0F;
float f12 = (k >> 8 & 255) / 255.0F;
float f4 = (k & 255) / 255.0F;
GL11.glColor4f(f11, f12, f4, 1.0F);
this.renderManager.itemRenderer.renderItem(robot, itemstack1, 0);
}
GL11.glPopMatrix();
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.core.robots;
import java.util.Date;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.EntityLiving;
@ -60,6 +62,11 @@ public class EntityRobot extends EntityLiving implements
public RobotAIBase currentAI;
public ItemStack itemInUse;
public float itemAngle1 = 0;
public float itemAngle2 = 0;
public boolean itemActive = false;
public float itemActiveStage = 0;
public long lastUpdateTime = 0;
protected RobotAIBase nextAI;
@ -103,6 +110,8 @@ public class EntityRobot extends EntityLiving implements
protected void entityInit() {
super.entityInit();
setNullBoundingBox();
preventEntitySpawning = false;
noClip = true;
isImmuneToFire = true;
@ -112,6 +121,8 @@ public class EntityRobot extends EntityLiving implements
dataWatcher.addObject(14, Float.valueOf(0));
dataWatcher.addObject(15, Byte.valueOf((byte) 0));
dataWatcher.addObject(16, "");
dataWatcher.addObject(17, Float.valueOf(0));
dataWatcher.addObject(18, Float.valueOf(0));
}
protected void updateDataClient() {
@ -126,6 +137,9 @@ public class EntityRobot extends EntityLiving implements
if (boardNBT != null) {
texture = ((RedstoneBoardRobotNBT) boardNBT).getRobotTexture();
}
itemAngle1 = dataWatcher.getWatchableObjectFloat(17);
itemAngle2 = dataWatcher.getWatchableObjectFloat(18);
}
protected void updateDataServer() {
@ -133,6 +147,8 @@ public class EntityRobot extends EntityLiving implements
dataWatcher.updateObject(13, Float.valueOf((float) laser.tail.y));
dataWatcher.updateObject(14, Float.valueOf((float) laser.tail.z));
dataWatcher.updateObject(15, Byte.valueOf((byte) (laser.isVisible ? 1 : 0)));
dataWatcher.updateObject(17, Float.valueOf(itemAngle1));
dataWatcher.updateObject(18, Float.valueOf(itemAngle2));
}
protected void init() {
@ -476,4 +492,21 @@ public class EntityRobot extends EntityLiving implements
public void setHealth(float par1) {
// deactivate healh management
}
public void setItemAngle(float a1, float a2) {
itemAngle1 = a1;
itemAngle2 = a2;
updateDataServer();
}
public void setItemActive(boolean isActive) {
RPCHandler.rpcBroadcastPlayers(worldObj, this, "rpcSetItemActive", isActive);
}
@RPC(RPCSide.CLIENT)
private void rpcSetItemActive(boolean isActive) {
itemActive = isActive;
itemActiveStage = 0;
lastUpdateTime = new Date().getTime();
}
}

View file

@ -80,6 +80,28 @@ public class BoardRobotLumberjack implements IRedstoneBoardRobot<EntityRobot> {
if (robot.currentAI.isDone()) {
stage = Stages.CUT_WOOD;
blockDamage = 0;
float a1 = (float) Math.atan2(woodToChop.z - Math.floor(robot.posZ),
woodToChop.x - Math.floor(robot.posX));
float a2 = 0;
if (Math.floor(robot.posY) < woodToChop.y) {
a2 = (float) -Math.PI / 4;
if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) {
a2 -= (float) Math.PI / 4;
}
} else if (Math.floor(robot.posY) > woodToChop.y) {
a2 = (float) Math.PI / 2;
if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) {
a2 += (float) Math.PI / 4;
}
}
robot.setItemAngle(a1, a2);
robot.setItemActive(true);
}
} else if (stage == Stages.CUT_WOOD) {
Block block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z);
@ -97,6 +119,7 @@ public class BoardRobotLumberjack implements IRedstoneBoardRobot<EntityRobot> {
stage = Stages.LOOK_FOR_WOOD;
woodToChop = null;
woodScanner = null;
robot.setItemActive(false);
} else {
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
woodToChop.y, woodToChop.z, (int) (blockDamage * 10.0F) - 1);

View file

@ -786,7 +786,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z,
player);
if (rayTraceResult.hitPart == Part.RobotStation) {
if (rayTraceResult != null && rayTraceResult.hitPart == Part.RobotStation) {
EntityRobot robot = ((ItemRobot) currentItem.getItem())
.createRobot(currentItem, world);