Change TravItem position to primitives
This commit is contained in:
parent
fd3555a56a
commit
ab64958955
6 changed files with 70 additions and 73 deletions
|
@ -45,6 +45,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class PipeTransportItems extends PipeTransport {
|
||||
|
@ -124,11 +125,10 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
|
||||
public void readjustSpeed(TravelingItem item) {
|
||||
if (container.pipe instanceof IPipeTransportItemsHook) {
|
||||
if (container.pipe instanceof IPipeTransportItemsHook)
|
||||
((IPipeTransportItemsHook) container.pipe).readjustSpeed(item);
|
||||
} else {
|
||||
else
|
||||
defaultReajustSpeed(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void defaultReajustSpeed(TravelingItem item) {
|
||||
|
@ -145,6 +145,26 @@ public class PipeTransportItems extends PipeTransport {
|
|||
item.setSpeed(speed);
|
||||
}
|
||||
|
||||
private void readjustPosition(TravelingItem item) {
|
||||
double x = item.xCoord;
|
||||
double y = item.yCoord;
|
||||
double z = item.zCoord;
|
||||
|
||||
x = Math.max(x, container.xCoord + 0.01);
|
||||
y = Math.max(y, container.yCoord + 0.01);
|
||||
z = Math.max(z, container.zCoord + 0.01);
|
||||
|
||||
x = Math.min(x, container.xCoord + 0.99);
|
||||
y = Math.min(y, container.yCoord + 0.99);
|
||||
z = Math.min(z, container.zCoord + 0.99);
|
||||
|
||||
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
|
||||
y = container.yCoord + Utils.getPipeFloorOf(item.getItemStack());
|
||||
}
|
||||
|
||||
item.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
|
||||
if (item.isCorrupted())
|
||||
// Safe guard - if for any reason the item is corrupted at this
|
||||
|
@ -157,12 +177,8 @@ public class PipeTransportItems extends PipeTransport {
|
|||
items.add(item);
|
||||
|
||||
readjustSpeed(item);
|
||||
readjustPosition(item);
|
||||
|
||||
// Reajusting Ypos to make sure the object looks like sitting on the
|
||||
// pipe.
|
||||
if (inputOrientation != ForgeDirection.UP && inputOrientation != ForgeDirection.DOWN) {
|
||||
item.setPosition(item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
|
||||
}
|
||||
|
||||
if (!container.worldObj.isRemote) {
|
||||
item.output = resolveDestination(item);
|
||||
|
@ -221,12 +237,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
item.input = item.output.getOpposite();
|
||||
|
||||
readjustSpeed(item);
|
||||
|
||||
// Reajusting Ypos to make sure the object looks like sitting on the
|
||||
// pipe.
|
||||
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
|
||||
item.setPosition(item.getPosition().x, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), item.getPosition().z);
|
||||
}
|
||||
readjustPosition(item);
|
||||
|
||||
if (!container.worldObj.isRemote) {
|
||||
item.output = resolveDestination(item);
|
||||
|
@ -322,11 +333,9 @@ public class PipeTransportItems extends PipeTransport {
|
|||
Position motion = new Position(0, 0, 0, item.toCenter ? item.input : item.output);
|
||||
motion.moveForwards(item.getSpeed());
|
||||
|
||||
Position pos = item.getPosition();
|
||||
item.setPosition(pos.x + motion.x, pos.y + motion.y, pos.z + motion.z);
|
||||
pos = item.getPosition();
|
||||
item.movePosition(motion.x, motion.y, motion.z);
|
||||
|
||||
if ((item.toCenter && middleReached(item, pos)) || outOfBounds(pos)) {
|
||||
if ((item.toCenter && middleReached(item)) || outOfBounds(item)) {
|
||||
item.toCenter = false;
|
||||
|
||||
// Reajusting to the middle
|
||||
|
@ -352,7 +361,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
}
|
||||
|
||||
} else if (!item.toCenter && endReached(pos)) {
|
||||
} else if (!item.toCenter && endReached(item)) {
|
||||
TileEntity tile = container.getTile(item.output);
|
||||
|
||||
if (travelHook != null) {
|
||||
|
@ -409,18 +418,18 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean middleReached(TravelingItem item, Position pos) {
|
||||
protected boolean middleReached(TravelingItem item) {
|
||||
float middleLimit = item.getSpeed() * 1.01F;
|
||||
return (Math.abs(container.xCoord + 0.5 - pos.x) < middleLimit && Math.abs(container.yCoord + Utils.getPipeFloorOf(item.getItemStack()) - pos.y) < middleLimit && Math
|
||||
.abs(container.zCoord + 0.5 - pos.z) < middleLimit);
|
||||
return (Math.abs(container.xCoord + 0.5 - item.xCoord) < middleLimit && Math.abs(container.yCoord + Utils.getPipeFloorOf(item.getItemStack()) - item.yCoord) < middleLimit && Math
|
||||
.abs(container.zCoord + 0.5 - item.zCoord) < middleLimit);
|
||||
}
|
||||
|
||||
protected boolean endReached(Position pos) {
|
||||
return pos.x > container.xCoord + 1 || pos.x < container.xCoord || pos.y > container.yCoord + 1 || pos.y < container.yCoord || pos.z > container.zCoord + 1 || pos.z < container.zCoord;
|
||||
protected boolean endReached(TravelingItem item) {
|
||||
return item.xCoord > container.xCoord + 1 || item.xCoord < container.xCoord || item.yCoord > container.yCoord + 1 || item.yCoord < container.yCoord || item.zCoord > container.zCoord + 1 || item.zCoord < container.zCoord;
|
||||
}
|
||||
|
||||
protected boolean outOfBounds(Position pos) {
|
||||
return pos.x > container.xCoord + 2 || pos.x < container.xCoord - 1 || pos.y > container.yCoord + 2 || pos.y < container.yCoord - 1 || pos.z > container.zCoord + 2 || pos.z < container.zCoord - 1;
|
||||
protected boolean outOfBounds(TravelingItem item) {
|
||||
return item.xCoord > container.xCoord + 2 || item.xCoord < container.xCoord - 1 || item.yCoord > container.yCoord + 2 || item.yCoord < container.yCoord - 1 || item.zCoord > container.zCoord + 2 || item.zCoord < container.zCoord - 1;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
|
@ -500,9 +509,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
}
|
||||
|
||||
if (item.getPosition() == null) {
|
||||
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||
}
|
||||
item.setPosition(packet.getItemX(), packet.getItemY(), packet.getItemZ());
|
||||
|
||||
item.setSpeed(packet.getSpeed());
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.entity.item.EntityItem;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -27,7 +26,7 @@ public class TravelingItem {
|
|||
protected float speed = 0.01F;
|
||||
protected ItemStack item;
|
||||
protected TileEntity container;
|
||||
protected Position position;
|
||||
public double xCoord, yCoord, zCoord;
|
||||
public final int id;
|
||||
public boolean toCenter = true;
|
||||
public EnumColor color;
|
||||
|
@ -47,17 +46,23 @@ public class TravelingItem {
|
|||
|
||||
public TravelingItem(double x, double y, double z, ItemStack stack) {
|
||||
this();
|
||||
this.position = new Position(x, y, z);
|
||||
this.xCoord = x;
|
||||
this.yCoord = y;
|
||||
this.zCoord = z;
|
||||
this.item = stack.copy();
|
||||
}
|
||||
|
||||
/* GETTING & SETTING */
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
public void setPosition(double x, double y, double z) {
|
||||
this.xCoord = x;
|
||||
this.yCoord = y;
|
||||
this.zCoord = z;
|
||||
}
|
||||
|
||||
public void setPosition(double x, double y, double z) {
|
||||
position = new Position(x, y, z);
|
||||
public void movePosition(double x, double y, double z) {
|
||||
this.xCoord += x;
|
||||
this.yCoord += y;
|
||||
this.zCoord += z;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
|
@ -116,27 +121,14 @@ public class TravelingItem {
|
|||
if (c != -1)
|
||||
color = EnumColor.fromId(c);
|
||||
|
||||
NBTTagList contribList = data.getTagList("contribList");
|
||||
|
||||
for (int i = 0; i < contribList.tagCount(); ++i) {
|
||||
NBTTagCompound cpt = (NBTTagCompound) contribList.tagAt(i);
|
||||
String key = cpt.getString("key");
|
||||
|
||||
String className = cpt.getString("class");
|
||||
|
||||
if (getClass().getName().startsWith("net.minecraft.src")) {
|
||||
className = "net.minecraft.src." + className;
|
||||
}
|
||||
|
||||
if (data.hasKey("extraData"))
|
||||
extraData = data.getCompoundTag("extraData");
|
||||
}
|
||||
if (data.hasKey("extraData"))
|
||||
extraData = data.getCompoundTag("extraData");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
data.setDouble("x", position.x);
|
||||
data.setDouble("y", position.y);
|
||||
data.setDouble("z", position.z);
|
||||
data.setDouble("x", xCoord);
|
||||
data.setDouble("y", yCoord);
|
||||
data.setDouble("z", zCoord);
|
||||
data.setFloat("speed", getSpeed());
|
||||
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
||||
getItemStack().writeToNBT(nbttagcompound2);
|
||||
|
@ -160,7 +152,7 @@ public class TravelingItem {
|
|||
Position motion = new Position(0, 0, 0, dir);
|
||||
motion.moveForwards(0.1 + getSpeed() * 2F);
|
||||
|
||||
EntityItem entityitem = new EntityItem(container.worldObj, position.x, position.y, position.z, getItemStack());
|
||||
EntityItem entityitem = new EntityItem(container.worldObj, xCoord, yCoord, zCoord, getItemStack());
|
||||
|
||||
entityitem.lifespan = BuildCraftCore.itemLifespan;
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
|
@ -176,11 +168,11 @@ public class TravelingItem {
|
|||
}
|
||||
|
||||
public float getEntityBrightness(float f) {
|
||||
int i = MathHelper.floor_double(position.x);
|
||||
int j = MathHelper.floor_double(position.z);
|
||||
int i = MathHelper.floor_double(xCoord);
|
||||
int j = MathHelper.floor_double(zCoord);
|
||||
if (container.worldObj.blockExists(i, 128 / 2, j)) {
|
||||
double d = 0.66000000000000003D;
|
||||
int k = MathHelper.floor_double(position.y + d);
|
||||
int k = MathHelper.floor_double(yCoord + d);
|
||||
return container.worldObj.getLightBrightness(i, k, j);
|
||||
} else
|
||||
return 0.0F;
|
||||
|
|
|
@ -38,9 +38,9 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
|||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeFloat((float) item.getPosition().x);
|
||||
data.writeFloat((float) item.getPosition().y);
|
||||
data.writeFloat((float) item.getPosition().z);
|
||||
data.writeFloat((float) item.xCoord);
|
||||
data.writeFloat((float) item.yCoord);
|
||||
data.writeFloat((float) item.zCoord);
|
||||
|
||||
data.writeShort(item.id);
|
||||
|
||||
|
@ -112,15 +112,15 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
|||
return color;
|
||||
}
|
||||
|
||||
public double getPosX() {
|
||||
public double getItemX() {
|
||||
return itemX;
|
||||
}
|
||||
|
||||
public double getPosY() {
|
||||
public double getItemY() {
|
||||
return itemY;
|
||||
}
|
||||
|
||||
public double getPosZ() {
|
||||
public double getItemZ() {
|
||||
return itemZ;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,13 +140,12 @@ public class PipeItemsDaizuli extends Pipe<PipeTransportItems> implements IPipeT
|
|||
|
||||
@Override
|
||||
public void readjustSpeed(TravelingItem item) {
|
||||
if (item.getSpeed() > Utils.pipeNormalSpeed) {
|
||||
if (item.getSpeed() > Utils.pipeNormalSpeed)
|
||||
item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F);
|
||||
}
|
||||
|
||||
if (item.getSpeed() < Utils.pipeNormalSpeed) {
|
||||
|
||||
if (item.getSpeed() < Utils.pipeNormalSpeed)
|
||||
item.setSpeed(Utils.pipeNormalSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,11 +45,11 @@ public class PipeItemsGold extends Pipe implements IPipeTransportItemsHook {
|
|||
|
||||
@Override
|
||||
public void entityEntered(TravelingItem item, ForgeDirection orientation) {
|
||||
item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 30F));
|
||||
readjustSpeed(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readjustSpeed(TravelingItem item) {
|
||||
item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 30F));
|
||||
item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 20F));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -409,13 +409,12 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
float light = pipe.container.worldObj.getLightBrightness(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
|
||||
int count = 0;
|
||||
for (TravelingItem travellingItem : pipe.transport.items) {
|
||||
for (TravelingItem item : pipe.transport.items) {
|
||||
if (count >= MAX_ITEMS_TO_RENDER) {
|
||||
break;
|
||||
}
|
||||
|
||||
doRenderItem(travellingItem, x + travellingItem.getPosition().x - pipe.container.xCoord, y + travellingItem.getPosition().y - pipe.container.yCoord, z + travellingItem.getPosition().z
|
||||
- pipe.container.zCoord, light, travellingItem.color);
|
||||
doRenderItem(item, x + item.xCoord - pipe.container.xCoord, y + item.yCoord - pipe.container.yCoord, z + item.zCoord - pipe.container.zCoord, light, item.color);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue