Started rewrite of liquid pipes for the new liquid API, will only connect to TEs that implement the new one.
Missing: center pipesection pulling fairly from multiple inputs, bounceback timeout when target tile haven't accepted liquid in a while. Other: Netsync, NBT save, code cleanup, triggers,
This commit is contained in:
parent
d6f5adac9e
commit
0b38427203
13 changed files with 550 additions and 404 deletions
|
@ -28,6 +28,8 @@ import net.minecraft.src.TileEntitySpecialRenderer;
|
|||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.EntityPassiveItem;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ILiquidTank;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.core.RenderEntityBlock;
|
||||
import net.minecraft.src.buildcraft.core.RenderEntityBlock.BlockInterface;
|
||||
|
@ -73,7 +75,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
renderBlocks = new RenderBlocks();
|
||||
}
|
||||
|
||||
private DisplayLiquidList getDisplayLiquidLists(int liquidId, World world) {
|
||||
private DisplayLiquidList getDisplayLiquidLists(int liquidId, int meta, World world) {
|
||||
if (displayLiquidLists.containsKey(liquidId))
|
||||
return displayLiquidLists.get(liquidId);
|
||||
|
||||
|
@ -84,7 +86,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
if (liquidId < Block.blocksList.length && Block.blocksList[liquidId] != null)
|
||||
block.texture = Block.blocksList[liquidId].blockIndexInTexture;
|
||||
else
|
||||
block.texture = Item.itemsList[liquidId].getIconFromDamage(0);
|
||||
block.texture = Item.itemsList[liquidId].getIconFromDamage(meta);
|
||||
|
||||
float size = Utils.pipeMaxPos - Utils.pipeMinPos;
|
||||
|
||||
// render size
|
||||
|
@ -280,14 +283,17 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
|
||||
boolean sides = false, above = false;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
if (liq.getSide(i) > 0) {
|
||||
DisplayLiquidList d = getListFromBuffer(liq.side[i], pipe.worldObj);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
ILiquidTank tank = liq.getTanks()[i];
|
||||
LiquidStack liquid = tank.getLiquid();
|
||||
int amount = liquid != null ? liquid.amount : 0;
|
||||
if ( amount > 0) {
|
||||
DisplayLiquidList d = getListFromBuffer(liquid, pipe.worldObj);
|
||||
|
||||
if (d == null)
|
||||
continue;
|
||||
|
||||
int stage = (int) ((float) liq.getSide(i) / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
int stage = (int) ((float) amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
|
||||
GL11.glPushMatrix();
|
||||
int list = 0;
|
||||
|
@ -315,14 +321,17 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
GL11.glCallList(list);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
// CENTER
|
||||
ILiquidTank tank = liq.getTanks()[Orientations.Unknown.ordinal()];
|
||||
LiquidStack liquid = tank.getLiquid();
|
||||
|
||||
if (liq.getCenter() > 0) {
|
||||
DisplayLiquidList d = getListFromBuffer(liq.center, pipe.worldObj);
|
||||
int amount = liquid != null ? liquid.amount : 0;
|
||||
if ( amount > 0) {
|
||||
DisplayLiquidList d = getListFromBuffer(liq.getTanks()[Orientations.Unknown.ordinal()].getLiquid(), pipe.worldObj);
|
||||
|
||||
if (d != null) {
|
||||
int stage = (int) ((float) liq.getCenter() / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
int stage = (int) ((float) amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
|
||||
if (above)
|
||||
GL11.glCallList(d.centerVertical[stage]);
|
||||
|
@ -337,9 +346,9 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public DisplayLiquidList getListFromBuffer(LiquidBuffer buf, World world) {
|
||||
public DisplayLiquidList getListFromBuffer(LiquidStack stack, World world) {
|
||||
|
||||
int liquidId = buf.liquidId;
|
||||
int liquidId = stack.itemID;
|
||||
|
||||
if (liquidId == 0)
|
||||
return null;
|
||||
|
@ -356,7 +365,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
else
|
||||
MinecraftForgeClient.bindTexture("/terrain.png");
|
||||
|
||||
return getDisplayLiquidLists(liquidId, world);
|
||||
return getDisplayLiquidLists(liquidId, stack.itemMeta, world);
|
||||
}
|
||||
|
||||
private void renderSolids(Pipe pipe, double x, double y, double z) {
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
|
||||
public interface IPipeTransportLiquidsHook {
|
||||
|
||||
public int fill(Orientations from, int quantity, int id, boolean doFill);
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
|
|
|
@ -14,21 +14,16 @@ import net.minecraft.src.BuildCraftCore;
|
|||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NBTTagList;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.mod_BuildCraftTransport;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.ISpecialInventory;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
|
||||
import net.minecraft.src.buildcraft.api.TileNetworkData;
|
||||
import net.minecraft.src.buildcraft.core.CoreProxy;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.core.GuiIds;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketIds;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketNBT;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
||||
import net.minecraft.src.buildcraft.core.network.TilePacketWrapper;
|
||||
import net.minecraft.src.buildcraft.core.utils.SimpleInventory;
|
||||
|
||||
public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
||||
|
|
|
@ -13,9 +13,9 @@ import net.minecraft.src.EntityPlayer;
|
|||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.buildcraft.api.ILiquidContainer;
|
||||
import net.minecraft.src.buildcraft.api.IPipeEntry;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
|
||||
import net.minecraft.src.buildcraft.api.tools.IToolWrench;
|
||||
|
||||
public class PipeLogicIron extends PipeLogic {
|
||||
|
@ -49,7 +49,7 @@ public class PipeLogicIron extends PipeLogic {
|
|||
if (((TileGenericPipe) tile).pipe.logic instanceof PipeLogicWood)
|
||||
continue;
|
||||
|
||||
if (tile instanceof IPipeEntry || tile instanceof IInventory || tile instanceof ILiquidContainer
|
||||
if (tile instanceof IPipeEntry || tile instanceof IInventory || tile instanceof ITankContainer
|
||||
|| tile instanceof TileGenericPipe) {
|
||||
|
||||
worldObj.setBlockMetadata(xCoord, yCoord, zCoord, nextMetadata);
|
||||
|
|
|
@ -16,8 +16,8 @@ import net.minecraft.src.IInventory;
|
|||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.ILiquidContainer;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
|
||||
import net.minecraft.src.buildcraft.api.tools.IToolWrench;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class PipeLogicWood extends PipeLogic {
|
|||
}
|
||||
|
||||
public boolean isInput(TileEntity tile) {
|
||||
return !(tile instanceof TileGenericPipe) && (tile instanceof IInventory || tile instanceof ILiquidContainer)
|
||||
return !(tile instanceof TileGenericPipe) && (tile instanceof IInventory || tile instanceof ITankContainer)
|
||||
&& Utils.checkPipesConnections(container, tile);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,22 +11,22 @@ package net.minecraft.src.buildcraft.transport;
|
|||
|
||||
import net.minecraft.src.BuildCraftCore;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.ILiquidContainer;
|
||||
import net.minecraft.src.buildcraft.api.IPipeEntry;
|
||||
import net.minecraft.src.buildcraft.api.LiquidSlot;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.Position;
|
||||
import net.minecraft.src.buildcraft.api.TileNetworkData;
|
||||
import net.minecraft.src.buildcraft.api.Trigger;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ILiquidTank;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidTank;
|
||||
import net.minecraft.src.buildcraft.core.IMachine;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
|
||||
public class PipeTransportLiquids extends PipeTransport implements ILiquidContainer {
|
||||
public class PipeTransportLiquids extends PipeTransport implements ITankContainer {
|
||||
|
||||
/**
|
||||
* The amount of liquid contained by a pipe section. For simplicity, all
|
||||
|
@ -34,11 +34,79 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
*/
|
||||
public static int LIQUID_IN_PIPE = BuildCraftAPI.BUCKET_VOLUME / 4;
|
||||
|
||||
public int travelDelay = 6;
|
||||
public int flowRate = 20;
|
||||
public short travelDelay = 8;
|
||||
public short flowRate = 20;
|
||||
|
||||
private final PipeSection[] internalTanks = new PipeSection[Orientations.values().length];
|
||||
|
||||
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)
|
||||
private short available;
|
||||
|
||||
public PipeSection() {
|
||||
super(null, PipeTransportLiquids.LIQUID_IN_PIPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(LiquidStack resource, boolean doFill) {
|
||||
int interalAmmount = this.getLiquid() != null ? this.getLiquid().amount : 0;
|
||||
int maxToFill = Math.min(resource.amount, Math.min(flowRate - incomming[currentTime], this.getCapacity() - interalAmmount ));
|
||||
if (maxToFill <= 0) return 0;
|
||||
|
||||
LiquidStack stackToFill = resource.copy();
|
||||
stackToFill.amount = maxToFill;
|
||||
int filled = super.fill(stackToFill, doFill);
|
||||
|
||||
if (doFill) {
|
||||
incomming[currentTime] += filled;
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int maxDrain, boolean doDrain) {
|
||||
int maxToDrain = Math.min(maxDrain, Math.min(flowRate, available));
|
||||
if (maxToDrain < 0) return null;
|
||||
|
||||
LiquidStack drained = super.drain(maxToDrain, doDrain);
|
||||
if (drained == null) return null;
|
||||
|
||||
if (doDrain){
|
||||
available -= drained.amount;
|
||||
}
|
||||
|
||||
return drained;
|
||||
}
|
||||
|
||||
public void moveLiquids() {
|
||||
//Processes the inbound liquid
|
||||
available += incomming[currentTime];
|
||||
incomming[currentTime] = 0;
|
||||
}
|
||||
|
||||
public void setTime(short newTime){
|
||||
currentTime = newTime;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
this.setLiquid(null);
|
||||
available = 0;
|
||||
incomming = new short[travelDelay];
|
||||
|
||||
}
|
||||
|
||||
public int getAvailable(){
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
public class LiquidBuffer {
|
||||
|
||||
short[] in = new short[travelDelay];
|
||||
short ready;
|
||||
short[] out = new short[travelDelay];
|
||||
|
@ -53,7 +121,7 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
|
||||
public int average;
|
||||
@TileNetworkData
|
||||
public short liquidId = 0;
|
||||
public int liquidId = 0;
|
||||
|
||||
int totalBounced = 0;
|
||||
boolean bouncing = false;
|
||||
|
@ -83,7 +151,7 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
emptyTime = 0;
|
||||
}
|
||||
|
||||
public int fill(int toFill, boolean doFill, short liquidId) {
|
||||
public int fill(int toFill, boolean doFill, int liquidId) {
|
||||
if (worldObj == null)
|
||||
return 0;
|
||||
|
||||
|
@ -124,142 +192,140 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
}
|
||||
|
||||
public void update() {
|
||||
bouncing = false;
|
||||
|
||||
int date = (int) (worldObj.getWorldTime() % travelDelay);
|
||||
|
||||
ready += in[date];
|
||||
in[date] = 0;
|
||||
|
||||
if (out[date] != 0) {
|
||||
int extracted = 0;
|
||||
|
||||
if (orientation < 6) {
|
||||
if (isInput[orientation])
|
||||
extracted = center.fill(out[date], true, liquidId);
|
||||
if (isOutput[orientation]) {
|
||||
Position p = new Position(xCoord, yCoord, zCoord, Orientations.values()[orientation]);
|
||||
p.moveForwards(1);
|
||||
|
||||
ILiquidContainer nextPipe = (ILiquidContainer) container.getTile(Orientations.values()[orientation]);
|
||||
extracted = nextPipe.fill(p.orientation.reverse(), out[date], liquidId, true);
|
||||
|
||||
if (extracted == 0) {
|
||||
totalBounced++;
|
||||
|
||||
if (totalBounced > 20)
|
||||
bouncing = true;
|
||||
|
||||
extracted += center.fill(out[date], true, liquidId);
|
||||
} else
|
||||
totalBounced = 0;
|
||||
}
|
||||
} else {
|
||||
int outputNumber = 0;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
if (isOutput[i])
|
||||
outputNumber++;
|
||||
|
||||
filled = new boolean[] { false, false, false, false, false, false };
|
||||
|
||||
// try first, to detect filled outputs
|
||||
extracted = splitLiquid(out[date], outputNumber);
|
||||
|
||||
if (extracted < out[date]) {
|
||||
outputNumber = 0;
|
||||
|
||||
// try a second time, if to split the remaining in non
|
||||
// filled if any
|
||||
for (int i = 0; i < 6; ++i)
|
||||
if (isOutput[i] && !filled[i])
|
||||
outputNumber++;
|
||||
|
||||
extracted += splitLiquid(out[date] - extracted, outputNumber);
|
||||
}
|
||||
}
|
||||
|
||||
qty -= extracted;
|
||||
ready += out[date] - extracted;
|
||||
out[date] = 0;
|
||||
}
|
||||
|
||||
int avgDate = (int) (worldObj.getWorldTime() % lastQty.length);
|
||||
|
||||
lastTotal += qty - lastQty[avgDate];
|
||||
lastQty[avgDate] = qty;
|
||||
|
||||
average = lastTotal / lastQty.length;
|
||||
|
||||
if (qty != 0 && average == 0)
|
||||
average = 1;
|
||||
// bouncing = false;
|
||||
//
|
||||
// int date = (int) (worldObj.getWorldTime() % travelDelay);
|
||||
//
|
||||
// ready += in[date];
|
||||
// in[date] = 0;
|
||||
//
|
||||
// if (out[date] != 0) {
|
||||
// int extracted = 0;
|
||||
//
|
||||
// if (orientation < 6) {
|
||||
// if (isInput[orientation])
|
||||
// extracted = center.fill(out[date], true, liquidId);
|
||||
// if (isOutput[orientation]) {
|
||||
// Position p = new Position(xCoord, yCoord, zCoord, Orientations.values()[orientation]);
|
||||
// p.moveForwards(1);
|
||||
//
|
||||
// ITankContainer nextPipe = (ITankContainer) container.getTile(Orientations.values()[orientation]);
|
||||
// extracted = nextPipe.fill(p.orientation.reverse(), new LiquidStack(out[date], liquidId), true);
|
||||
//
|
||||
// if (extracted == 0) {
|
||||
// totalBounced++;
|
||||
//
|
||||
// if (totalBounced > 20)
|
||||
// bouncing = true;
|
||||
//
|
||||
// extracted += center.fill(out[date], true, liquidId);
|
||||
// } else
|
||||
// totalBounced = 0;
|
||||
// }
|
||||
// } else {
|
||||
// int outputNumber = 0;
|
||||
//
|
||||
// for (int i = 0; i < 6; ++i)
|
||||
// if (isOutput[i])
|
||||
// outputNumber++;
|
||||
//
|
||||
// filled = new boolean[] { false, false, false, false, false, false };
|
||||
//
|
||||
// // try first, to detect filled outputs
|
||||
// extracted = splitLiquid(out[date], outputNumber);
|
||||
//
|
||||
// if (extracted < out[date]) {
|
||||
// outputNumber = 0;
|
||||
//
|
||||
// // try a second time, if to split the remaining in non
|
||||
// // filled if any
|
||||
// for (int i = 0; i < 6; ++i)
|
||||
// if (isOutput[i] && !filled[i])
|
||||
// outputNumber++;
|
||||
//
|
||||
// extracted += splitLiquid(out[date] - extracted, outputNumber);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// qty -= extracted;
|
||||
// ready += out[date] - extracted;
|
||||
// out[date] = 0;
|
||||
// }
|
||||
//
|
||||
// int avgDate = (int) (worldObj.getWorldTime() % lastQty.length);
|
||||
//
|
||||
// lastTotal += qty - lastQty[avgDate];
|
||||
// lastQty[avgDate] = qty;
|
||||
//
|
||||
// average = lastTotal / lastQty.length;
|
||||
//
|
||||
// if (qty != 0 && average == 0)
|
||||
// average = 1;
|
||||
}
|
||||
|
||||
private int splitLiquid(int quantity, int outputNumber) {
|
||||
int extracted = 0;
|
||||
// private int splitLiquid(int quantity, int outputNumber) {
|
||||
// int extracted = 0;
|
||||
//
|
||||
// int slotExtract = (int) Math.ceil(((double) quantity / (double) outputNumber));
|
||||
//
|
||||
// int[] splitVector = getSplitVector(worldObj);
|
||||
//
|
||||
// for (int r = 0; r < 6; ++r) {
|
||||
// int toExtract = slotExtract <= quantity ? slotExtract : quantity;
|
||||
//
|
||||
// int i = splitVector[r];
|
||||
//
|
||||
// if (isOutput[i] && !filled[i]) {
|
||||
// extracted += side[i].fill(toExtract, true, liquidId);
|
||||
// quantity -= toExtract;
|
||||
//
|
||||
// if (extracted != toExtract)
|
||||
// filled[i] = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return extracted;
|
||||
// }
|
||||
|
||||
int slotExtract = (int) Math.ceil(((double) quantity / (double) outputNumber));
|
||||
|
||||
int[] splitVector = getSplitVector(worldObj);
|
||||
|
||||
for (int r = 0; r < 6; ++r) {
|
||||
int toExtract = slotExtract <= quantity ? slotExtract : quantity;
|
||||
|
||||
int i = splitVector[r];
|
||||
|
||||
if (isOutput[i] && !filled[i]) {
|
||||
extracted += side[i].fill(toExtract, true, liquidId);
|
||||
quantity -= toExtract;
|
||||
|
||||
if (extracted != toExtract)
|
||||
filled[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
in[i] = nbttagcompound.getShort("in[" + i + "]");
|
||||
out[i] = nbttagcompound.getShort("out[" + i + "]");
|
||||
}
|
||||
|
||||
ready = nbttagcompound.getShort("ready");
|
||||
qty = nbttagcompound.getShort("qty");
|
||||
liquidId = nbttagcompound.getShort("liquidId");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
nbttagcompound.setShort("in[" + i + "]", in[i]);
|
||||
nbttagcompound.setShort("out[" + i + "]", out[i]);
|
||||
}
|
||||
|
||||
nbttagcompound.setShort("ready", ready);
|
||||
nbttagcompound.setShort("qty", qty);
|
||||
nbttagcompound.setShort("liquidId", liquidId);
|
||||
}
|
||||
// public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
// for (int i = 0; i < travelDelay; ++i) {
|
||||
// in[i] = nbttagcompound.getShort("in[" + i + "]");
|
||||
// out[i] = nbttagcompound.getShort("out[" + i + "]");
|
||||
// }
|
||||
//
|
||||
// ready = nbttagcompound.getShort("ready");
|
||||
// qty = nbttagcompound.getShort("qty");
|
||||
// liquidId = nbttagcompound.getInteger("liquidId");
|
||||
// }
|
||||
//
|
||||
// public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
// for (int i = 0; i < travelDelay; ++i) {
|
||||
// nbttagcompound.setShort("in[" + i + "]", in[i]);
|
||||
// nbttagcompound.setShort("out[" + i + "]", out[i]);
|
||||
// }
|
||||
//
|
||||
// nbttagcompound.setShort("ready", ready);
|
||||
// nbttagcompound.setShort("qty", qty);
|
||||
// nbttagcompound.setInteger("liquidId", liquidId);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public @TileNetworkData(staticSize = 6)
|
||||
LiquidBuffer[] side = new LiquidBuffer[6];
|
||||
public @TileNetworkData
|
||||
LiquidBuffer center;
|
||||
// public @TileNetworkData(staticSize = 6)
|
||||
// LiquidBuffer[] side = new LiquidBuffer[6];
|
||||
// public @TileNetworkData
|
||||
// LiquidBuffer center;
|
||||
|
||||
boolean[] isInput = new boolean[6];
|
||||
boolean[] isInput = new boolean[] { false, false, false, false, false, false, false };
|
||||
|
||||
// Computed at each update
|
||||
boolean isOutput[] = new boolean[] { false, false, false, false, false, false };
|
||||
boolean isOutput[] = new boolean[] { false, false, false, false, false, false, false };
|
||||
|
||||
public PipeTransportLiquids() {
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
side[j] = new LiquidBuffer(j);
|
||||
isInput[j] = false;
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
internalTanks[direction.ordinal()] = new PipeSection();
|
||||
isInput[direction.ordinal()] = false;
|
||||
}
|
||||
|
||||
center = new LiquidBuffer(6);
|
||||
}
|
||||
|
||||
public boolean canReceiveLiquid(Orientations o) {
|
||||
|
@ -271,7 +337,7 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
if (!Utils.checkPipesConnections(container, entity))
|
||||
return false;
|
||||
|
||||
if (entity instanceof IPipeEntry || entity instanceof ILiquidContainer)
|
||||
if (entity instanceof IPipeEntry || entity instanceof ITankContainer)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -287,174 +353,215 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
// @Override
|
||||
// public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
// super.readFromNBT(nbttagcompound);
|
||||
//
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// if (nbttagcompound.hasKey("side[" + i + "]"))
|
||||
// side[i].readFromNBT(nbttagcompound.getCompoundTag("side[" + i + "]"));
|
||||
//
|
||||
// isInput[i] = nbttagcompound.getBoolean("isInput[" + i + "]");
|
||||
// }
|
||||
//
|
||||
// if (nbttagcompound.hasKey("center"))
|
||||
// center.readFromNBT(nbttagcompound.getCompoundTag("center"));
|
||||
//
|
||||
// NBTTagCompound sub = new NBTTagCompound();
|
||||
// center.writeToNBT(sub);
|
||||
// nbttagcompound.setTag("center", sub);
|
||||
// }
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if (nbttagcompound.hasKey("side[" + i + "]"))
|
||||
side[i].readFromNBT(nbttagcompound.getCompoundTag("side[" + i + "]"));
|
||||
|
||||
isInput[i] = nbttagcompound.getBoolean("isInput[" + i + "]");
|
||||
}
|
||||
|
||||
if (nbttagcompound.hasKey("center"))
|
||||
center.readFromNBT(nbttagcompound.getCompoundTag("center"));
|
||||
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
center.writeToNBT(sub);
|
||||
nbttagcompound.setTag("center", sub);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
side[i].writeToNBT(sub);
|
||||
nbttagcompound.setTag("side[" + i + "]", sub);
|
||||
|
||||
nbttagcompound.setBoolean("isInput[" + i + "]", isInput[i]);
|
||||
}
|
||||
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
center.writeToNBT(sub);
|
||||
nbttagcompound.setTag("center", sub);
|
||||
}
|
||||
|
||||
protected void doWork() {}
|
||||
// @Override
|
||||
// public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
// super.writeToNBT(nbttagcompound);
|
||||
//
|
||||
// for (int i = 0; i < 6; ++i) {
|
||||
// NBTTagCompound sub = new NBTTagCompound();
|
||||
// side[i].writeToNBT(sub);
|
||||
// nbttagcompound.setTag("side[" + i + "]", sub);
|
||||
//
|
||||
// nbttagcompound.setBoolean("isInput[" + i + "]", isInput[i]);
|
||||
// }
|
||||
//
|
||||
// NBTTagCompound sub = new NBTTagCompound();
|
||||
// center.writeToNBT(sub);
|
||||
// nbttagcompound.setTag("center", sub);
|
||||
// }
|
||||
|
||||
public void onDropped(EntityItem item) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the pipe, and return the amount of liquid that has been used.
|
||||
*/
|
||||
@Override
|
||||
public int fill(Orientations from, int quantity, int id, boolean doFill) {
|
||||
isInput[from.ordinal()] = true;
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportLiquidsHook)
|
||||
return ((IPipeTransportLiquidsHook) this.container.pipe).fill(from, quantity, id, doFill);
|
||||
else
|
||||
return side[from.ordinal()].fill(quantity, doFill, (short) id);
|
||||
}
|
||||
|
||||
int lockedTime = 0;
|
||||
|
||||
private void moveLiquids() {
|
||||
isOutput = new boolean[] { false, false, false, false, false, false };
|
||||
short newTimeSlot = (short) (worldObj.getWorldTime() % travelDelay);
|
||||
|
||||
//Processes all internal tanks
|
||||
for (Orientations direction : Orientations.values()){
|
||||
internalTanks[direction.ordinal()].setTime(newTimeSlot);
|
||||
internalTanks[direction.ordinal()].moveLiquids();
|
||||
}
|
||||
|
||||
|
||||
short outputCount = computeOutputs();
|
||||
|
||||
int outputNumber = computeOutputs();
|
||||
|
||||
if (outputNumber == 0)
|
||||
if (outputCount == 0) {
|
||||
lockedTime++;
|
||||
else
|
||||
} else {
|
||||
lockedTime = 0;
|
||||
}
|
||||
|
||||
//If enough time has passed, previous input sides are now valid destinations
|
||||
if (lockedTime > 20) {
|
||||
for (int i = 0; i < 6; ++i)
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
isInput[i] = false;
|
||||
|
||||
outputNumber = computeOutputs();
|
||||
}
|
||||
outputCount = computeOutputs();
|
||||
}
|
||||
|
||||
int[] rndIt = getSplitVector(worldObj);
|
||||
|
||||
for (int r = 0; r < 6; ++r) {
|
||||
int i = rndIt[r];
|
||||
|
||||
side[i].empty(flowRate);
|
||||
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
if (!container.pipe.outputOpen(direction)) continue;
|
||||
//TODO: Grab equally from all non output sides
|
||||
|
||||
//Move liquid from non output sides to the center
|
||||
if (!isOutput[direction.ordinal()]){
|
||||
LiquidStack liquidToPush = internalTanks[direction.ordinal()].drain(flowRate, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = internalTanks[Orientations.Unknown.ordinal()].fill(liquidToPush, true);
|
||||
internalTanks[direction.ordinal()].drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] maxOutput = new int[] {0,0,0,0,0,0};
|
||||
|
||||
center.empty(flowRate);
|
||||
|
||||
// APPLY SCHEDULED FILLED ORDERS
|
||||
|
||||
center.update();
|
||||
|
||||
for (int r = 0; r < 6; ++r) {
|
||||
int i = rndIt[r];
|
||||
|
||||
side[i].update();
|
||||
|
||||
if (side[i].qty != 0)
|
||||
side[i].emptyTime = 0;
|
||||
|
||||
if (side[i].bouncing)
|
||||
isInput[i] = true;
|
||||
else if (side[i].qty == 0)
|
||||
side[i].emptyTime++;
|
||||
|
||||
if (side[i].emptyTime > 20)
|
||||
isInput[i] = false;
|
||||
int transferCount = 0;
|
||||
LiquidStack pushStack = internalTanks[Orientations.Unknown.ordinal()].getLiquid();
|
||||
int totalAvailable = internalTanks[Orientations.Unknown.ordinal()].getAvailable();
|
||||
if (pushStack != null){
|
||||
LiquidStack testStack = pushStack.copy();
|
||||
testStack.amount = flowRate;
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
if (!isOutput[direction.ordinal()]) continue;
|
||||
|
||||
maxOutput[direction.ordinal()] = internalTanks[direction.ordinal()].fill(testStack, false);
|
||||
if(maxOutput[direction.ordinal()] > 0){
|
||||
transferCount++;
|
||||
}
|
||||
}
|
||||
//Move liquid from the center to the output sides
|
||||
for (Orientations direction : Orientations.dirs()) {
|
||||
if (!container.pipe.outputOpen(direction)) continue;
|
||||
if (isOutput[direction.ordinal()]) {
|
||||
if (maxOutput[direction.ordinal()] == 0) continue;
|
||||
int ammountToPush = (int) ((double) maxOutput[direction.ordinal()] / (double) flowRate / (double) transferCount * (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);
|
||||
internalTanks[Orientations.Unknown.ordinal()].drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Move liquid from the non-center to the connected output blocks
|
||||
if (outputCount > 0){
|
||||
for (Orientations o : Orientations.dirs()){
|
||||
if (isOutput[o.ordinal()]){
|
||||
TileEntity target = this.container.getTile(o);
|
||||
if (!(target instanceof ITankContainer)) continue;
|
||||
|
||||
LiquidStack liquidToPush = internalTanks[o.ordinal()].drain(flowRate, false);
|
||||
if (liquidToPush != null) {
|
||||
int filled = ((ITankContainer)target).fill(o.reverse(), liquidToPush, true);
|
||||
internalTanks[o.ordinal()].drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// int[] rndIt = getSplitVector(worldObj);
|
||||
//
|
||||
// for (int r = 0; r < 6; ++r) {
|
||||
// int i = rndIt[r];
|
||||
//
|
||||
// side[i].empty(flowRate);
|
||||
// }
|
||||
//
|
||||
// center.empty(flowRate);
|
||||
//
|
||||
// // APPLY SCHEDULED FILLED ORDERS
|
||||
//
|
||||
// center.update();
|
||||
//
|
||||
// for (int r = 0; r < 6; ++r) {
|
||||
// int i = rndIt[r];
|
||||
//
|
||||
// side[i].update();
|
||||
//
|
||||
// if (side[i].qty != 0)
|
||||
// side[i].emptyTime = 0;
|
||||
//
|
||||
// if (side[i].bouncing)
|
||||
// isInput[i] = true;
|
||||
// else if (side[i].qty == 0)
|
||||
// side[i].emptyTime++;
|
||||
//
|
||||
// if (side[i].emptyTime > 20)
|
||||
// isInput[i] = false;
|
||||
// }
|
||||
}
|
||||
|
||||
private int computeOutputs() {
|
||||
int outputNumber = 0;
|
||||
private short computeOutputs() {
|
||||
short outputCount = 0;
|
||||
|
||||
for (Orientations o : Orientations.dirs()) {
|
||||
isOutput[o.ordinal()] = container.pipe.outputOpen(o) && canReceiveLiquid(o) && !isInput[o.ordinal()];
|
||||
|
||||
if (isOutput[o.ordinal()])
|
||||
outputNumber++;
|
||||
if (isOutput[o.ordinal()]){
|
||||
outputCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return outputNumber;
|
||||
return outputCount;
|
||||
}
|
||||
|
||||
public int getSide(int orientation) {
|
||||
if (side[orientation].average > LIQUID_IN_PIPE)
|
||||
return LIQUID_IN_PIPE;
|
||||
else
|
||||
return side[orientation].average;
|
||||
}
|
||||
|
||||
public int getCenter() {
|
||||
if (center.average > LIQUID_IN_PIPE)
|
||||
return LIQUID_IN_PIPE;
|
||||
else
|
||||
return center.average;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLiquidQuantity() {
|
||||
int total = center.qty;
|
||||
|
||||
for (LiquidBuffer b : side)
|
||||
total += b.qty;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int empty(int quantityMax, boolean doEmpty) {
|
||||
return 0;
|
||||
}
|
||||
// public int getSide(int orientation) {
|
||||
// if (side[orientation].average > LIQUID_IN_PIPE)
|
||||
// return LIQUID_IN_PIPE;
|
||||
// else
|
||||
// return side[orientation].average;
|
||||
// }
|
||||
//
|
||||
// public int getCenter() {
|
||||
// if (center.average > LIQUID_IN_PIPE)
|
||||
// return LIQUID_IN_PIPE;
|
||||
// else
|
||||
// return center.average;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(int blockId) {
|
||||
super.onNeighborBlockChange(blockId);
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[i]), container))
|
||||
side[i].reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLiquidId() {
|
||||
return center.liquidId;
|
||||
for (int i = 0; i < 6; ++i){
|
||||
if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[i]), container)) {
|
||||
internalTanks[i].reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPipeConnected(TileEntity tile) {
|
||||
if (tile instanceof ILiquidContainer) {
|
||||
ILiquidContainer liq = (ILiquidContainer) tile;
|
||||
if (tile instanceof ITankContainer) {
|
||||
ITankContainer liq = (ITankContainer) tile;
|
||||
|
||||
if (liq.getLiquidSlots() != null && liq.getLiquidSlots().length > 0)
|
||||
if (liq.getTanks() != null && liq.getTanks().length > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -492,14 +599,41 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidSlot[] getLiquidSlots() {
|
||||
return new LiquidSlot[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsConnect(PipeTransport with) {
|
||||
return with instanceof PipeTransportLiquids;
|
||||
}
|
||||
|
||||
/** ITankContainer implementation **/
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
return fill(from.ordinal(), resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
||||
isInput[tankIndex] = true;
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportLiquidsHook)
|
||||
return ((IPipeTransportLiquidsHook) this.container.pipe).fill(Orientations.values()[tankIndex], resource, doFill);
|
||||
else
|
||||
return internalTanks[tankIndex].fill(resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(Orientations from, int maxDrain, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank[] getTanks() {
|
||||
return internalTanks;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.src.BuildCraftCore;
|
||||
import net.minecraft.src.BuildCraftTransport;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
@ -34,9 +32,11 @@ import net.minecraft.src.buildcraft.api.Position;
|
|||
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
|
||||
import net.minecraft.src.buildcraft.api.TileNetworkData;
|
||||
import net.minecraft.src.buildcraft.api.Trigger;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ILiquidTank;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.api.power.IPowerProvider;
|
||||
import net.minecraft.src.buildcraft.api.power.IPowerReceptor;
|
||||
import net.minecraft.src.buildcraft.api.power.PowerProvider;
|
||||
import net.minecraft.src.buildcraft.core.CoreProxy;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.core.IDropControlInventory;
|
||||
|
@ -49,7 +49,7 @@ import net.minecraft.src.buildcraft.core.network.PacketPipeDescription;
|
|||
import net.minecraft.src.buildcraft.core.network.PacketTileUpdate;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
||||
|
||||
public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiquidContainer, IPipeEntry,
|
||||
public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITankContainer, IPipeEntry,
|
||||
IPipeTile, ISynchronizedTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory {
|
||||
|
||||
public TileBuffer[] tileBuffer;
|
||||
|
@ -220,38 +220,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
((IPowerReceptor) pipe).doWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, int quantity, int id, boolean doFill) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ILiquidContainer)
|
||||
return ((ILiquidContainer) pipe.transport).fill(from, quantity, id, doFill);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int empty(int quantityMax, boolean doEmpty) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ILiquidContainer)
|
||||
return ((ILiquidContainer) pipe.transport).empty(quantityMax, doEmpty);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLiquidQuantity() {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ILiquidContainer)
|
||||
return ((ILiquidContainer) pipe.transport).getLiquidQuantity();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLiquidId() {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ILiquidContainer)
|
||||
return ((ILiquidContainer) pipe.transport).getLiquidId();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void scheduleNeighborChange() {
|
||||
blockNeighborChange = true;
|
||||
}
|
||||
|
@ -338,11 +306,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidSlot[] getLiquidSlots() {
|
||||
return new LiquidSlot[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blockRemoved(Orientations from) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -431,4 +394,47 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** ITankContainer implementation **/
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
|
||||
return ((ITankContainer) pipe.transport).fill(from, resource, doFill);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
|
||||
return ((ITankContainer) pipe.transport).fill(tankIndex, resource, doFill);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(Orientations from, int maxDrain, boolean doDrain) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
|
||||
return ((ITankContainer) pipe.transport).drain(from, maxDrain, doDrain);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
|
||||
return ((ITankContainer) pipe.transport).drain(tankIndex, maxDrain, doDrain);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank[] getTanks() {
|
||||
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
|
||||
return ((ITankContainer) pipe.transport).getTanks();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.Trigger;
|
||||
import net.minecraft.src.buildcraft.api.TriggerParameter;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
|
||||
|
@ -74,60 +73,61 @@ public class TriggerPipeContents extends Trigger implements ITriggerPipe {
|
|||
|
||||
@Override
|
||||
public boolean isTriggerActive(Pipe pipe, TriggerParameter parameter) {
|
||||
if (pipe.transport instanceof PipeTransportItems) {
|
||||
PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
|
||||
|
||||
if (kind == Kind.Empty)
|
||||
return transportItems.travelingEntities.isEmpty();
|
||||
else if (kind == Kind.ContainsItems)
|
||||
if (parameter != null && parameter.getItem() != null) {
|
||||
for (EntityData data : transportItems.travelingEntities.values())
|
||||
if (data.item.item.itemID == parameter.getItem().itemID
|
||||
&& data.item.item.getItemDamage() == parameter.getItem().getItemDamage())
|
||||
return true;
|
||||
} else
|
||||
return !transportItems.travelingEntities.isEmpty();
|
||||
} else if (pipe.transport instanceof PipeTransportLiquids) {
|
||||
PipeTransportLiquids transportLiquids = (PipeTransportLiquids) pipe.transport;
|
||||
|
||||
int seachedLiquidId = 0;
|
||||
|
||||
if (parameter != null && parameter.getItem() != null)
|
||||
seachedLiquidId = LiquidManager.getLiquidIDForFilledItem(parameter.getItem());
|
||||
|
||||
if (kind == Kind.Empty) {
|
||||
for (LiquidBuffer b : transportLiquids.side)
|
||||
if (b.average != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
for (LiquidBuffer b : transportLiquids.side)
|
||||
if (b.average != 0)
|
||||
if (seachedLiquidId == 0 || b.liquidId == seachedLiquidId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} else if (pipe.transport instanceof PipeTransportPower) {
|
||||
PipeTransportPower transportPower = (PipeTransportPower) pipe.transport;
|
||||
|
||||
if (kind == Kind.Empty) {
|
||||
for (short s : transportPower.displayPower)
|
||||
if (s != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
for (short s : transportPower.displayPower)
|
||||
if (s != 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// if (pipe.transport instanceof PipeTransportItems) {
|
||||
// PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
|
||||
//
|
||||
// if (kind == Kind.Empty)
|
||||
// return transportItems.travelingEntities.isEmpty();
|
||||
// else if (kind == Kind.ContainsItems)
|
||||
// if (parameter != null && parameter.getItem() != null) {
|
||||
// for (EntityData data : transportItems.travelingEntities.values())
|
||||
// if (data.item.item.itemID == parameter.getItem().itemID
|
||||
// && data.item.item.getItemDamage() == parameter.getItem().getItemDamage())
|
||||
// return true;
|
||||
// } else
|
||||
// return !transportItems.travelingEntities.isEmpty();
|
||||
// } else if (pipe.transport instanceof PipeTransportLiquids) {
|
||||
// PipeTransportLiquids transportLiquids = (PipeTransportLiquids) pipe.transport;
|
||||
//
|
||||
// int seachedLiquidId = 0;
|
||||
//
|
||||
// if (parameter != null && parameter.getItem() != null)
|
||||
// seachedLiquidId = LiquidManager.getLiquidIDForFilledItem(parameter.getItem());
|
||||
//
|
||||
// if (kind == Kind.Empty) {
|
||||
// for (LiquidBuffer b : transportLiquids.side)
|
||||
// if (b.average != 0)
|
||||
// return false;
|
||||
//
|
||||
// return true;
|
||||
// } else {
|
||||
// for (LiquidBuffer b : transportLiquids.side)
|
||||
// if (b.average != 0)
|
||||
// if (seachedLiquidId == 0 || b.liquidId == seachedLiquidId)
|
||||
// return true;
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
// } else if (pipe.transport instanceof PipeTransportPower) {
|
||||
// PipeTransportPower transportPower = (PipeTransportPower) pipe.transport;
|
||||
//
|
||||
// if (kind == Kind.Empty) {
|
||||
// for (short s : transportPower.displayPower)
|
||||
// if (s != 0)
|
||||
// return false;
|
||||
//
|
||||
// return true;
|
||||
// } else {
|
||||
// for (short s : transportPower.displayPower)
|
||||
// if (s != 0)
|
||||
// return true;
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,7 @@ public class PipeLiquidsGold extends Pipe {
|
|||
super(new PipeTransportLiquids(), new PipeLogicGold(), itemID);
|
||||
|
||||
((PipeTransportLiquids) transport).flowRate = 80;
|
||||
((PipeTransportLiquids) transport).travelDelay = 2;
|
||||
((PipeTransportLiquids) transport).travelDelay = 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
package net.minecraft.src.buildcraft.transport.pipes;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.transport.IPipeTransportLiquidsHook;
|
||||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicSandstone;
|
||||
|
@ -27,13 +28,13 @@ public class PipeLiquidsSandstone extends Pipe implements IPipeTransportLiquidsH
|
|||
}
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, int quantity, int id, boolean doFill) {
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
if (container.tileBuffer == null || container.tileBuffer[from.ordinal()] == null)
|
||||
return 0;
|
||||
|
||||
if (!(container.tileBuffer[from.ordinal()].getTile() instanceof TileGenericPipe))
|
||||
return 0;
|
||||
|
||||
return ((PipeTransportLiquids)this.transport).side[from.ordinal()].fill(quantity, doFill, (short) id);
|
||||
return ((PipeTransportLiquids)this.transport).getTanks()[from.ordinal()].fill(resource, doFill);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
package net.minecraft.src.buildcraft.transport.pipes;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.transport.IPipeTransportLiquidsHook;
|
||||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicVoid;
|
||||
|
@ -27,7 +28,7 @@ public class PipeLiquidsVoid extends Pipe implements IPipeTransportLiquidsHook{
|
|||
}
|
||||
|
||||
@Override
|
||||
public int fill(Orientations from, int quantity, int id, boolean doFill) {
|
||||
return quantity;
|
||||
public int fill(Orientations from, LiquidStack resource, boolean doFill) {
|
||||
return resource.amount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import net.minecraft.src.Block;
|
|||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.ILiquidContainer;
|
||||
import net.minecraft.src.buildcraft.api.Orientations;
|
||||
import net.minecraft.src.buildcraft.api.Position;
|
||||
import net.minecraft.src.buildcraft.api.TileNetworkData;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ITankContainer;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.api.power.IPowerProvider;
|
||||
import net.minecraft.src.buildcraft.api.power.IPowerReceptor;
|
||||
import net.minecraft.src.buildcraft.api.power.PowerFramework;
|
||||
import net.minecraft.src.buildcraft.api.power.PowerProvider;
|
||||
import net.minecraft.src.buildcraft.transport.Pipe;
|
||||
import net.minecraft.src.buildcraft.transport.PipeLogicWood;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportLiquids;
|
||||
|
@ -65,11 +65,11 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
|||
int blockId = w.getBlockId((int) pos.x, (int) pos.y, (int) pos.z);
|
||||
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||
|
||||
if (tile == null || !(tile instanceof ILiquidContainer)
|
||||
if (tile == null || !(tile instanceof ITankContainer)
|
||||
|| PipeLogicWood.isExcludedFromExtraction(Block.blocksList[blockId]))
|
||||
return;
|
||||
|
||||
if (tile instanceof ILiquidContainer)
|
||||
if (tile instanceof ITankContainer)
|
||||
if (liquidToExtract <= BuildCraftAPI.BUCKET_VOLUME)
|
||||
liquidToExtract += powerProvider.useEnergy(1, 1, true) * BuildCraftAPI.BUCKET_VOLUME;
|
||||
}
|
||||
|
@ -96,18 +96,18 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
|
|||
|
||||
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||
|
||||
if (tile instanceof ILiquidContainer) {
|
||||
ILiquidContainer container = (ILiquidContainer) tile;
|
||||
if (tile instanceof ITankContainer) {
|
||||
ITankContainer container = (ITankContainer) tile;
|
||||
|
||||
int flowRate = ((PipeTransportLiquids) transport).flowRate;
|
||||
|
||||
int extracted = container.empty(liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
|
||||
LiquidStack extracted = container.drain(pos.orientation.reverse(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
|
||||
|
||||
extracted = ((PipeTransportLiquids) transport).fill(pos.orientation, extracted, container.getLiquidId(), true);
|
||||
int inserted = ((PipeTransportLiquids) transport).fill(pos.orientation, extracted, true);
|
||||
|
||||
container.empty(extracted, true);
|
||||
container.drain(pos.orientation.reverse(), inserted, true);
|
||||
|
||||
liquidToExtract -= extracted;
|
||||
liquidToExtract -= inserted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue