Fix up quarry, also trying to fix other entities to be less

derpy
This commit is contained in:
Christian 2012-08-25 13:04:35 -04:00
parent 38fe0d4081
commit d86472a495
10 changed files with 304 additions and 368 deletions

View file

@ -40,6 +40,7 @@ import buildcraft.core.BuildCraftConfiguration;
import buildcraft.core.DefaultActionProvider;
import buildcraft.core.DefaultProps;
import buildcraft.core.DefaultTriggerProvider;
import buildcraft.core.EntityBlock;
import buildcraft.core.EntityEnergyLaser;
import buildcraft.core.EntityLaser;
import buildcraft.core.EntityRobot;
@ -59,6 +60,7 @@ import buildcraft.core.utils.Localization;
import buildcraft.transport.TriggerRedstoneInput;
import net.minecraft.src.Block;
import net.minecraft.src.EntityList;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.Configuration;
@ -238,6 +240,12 @@ public class BuildCraftCore {
EntityRegistry.registerModEntity(EntityRobot.class, "bcRobot", EntityIds.ROBOT, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityLaser.class, "bcLaser", EntityIds.LASER, instance, 50, 1, true);
EntityRegistry.registerModEntity(EntityEnergyLaser.class, "bcEnergyLaser", EntityIds.ENERGY_LASER, instance, 50, 1, true);
EntityList.classToStringMapping.remove(EntityRobot.class);
EntityList.classToStringMapping.remove(EntityLaser.class);
EntityList.classToStringMapping.remove(EntityEnergyLaser.class);
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcRobot");
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser");
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser");
ProxyCore.proxy.initializeRendering();
ProxyCore.proxy.initializeEntityRendering();

View file

@ -95,7 +95,7 @@ public class BuildCraftFactory {
public void load(FMLInitializationEvent evt) {
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler());
EntityRegistry.registerModEntity(EntityMechanicalArm.class, "bcMechanicalArm", EntityIds.MECHANICAL_ARM, instance, 50, 1, true);
// EntityRegistry.registerModEntity(EntityMechanicalArm.class, "bcMechanicalArm", EntityIds.MECHANICAL_ARM, instance, 50, 1, true);
ProxyCore.proxy.registerTileEntity(TileQuarry.class, "Machine");
ProxyCore.proxy.registerTileEntity(TileMiningWell.class, "MiningWell");

View file

@ -33,37 +33,26 @@ public class EntityBlock extends Entity {
public EntityBlock(World world, double xPos, double yPos, double zPos) {
super(world);
setPosition(xPos, yPos, zPos);
setPositionAndRotation(xPos, yPos, zPos, 0, 0);
}
public EntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize) {
this(world);
motionX = 0.0D;
motionY = 0.0D;
motionZ = 0.0D;
prevPosX = i;
prevPosY = j;
prevPosZ = k;
this.iSize = iSize;
this.jSize = jSize;
this.kSize = kSize;
setPosition(i, j, k);
setPositionAndRotation(i, j, k, 0, 0);
setVelocity(0, 0, 0);
}
public EntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, int textureID) {
this(world, i, j, k, iSize, jSize, kSize);
texture = textureID;
}
@Override
public void setPosition(double d, double d1, double d2) {
posX = d;
posY = d1;
posZ = d2;
super.setPosition(d, d1, d2);
boundingBox.minX = posX;
boundingBox.minY = posY;
boundingBox.minZ = posZ;

View file

@ -19,20 +19,20 @@ public class EntityEnergyLaser extends EntityLaser {
private final float power [] = new float [100];
private int powerIndex = 0;
public float powerAverage = 0;
public EntityEnergyLaser(World world) {
super(world);
}
public EntityEnergyLaser(World world, Position head, Position tail) {
super(world, head, tail);
for (int j = 0; j < power.length; ++j)
power [j] = 0;
}
public void pushPower (float p) {
powerAverage -= power [powerIndex];
powerAverage += p;
power[powerIndex] = p;
@ -48,7 +48,7 @@ public class EntityEnergyLaser extends EntityLaser {
@Override
public String getTexture () {
if (getPowerAverage () <= 1.0)
return DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png";
else if (getPowerAverage() <= 2.0)

View file

@ -21,7 +21,7 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.World;
public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
protected Position head, tail;
public double renderSize = 0;
@ -40,8 +40,8 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
this.head = head;
this.tail = tail;
setPosition(head.x, head.y, head.z);
setPositionAndRotation(head.x, head.y, head.z, 0, 0);
init();
}
@ -52,16 +52,16 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
noClip = true;
isImmuneToFire = true;
setPosition(head.x, head.y, head.z);
setPositionAndRotation(head.x, head.y, head.z, 0, 0);
setSize(10, 10);
dataWatcher.addObject(8 , Integer.valueOf(encodeDouble(head.x)));
dataWatcher.addObject(9 , Integer.valueOf(encodeDouble(head.y)));
dataWatcher.addObject(10, Integer.valueOf(encodeDouble(head.z)));
dataWatcher.addObject(11, Integer.valueOf(encodeDouble(tail.x)));
dataWatcher.addObject(12, Integer.valueOf(encodeDouble(tail.y)));
dataWatcher.addObject(13, Integer.valueOf(encodeDouble(tail.z)));
dataWatcher.addObject(14, Byte.valueOf((byte) 0));
}
@ -84,14 +84,14 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
@Override
public void onUpdate() {
if (head == null || tail == null)
return;
if (ProxyCore.proxy.isRemote(worldObj)) {
updateData();
}
boundingBox.minX = Math.min(head.x, tail.x);
boundingBox.minY = Math.min(head.y, tail.y);
boundingBox.minZ = Math.min(head.z, tail.z);
@ -99,7 +99,7 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
boundingBox.maxX = Math.max(head.x, tail.x);
boundingBox.maxY = Math.max(head.y, tail.y);
boundingBox.maxZ = Math.max(head.z, tail.z);
boundingBox.minX--;
boundingBox.minY--;
boundingBox.minZ--;
@ -107,7 +107,7 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
boundingBox.maxX++;
boundingBox.maxY++;
boundingBox.maxZ++;
double dx = head.x - tail.x;
double dy = head.y - tail.y;
double dz = head.z - tail.z;
@ -117,7 +117,7 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
dx = Math.sqrt(renderSize * renderSize - dy * dy);
angleY = -Math.atan2(dy, dx) * 180 / Math.PI;
}
protected void updateData() {
head.x = decodeDouble(dataWatcher.getWatchableObjectInt(8));
@ -127,40 +127,40 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
tail.y = decodeDouble(dataWatcher.getWatchableObjectInt(12));
tail.z = decodeDouble(dataWatcher.getWatchableObjectInt(13));
}
@Override
public void setPosition(double x, double y, double z) {
posX = x;
posY = y;
posZ = z;
}
//
// @Override
// public void setPosition(double x, double y, double z) {
//
// posX = x;
// posY = y;
// posZ = z;
// }
//
public void setPositions(Position head, Position tail) {
this.head = head;
this.tail = tail;
setPosition(head.x, head.y, head.z);
setPositionAndRotation(head.x, head.y, head.z, 0, 0);
dataWatcher.updateObject(8 , Integer.valueOf(encodeDouble(head.x)));
dataWatcher.updateObject(9 , Integer.valueOf(encodeDouble(head.y)));
dataWatcher.updateObject(10, Integer.valueOf(encodeDouble(head.z)));
dataWatcher.updateObject(11, Integer.valueOf(encodeDouble(tail.x)));
dataWatcher.updateObject(12, Integer.valueOf(encodeDouble(tail.y)));
dataWatcher.updateObject(13, Integer.valueOf(encodeDouble(tail.z)));
onUpdate();
}
public void show() {
dataWatcher.updateObject(14, Byte.valueOf((byte) 1));
}
public void hide() {
dataWatcher.updateObject(14, Byte.valueOf((byte) 0));
}
public boolean isVisible() {
return dataWatcher.getWatchableObjectByte(14) == 0 ? false : true;
}
@ -172,11 +172,11 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
public String getTexture() {
return texture;
}
private int encodeDouble(double d) {
return (int) (d * 8000);
}
private double decodeDouble(int i) {
return (i / 8000D);
}
@ -186,12 +186,12 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
@Override
protected void readEntityFromNBT(NBTTagCompound nbt) {
double headX = nbt.getDouble("headX");
double headY = nbt.getDouble("headZ");
double headZ = nbt.getDouble("headY");
head = new Position(headX, headY, headZ);
double tailX = nbt.getDouble("tailX");
double tailY = nbt.getDouble("tailZ");
double tailZ = nbt.getDouble("tailY");
@ -200,11 +200,11 @@ public class EntityLaser extends Entity implements IEntityAdditionalSpawnData {
@Override
protected void writeEntityToNBT(NBTTagCompound nbt) {
nbt.setDouble("headX", head.x);
nbt.setDouble("headY", head.y);
nbt.setDouble("headZ", head.z);
nbt.setDouble("tailX", tail.x);
nbt.setDouble("tailY", tail.y);
nbt.setDouble("tailZ", tail.z);

View file

@ -79,7 +79,7 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
motionY = 0;
motionZ = 0;
setPosition(destX, destY, destZ);
setLocationAndAngles(destX, destY, destZ, 0, 0);
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
worldObj.spawnEntityInWorld(laser);

View file

@ -8,10 +8,10 @@ import net.minecraft.src.Tessellator;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
public class RenderingMarkers implements ISimpleBlockRenderingHandler {
public RenderingMarkers() {
initializeMarkerMatrix();
}
}
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
@ -20,16 +20,13 @@ public class RenderingMarkers implements ISimpleBlockRenderingHandler {
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
Block block, int modelId, RenderBlocks renderer) {
if (block.getRenderType() == BuildCraftCore.markerModel)
return true;
Tessellator tessellator = Tessellator.instance;
float f = block.getBlockBrightness(world, x, y, z);
if (Block.lightValue[block.blockID] > 0)
f = 1.0F;
tessellator.setColorOpaque_F(f, f, f);
renderMarkerWithMeta(world, block, x, y, z, world.getBlockMetadata(x, y, z));
renderMarkerWithMeta(world, block, x, y, z, world.getBlockMetadata(x, y, z));
return true;
}

View file

@ -1,88 +1,135 @@
/**
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import com.google.common.collect.SetMultimap;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Position;
import buildcraft.core.EntityBlock;
import net.minecraft.src.Entity;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
public class EntityMechanicalArm extends Entity {
double sizeX, sizeZ;
public class EntityMechanicalArm extends Entity implements IEntityAdditionalSpawnData {
EntityBlock xArm, yArm, zArm, head;
double angle;
public double targetX, targetY, targetZ;
public double headPosX, headPosY, headPosZ;
public double speed = 0.03;
double baseY;
public IArmListener listener;
boolean inProgressionXZ = false;
boolean inProgressionY = false;
protected TileEntity parent;
protected TileQuarry parent;
private double armSizeX;
private double armSizeZ;
private double xRoot;
private double yRoot;
private double zRoot;
private double angle;
public EntityMechanicalArm(World world) {
super(world);
Thread.dumpStack();
makeParts(world);
// Head X, Y, Z
dataWatcher.addObject(2, 1);
dataWatcher.addObject(3, 1);
dataWatcher.addObject(4, 1);
// Target X, Y, Z
dataWatcher.addObject(5, 1);
dataWatcher.addObject(6, 1);
dataWatcher.addObject(7, 1);
// Speed
dataWatcher.addObject(8, (int)(0.03 * 8000D));
}
public EntityMechanicalArm(World world, double i, double j, double k, double width, double height, TileEntity parent) {
super(world);
public EntityMechanicalArm(World world, double i, double j, double k, double width, double height, TileQuarry parent) {
this(world);
setPositionAndRotation(parent.xCoord, parent.yCoord, parent.zCoord, 0, 0);
this.xRoot = i;
this.yRoot = j;
this.zRoot = k;
setVelocity(0, 0, 0);
setArmSize(width, height);
setHead(i, j - 2, k);
setTarget(i, j - 2, k);
setPosition(i, j, k);
motionX = 0.0D;
motionY = 0.0D;
motionZ = 0.0D;
prevPosX = i;
prevPosY = j;
prevPosZ = k;
sizeX = height;
sizeZ = width;
noClip = true;
baseY = j;
headPosX = i;
headPosY = j - 2;
headPosZ = k;
setTarget(headPosX, headPosY, headPosZ);
inProgressionXZ = false;
inProgressionY = false;
xArm = new EntityBlock(world, i, j, k, width, 0.5, 0.5);
this.parent = parent;
parent.setArm(this);
updatePosition();
}
public void setArmSpeed(double speed)
{
dataWatcher.updateObject(8, (int)(speed * 8000D));
}
public double getArmSpeed()
{
return dataWatcher.getWatchableObjectInt(8) / 8000D;
}
void setHead(double x, double y, double z)
{
dataWatcher.updateObject(2, ((int)(x * 32D)));
dataWatcher.updateObject(3, ((int)(y * 32D)));
dataWatcher.updateObject(4, ((int)(z * 32D)));
}
void setTarget(double x, double y, double z) {
dataWatcher.updateObject(5, ((int)(x * 32D)));
dataWatcher.updateObject(6, ((int)(y * 32D)));
dataWatcher.updateObject(7, ((int)(z * 32D)));
}
private void setArmSize(double x, double z)
{
armSizeX = x;
xArm.iSize = x;
armSizeZ = z;
zArm.kSize = z;
updatePosition();
}
private void makeParts(World world) {
xArm = new EntityBlock(world, 0, 0, 0, 1, 0.5, 0.5);
xArm.texture = BuildCraftFactory.drillTexture;
world.spawnEntityInWorld(xArm);
yArm = new EntityBlock(world, i, j, k, 0.5, 1, 0.5);
yArm = new EntityBlock(world, 0, 0, 0, 0.5, 1, 0.5);
yArm.texture = BuildCraftFactory.drillTexture;
world.spawnEntityInWorld(yArm);
zArm = new EntityBlock(world, i, j, k, 0.5, 0.5, height);
zArm = new EntityBlock(world, 0, 0, 0, 0.5, 0.5, 1);
zArm.texture = BuildCraftFactory.drillTexture;
world.spawnEntityInWorld(zArm);
head = new EntityBlock(world, i, j, k, 0.2, 1, 0.2);
head = new EntityBlock(world, 0, 0, 0, 0.2, 1, 0.2);
head.texture = 2 * 16 + 10;
world.spawnEntityInWorld(head);
head.shadowSize = 1.0F;
updatePosition();
this.parent = parent;
world.spawnEntityInWorld(xArm);
world.spawnEntityInWorld(yArm);
world.spawnEntityInWorld(zArm);
world.spawnEntityInWorld(head);
}
@Override
@ -90,199 +137,172 @@ public class EntityMechanicalArm extends Entity {
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
sizeX = nbttagcompound.getDouble("sizeX");
sizeZ = nbttagcompound.getDouble("sizeZ");
xRoot = nbttagcompound.getDouble("xRoot");
yRoot = nbttagcompound.getDouble("yRoot");
zRoot = nbttagcompound.getDouble("zRoot");
armSizeX = nbttagcompound.getDouble("armSizeX");
armSizeZ = nbttagcompound.getDouble("armSizeZ");
setArmSize(armSizeX, armSizeZ);
updatePosition();
}
targetX = nbttagcompound.getDouble("targetX");
targetY = nbttagcompound.getDouble("targetY");
targetZ = nbttagcompound.getDouble("targetZ");
angle = nbttagcompound.getDouble("angle");
private void findAndJoinQuarry() {
TileEntity te = worldObj.getBlockTileEntity((int)posX, (int)posY, (int)posZ);
if (te != null && te instanceof TileQuarry)
{
parent = (TileQuarry) te;
parent.setArm(this);
headPosX = nbttagcompound.getDouble("headPosX");
headPosY = nbttagcompound.getDouble("headPosY");
headPosZ = nbttagcompound.getDouble("headPosZ");
baseY = nbttagcompound.getDouble("baseY");
speed = nbttagcompound.getDouble("speed");
inProgressionXZ = nbttagcompound.getBoolean("progressionXY");
inProgressionY = nbttagcompound.getBoolean("progressionY");
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
xArmStore = nbttagcompound.getCompoundTag("xArm");
yArmStore = nbttagcompound.getCompoundTag("yArm");
zArmStore = nbttagcompound.getCompoundTag("zArm");
headStore = nbttagcompound.getCompoundTag("head");
xArm = new EntityBlock(worldObj);
yArm = new EntityBlock(worldObj);
zArm = new EntityBlock(worldObj);
head = new EntityBlock(worldObj);
xArm.texture = BuildCraftFactory.drillTexture;
yArm.texture = BuildCraftFactory.drillTexture;
zArm.texture = BuildCraftFactory.drillTexture;
head.texture = 2 * 16 + 10;
xArm.readFromNBT(xArmStore);
yArm.readFromNBT(yArmStore);
zArm.readFromNBT(zArmStore);
head.readFromNBT(headStore);
}
else
{
setDead();
}
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setDouble("sizeX", sizeX);
nbttagcompound.setDouble("sizeZ", sizeZ);
nbttagcompound.setDouble("targetX", targetX);
nbttagcompound.setDouble("targetY", targetY);
nbttagcompound.setDouble("targetZ", targetZ);
nbttagcompound.setDouble("angle", angle);
nbttagcompound.setDouble("headPosX", headPosX);
nbttagcompound.setDouble("headPosY", headPosY);
nbttagcompound.setDouble("headPosZ", headPosZ);
nbttagcompound.setDouble("baseY", baseY);
nbttagcompound.setDouble("speed", speed);
nbttagcompound.setBoolean("progressionXY", inProgressionXZ);
nbttagcompound.setBoolean("progressionY", inProgressionY);
NBTTagCompound xArmStore, yArmStore, zArmStore, headStore;
xArmStore = new NBTTagCompound();
yArmStore = new NBTTagCompound();
zArmStore = new NBTTagCompound();
headStore = new NBTTagCompound();
nbttagcompound.setTag("xArm", xArmStore);
nbttagcompound.setTag("yArm", yArmStore);
nbttagcompound.setTag("zArm", zArmStore);
nbttagcompound.setTag("head", headStore);
xArm.writeToNBT(xArmStore);
yArm.writeToNBT(yArmStore);
zArm.writeToNBT(zArmStore);
head.writeToNBT(headStore);
}
public void setTarget(double x, double y, double z) {
targetX = x;
targetY = y;
targetZ = z;
double dX = targetX - headPosX;
double dZ = targetZ - headPosZ;
angle = Math.atan2(dZ, dX);
inProgressionXZ = true;
inProgressionY = true;
}
public double[] getTarget() {
return new double[] { targetX, targetY, targetZ };
nbttagcompound.setDouble("xRoot", xRoot);
nbttagcompound.setDouble("yRoot", yRoot);
nbttagcompound.setDouble("zRoot", zRoot);
nbttagcompound.setDouble("armSizeX", armSizeX);
nbttagcompound.setDouble("armSizeZ", armSizeZ);
}
@Override
public void onUpdate() {
if (parent != null && worldObj.getBlockTileEntity(parent.xCoord, parent.yCoord, parent.zCoord) != parent) {
if (worldObj.isRemote)
{
super.onUpdate();
updatePosition();
return;
}
super.onUpdate();
if (parent == null)
{
findAndJoinQuarry();
}
if (parent == null)
{
setDead();
return;
}
if (speed > 0) {
doMove(speed);
double[] target = getTarget();
double[] head = getHead();
double dX = target[0] - head[0];
double dY = target[1] - head[1];
double dZ = target[2] - head[2];
if (dX != 0 || dY != 0 || dZ != 0)
{
angle = Math.atan2(target[2]-head[2], target[0]-head[0]);
inProgressionXZ = true;
inProgressionY = true;
}
if (getArmSpeed() > 0) {
doMove(getArmSpeed());
}
}
public void doMove(double instantSpeed) {
super.onUpdate();
double[] target = getTarget();
double[] head = getHead();
if (inProgressionXZ) {
if (Math.abs(targetX - headPosX) < instantSpeed * 2 && Math.abs(targetZ - headPosZ) < instantSpeed * 2) {
headPosX = targetX;
headPosZ = targetZ;
if (Math.abs(target[0] - head[0]) < instantSpeed * 2 && Math.abs(target[2] - head[2]) < instantSpeed * 2) {
head[0] = target[0];
head[2] = target[2];
inProgressionXZ = false;
if (listener != null && !inProgressionY) {
listener.positionReached(this);
head[1] = target[1];
}
} else {
headPosX += Math.cos(angle) * instantSpeed;
headPosZ += Math.sin(angle) * instantSpeed;
head[0] += Math.cos(angle) * instantSpeed;
head[2] += Math.sin(angle) * instantSpeed;
}
setHead(head[0], head[1], head[2]);
}
if (inProgressionY) {
if (Math.abs(targetY - headPosY) < instantSpeed * 2) {
headPosY = targetY;
if (Math.abs(target[1] - head[1]) < instantSpeed * 2) {
head[1] = target[1];
inProgressionY = false;
if (listener != null && !inProgressionXZ) {
listener.positionReached(this);
head[0] = target[0];
head[2] = target[2];
}
} else {
if (targetY > headPosY) {
headPosY += instantSpeed / 2;
if (target[1] > head[1]) {
head[1] += instantSpeed / 2;
} else {
headPosY -= instantSpeed / 2;
head[1] -= instantSpeed / 2;
}
}
setHead(head[0],head[1],head[2]);
}
updatePosition();
}
public void updatePosition() {
xArm.setPosition(xArm.posX, xArm.posY, headPosZ + 0.25);
yArm.jSize = baseY - headPosY - 1;
yArm.setPosition(headPosX + 0.25, headPosY + 1, headPosZ + 0.25);
zArm.setPosition(headPosX + 0.25, zArm.posY, zArm.posZ);
head.setPosition(headPosX + 0.4, headPosY, headPosZ + 0.4);
double[] head = getHead();
this.xArm.setPosition(xRoot, yRoot, head[2] + 0.25);
this.yArm.jSize = yRoot - head[1]- 1;
this.yArm.setPosition(head[0] + 0.25, head[1] + 1, head[2] + 0.25);
this.zArm.setPosition(head[0] + 0.25, yRoot, zRoot);
this.head.setPosition(head[0] + 0.4, head[1], head[2] + 0.4);
}
public void joinToWorld(World w) {
super.worldObj = w;
xArm.worldObj = w;
yArm.worldObj = w;
zArm.worldObj = w;
head.worldObj = w;
w.spawnEntityInWorld(this);
w.spawnEntityInWorld(xArm);
w.spawnEntityInWorld(yArm);
w.spawnEntityInWorld(zArm);
w.spawnEntityInWorld(head);
if (!w.isRemote)
{
w.spawnEntityInWorld(this);
}
}
@Override
public void setDead() {
xArm.setDead();
yArm.setDead();
zArm.setDead();
head.setDead();
if (worldObj!=null && worldObj.isRemote)
{
xArm.setDead();
yArm.setDead();
zArm.setDead();
head.setDead();
}
super.setDead();
}
public double[] getHeadPosition() {
return new double[] { headPosX, headPosY, headPosZ };
@Override
public void writeSpawnData(ByteArrayDataOutput data) {
data.writeDouble(armSizeX);
data.writeDouble(armSizeZ);
}
public void setHeadPosition(double x, double y, double z) {
headPosX = x;
headPosY = y;
headPosZ = z;
@Override
public void readSpawnData(ByteArrayDataInput data) {
armSizeX = data.readDouble();
armSizeZ = data.readDouble();
setArmSize(armSizeX, armSizeZ);
updatePosition();
}
public double[] getTarget()
{
return new double[] { this.dataWatcher.getWatchableObjectInt(5) / 32D, this.dataWatcher.getWatchableObjectInt(6) / 32D, this.dataWatcher.getWatchableObjectInt(7) / 32D };
}
public double[] getHead()
{
return new double[] { this.dataWatcher.getWatchableObjectInt(2) / 32D, this.dataWatcher.getWatchableObjectInt(3) / 32D, this.dataWatcher.getWatchableObjectInt(4) / 32D };
}
}

View file

@ -1,53 +0,0 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import net.minecraft.src.Entity;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.World;
public class EntityModel extends Entity {
public EntityModel(World world, double i, double j, double k) {
super(world);
// TODO Auto-generated constructor stub
motionX = 0.0D;
motionY = 0.0D;
motionZ = 0.0D;
prevPosX = i;
prevPosY = j;
prevPosZ = k;
setPosition(i, j, k);
// this.blockID = blockID;
// this.iSize = iSize;
// this.jSize = jSize;
// this.kSize = kSize;
}
@Override
protected void entityInit() {
// TODO Auto-generated method stub
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
// TODO Auto-generated method stub
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
// TODO Auto-generated method stub
}
}

View file

@ -64,16 +64,12 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
public @TileNetworkData
boolean builderDone = false;
boolean loadArm = false;
BptBuilderBase bluePrintBuilder;
public IPowerProvider powerProvider;
public static int MAX_ENERGY = 7000;
NBTTagCompound armStore = null;
public TileQuarry() {
powerProvider = PowerFramework.currentFramework.createPowerProvider();
@ -81,11 +77,6 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
}
public void createUtilsIfNeeded() {
if (!box.isInitialized() && ProxyCore.proxy.isRemote(worldObj)) {
return;
}
if (bluePrintBuilder == null) {
if (!box.isInitialized()) {
@ -99,26 +90,12 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
box.deleteLasers();
if (armStore != null){
arm = new EntityMechanicalArm(worldObj);
arm.readFromNBT(armStore);
arm.listener = this;
loadArm = true;
armStore = null;
}
if (arm == null) {
createArm();
}
if (loadArm) {
arm.joinToWorld(worldObj);
loadArm = false;
if (findTarget(false)) {
isDigging = true;
}
if (findTarget(false)) {
isDigging = true;
}
} else {
@ -132,27 +109,28 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
private void createArm() {
arm = new EntityMechanicalArm(worldObj,
worldObj.spawnEntityInWorld(new EntityMechanicalArm(worldObj,
box.xMin + Utils.pipeMaxPos,
yCoord + bluePrintBuilder.bluePrint.sizeY - 1 + Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos,
bluePrintBuilder.bluePrint.sizeX - 2 + Utils.pipeMinPos * 2,
bluePrintBuilder.bluePrint.sizeZ - 2 + Utils.pipeMinPos * 2, this);
bluePrintBuilder.bluePrint.sizeZ - 2 + Utils.pipeMinPos * 2, this));
}
// Callback from the arm once it's created
public void setArm(EntityMechanicalArm arm)
{
this.arm = arm;
arm.listener = this;
loadArm = true;
isDigging = true;
}
@Override
public void updateEntity() {
if (worldObj!=null && worldObj.isRemote)
{
return;
}
super.updateEntity();
if (inProcess && arm != null) {
arm.speed = 0;
arm.setArmSpeed(0);
float energyToUse = 2 + powerProvider.getEnergyStored() / 1000;
float energy = powerProvider.useEnergy(energyToUse, energyToUse, true);
@ -163,18 +141,17 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
}
if (arm != null) {
double[] head = arm.getHead();
headPosX = head[0];
headPosY = head[1];
headPosZ = head[2];
headPosX = arm.headPosX;
headPosY = arm.headPosY;
headPosZ = arm.headPosZ;
speed = arm.speed;
speed = arm.getArmSpeed();
}
if (ProxyCore.proxy.isSimulating(worldObj)) {
sendNetworkUpdate();
}
if (inProcess || !isDigging) {
return;
}
@ -201,7 +178,6 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
}
if (builder == null) {
dig();
}
@ -241,7 +217,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
//I believe the issue is box going null becuase of bad chunkloader positioning
if (arm != null && box != null)
arm.setTarget(box.xMin + arm.sizeX / 2, yCoord + 2, box.zMin + arm.sizeX / 2);
arm.setTarget((double)box.xMin + (box.xMax - box.xMin) / 2D, yCoord + 2D, (double)box.zMin + ( box.zMax - box.zMin) / 2D);
isDigging = false;
}
@ -251,7 +227,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
public boolean findTarget(boolean doSet) {
if (ProxyCore.proxy.isRemote(worldObj))
if (worldObj.isRemote)
return false;
boolean[][] blockedColumns = new boolean[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
@ -299,10 +275,6 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
} else if (canDig(blockId)) {
if (doSet && arm != null) {
arm.setTarget(bx, by + 1, bz);
targetX = (int) arm.targetX;
targetY = (int) arm.targetY;
targetZ = (int) arm.targetZ;
}
return true;
@ -347,11 +319,9 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
targetX = nbttagcompound.getInteger("targetX");
targetY = nbttagcompound.getInteger("targetY");
targetZ = nbttagcompound.getInteger("targetZ");
if (nbttagcompound.getBoolean("hasArm")) {
armStore = nbttagcompound.getCompoundTag("arm");
}
headPosX = nbttagcompound.getDouble("headPosX");
headPosY = nbttagcompound.getDouble("headPosY");
headPosZ = nbttagcompound.getDouble("headPosZ");
}
@Override
@ -363,13 +333,9 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
nbttagcompound.setInteger("targetX", targetX);
nbttagcompound.setInteger("targetY", targetY);
nbttagcompound.setInteger("targetZ", targetZ);
nbttagcompound.setBoolean("hasArm", arm != null);
if (arm != null) {
NBTTagCompound armStore = new NBTTagCompound();
nbttagcompound.setTag("arm", armStore);
arm.writeToNBT(armStore);
}
nbttagcompound.setDouble("headPosX", headPosX);
nbttagcompound.setDouble("headPosY", headPosY);
nbttagcompound.setDouble("headPosZ", headPosZ);
NBTTagCompound boxTag = new NBTTagCompound();
box.writeToNBT(boxTag);
@ -380,10 +346,15 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
public void positionReached(EntityMechanicalArm arm) {
inProcess = false;
if (ProxyCore.proxy.isRemote(worldObj)) {
if (worldObj.isRemote) {
return;
}
double[] targ = arm.getTarget();
targetX = (int)targ[0];
targetY = (int)targ[1];
targetZ = (int)targ[2];
int i = targetX;
int j = targetY - 1;
int k = targetZ;
@ -409,7 +380,8 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
}
// Collect any lost items laying around
AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(arm.headPosX - 1.5, arm.headPosY, arm.headPosZ - 1.5, arm.headPosX + 2.5, arm.headPosY + 2.5, arm.headPosZ + 2.5);
double[] armHead = arm.getHead();
AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(armHead[0] - 1.5, armHead[1], armHead[2] - 1.5, armHead[0] + 2.5, armHead[1] + 2.5, armHead[2] + 2.5);
List result = worldObj.getEntitiesWithinAABB(EntityItem.class, axis);
for (int ii = 0; ii < result.size(); ii++) {
if (result.get(ii) instanceof EntityItem) {
@ -473,6 +445,11 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
destroy();
}
@Override
public void onChunkUnload() {
destroy();
}
@Override
public void destroy() {
@ -600,11 +577,11 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
super.postPacketHandling(packet);
createUtilsIfNeeded();
//
if (arm != null) {
arm.setHeadPosition(headPosX, headPosY, headPosZ);
arm.setTarget(targetX, targetY, targetZ);
arm.speed = speed;
arm.setHead(headPosX, headPosY, headPosZ);
// arm.setTarget(targetX, targetY, targetZ);
// arm.setArmSpeed(speed);
}
}
@ -612,9 +589,7 @@ public class TileQuarry extends TileMachine implements IArmListener, IMachine, I
public void initialize() {
super.initialize();
if (!ProxyCore.proxy.isRemote(worldObj)) {
createUtilsIfNeeded();
}
createUtilsIfNeeded();
sendNetworkUpdate();
}