Fix Tanks filling and added safety check on load
This commit is contained in:
parent
1c6cb011c8
commit
2bd1e96e11
1 changed files with 27 additions and 19 deletions
|
@ -23,6 +23,7 @@ import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.network.PacketPayload;
|
import buildcraft.core.network.PacketPayload;
|
||||||
import buildcraft.core.network.PacketUpdate;
|
import buildcraft.core.network.PacketUpdate;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
public class TileTank extends TileBuildCraft implements ITankContainer {
|
public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
|
|
||||||
|
@ -38,8 +39,9 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
hasUpdate = false;
|
hasUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CoreProxy.proxy.isRenderWorld(worldObj))
|
if (CoreProxy.proxy.isRenderWorld(worldObj)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Have liquid flow down into tanks below if any.
|
// Have liquid flow down into tanks below if any.
|
||||||
if (tank.getLiquid() != null) {
|
if (tank.getLiquid() != null) {
|
||||||
|
@ -84,7 +86,9 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
} else {
|
} else {
|
||||||
LiquidStack liquid = new LiquidStack(0, 0, 0);
|
LiquidStack liquid = new LiquidStack(0, 0, 0);
|
||||||
liquid.readFromNBT(data.getCompoundTag("tank"));
|
liquid.readFromNBT(data.getCompoundTag("tank"));
|
||||||
tank.setLiquid(liquid);
|
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0) {
|
||||||
|
tank.setLiquid(liquid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,24 +138,27 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
|
|
||||||
public static TileTank getTankBelow(TileTank tile) {
|
public static TileTank getTankBelow(TileTank tile) {
|
||||||
TileEntity below = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord - 1, tile.zCoord);
|
TileEntity below = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord - 1, tile.zCoord);
|
||||||
if (below instanceof TileTank)
|
if (below instanceof TileTank) {
|
||||||
return (TileTank) below;
|
return (TileTank) below;
|
||||||
else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileTank getTankAbove(TileTank tile) {
|
public static TileTank getTankAbove(TileTank tile) {
|
||||||
TileEntity above = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord + 1, tile.zCoord);
|
TileEntity above = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord + 1, tile.zCoord);
|
||||||
if (above instanceof TileTank)
|
if (above instanceof TileTank) {
|
||||||
return (TileTank) above;
|
return (TileTank) above;
|
||||||
else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveLiquidBelow() {
|
public void moveLiquidBelow() {
|
||||||
TileTank below = getTankBelow(this);
|
TileTank below = getTankBelow(this);
|
||||||
if (below == null)
|
if (below == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int used = below.tank.fill(tank.getLiquid(), true);
|
int used = below.tank.fill(tank.getLiquid(), true);
|
||||||
if (used > 0) {
|
if (used > 0) {
|
||||||
|
@ -170,16 +177,18 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
||||||
if (tankIndex != 0 || resource == null)
|
if (tankIndex != 0 || resource == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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.isLiquidEqual(resource))
|
if (liquid != null && liquid.amount > 0 && !liquid.isLiquidEqual(resource)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (tankToFill != null && resource.amount > 0) {
|
while (tankToFill != null && resource.amount > 0) {
|
||||||
int used = tankToFill.tank.fill(resource, doFill);
|
int used = tankToFill.tank.fill(resource, doFill);
|
||||||
|
@ -191,9 +200,6 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
totalUsed += used;
|
totalUsed += used;
|
||||||
tankToFill = getTankAbove(tankToFill);
|
tankToFill = getTankAbove(tankToFill);
|
||||||
}
|
}
|
||||||
if (totalUsed > 0) {
|
|
||||||
hasUpdate = true;
|
|
||||||
}
|
|
||||||
return totalUsed;
|
return totalUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,8 +225,9 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
|
|
||||||
if (tile != null && tile.tank.getLiquid() != null) {
|
if (tile != null && tile.tank.getLiquid() != null) {
|
||||||
compositeTank.setLiquid(tile.tank.getLiquid().copy());
|
compositeTank.setLiquid(tile.tank.getLiquid().copy());
|
||||||
} else
|
} else {
|
||||||
return new ILiquidTank[] { compositeTank };
|
return new ILiquidTank[]{compositeTank};
|
||||||
|
}
|
||||||
|
|
||||||
tile = getTankAbove(tile);
|
tile = getTankAbove(tile);
|
||||||
|
|
||||||
|
@ -240,13 +247,14 @@ public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
compositeTank.setCapacity(capacity);
|
compositeTank.setCapacity(capacity);
|
||||||
return new ILiquidTank[] { compositeTank };
|
return new ILiquidTank[]{compositeTank};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
|
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
|
||||||
if (direction == DOWN && worldObj != null && worldObj.getBlockId(xCoord, yCoord - 1, zCoord) != BuildCraftFactory.tankBlock.blockID)
|
if (direction == DOWN && worldObj != null && worldObj.getBlockId(xCoord, yCoord - 1, zCoord) != BuildCraftFactory.tankBlock.blockID) {
|
||||||
return tank;
|
return tank;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue