Refactored TileTank and fixed NPE in Pipes
This commit is contained in:
parent
3ab29dcfad
commit
093d5229e2
6 changed files with 258 additions and 310 deletions
|
@ -25,7 +25,6 @@ import org.lwjgl.opengl.GL11;
|
|||
import buildcraft.api.liquids.LiquidStack;
|
||||
import buildcraft.core.RenderEntityBlock;
|
||||
import buildcraft.core.RenderEntityBlock.BlockInterface;
|
||||
import buildcraft.factory.TileTank;
|
||||
|
||||
public class RenderTank extends TileEntitySpecialRenderer {
|
||||
|
||||
|
@ -72,7 +71,7 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
|||
|
||||
TileTank tank = ((TileTank) tileentity);
|
||||
|
||||
LiquidStack liquid = tank.getLiquid();
|
||||
LiquidStack liquid = tank.tank.getLiquid();
|
||||
|
||||
if (liquid == null || liquid.amount <= 0
|
||||
|| liquid.itemID <= 0)
|
||||
|
@ -97,7 +96,7 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
|||
|
||||
GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
|
||||
|
||||
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (tank.getTankCapacity()) * (displayStages - 1))]);
|
||||
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (tank.tank.getCapacity()) * (displayStages - 1))]);
|
||||
|
||||
GL11.glEnable(2896 /* GL_LIGHTING */);
|
||||
GL11.glPopMatrix();
|
||||
|
|
|
@ -61,7 +61,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
receptor.getPowerProvider().update(receptor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
|
@ -78,9 +78,8 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
}
|
||||
|
||||
public void sendNetworkUpdate() {
|
||||
if (this instanceof ISynchronizedTile)
|
||||
CoreProxy.sendToPlayers(((ISynchronizedTile) this).getUpdatePacket(), worldObj, xCoord, yCoord, zCoord,
|
||||
DefaultProps.NETWORK_UPDATE_RANGE, mod_BuildCraftCore.instance);
|
||||
CoreProxy.sendToPlayers(getUpdatePacket(), worldObj, xCoord, yCoord, zCoord,
|
||||
DefaultProps.NETWORK_UPDATE_RANGE, mod_BuildCraftCore.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
@ -93,7 +93,7 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
|
|||
|
||||
ItemStack current = entityplayer.inventory.getCurrentItem();
|
||||
if (current != null) {
|
||||
|
||||
|
||||
LiquidStack liquid = LiquidManager.getLiquidForFilledItem(current);
|
||||
|
||||
TileTank tank = (TileTank) world.getBlockTileEntity(i, j, k);
|
||||
|
@ -108,31 +108,33 @@ public class BlockTank extends BlockContainer implements ITextureProvider {
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
// Handle empty containers
|
||||
} else {
|
||||
|
||||
|
||||
LiquidStack available = tank.getTanks()[0].getLiquid();
|
||||
ItemStack filled = LiquidManager.fillLiquidContainer(available, current);
|
||||
|
||||
liquid = LiquidManager.getLiquidForFilledItem(filled);
|
||||
if(liquid != null) {
|
||||
|
||||
if(current.stackSize > 1) {
|
||||
if(!entityplayer.inventory.addItemStackToInventory(filled))
|
||||
return false;
|
||||
else
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
|
||||
Utils.consumeItem(current));
|
||||
} else {
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
|
||||
Utils.consumeItem(current));
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
|
||||
}
|
||||
|
||||
tank.drain(Orientations.Unknown, liquid.amount, true);
|
||||
return true;
|
||||
}
|
||||
if(available != null){
|
||||
ItemStack filled = LiquidManager.fillLiquidContainer(available, current);
|
||||
|
||||
liquid = LiquidManager.getLiquidForFilledItem(filled);
|
||||
if(liquid != null) {
|
||||
|
||||
if(current.stackSize > 1) {
|
||||
if(!entityplayer.inventory.addItemStackToInventory(filled))
|
||||
return false;
|
||||
else
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
|
||||
Utils.consumeItem(current));
|
||||
} else {
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem,
|
||||
Utils.consumeItem(current));
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
|
||||
}
|
||||
|
||||
tank.drain(Orientations.Unknown, liquid.amount, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
/**
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.factory;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.APIProxy;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.Orientations;
|
||||
|
@ -19,247 +17,192 @@ import buildcraft.api.liquids.ILiquidTank;
|
|||
import buildcraft.api.liquids.ITankContainer;
|
||||
import buildcraft.api.liquids.LiquidStack;
|
||||
import buildcraft.api.liquids.LiquidTank;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public class TileTank extends TileBuildCraft implements ITankContainer {
|
||||
public class TileTank extends TileBuildCraft implements ITankContainer
|
||||
{
|
||||
|
||||
public @TileNetworkData
|
||||
int stored = 0;
|
||||
public @TileNetworkData
|
||||
int liquidId = 0;
|
||||
public final ILiquidTank tank = new LiquidTank(BuildCraftAPI.BUCKET_VOLUME * 16);
|
||||
public boolean hasUpdate = false;
|
||||
public SafeTimeTracker tracker = new SafeTimeTracker();
|
||||
|
||||
public boolean hasUpdate = false;
|
||||
public SafeTimeTracker tracker = new SafeTimeTracker();
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if(APIProxy.isServerSide() && hasUpdate && tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
hasUpdate = false;
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (APIProxy.isServerSide() && hasUpdate && tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
hasUpdate = false;
|
||||
}
|
||||
|
||||
if(APIProxy.isRemote())
|
||||
return;
|
||||
|
||||
// Have liquid flow down into tanks below if any.
|
||||
if(stored > 0)
|
||||
moveLiquidBelow();
|
||||
}
|
||||
if(APIProxy.isRemote()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
// Have liquid flow down into tanks below if any.
|
||||
if(tank.getLiquid() != null) {
|
||||
moveLiquidBelow();
|
||||
}
|
||||
}
|
||||
|
||||
stored = nbttagcompound.getInteger("stored");
|
||||
liquidId = nbttagcompound.getInteger("liquidId");
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload()
|
||||
{
|
||||
PacketPayload payload = new PacketPayload(3, 0, 0);
|
||||
if(tank.getLiquid() != null) {
|
||||
payload.intPayload[0] = tank.getLiquid().itemID;
|
||||
payload.intPayload[1] = tank.getLiquid().itemMeta;
|
||||
payload.intPayload[2] = tank.getLiquid().amount;
|
||||
} else {
|
||||
payload.intPayload[0] = 0;
|
||||
payload.intPayload[1] = 0;
|
||||
payload.intPayload[2] = 0;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
if (liquidId == 0) {
|
||||
stored = 0;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet)
|
||||
{
|
||||
if(packet.payload.intPayload[0] > 0) {
|
||||
LiquidStack liquid = new LiquidStack(packet.payload.intPayload[0], packet.payload.intPayload[2], packet.payload.intPayload[1]);
|
||||
tank.setLiquid(liquid);
|
||||
} else {
|
||||
tank.setLiquid(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT(data);
|
||||
LiquidStack liquid = new LiquidStack(0, 0, 0);
|
||||
liquid.readFromNBT(data.getCompoundTag("tank"));
|
||||
tank.setLiquid(liquid);
|
||||
}
|
||||
|
||||
nbttagcompound.setInteger("stored", stored);
|
||||
nbttagcompound.setInteger("liquidId", liquidId);
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT(data);
|
||||
data.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
/* HELPER FUNCTIONS */
|
||||
/**
|
||||
* @return Last tank block below this one or this one if it is the last.
|
||||
*/
|
||||
public TileTank getBottomTank() {
|
||||
|
||||
TileTank lastTank = this;
|
||||
/* HELPER FUNCTIONS */
|
||||
/**
|
||||
* @return Last tank block below this one or this one if it is the last.
|
||||
*/
|
||||
public TileTank getBottomTank()
|
||||
{
|
||||
|
||||
while(true) {
|
||||
TileTank below = getTankBelow(lastTank);
|
||||
if(below != null) {
|
||||
lastTank = below;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
return lastTank;
|
||||
}
|
||||
|
||||
public TileTank getTankBelow(TileTank tile) {
|
||||
TileEntity below = worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord - 1, tile.zCoord);
|
||||
if(below instanceof TileTank)
|
||||
return(TileTank)below;
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public TileTank getTankAbove(TileTank tile) {
|
||||
TileEntity above = worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord + 1, tile.zCoord);
|
||||
if(above instanceof TileTank)
|
||||
return(TileTank)above;
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public void moveLiquidBelow() {
|
||||
TileTank below = getTankBelow(this);
|
||||
if(below == null)
|
||||
return;
|
||||
if(below.stored >= below.getTankCapacity())
|
||||
return;
|
||||
if(below.liquidId > 0
|
||||
&& below.liquidId != this.liquidId)
|
||||
return;
|
||||
|
||||
int toMove = Math.min(stored, 100);
|
||||
int moved = Math.min(toMove, below.getTankCapacity() - below.stored);
|
||||
stored -= moved;
|
||||
below.liquidId = liquidId;
|
||||
below.stored += moved;
|
||||
|
||||
}
|
||||
TileTank lastTank = this;
|
||||
|
||||
/* ITANKCONTAINER */
|
||||
@Override
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
return getBottomTank().actualFill(from, resource.amount, resource.itemID, doFill);
|
||||
}
|
||||
while(true) {
|
||||
TileTank below = getTankBelow(lastTank);
|
||||
if(below != null) {
|
||||
lastTank = below;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
||||
return getBottomTank().actualFill(Orientations.YPos, resource.amount, resource.itemID, doFill);
|
||||
}
|
||||
return lastTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(Orientations from, int maxEmpty, boolean doDrain) {
|
||||
int drained = getBottomTank().actualEmtpy(maxEmpty, doDrain);
|
||||
return new LiquidStack(liquidId, drained);
|
||||
}
|
||||
public TileTank getTopTank()
|
||||
{
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int tankIndex, int maxEmpty, boolean doDrain) {
|
||||
int drained = getBottomTank().actualEmtpy(maxEmpty, doDrain);
|
||||
return new LiquidStack(liquidId, drained);
|
||||
}
|
||||
TileTank lastTank = this;
|
||||
|
||||
@Override
|
||||
public ILiquidTank[] getTanks() {
|
||||
int resultLiquidId = 0;
|
||||
int resultLiquidQty = 0;
|
||||
int resultCapacity = 0;
|
||||
while(true) {
|
||||
TileTank above = getTankAbove(lastTank);
|
||||
if(above != null) {
|
||||
lastTank = above;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stored != 0) {
|
||||
resultLiquidId = liquidId;
|
||||
}
|
||||
return lastTank;
|
||||
}
|
||||
|
||||
resultLiquidQty += stored;
|
||||
resultCapacity += getTankCapacity();
|
||||
public static TileTank getTankBelow(TileTank tile)
|
||||
{
|
||||
TileEntity below = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord - 1, tile.zCoord);
|
||||
if(below instanceof TileTank) {
|
||||
return (TileTank)below;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (int ySearch = yCoord - 1; ySearch >= 0; --ySearch) {
|
||||
if (worldObj.getBlockId(xCoord, ySearch, zCoord) != BuildCraftFactory.tankBlock.blockID) {
|
||||
break;
|
||||
}
|
||||
public static TileTank getTankAbove(TileTank tile)
|
||||
{
|
||||
TileEntity above = tile.worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord + 1, tile.zCoord);
|
||||
if(above instanceof TileTank) {
|
||||
return (TileTank)above;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
TileTank tank = (TileTank) worldObj.getBlockTileEntity(xCoord, ySearch, zCoord);
|
||||
public void moveLiquidBelow()
|
||||
{
|
||||
TileTank below = getTankBelow(this);
|
||||
if(below == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tank.stored != 0) {
|
||||
resultLiquidId = tank.liquidId;
|
||||
}
|
||||
int used = below.tank.fill(tank.getLiquid(), true);
|
||||
tank.drain(used, true);
|
||||
}
|
||||
|
||||
resultLiquidQty += tank.stored;
|
||||
resultCapacity += tank.getTankCapacity();
|
||||
}
|
||||
/* ITANKCONTAINER */
|
||||
@Override
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
return fill(0, resource, doFill);
|
||||
}
|
||||
|
||||
for (int ySearch = yCoord + 1; ySearch < 128; ++ySearch) {
|
||||
if (worldObj.getBlockId(xCoord, ySearch, zCoord) != BuildCraftFactory.tankBlock.blockID) {
|
||||
break;
|
||||
}
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
|
||||
{
|
||||
if(tankIndex != 0 || resource == null)
|
||||
return 0;
|
||||
|
||||
TileTank tank = (TileTank) worldObj.getBlockTileEntity(xCoord, ySearch, zCoord);
|
||||
resource = resource.copy();
|
||||
int totalUsed = 0;
|
||||
TileTank tankToFill = getBottomTank();
|
||||
while(tankToFill != null && resource.amount > 0){
|
||||
int used = tankToFill.tank.fill(resource, doFill);
|
||||
resource.amount -= used;
|
||||
totalUsed += used;
|
||||
tankToFill = getTankAbove(tankToFill);
|
||||
}
|
||||
return totalUsed;
|
||||
}
|
||||
|
||||
if (tank.stored != 0) {
|
||||
resultLiquidId = tank.liquidId;
|
||||
}
|
||||
@Override
|
||||
public LiquidStack drain(Orientations from, int maxEmpty, boolean doDrain)
|
||||
{
|
||||
return drain(0, maxEmpty, doDrain);
|
||||
}
|
||||
|
||||
resultLiquidQty += tank.stored;
|
||||
resultCapacity += tank.getTankCapacity();
|
||||
}
|
||||
|
||||
return new ILiquidTank[] { new LiquidTank(resultLiquidId, resultLiquidQty, resultCapacity) };
|
||||
}
|
||||
|
||||
private int actualFill(Orientations from, int quantity, int id, boolean doFill) {
|
||||
if (stored != 0 && id != liquidId)
|
||||
return 0;
|
||||
|
||||
liquidId = id;
|
||||
int used = 0;
|
||||
|
||||
TileTank above = getTankAbove(this);
|
||||
|
||||
if (stored + quantity <= getTankCapacity()) {
|
||||
if (doFill) {
|
||||
stored += quantity;
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
used = quantity;
|
||||
} else if (stored <= getTankCapacity()) {
|
||||
used = getTankCapacity() - stored;
|
||||
|
||||
if (doFill) {
|
||||
stored = getTankCapacity();
|
||||
hasUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (used < quantity && above != null)
|
||||
used = used + above.actualFill(from, quantity - used, id, doFill);
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
public int getTankCapacity() {
|
||||
return BuildCraftAPI.BUCKET_VOLUME * 16;
|
||||
}
|
||||
|
||||
public LiquidStack getLiquid() {
|
||||
return new LiquidStack(liquidId, stored, 0);
|
||||
}
|
||||
|
||||
private int actualEmtpy(int quantityMax, boolean doEmpty) {
|
||||
|
||||
if (stored >= quantityMax) {
|
||||
if (doEmpty) {
|
||||
stored -= quantityMax;
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
return quantityMax;
|
||||
|
||||
} else {
|
||||
int result = stored;
|
||||
|
||||
if (doEmpty) {
|
||||
stored = 0;
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
TileTank below = getTankBelow(this);
|
||||
|
||||
if (below != null)
|
||||
result += below.actualEmtpy(quantityMax - result, doEmpty);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public LiquidStack drain(int tankIndex, int maxEmpty, boolean doDrain)
|
||||
{
|
||||
return getBottomTank().tank.drain(maxEmpty, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank[] getTanks()
|
||||
{
|
||||
return new ILiquidTank[]{tank};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,31 +26,33 @@ import buildcraft.core.DefaultProps;
|
|||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.Utils;
|
||||
import buildcraft.transport.network.PacketLiquidUpdate;
|
||||
import buildcraft.transport.network.PacketPowerUpdate;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public class PipeTransportLiquids extends PipeTransport implements ITankContainer {
|
||||
|
||||
|
||||
|
||||
public class PipeSection extends LiquidTank {
|
||||
|
||||
|
||||
private short currentTime = 0;
|
||||
|
||||
|
||||
//Tracks how much of the liquid is inbound in timeslots
|
||||
private short[] incomming = new short[travelDelay];
|
||||
|
||||
//Tracks how much is currently available (has spent it's inbound delaytime)
|
||||
|
||||
|
||||
public PipeSection() {
|
||||
super(null, PipeTransportLiquids.LIQUID_IN_PIPE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int fill(LiquidStack resource, boolean doFill) {
|
||||
if(resource == null)
|
||||
return 0;
|
||||
|
||||
int maxToFill = Math.min(resource.amount, flowRate - incomming[currentTime]);
|
||||
if (maxToFill <= 0) return 0;
|
||||
|
||||
|
||||
LiquidStack stackToFill = resource.copy();
|
||||
stackToFill.amount = maxToFill;
|
||||
int filled = super.fill(stackToFill, doFill);
|
||||
|
@ -58,36 +60,36 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (doFill) {
|
||||
incomming[currentTime] += filled;
|
||||
}
|
||||
|
||||
|
||||
return filled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int maxDrain, boolean doDrain) {
|
||||
int maxToDrain = Math.min(maxDrain, Math.min(flowRate, getAvailable()));
|
||||
if (maxToDrain < 0) return null;
|
||||
|
||||
|
||||
LiquidStack drained = super.drain(maxToDrain, doDrain);
|
||||
if (drained == null) return null;
|
||||
|
||||
|
||||
return drained;
|
||||
}
|
||||
|
||||
|
||||
public void moveLiquids() {
|
||||
//Processes the inbound liquid
|
||||
incomming[currentTime] = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setTime(short newTime){
|
||||
currentTime = newTime;
|
||||
}
|
||||
|
||||
|
||||
public void reset(){
|
||||
this.setLiquid(null);
|
||||
incomming = new short[travelDelay];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getAvailable(){
|
||||
int all = this.getLiquid() != null ? this.getLiquid().amount : 0;
|
||||
for(short slot : incomming){
|
||||
|
@ -98,7 +100,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
public void readFromNBT(NBTTagCompound compoundTag) {
|
||||
this.setCapacity(compoundTag.getInteger("capacity"));
|
||||
|
||||
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
incomming[i] = compoundTag.getShort("in[" + i + "]");
|
||||
}
|
||||
|
@ -107,15 +109,15 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
public void writeToNBT(NBTTagCompound subTag) {
|
||||
subTag.setInteger("capacity", this.getCapacity());
|
||||
|
||||
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
incomming[i] = subTag.getShort("in[" + i + "]");
|
||||
}
|
||||
|
||||
|
||||
if (this.getLiquid() != null){
|
||||
this.getLiquid().writeToNBT(subTag);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +125,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
None, Input, Output
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The amount of liquid contained by a pipe section. For simplicity, all
|
||||
* pipe sections are assumed to be of the same volume.
|
||||
|
@ -132,23 +134,23 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public static short INPUT_TTL = 60; //100
|
||||
public static short OUTPUT_TTL = 80; //80
|
||||
public static short OUTPUT_COOLDOWN = 30; //30
|
||||
|
||||
|
||||
|
||||
public short travelDelay = 12;
|
||||
public short flowRate = 20;
|
||||
public LiquidStack[] renderCache = new LiquidStack[Orientations.values().length];
|
||||
|
||||
|
||||
private final PipeSection[] internalTanks = new PipeSection[Orientations.values().length];
|
||||
|
||||
|
||||
private final TransferState[] transferState = new TransferState[Orientations.dirs().length];
|
||||
|
||||
|
||||
private final short[] inputTTL = new short[] { 0, 0, 0, 0, 0, 0 };
|
||||
private final short[] outputTTL = new short[] { OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL };
|
||||
private final short[] outputCooldown = new short[] {0, 0, 0, 0, 0, 0 };
|
||||
|
||||
|
||||
private final SafeTimeTracker tracker = new SafeTimeTracker();
|
||||
|
||||
|
||||
|
||||
|
||||
public PipeTransportLiquids() {
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
internalTanks[direction.ordinal()] = new PipeSection();
|
||||
|
@ -163,7 +165,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
if (!Utils.checkPipesConnections(container, entity))
|
||||
return false;
|
||||
|
||||
|
||||
if (entity instanceof TileGenericPipe){
|
||||
if (!((TileGenericPipe)entity).pipe.inputOpen(o.reverse())){
|
||||
return false;
|
||||
|
@ -184,7 +186,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
moveLiquids();
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
LiquidStack liquid = internalTanks[direction.ordinal()].getLiquid();
|
||||
|
||||
|
||||
if (liquid != null){
|
||||
if (renderCache[direction.ordinal()] == null){
|
||||
renderCache[direction.ordinal()] = liquid.copy();
|
||||
|
@ -200,7 +202,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (renderCache[direction.ordinal()].amount == 0 && currentLiquid > 0){
|
||||
renderCache[direction.ordinal()].amount = currentLiquid;
|
||||
}
|
||||
|
||||
|
||||
//Uncomment to disable the avaraging
|
||||
//renderCache[direction.ordinal()].amount = (liquid != null ? liquid.amount : 0);
|
||||
}
|
||||
|
@ -212,16 +214,16 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (APIProxy.isServerSide())
|
||||
if (tracker.markTimeIfDelay(worldObj, 1 * BuildCraftCore.updateFactor)){
|
||||
|
||||
|
||||
PacketLiquidUpdate packet = new PacketLiquidUpdate(xCoord, yCoord, zCoord);
|
||||
packet.displayLiquid = this.renderCache;
|
||||
CoreProxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord,
|
||||
DefaultProps.NETWORK_UPDATE_RANGE, mod_BuildCraftCore.instance);
|
||||
}
|
||||
|
||||
|
||||
//this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor);
|
||||
}
|
||||
|
||||
|
@ -255,14 +257,14 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
|
||||
private void moveLiquids() {
|
||||
short newTimeSlot = (short) (worldObj.getWorldTime() % travelDelay);
|
||||
|
||||
|
||||
//Processes all internal tanks
|
||||
for (Orientations direction : Orientations.values()){
|
||||
internalTanks[direction.ordinal()].setTime(newTimeSlot);
|
||||
internalTanks[direction.ordinal()].moveLiquids();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
if (transferState[direction.ordinal()] == TransferState.Input){
|
||||
if ((inputTTL[direction.ordinal()]--) < 1){
|
||||
|
@ -270,11 +272,11 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
short outputCount = computeOutputs();
|
||||
moveFromPipe(outputCount);
|
||||
moveFromCenter();
|
||||
moveToCenter();
|
||||
moveToCenter();
|
||||
}
|
||||
|
||||
private void moveFromPipe(short outputCount) {
|
||||
|
@ -284,7 +286,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (transferState[o.ordinal()] == TransferState.Output){
|
||||
TileEntity target = this.container.getTile(o);
|
||||
if (!(target instanceof ITankContainer)) continue;
|
||||
|
||||
|
||||
LiquidStack liquidToPush = internalTanks[o.ordinal()].drain(flowRate, false);
|
||||
if (liquidToPush != null && liquidToPush.amount > 0) {
|
||||
int filled = ((ITankContainer)target).fill(o.reverse(), liquidToPush, true);
|
||||
|
@ -310,7 +312,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
testStack.amount = flowRate;
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
if (transferState[direction.ordinal()] != TransferState.Output ) continue;
|
||||
|
||||
|
||||
maxOutput[direction.ordinal()] = internalTanks[direction.ordinal()].fill(testStack, false);
|
||||
if(maxOutput[direction.ordinal()] > 0){
|
||||
transferOutCount++;
|
||||
|
@ -323,7 +325,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (maxOutput[direction.ordinal()] == 0) continue;
|
||||
int ammountToPush = (int) ((double) maxOutput[direction.ordinal()] / (double) flowRate / (double) transferOutCount * (double) Math.min(flowRate, totalAvailable));
|
||||
if (ammountToPush < 1) ammountToPush++;
|
||||
|
||||
|
||||
LiquidStack liquidToPush = internalTanks[Orientations.Unknown.ordinal()].drain(ammountToPush, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = internalTanks[direction.ordinal()].fill(liquidToPush, true);
|
||||
|
@ -342,8 +344,8 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
if (stackInCenter != null){
|
||||
spaceAvailable -= stackInCenter.amount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
LiquidStack testStack = internalTanks[direction.ordinal()].drain(flowRate, false);
|
||||
if (testStack == null) continue;
|
||||
|
@ -355,18 +357,18 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
for (Orientations direction : Orientations.dirs()){
|
||||
//Move liquid from input sides to the center
|
||||
if (transferState[direction.ordinal()] != TransferState.Output && maxInput[direction.ordinal()] > 0){
|
||||
|
||||
|
||||
int ammountToDrain = (int) ((double) maxInput[direction.ordinal()] / (double) flowRate / (double) transferInCount * (double) Math.min(flowRate, spaceAvailable));
|
||||
if (ammountToDrain < 1){
|
||||
ammountToDrain++;
|
||||
}
|
||||
|
||||
|
||||
LiquidStack liquidToPush = internalTanks[direction.ordinal()].drain(ammountToDrain, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = internalTanks[Orientations.Unknown.ordinal()].fill(liquidToPush, true);
|
||||
internalTanks[direction.ordinal()].drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,7 +383,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
}
|
||||
if (outputCooldown[o.ordinal()] > 0){
|
||||
outputCooldown[o.ordinal()]--;
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
if (outputTTL[o.ordinal()] <= 0){
|
||||
|
@ -390,7 +392,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
outputTTL[o.ordinal()] = OUTPUT_TTL;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (canReceiveLiquid(o)) {
|
||||
transferState[o.ordinal()] = TransferState.Output;
|
||||
outputCount++;
|
||||
|
@ -433,14 +435,14 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
public boolean allowsConnect(PipeTransport with) {
|
||||
return with instanceof PipeTransportLiquids;
|
||||
}
|
||||
|
||||
|
||||
public void handleLiquidPacket(PacketLiquidUpdate packetLiquid) {
|
||||
this.renderCache = packetLiquid.displayLiquid;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** ITankContainer implementation **/
|
||||
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
return fill(from.ordinal(), resource, doFill);
|
||||
|
@ -449,12 +451,12 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
||||
int filled;
|
||||
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportLiquidsHook)
|
||||
filled = ((IPipeTransportLiquidsHook) this.container.pipe).fill(Orientations.values()[tankIndex], resource, doFill);
|
||||
else
|
||||
filled = internalTanks[tankIndex].fill(resource, doFill);
|
||||
|
||||
|
||||
if (filled > 0 && doFill && tankIndex != Orientations.Unknown.ordinal()){
|
||||
transferState[tankIndex] = TransferState.Input;
|
||||
inputTTL[tankIndex] = INPUT_TTL;
|
||||
|
|
|
@ -70,7 +70,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
|||
return;
|
||||
|
||||
if (liquidToExtract <= BuildCraftAPI.BUCKET_VOLUME)
|
||||
liquidToExtract += powerProvider.useEnergy(1, 1, true) * BuildCraftAPI.BUCKET_VOLUME;
|
||||
liquidToExtract += powerProvider.useEnergy(1, 1, true) * BuildCraftAPI.BUCKET_VOLUME;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,9 +103,12 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
|||
|
||||
LiquidStack extracted = container.drain(pos.orientation.reverse(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
|
||||
|
||||
int inserted = ((PipeTransportLiquids) transport).fill(pos.orientation, extracted, true);
|
||||
int inserted = 0;
|
||||
if(extracted != null) {
|
||||
inserted = ((PipeTransportLiquids) transport).fill(pos.orientation, extracted, true);
|
||||
|
||||
container.drain(pos.orientation.reverse(), inserted, true);
|
||||
container.drain(pos.orientation.reverse(), inserted, true);
|
||||
}
|
||||
|
||||
liquidToExtract -= inserted;
|
||||
}
|
||||
|
@ -116,7 +119,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
|||
public String getTextureFile() {
|
||||
return DefaultProps.TEXTURE_BLOCKS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getTextureIndex(Orientations direction) {
|
||||
if (direction == Orientations.Unknown)
|
||||
|
|
Loading…
Reference in a new issue