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