Fixed liquid junction issue

Closes #336
This commit is contained in:
CovertJaguar 2012-12-09 13:53:31 -08:00
parent 5886faecc4
commit 9a465cff69
3 changed files with 38 additions and 30 deletions

View file

@ -9,18 +9,7 @@
package buildcraft.transport;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import cpw.mods.fml.common.network.PacketDispatcher;
import buildcraft.BuildCraftTransport;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.Position;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.inventory.ISpecialInventory;
@ -34,7 +23,14 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketPipeTransportContent;
import cpw.mods.fml.common.network.PacketDispatcher;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import net.minecraft.src.EntityItem;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
@ -42,6 +38,7 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.Packet;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeTransportItems extends PipeTransport {
@ -165,10 +162,11 @@ public class PipeTransportItems extends PipeTransport {
data.blacklist.add(data.input.getOpposite());
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS)
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (!data.blacklist.contains(o) && container.pipe.outputOpen(o))
if (canReceivePipeObjects(o, data.item))
result.add(o);
}
if (result.size() == 0 && allowBouncing) {
if (canReceivePipeObjects(data.input.getOpposite(), data.item))
@ -345,7 +343,7 @@ public class PipeTransportItems extends PipeTransport {
NBTTagList nbttaglist = nbt.getTagList("travelingEntities");
for (int j = 0; j < nbttaglist.tagCount(); ++j)
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
try {
NBTTagCompound dataTag = (NBTTagCompound) nbttaglist.tagAt(j);
@ -370,6 +368,7 @@ public class PipeTransportItems extends PipeTransport {
// two versions - ignore these errors.
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
@ -403,7 +402,7 @@ public class PipeTransportItems extends PipeTransport {
EntityData data = travelingEntities.remove(packet.getEntityId());
IPipedItem item = null;
IPipedItem item;
if(data == null) {
item = EntityPassiveItem.getOrCreate(worldObj, packet.getEntityId());
} else {

View file

@ -137,13 +137,15 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
public byte initClient = 0;
public short travelDelay = 12;
public short flowRate = 20;
public short flowRate = 10;
public LiquidStack[] renderCache = new LiquidStack[orientations.length];
private final PipeSection[] internalTanks = new PipeSection[orientations.length];
private final TransferState[] transferState = new TransferState[directions.length];
private final int[] inputPerTick = new int[directions.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 };
@ -358,7 +360,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
}
private void moveToCenter() {
int [] maxInput = new int[] {0,0,0,0,0,0};
int transferInCount = 0;
LiquidStack stackInCenter = internalTanks[ForgeDirection.UNKNOWN.ordinal()].drain(flowRate, false);
int spaceAvailable = internalTanks[ForgeDirection.UNKNOWN.ordinal()].getCapacity();
@ -367,27 +368,35 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
}
for (ForgeDirection direction : directions){
LiquidStack testStack = internalTanks[direction.ordinal()].drain(flowRate, false);
if (testStack == null) continue;
if (stackInCenter != null && !stackInCenter.isLiquidEqual(testStack)) continue;
maxInput[direction.ordinal()] = testStack.amount;
for (ForgeDirection dir : directions) {
inputPerTick[dir.ordinal()] = 0;
if (transferState[dir.ordinal()] == TransferState.Output) {
continue;
}
LiquidStack testStack = internalTanks[dir.ordinal()].drain(flowRate, false);
if (testStack == null) {
continue;
}
if (stackInCenter != null && !stackInCenter.isLiquidEqual(testStack)) {
continue;
}
inputPerTick[dir.ordinal()] = testStack.amount;
transferInCount++;
}
for (ForgeDirection direction : directions){
for (ForgeDirection dir : directions) {
//Move liquid from input sides to the center
if (transferState[direction.ordinal()] != TransferState.Output && maxInput[direction.ordinal()] > 0){
if (transferState[dir.ordinal()] != TransferState.Output && inputPerTick[dir.ordinal()] > 0) {
int ammountToDrain = (int) ((double) maxInput[direction.ordinal()] / (double) flowRate / (double) transferInCount * (double) Math.min(flowRate, spaceAvailable));
if (ammountToDrain < 1){
int ammountToDrain = (int) ((double) inputPerTick[dir.ordinal()] / (double) flowRate / (double) transferInCount * (double) Math.min(flowRate, spaceAvailable));
if (ammountToDrain < 1) {
ammountToDrain++;
}
LiquidStack liquidToPush = internalTanks[direction.ordinal()].drain(ammountToDrain, false);
LiquidStack liquidToPush = internalTanks[dir.ordinal()].drain(ammountToDrain, false);
if (liquidToPush != null) {
int filled = internalTanks[ForgeDirection.UNKNOWN.ordinal()].fill(liquidToPush, true);
internalTanks[direction.ordinal()].drain(filled, true);
internalTanks[dir.ordinal()].drain(filled, true);
}
}
}

View file

@ -8,17 +8,17 @@
package buildcraft.transport.pipes;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.core.DefaultProps;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportLiquids;
import net.minecraftforge.common.ForgeDirection;
public class PipeLiquidsGold extends Pipe {
public PipeLiquidsGold(int itemID) {
super(new PipeTransportLiquids(), new PipeLogicGold(), itemID);
((PipeTransportLiquids) transport).flowRate = 80;
((PipeTransportLiquids) transport).flowRate = 40;
((PipeTransportLiquids) transport).travelDelay = 4;
}