Merge branch 'master' of github.com:SirSengir/BuildCraft
This commit is contained in:
commit
81b5004112
15 changed files with 507 additions and 518 deletions
|
@ -28,11 +28,12 @@ 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;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportLiquids.LiquidBuffer;
|
||||
import net.minecraft.src.forge.ForgeHooksClient;
|
||||
import net.minecraft.src.forge.IItemRenderer;
|
||||
import net.minecraft.src.forge.IItemRenderer.ItemRenderType;
|
||||
|
@ -61,7 +62,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
public int[] centerVertical = new int[displayLiquidStages];
|
||||
}
|
||||
|
||||
private HashMap<Integer, DisplayLiquidList> displayLiquidLists = new HashMap<Integer, DisplayLiquidList>();
|
||||
private HashMap<Integer, HashMap<Integer, DisplayLiquidList>> displayLiquidLists = new HashMap<Integer, HashMap<Integer, DisplayLiquidList>>();
|
||||
|
||||
|
||||
private final int[] angleY = { 0, 0, 270, 90, 0, 180 };
|
||||
private final int[] angleZ = { 90, 270, 0, 0, 0, 0 };
|
||||
|
@ -77,18 +79,26 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
renderBlocks = new RenderBlocks();
|
||||
}
|
||||
|
||||
private DisplayLiquidList getDisplayLiquidLists(int liquidId, World world) {
|
||||
if (displayLiquidLists.containsKey(liquidId))
|
||||
return displayLiquidLists.get(liquidId);
|
||||
private DisplayLiquidList getDisplayLiquidLists(int liquidId, int meta, World world) {
|
||||
if (displayLiquidLists.containsKey(liquidId)){
|
||||
HashMap<Integer, DisplayLiquidList> x = displayLiquidLists.get(liquidId);
|
||||
if (x.containsKey(meta)){
|
||||
return x.get(meta);
|
||||
}
|
||||
} else {
|
||||
displayLiquidLists.put(liquidId, new HashMap<Integer, DisplayLiquidList>());
|
||||
}
|
||||
|
||||
|
||||
DisplayLiquidList d = new DisplayLiquidList();
|
||||
displayLiquidLists.put(liquidId, d);
|
||||
displayLiquidLists.get(liquidId).put(meta, d);
|
||||
|
||||
BlockInterface block = new BlockInterface();
|
||||
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
|
||||
|
@ -288,14 +298,20 @@ 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();
|
||||
LiquidStack liquid = liq.renderCache[i];
|
||||
//int amount = liquid != null ? liquid.amount : 0;
|
||||
//int amount = liquid != null ? liq.renderAmmount[i] : 0;
|
||||
|
||||
if ( liquid != null && liquid.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) liquid.amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
|
||||
GL11.glPushMatrix();
|
||||
int list = 0;
|
||||
|
@ -323,14 +339,20 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
GL11.glCallList(list);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
// CENTER
|
||||
// ILiquidTank tank = liq.getTanks()[Orientations.Unknown.ordinal()];
|
||||
// LiquidStack liquid = tank.getLiquid();
|
||||
LiquidStack liquid = liq.renderCache[Orientations.Unknown.ordinal()];
|
||||
|
||||
if (liq.getCenter() > 0) {
|
||||
DisplayLiquidList d = getListFromBuffer(liq.center, pipe.worldObj);
|
||||
//int amount = liquid != null ? liquid.amount : 0;
|
||||
//int amount = liquid != null ? liq.renderAmmount[Orientations.Unknown.ordinal()] : 0;
|
||||
if (liquid != null && liquid.amount > 0) {
|
||||
//DisplayLiquidList d = getListFromBuffer(liq.getTanks()[Orientations.Unknown.ordinal()].getLiquid(), pipe.worldObj);
|
||||
DisplayLiquidList d = getListFromBuffer(liquid, pipe.worldObj);
|
||||
|
||||
if (d != null) {
|
||||
int stage = (int) ((float) liq.getCenter() / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
int stage = (int) ((float) liquid.amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
|
||||
|
||||
if (above)
|
||||
GL11.glCallList(d.centerVertical[stage]);
|
||||
|
@ -345,9 +367,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;
|
||||
|
@ -363,7 +385,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
|
|||
// and if o is null, something else is wrong somewhere
|
||||
MinecraftForgeClient.bindTexture(((ITextureProvider) o).getTextureFile());
|
||||
|
||||
return getDisplayLiquidLists(liquidId, world);
|
||||
return getDisplayLiquidLists(liquidId, stack.itemMeta, world);
|
||||
}
|
||||
|
||||
private void renderSolids(Pipe pipe, double x, double y, double z) {
|
||||
|
|
|
@ -14,8 +14,6 @@ public class LiquidStack {
|
|||
public int amount;
|
||||
public int itemMeta;
|
||||
|
||||
public NBTTagCompound stackTagCompound;
|
||||
|
||||
private LiquidStack() {
|
||||
}
|
||||
|
||||
|
@ -41,8 +39,6 @@ public class LiquidStack {
|
|||
nbttagcompound.setShort("Id", (short) itemID);
|
||||
nbttagcompound.setInteger("Amount", amount);
|
||||
nbttagcompound.setShort("Meta", (short) itemMeta);
|
||||
if (stackTagCompound != null)
|
||||
nbttagcompound.setTag("Tag", stackTagCompound);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
|
@ -50,35 +46,13 @@ public class LiquidStack {
|
|||
itemID = nbttagcompound.getShort("Id");
|
||||
amount = nbttagcompound.getInteger("Amount");
|
||||
itemMeta = nbttagcompound.getShort("Meta");
|
||||
if (nbttagcompound.hasKey("Tag"))
|
||||
stackTagCompound = nbttagcompound.getCompoundTag("tag");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of this LiquidStack
|
||||
*/
|
||||
public LiquidStack copy() {
|
||||
LiquidStack copy = new LiquidStack(itemID, amount, itemMeta);
|
||||
if (stackTagCompound != null) {
|
||||
copy.stackTagCompound = (NBTTagCompound) stackTagCompound.copy();
|
||||
if (!copy.stackTagCompound.equals(stackTagCompound))
|
||||
return copy;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NBTTagCompound associated with this LiquidStack
|
||||
*/
|
||||
public NBTTagCompound getTagCompound() {
|
||||
return stackTagCompound;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nbttagcompound Sets the NBTTagCompound on this LiquidStack
|
||||
*/
|
||||
public void setTagCompound(NBTTagCompound nbttagcompound) {
|
||||
stackTagCompound = nbttagcompound;
|
||||
return new LiquidStack(itemID, amount, itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,5 +106,4 @@ public class LiquidStack {
|
|||
liquidstack.readFromNBT(nbttagcompound);
|
||||
return liquidstack.itemID == 0 ? null : liquidstack;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,14 @@ import net.minecraft.src.buildcraft.api.TileNetworkData;
|
|||
import net.minecraft.src.buildcraft.api.recipes.AssemblyRecipe;
|
||||
import net.minecraft.src.buildcraft.core.CoreProxy;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.core.IMachine;
|
||||
import net.minecraft.src.buildcraft.core.StackUtil;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketIds;
|
||||
import net.minecraft.src.buildcraft.core.network.PacketUpdate;
|
||||
import net.minecraft.src.buildcraft.core.network.TilePacketWrapper;
|
||||
|
||||
public class TileAssemblyTable extends TileEntity implements IInventory, IPipeConnection {
|
||||
public class TileAssemblyTable extends TileEntity implements IMachine, IInventory, IPipeConnection {
|
||||
|
||||
ItemStack[] items = new ItemStack[12];
|
||||
|
||||
|
@ -433,4 +434,24 @@ public class TileAssemblyTable extends TileEntity implements IInventory, IPipeCo
|
|||
iCrafting.updateCraftingInventoryInfo(container, 1, (int) energyStored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return currentRecipe != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageLiquids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageSolids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowActions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,10 +16,12 @@ 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;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeLiquidsVoid;
|
||||
import net.minecraft.src.buildcraft.transport.pipes.PipeLiquidsWood;
|
||||
|
||||
public class PipeLogicWood extends PipeLogic {
|
||||
|
||||
|
@ -49,7 +51,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);
|
||||
}
|
||||
|
||||
|
@ -118,4 +120,13 @@ public class PipeLogicWood extends PipeLogic {
|
|||
if (!APIProxy.isClient(worldObj))
|
||||
switchSourceIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(Orientations to) {
|
||||
if (this.container.pipe instanceof PipeLiquidsWood){
|
||||
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
return meta != to.ordinal();
|
||||
}
|
||||
return super.outputOpen(to);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,268 +10,159 @@
|
|||
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.gates.ITrigger;
|
||||
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 {
|
||||
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
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){
|
||||
all -= slot;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compoundTag) {
|
||||
this.setCapacity(compoundTag.getInteger("capacity"));
|
||||
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
incomming[i] = compoundTag.getShort("in[" + i + "]");
|
||||
}
|
||||
setLiquid(LiquidStack.loadLiquidStackFromNBT(compoundTag));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public enum TransferState {
|
||||
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.
|
||||
*/
|
||||
public static int LIQUID_IN_PIPE = BuildCraftAPI.BUCKET_VOLUME / 4;
|
||||
public static short INPUT_TTL = 60; //100
|
||||
public static short OUTPUT_TTL = 80; //80
|
||||
public static short OUTPUT_COOLDOWN = 30; //30
|
||||
|
||||
|
||||
public int travelDelay = 6;
|
||||
public int flowRate = 20;
|
||||
|
||||
public class LiquidBuffer {
|
||||
|
||||
short[] in = new short[travelDelay];
|
||||
short ready;
|
||||
short[] out = new short[travelDelay];
|
||||
short qty;
|
||||
int orientation;
|
||||
|
||||
short[] lastQty = new short[100];
|
||||
int lastTotal = 0;
|
||||
|
||||
int emptyTime = 0;
|
||||
|
||||
@TileNetworkData(intKind = TileNetworkData.UNSIGNED_BYTE)
|
||||
public int average;
|
||||
@TileNetworkData
|
||||
public short liquidId = 0;
|
||||
|
||||
int totalBounced = 0;
|
||||
boolean bouncing = false;
|
||||
|
||||
private boolean[] filled;
|
||||
|
||||
public LiquidBuffer(int o) {
|
||||
this.orientation = o;
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (int i = 0; i < travelDelay; ++i) {
|
||||
in[i] = 0;
|
||||
out[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lastQty.length; ++i)
|
||||
lastQty[i] = 0;
|
||||
|
||||
ready = 0;
|
||||
qty = 0;
|
||||
liquidId = 0;
|
||||
lastTotal = 0;
|
||||
totalBounced = 0;
|
||||
emptyTime = 0;
|
||||
}
|
||||
|
||||
public int fill(int toFill, boolean doFill, short liquidId) {
|
||||
if (worldObj == null)
|
||||
return 0;
|
||||
|
||||
if (qty > 0 && this.liquidId != liquidId && this.liquidId != 0)
|
||||
return 0;
|
||||
|
||||
if (this.liquidId != liquidId)
|
||||
reset();
|
||||
|
||||
this.liquidId = liquidId;
|
||||
|
||||
int date = (int) (worldObj.getWorldTime() % travelDelay);
|
||||
int newDate = date > 0 ? date - 1 : travelDelay - 1;
|
||||
|
||||
if (qty + toFill > LIQUID_IN_PIPE + flowRate)
|
||||
toFill = LIQUID_IN_PIPE + flowRate - qty;
|
||||
|
||||
if (doFill) {
|
||||
qty += toFill;
|
||||
in[newDate] += toFill;
|
||||
}
|
||||
|
||||
return toFill;
|
||||
}
|
||||
|
||||
public int empty(int toEmpty) {
|
||||
int date = (int) (worldObj.getWorldTime() % travelDelay);
|
||||
int newDate = date > 0 ? date - 1 : travelDelay - 1;
|
||||
|
||||
if (ready - toEmpty < 0)
|
||||
toEmpty = ready;
|
||||
|
||||
ready -= toEmpty;
|
||||
|
||||
out[newDate] += toEmpty;
|
||||
|
||||
return toEmpty;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 @TileNetworkData(staticSize = 6)
|
||||
LiquidBuffer[] side = new LiquidBuffer[6];
|
||||
public @TileNetworkData
|
||||
LiquidBuffer center;
|
||||
|
||||
boolean[] isInput = new boolean[6];
|
||||
|
||||
// Computed at each update
|
||||
boolean isOutput[] = new boolean[] { false, false, false, false, false, false };
|
||||
|
||||
public short travelDelay = 12;
|
||||
public short flowRate = 20;
|
||||
public final 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 };
|
||||
|
||||
|
||||
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();
|
||||
if (direction != Orientations.Unknown){
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
}
|
||||
}
|
||||
|
||||
center = new LiquidBuffer(6);
|
||||
}
|
||||
|
||||
public boolean canReceiveLiquid(Orientations o) {
|
||||
TileEntity entity = container.getTile(o);
|
||||
|
||||
if (isInput[o.ordinal()])
|
||||
return false;
|
||||
|
||||
if (!Utils.checkPipesConnections(container, entity))
|
||||
return false;
|
||||
|
||||
if (entity instanceof TileGenericPipe){
|
||||
if (!((TileGenericPipe)entity).pipe.inputOpen(o.reverse())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof IPipeEntry || entity instanceof ILiquidContainer)
|
||||
if (entity instanceof IPipeEntry || entity instanceof ITankContainer)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -283,6 +174,35 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
return;
|
||||
|
||||
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();
|
||||
} else {
|
||||
renderCache[direction.ordinal()].itemID = liquid.itemID;
|
||||
renderCache[direction.ordinal()].itemMeta = liquid.itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
if (renderCache[direction.ordinal()] != null){
|
||||
int currentLiquid = liquid != null ? liquid.amount : 0;
|
||||
renderCache[direction.ordinal()].amount = (short) Math.min(LIQUID_IN_PIPE, ((renderCache[direction.ordinal()].amount * 9 + currentLiquid) / 10));
|
||||
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);
|
||||
}
|
||||
|
||||
//Uncomment to disable the renderstate and show actual values
|
||||
// renderCache[direction.ordinal()] = internalTanks[direction.ordinal()].getLiquid();
|
||||
// if (renderCache[direction.ordinal()] != null){
|
||||
// renderCache[direction.ordinal()] = renderCache[direction.ordinal()].copy();
|
||||
// }
|
||||
}
|
||||
|
||||
this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor);
|
||||
}
|
||||
|
@ -291,215 +211,247 @@ public class PipeTransportLiquids extends PipeTransport implements ILiquidContai
|
|||
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 + "]");
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
if (nbttagcompound.hasKey("tank[" + direction.ordinal() + "]")){
|
||||
internalTanks[direction.ordinal()].readFromNBT(nbttagcompound.getCompoundTag("tank[" + direction.ordinal() + "]"));
|
||||
}
|
||||
if (direction != Orientations.Unknown){
|
||||
transferState[direction.ordinal()] = TransferState.values()[nbttagcompound.getShort("transferState[" + direction.ordinal() + "]")];
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
for (Orientations direction : Orientations.values()) {
|
||||
NBTTagCompound subTag = new NBTTagCompound();
|
||||
internalTanks[direction.ordinal()].writeToNBT(subTag);
|
||||
nbttagcompound.setTag("tank[" + direction.ordinal() + "]", subTag);
|
||||
if (direction != Orientations.Unknown){
|
||||
nbttagcompound.setShort("transferState[" + direction.ordinal() + "]", (short)transferState[direction.ordinal()].ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
center.writeToNBT(sub);
|
||||
nbttagcompound.setTag("center", sub);
|
||||
}
|
||||
|
||||
protected void doWork() {}
|
||||
|
||||
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 };
|
||||
|
||||
int outputNumber = computeOutputs();
|
||||
|
||||
if (outputNumber == 0)
|
||||
lockedTime++;
|
||||
else
|
||||
lockedTime = 0;
|
||||
|
||||
if (lockedTime > 20) {
|
||||
for (int i = 0; i < 6; ++i)
|
||||
isInput[i] = false;
|
||||
|
||||
outputNumber = computeOutputs();
|
||||
short newTimeSlot = (short) (worldObj.getWorldTime() % travelDelay);
|
||||
|
||||
//Processes all internal tanks
|
||||
for (Orientations direction : Orientations.values()){
|
||||
internalTanks[direction.ordinal()].setTime(newTimeSlot);
|
||||
internalTanks[direction.ordinal()].moveLiquids();
|
||||
|
||||
}
|
||||
|
||||
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 (transferState[direction.ordinal()] == TransferState.Input){
|
||||
if ((inputTTL[direction.ordinal()]--) < 1){
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
short outputCount = computeOutputs();
|
||||
moveFromPipe(outputCount);
|
||||
moveFromCenter();
|
||||
moveToCenter();
|
||||
}
|
||||
|
||||
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 void moveFromPipe(short outputCount) {
|
||||
//Move liquid from the non-center to the connected output blocks
|
||||
if (outputCount > 0){
|
||||
for (Orientations o : Orientations.dirs()){
|
||||
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);
|
||||
internalTanks[o.ordinal()].drain(filled, true);
|
||||
if (filled <= 0){
|
||||
outputTTL[o.ordinal()]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int computeOutputs() {
|
||||
int outputNumber = 0;
|
||||
private void moveFromCenter() {
|
||||
//Split liquids moving to output equally based on flowrate, how much each side can accept and available liquid
|
||||
int[] maxOutput = new int[] {0,0,0,0,0,0};
|
||||
int transferOutCount = 0;
|
||||
LiquidStack pushStack = internalTanks[Orientations.Unknown.ordinal()].getLiquid();
|
||||
int totalAvailable = internalTanks[Orientations.Unknown.ordinal()].getAvailable();
|
||||
if (totalAvailable < 1) return;
|
||||
if (pushStack != null){
|
||||
LiquidStack testStack = pushStack.copy();
|
||||
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++;
|
||||
}
|
||||
}
|
||||
if (transferOutCount <= 0) return;
|
||||
//Move liquid from the center to the output sides
|
||||
for (Orientations direction : Orientations.dirs()) {
|
||||
if (transferState[direction.ordinal()] == TransferState.Output) {
|
||||
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);
|
||||
internalTanks[Orientations.Unknown.ordinal()].drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveToCenter() {
|
||||
int [] maxInput = new int[] {0,0,0,0,0,0};
|
||||
int transferInCount = 0;
|
||||
LiquidStack stackInCenter = internalTanks[Orientations.Unknown.ordinal()].drain(flowRate, false);
|
||||
int spaceAvailable = internalTanks[Orientations.Unknown.ordinal()].getCapacity();
|
||||
if (stackInCenter != null){
|
||||
spaceAvailable -= stackInCenter.amount;
|
||||
}
|
||||
|
||||
|
||||
for (Orientations direction : Orientations.dirs()){
|
||||
LiquidStack testStack = internalTanks[direction.ordinal()].drain(flowRate, false);
|
||||
if (testStack == null) continue;
|
||||
if (stackInCenter != null && !stackInCenter.isLiquidEqual(testStack)) continue;
|
||||
maxInput[direction.ordinal()] = testStack.amount;
|
||||
transferInCount++;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (transferState[o.ordinal()] == TransferState.Input) continue;
|
||||
if (!container.pipe.outputOpen(o)){
|
||||
transferState[o.ordinal()] = TransferState.None;
|
||||
continue;
|
||||
}
|
||||
if (outputCooldown[o.ordinal()] > 0){
|
||||
outputCooldown[o.ordinal()]--;
|
||||
|
||||
continue;
|
||||
}
|
||||
if (outputTTL[o.ordinal()] <= 0){
|
||||
transferState[o.ordinal()] = TransferState.None;
|
||||
outputCooldown[o.ordinal()] = OUTPUT_COOLDOWN;
|
||||
outputTTL[o.ordinal()] = OUTPUT_TTL;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (canReceiveLiquid(o)) {
|
||||
transferState[o.ordinal()] = TransferState.Output;
|
||||
outputCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return outputNumber;
|
||||
}
|
||||
|
||||
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;
|
||||
return outputCount;
|
||||
}
|
||||
|
||||
@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 (Orientations direction : Orientations.dirs()){
|
||||
if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[direction.ordinal()]), container)) {
|
||||
internalTanks[direction.ordinal()].reset();
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
renderCache[direction.ordinal()] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
return tile instanceof TileGenericPipe || (tile instanceof IMachine && ((IMachine) tile).manageLiquids());
|
||||
}
|
||||
|
||||
private static long lastSplit = -1;
|
||||
|
||||
private static int[] splitVector;
|
||||
|
||||
public static int[] getSplitVector(World worldObj) {
|
||||
if (lastSplit == worldObj.getWorldTime())
|
||||
return splitVector;
|
||||
|
||||
lastSplit = worldObj.getWorldTime();
|
||||
|
||||
splitVector = new int[6];
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
splitVector[i] = i;
|
||||
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
int a = worldObj.rand.nextInt(6);
|
||||
int b = worldObj.rand.nextInt(6);
|
||||
|
||||
int tmp = splitVector[a];
|
||||
splitVector[a] = splitVector[b];
|
||||
splitVector[b] = tmp;
|
||||
}
|
||||
|
||||
return splitVector;
|
||||
}
|
||||
|
||||
public boolean isTriggerActive(ITrigger trigger) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -35,9 +33,11 @@ import net.minecraft.src.buildcraft.api.TileNetworkData;
|
|||
import net.minecraft.src.buildcraft.api.gates.IOverrideDefaultTriggers;
|
||||
import net.minecraft.src.buildcraft.api.gates.ITrigger;
|
||||
import net.minecraft.src.buildcraft.api.gates.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;
|
||||
|
@ -50,7 +50,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;
|
||||
|
@ -121,7 +121,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
bindPipe();
|
||||
if (pipe != null) {
|
||||
pipe.validate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean initialized = false;
|
||||
|
@ -227,38 +227,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;
|
||||
}
|
||||
|
@ -345,11 +313,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
|
||||
|
@ -445,4 +408,47 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
pipe.onChunkUnload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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,12 +9,12 @@
|
|||
|
||||
package net.minecraft.src.buildcraft.transport;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.gates.ITriggerParameter;
|
||||
import net.minecraft.src.buildcraft.api.gates.Trigger;
|
||||
import net.minecraft.src.buildcraft.api.liquids.ILiquidTank;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.transport.PipeTransportLiquids.LiquidBuffer;
|
||||
|
||||
public class TriggerPipeContents extends Trigger implements ITriggerPipe {
|
||||
|
||||
|
@ -90,21 +90,21 @@ public class TriggerPipeContents extends Trigger implements ITriggerPipe {
|
|||
} else if (pipe.transport instanceof PipeTransportLiquids) {
|
||||
PipeTransportLiquids transportLiquids = (PipeTransportLiquids) pipe.transport;
|
||||
|
||||
int seachedLiquidId = 0;
|
||||
LiquidStack searchedLiquid = null;
|
||||
|
||||
if (parameter != null && parameter.getItem() != null)
|
||||
seachedLiquidId = LiquidManager.getLiquidIDForFilledItem(parameter.getItem());
|
||||
searchedLiquid = LiquidManager.getLiquidForFilledItem(parameter.getItem());
|
||||
|
||||
if (kind == Kind.Empty) {
|
||||
for (LiquidBuffer b : transportLiquids.side)
|
||||
if (b.average != 0)
|
||||
for (ILiquidTank b : transportLiquids.getTanks())
|
||||
if (b.getLiquid() != null && b.getLiquid().amount != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
for (LiquidBuffer b : transportLiquids.side)
|
||||
if (b.average != 0)
|
||||
if (seachedLiquidId == 0 || b.liquidId == seachedLiquidId)
|
||||
for (ILiquidTank b : transportLiquids.getTanks())
|
||||
if (b.getLiquid() != null && b.getLiquid().amount != 0)
|
||||
if (searchedLiquid == null || searchedLiquid.isLiquidEqual(b.getLiquid()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -103,6 +103,8 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
|
|||
IInventory inventory = (IInventory) tile;
|
||||
|
||||
ItemStack[] extracted = checkExtract(inventory, true, pos.orientation.reverse());
|
||||
if (extracted == null)
|
||||
return;
|
||||
|
||||
for(ItemStack stack : extracted) {
|
||||
if (stack == null || stack.stackSize == 0) {
|
||||
|
|
|
@ -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