Fix up for liquidstack immutability

This commit is contained in:
Christian 2013-03-29 15:40:27 -04:00
parent 53a8db85e8
commit b341914b84
5 changed files with 26 additions and 38 deletions

View file

@ -294,7 +294,7 @@ public class EngineIron extends Engine {
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(j, 0));
} else {
fuelTank.getLiquid().itemID = j;
fuelTank.setLiquid(new LiquidStack(j,fuelTank.getLiquid().amount,fuelTank.getLiquid().itemMeta));
}
break;
case 7:
@ -308,21 +308,21 @@ public class EngineIron extends Engine {
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(j, 0));
} else {
coolantTank.getLiquid().itemID = j;
coolantTank.setLiquid(new LiquidStack(j,coolantTank.getLiquid().amount,coolantTank.getLiquid().itemMeta));
}
break;
case 9:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(0, 0, j));
} else {
fuelTank.getLiquid().itemMeta = j;
fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID,fuelTank.getLiquid().amount,j));
}
break;
case 10:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(0, 0, j));
} else {
coolantTank.getLiquid().itemMeta = j;
coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID,coolantTank.getLiquid().amount,j));
}
}
}

View file

@ -15,6 +15,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.BuildCraftCore;
@ -84,9 +85,8 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
LiquidStack liquid = new LiquidStack(data.getInteger("liquidId"), data.getInteger("stored"), 0);
tank.setLiquid(liquid);
} else {
LiquidStack liquid = new LiquidStack(0, 0, 0);
liquid.readFromNBT(data.getCompoundTag("tank"));
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0) {
LiquidStack liquid = LiquidStack.loadLiquidStackFromNBT(data.getCompoundTag("tank"));
if (liquid != null) {
tank.setLiquid(liquid);
}
}
@ -95,7 +95,7 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
if (tank.getLiquid() != null) {
if (tank.containsValidLiquid()) {
data.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
@ -184,7 +184,7 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
resource = resource.copy();
int totalUsed = 0;
TileTank tankToFill = getBottomTank();
LiquidStack liquid = tankToFill.tank.getLiquid();
if (liquid != null && liquid.amount > 0 && !liquid.isLiquidEqual(resource)) {
return 0;

View file

@ -45,10 +45,9 @@ public class RenderTank extends TileEntitySpecialRenderer {
block.baseBlock = Block.waterStill;
block.texture = liquid.getRenderingIcon();
String spriteSet = "/gui/items.png";
String spriteSet = liquid.getTextureSheet();
if (liquid.itemID < Block.blocksList.length && Block.blocksList[liquid.itemID] != null) {
spriteSet = "/terrain.png";
block.baseBlock = Block.blocksList[liquid.itemID];
}
@ -79,9 +78,11 @@ public class RenderTank extends TileEntitySpecialRenderer {
TileTank tank = ((TileTank) tileentity);
String liquidName = tank.tank.getLiquidName();
LiquidStack liquid = tank.tank.getLiquid();
LiquidStack refLiquid = LiquidDictionary.getCanonicalLiquid(liquidName);
if (liquid == null)
return;
LiquidStack refLiquid = liquid.canonical();
if (refLiquid == null || liquid.amount <= 0)
return;

View file

@ -209,7 +209,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
/**
* Computes the PacketLiquidUpdate packet for transmission to a client
*
*
* @param initPacket
* everything is sent, no delta stuff ( first packet )
* @param persistChange
@ -257,16 +257,11 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
continue;
}
if (prev.itemID != current.itemID || initPacket) {
if (!prev.equals(current) || initPacket) {
changed = true;
renderCache[dir.ordinal()].itemID = current.itemID;
renderCache[dir.ordinal()] = current;
delta.set(dir.ordinal() * 3 + 0);
}
if (prev.itemMeta != current.itemMeta || initPacket) {
changed = true;
renderCache[dir.ordinal()].itemMeta = current.itemMeta;
delta.set(dir.ordinal() * 3 + 1);
delta.set(dir.ordinal() * 3 + 1);
}
int displayQty = (prev.amount * 4 + current.amount) / 5;

View file

@ -62,18 +62,15 @@ public class PacketLiquidUpdate extends PacketCoordinates {
// System.out.printf("read %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta);
for (ForgeDirection dir : ForgeDirection.values()) {
if (renderCache[dir.ordinal()] == null) {
renderCache[dir.ordinal()] = new LiquidStack(0, 0, 0);
}
if (delta.get(dir.ordinal() * 3 + 0)) {
renderCache[dir.ordinal()].itemID = data.readShort();
}
if (delta.get(dir.ordinal() * 3 + 1)) {
renderCache[dir.ordinal()].itemMeta = data.readShort();
int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 0;
renderCache[dir.ordinal()] = new LiquidStack(data.readShort(),amt,data.readShort());
}
if (delta.get(dir.ordinal() * 3 + 2)) {
renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readShort());
if (renderCache[dir.ordinal()] == null) {
renderCache[dir.ordinal()] = new LiquidStack(0,0);
}
renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readShort());
}
}
}
@ -92,15 +89,10 @@ public class PacketLiquidUpdate extends PacketCoordinates {
if (delta.get(dir.ordinal() * 3 + 0)) {
if (liquid != null) {
data.writeShort(liquid.itemID);
data.writeShort(liquid.itemMeta);
} else {
data.writeShort(0);
}
}
if (delta.get(dir.ordinal() * 3 + 1)) {
if (liquid != null) {
data.writeShort(liquid.itemMeta);
} else {
data.writeShort(0);
data.writeShort(0);
}
}
if (delta.get(dir.ordinal() * 3 + 2)) {