More entity refactoring

This commit is contained in:
Kyprus 2012-06-03 15:20:46 -04:00
parent f4409810d6
commit 65895a1cfc
7 changed files with 178 additions and 109 deletions

View file

@ -10,11 +10,11 @@ import org.lwjgl.opengl.GL11;
public class RenderLaser extends Render {
protected ModelBase model = new ModelBase() {
};
private ModelRenderer box;
protected ModelBase model = new ModelBase() { };
private final ModelRenderer box;
public RenderLaser() {
box = new ModelRenderer(model, 0, 0);
box.addBox(0, -0.5F, -0.5F, 16, 1, 1);
box.rotationPointX = 0;
@ -23,15 +23,13 @@ public class RenderLaser extends Render {
}
@Override
public void doRender(Entity entity, double x, double y, double z, float f,
float f1) {
public void doRender(Entity entity, double x, double y, double z, float f, float f1) {
doRender((EntityLaser) entity, x, y, z, f, f1);
entity.setAngles(45, 180);
}
private void doRender(EntityLaser laser, double x, double y, double z,
float f, float f1) {
private void doRender(EntityLaser laser, double x, double y, double z, float f, float f1) {
if (laser.hidden)
return;

View file

@ -24,6 +24,7 @@ import net.minecraft.src.buildcraft.api.APIProxy;
import net.minecraft.src.buildcraft.api.IPowerReceptor;
import net.minecraft.src.buildcraft.api.LaserKind;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.TileNetworkData;
@ -232,10 +233,11 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
for (BlockIndex b : path) {
if (previous != null) {
EntityLaser laser = new EntityLaser(worldObj);
laser.setPositions(previous.i + 0.5, previous.j + 0.5,
previous.k + 0.5, b.i + 0.5, b.j + 0.5, b.k + 0.5);
EntityLaser laser = new EntityLaser(worldObj,
new Position(previous.i + 0.5, previous.j + 0.5, previous.k + 0.5),
new Position(b.i + 0.5, b.j + 0.5, b.k + 0.5));
laser.setTexture("/net/minecraft/src/buildcraft/core/gui/stripes.png");
worldObj.spawnEntityInWorld(laser);
pathLasers.add(laser);

View file

@ -5,6 +5,7 @@ import java.util.TreeSet;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.core.BlockIndex;
import net.minecraft.src.buildcraft.core.EntityLaser;
import net.minecraft.src.buildcraft.core.WorldIterator;
@ -38,12 +39,13 @@ public class TilePathMarker extends TileMarker {
links[1] = marker;
}
}
public void createLaserAndConnect(TilePathMarker pathMarker) {
EntityLaser laser = new EntityLaser(worldObj);
laser.setPositions(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5,
pathMarker.xCoord + 0.5, pathMarker.yCoord + 0.5,
pathMarker.zCoord + 0.5);
public void createLaserAndConnect (TilePathMarker pathMarker) {
EntityLaser laser = new EntityLaser(worldObj,
new Position(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5),
new Position(pathMarker.xCoord + 0.5, pathMarker.yCoord + 0.5, pathMarker.zCoord + 0.5));
laser.setTexture("/net/minecraft/src/buildcraft/core/gui/laser_1.png");
worldObj.spawnEntityInWorld(laser);

View file

@ -10,17 +10,30 @@
package net.minecraft.src.buildcraft.core;
import net.minecraft.src.World;
import net.minecraft.src.buildcraft.api.Position;
public class EntityEnergyLaser extends EntityLaser {
public int displayStage = 0;
private float power[] = new float[100];
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];
public void pushPower (float p) {
powerAverage -= power [powerIndex];
powerAverage += p;
power[powerIndex] = p;
powerIndex++;
@ -33,16 +46,10 @@ public class EntityEnergyLaser extends EntityLaser {
return powerAverage / power.length;
}
public EntityEnergyLaser(World world) {
super(world);
for (int j = 0; j < power.length; ++j)
power[j] = 0;
}
@Override
public String getTexture() {
if (getPowerAverage() <= 1.0)
public String getTexture () {
if (getPowerAverage () <= 1.0)
return "/net/minecraft/src/buildcraft/core/gui/laser_1.png";
else if (getPowerAverage() <= 2.0)
return "/net/minecraft/src/buildcraft/core/gui/laser_2.png";

View file

@ -9,60 +9,116 @@
package net.minecraft.src.buildcraft.core;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.Entity;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.World;
import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.forge.ISpawnHandler;
public class EntityLaser extends Entity {
public class EntityLaser extends Entity implements ISpawnHandler {
public double x1, y1, z1, x2, y2, z2;
boolean hidden = false;
protected Position head, tail;
public boolean hidden = false;
public double renderSize = 0;
public double angleY = 0;
public double angleZ = 0;
public String texture;
public EntityLaser(World world) {
super(world);
}
public EntityLaser(World world, Position head, Position tail) {
super(world);
this.head = head;
this.tail = tail;
init();
}
protected void init() {
preventEntitySpawning = false;
noClip = true;
isImmuneToFire = true;
setPosition(x1, y1, z1);
setPosition(head.x, head.y, head.z);
setSize(10, 10);
}
public void setPositions(double x1, double y1, double z1, double x2,
double y2, double z2) {
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
setPosition(x1, y1, z1);
}
public void setTexture(String texture) {
this.texture = texture;
dataWatcher.addObject(8 , Integer.valueOf((int) head.x * 8000));
dataWatcher.addObject(9 , Integer.valueOf((int) head.y * 8000));
dataWatcher.addObject(10, Integer.valueOf((int) head.z * 8000));
dataWatcher.addObject(11, Integer.valueOf((int) tail.x * 8000));
dataWatcher.addObject(12, Integer.valueOf((int) tail.y * 8000));
dataWatcher.addObject(13, Integer.valueOf((int) tail.z * 8000));
updateGraphicData();
}
@Override
public void setPosition(double d, double d1, double d2) {
public void writeSpawnData(DataOutputStream data) throws IOException {
posX = d;
posY = d1;
posZ = d2;
data.writeDouble(head.x);
data.writeDouble(head.y);
data.writeDouble(head.z);
data.writeDouble(tail.x);
data.writeDouble(tail.y);
data.writeDouble(tail.z);
}
boundingBox.minX = x1 <= x2 ? x1 : x2;
boundingBox.minY = y1 <= y2 ? y1 : y2;
boundingBox.minZ = z1 <= z2 ? z1 : z2;
@Override
public void readSpawnData(DataInputStream data) throws IOException {
boundingBox.maxX = x1 <= x2 ? x2 : x1;
boundingBox.maxY = y1 <= y2 ? y2 : y1;
boundingBox.maxZ = z1 <= z2 ? z2 : z1;
head = new Position(data.readDouble(), data.readDouble(), data.readDouble());
tail = new Position(data.readDouble(), data.readDouble(), data.readDouble());
init();
}
public void setPositions(Position head, Position tail) {
this.head = head;
this.tail = tail;
dataWatcher.updateObject(8 , Integer.valueOf((int) head.x * 10000));
dataWatcher.updateObject(9 , Integer.valueOf((int) head.y * 10000));
dataWatcher.updateObject(10, Integer.valueOf((int) head.z * 10000));
dataWatcher.updateObject(11, Integer.valueOf((int) tail.x * 10000));
dataWatcher.updateObject(12, Integer.valueOf((int) tail.y * 10000));
dataWatcher.updateObject(13, Integer.valueOf((int) tail.z * 10000));
updateGraphicData();
}
@Override
public void setPosition(double x, double y, double z) {
posX = x;
posY = y;
posZ = z;
}
public void updateGraphicData() {
if (head == null || tail == null)
return;
//updatePositions();
boundingBox.minX = Math.min(head.x, tail.x);
boundingBox.minY = Math.min(head.y, tail.y);
boundingBox.minZ = Math.min(head.z, tail.z);
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--;
@ -72,27 +128,35 @@ public class EntityLaser extends Entity {
boundingBox.maxY++;
boundingBox.maxZ++;
updateGraphicData();
}
double renderSize = 0;
double angleY = 0;
double angleZ = 0;
public void updateGraphicData() {
double dx = x1 - x2;
double dy = y1 - y2;
double dz = z1 - z2;
double dx = head.x - tail.x;
double dy = head.y - tail.y;
double dz = head.z - tail.z;
renderSize = Math.sqrt(dx * dx + dy * dy + dz * dz);
angleZ = 360 - (Math.atan2(dz, dx) * 180.0 / Math.PI + 180.0);
dx = Math.sqrt(renderSize * renderSize - dy * dy);
angleY = -Math.atan2(dy, dx) * 180 / Math.PI;
}
protected void updatePositions() {
head.x = dataWatcher.getWatchableObjectInt(8) / 10000D;
head.y = dataWatcher.getWatchableObjectInt(9) / 10000D;
head.z = dataWatcher.getWatchableObjectInt(10) / 10000D;
tail.x = dataWatcher.getWatchableObjectInt(11) / 10000D;
tail.y = dataWatcher.getWatchableObjectInt(12) / 10000D;
tail.z = dataWatcher.getWatchableObjectInt(13) / 10000D;
}
public void setTexture(String texture) {
this.texture = texture;
}
@Override
public String getTexture() {
return texture;
}
@Override
protected void entityInit() {
@ -106,11 +170,6 @@ public class EntityLaser extends Entity {
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
}
public String getTexture() {
return texture;
}
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {}
public int getBrightnessForRender(float par1) {
return 210;
}
}

View file

@ -23,6 +23,7 @@ import net.minecraft.src.World;
import net.minecraft.src.buildcraft.api.APIProxy;
import net.minecraft.src.buildcraft.api.BptSlotInfo;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.core.BptSlot.Mode;
import net.minecraft.src.forge.ISpawnHandler;
@ -76,10 +77,9 @@ public class EntityRobot extends Entity implements ISpawnHandler {
motionZ = 0;
setPosition(destX, destY, destZ);
laser = new EntityEnergyLaser(worldObj);
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
laser.hidden = true;
laser.setPositions(posX, posY, posZ, posX, posY, posZ);
worldObj.spawnEntityInWorld(laser);
}
@ -129,20 +129,19 @@ public class EntityRobot extends Entity implements ISpawnHandler {
}
protected void move() {
if (!reachedDesination()) {
setPosition(posX + motionX, posY + motionY, posZ + motionZ);
return;
}
setPosition(posX + motionX,
posY + motionY,
posZ + motionZ);
if (APIProxy.isClient(worldObj))
return;
if (!reachedDesination())
return;
BlockIndex newDesination = getNewDesination();
if (newDesination != null) {
setDestination(newDesination.i, newDesination.j, newDesination.k);
}
@ -198,8 +197,8 @@ public class EntityRobot extends Entity implements ISpawnHandler {
protected void build() {
updateWait();
// TODO: rewrite
//TODO: possible rewrite
if (targets.size() > 0) {
Action a = targets.getFirst();
@ -264,8 +263,7 @@ public class EntityRobot extends Entity implements ISpawnHandler {
}
if (target != null)
laser.setPositions(posX, posY, posZ, target.x + 0.5,
target.y + 0.5, target.z + 0.5);
laser.setPositions (new Position(posX, posY, posZ), new Position(target.x + 0.5, target.y + 0.5, target.z + 0.5));
else
laser.hidden = true;

View file

@ -15,6 +15,7 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.buildcraft.api.IPowerReceptor;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
@ -25,10 +26,10 @@ import net.minecraft.src.buildcraft.factory.TileAssemblyTable;
public class TileLaser extends TileEntity implements IPowerReceptor {
private EntityEnergyLaser laser = null;
private SafeTimeTracker laserTickTracker = new SafeTimeTracker();
private SafeTimeTracker searchTracker = new SafeTimeTracker();
private final SafeTimeTracker laserTickTracker = new SafeTimeTracker();
private final SafeTimeTracker searchTracker = new SafeTimeTracker();
private TileAssemblyTable assemblyTable;
private PowerProvider powerProvider;
@ -171,12 +172,14 @@ public class TileLaser extends TileEntity implements IPowerReceptor {
pz = 0.3;
break;
}
laser.setPositions(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5
+ pz, assemblyTable.xCoord + 0.475
+ (worldObj.rand.nextFloat() - 0.5) / 5F,
assemblyTable.yCoord + 9F / 16F, assemblyTable.zCoord + 0.475
+ (worldObj.rand.nextFloat() - 0.5) / 5F);
Position head = new Position(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5 + pz);
Position tail = new Position(
assemblyTable.xCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F,
assemblyTable.yCoord + 9F / 16F,
assemblyTable.zCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F);
laser.setPositions(head, tail);
}
@Override