Fix up for liquidstack immutability
This commit is contained in:
parent
53a8db85e8
commit
b341914b84
5 changed files with 26 additions and 38 deletions
|
@ -294,7 +294,7 @@ public class EngineIron extends Engine {
|
||||||
if (fuelTank.getLiquid() == null) {
|
if (fuelTank.getLiquid() == null) {
|
||||||
fuelTank.setLiquid(new LiquidStack(j, 0));
|
fuelTank.setLiquid(new LiquidStack(j, 0));
|
||||||
} else {
|
} else {
|
||||||
fuelTank.getLiquid().itemID = j;
|
fuelTank.setLiquid(new LiquidStack(j,fuelTank.getLiquid().amount,fuelTank.getLiquid().itemMeta));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
@ -308,21 +308,21 @@ public class EngineIron extends Engine {
|
||||||
if (coolantTank.getLiquid() == null) {
|
if (coolantTank.getLiquid() == null) {
|
||||||
coolantTank.setLiquid(new LiquidStack(j, 0));
|
coolantTank.setLiquid(new LiquidStack(j, 0));
|
||||||
} else {
|
} else {
|
||||||
coolantTank.getLiquid().itemID = j;
|
coolantTank.setLiquid(new LiquidStack(j,coolantTank.getLiquid().amount,coolantTank.getLiquid().itemMeta));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
if (fuelTank.getLiquid() == null) {
|
if (fuelTank.getLiquid() == null) {
|
||||||
fuelTank.setLiquid(new LiquidStack(0, 0, j));
|
fuelTank.setLiquid(new LiquidStack(0, 0, j));
|
||||||
} else {
|
} else {
|
||||||
fuelTank.getLiquid().itemMeta = j;
|
fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID,fuelTank.getLiquid().amount,j));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
if (coolantTank.getLiquid() == null) {
|
if (coolantTank.getLiquid() == null) {
|
||||||
coolantTank.setLiquid(new LiquidStack(0, 0, j));
|
coolantTank.setLiquid(new LiquidStack(0, 0, j));
|
||||||
} else {
|
} else {
|
||||||
coolantTank.getLiquid().itemMeta = j;
|
coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID,coolantTank.getLiquid().amount,j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.liquids.ILiquidTank;
|
import net.minecraftforge.liquids.ILiquidTank;
|
||||||
import net.minecraftforge.liquids.ITankContainer;
|
import net.minecraftforge.liquids.ITankContainer;
|
||||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||||
|
import net.minecraftforge.liquids.LiquidDictionary;
|
||||||
import net.minecraftforge.liquids.LiquidStack;
|
import net.minecraftforge.liquids.LiquidStack;
|
||||||
import net.minecraftforge.liquids.LiquidTank;
|
import net.minecraftforge.liquids.LiquidTank;
|
||||||
import buildcraft.BuildCraftCore;
|
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);
|
LiquidStack liquid = new LiquidStack(data.getInteger("liquidId"), data.getInteger("stored"), 0);
|
||||||
tank.setLiquid(liquid);
|
tank.setLiquid(liquid);
|
||||||
} else {
|
} else {
|
||||||
LiquidStack liquid = new LiquidStack(0, 0, 0);
|
LiquidStack liquid = LiquidStack.loadLiquidStackFromNBT(data.getCompoundTag("tank"));
|
||||||
liquid.readFromNBT(data.getCompoundTag("tank"));
|
if (liquid != null) {
|
||||||
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0) {
|
|
||||||
tank.setLiquid(liquid);
|
tank.setLiquid(liquid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound data) {
|
public void writeToNBT(NBTTagCompound data) {
|
||||||
super.writeToNBT(data);
|
super.writeToNBT(data);
|
||||||
if (tank.getLiquid() != null) {
|
if (tank.containsValidLiquid()) {
|
||||||
data.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
|
data.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
resource = resource.copy();
|
resource = resource.copy();
|
||||||
int totalUsed = 0;
|
int totalUsed = 0;
|
||||||
TileTank tankToFill = getBottomTank();
|
TileTank tankToFill = getBottomTank();
|
||||||
|
|
||||||
LiquidStack liquid = tankToFill.tank.getLiquid();
|
LiquidStack liquid = tankToFill.tank.getLiquid();
|
||||||
if (liquid != null && liquid.amount > 0 && !liquid.isLiquidEqual(resource)) {
|
if (liquid != null && liquid.amount > 0 && !liquid.isLiquidEqual(resource)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -45,10 +45,9 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
||||||
block.baseBlock = Block.waterStill;
|
block.baseBlock = Block.waterStill;
|
||||||
block.texture = liquid.getRenderingIcon();
|
block.texture = liquid.getRenderingIcon();
|
||||||
|
|
||||||
String spriteSet = "/gui/items.png";
|
String spriteSet = liquid.getTextureSheet();
|
||||||
|
|
||||||
if (liquid.itemID < Block.blocksList.length && Block.blocksList[liquid.itemID] != null) {
|
if (liquid.itemID < Block.blocksList.length && Block.blocksList[liquid.itemID] != null) {
|
||||||
spriteSet = "/terrain.png";
|
|
||||||
block.baseBlock = Block.blocksList[liquid.itemID];
|
block.baseBlock = Block.blocksList[liquid.itemID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +78,11 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
||||||
|
|
||||||
TileTank tank = ((TileTank) tileentity);
|
TileTank tank = ((TileTank) tileentity);
|
||||||
|
|
||||||
String liquidName = tank.tank.getLiquidName();
|
|
||||||
LiquidStack liquid = tank.tank.getLiquid();
|
LiquidStack liquid = tank.tank.getLiquid();
|
||||||
LiquidStack refLiquid = LiquidDictionary.getCanonicalLiquid(liquidName);
|
if (liquid == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
LiquidStack refLiquid = liquid.canonical();
|
||||||
|
|
||||||
if (refLiquid == null || liquid.amount <= 0)
|
if (refLiquid == null || liquid.amount <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -209,7 +209,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the PacketLiquidUpdate packet for transmission to a client
|
* Computes the PacketLiquidUpdate packet for transmission to a client
|
||||||
*
|
*
|
||||||
* @param initPacket
|
* @param initPacket
|
||||||
* everything is sent, no delta stuff ( first packet )
|
* everything is sent, no delta stuff ( first packet )
|
||||||
* @param persistChange
|
* @param persistChange
|
||||||
|
@ -257,16 +257,11 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev.itemID != current.itemID || initPacket) {
|
if (!prev.equals(current) || initPacket) {
|
||||||
changed = true;
|
changed = true;
|
||||||
renderCache[dir.ordinal()].itemID = current.itemID;
|
renderCache[dir.ordinal()] = current;
|
||||||
delta.set(dir.ordinal() * 3 + 0);
|
delta.set(dir.ordinal() * 3 + 0);
|
||||||
}
|
delta.set(dir.ordinal() * 3 + 1);
|
||||||
|
|
||||||
if (prev.itemMeta != current.itemMeta || initPacket) {
|
|
||||||
changed = true;
|
|
||||||
renderCache[dir.ordinal()].itemMeta = current.itemMeta;
|
|
||||||
delta.set(dir.ordinal() * 3 + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int displayQty = (prev.amount * 4 + current.amount) / 5;
|
int displayQty = (prev.amount * 4 + current.amount) / 5;
|
||||||
|
|
|
@ -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);
|
// System.out.printf("read %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta);
|
||||||
|
|
||||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
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)) {
|
if (delta.get(dir.ordinal() * 3 + 0)) {
|
||||||
renderCache[dir.ordinal()].itemID = 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 + 1)) {
|
|
||||||
renderCache[dir.ordinal()].itemMeta = data.readShort();
|
|
||||||
}
|
}
|
||||||
if (delta.get(dir.ordinal() * 3 + 2)) {
|
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 (delta.get(dir.ordinal() * 3 + 0)) {
|
||||||
if (liquid != null) {
|
if (liquid != null) {
|
||||||
data.writeShort(liquid.itemID);
|
data.writeShort(liquid.itemID);
|
||||||
|
data.writeShort(liquid.itemMeta);
|
||||||
} else {
|
} else {
|
||||||
data.writeShort(0);
|
data.writeShort(0);
|
||||||
}
|
data.writeShort(0);
|
||||||
}
|
|
||||||
if (delta.get(dir.ordinal() * 3 + 1)) {
|
|
||||||
if (liquid != null) {
|
|
||||||
data.writeShort(liquid.itemMeta);
|
|
||||||
} else {
|
|
||||||
data.writeShort(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (delta.get(dir.ordinal() * 3 + 2)) {
|
if (delta.get(dir.ordinal() * 3 + 2)) {
|
||||||
|
|
Loading…
Reference in a new issue