diff --git a/src/dark/api/fluid/INetworkFluidPart.java b/src/dark/api/fluid/INetworkFluidPart.java index b1a09ee7..566c4d7c 100644 --- a/src/dark/api/fluid/INetworkFluidPart.java +++ b/src/dark/api/fluid/INetworkFluidPart.java @@ -1,16 +1,24 @@ package dark.api.fluid; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidTank; import dark.api.parts.INetworkPart; import dark.core.interfaces.ColorCode.IColorCoded; +import dark.core.prefab.helpers.Pair; public interface INetworkFluidPart extends IColorCoded, IFluidHandler, INetworkPart { + /** Gets an array of the fluid the tank can take */ + public int getNumberOfTanks(); + /** Gets the part's main tank for shared storage */ - public IFluidTank getTank(); + public IFluidTank getTank(int index); /** Sets the content of the part's main tank */ - public void setTankContent(FluidStack stack); + public int fillTankContent(int index, FluidStack stack, boolean doFill); + + public FluidStack drainTankContent(int index, int volume, boolean doDrain); } diff --git a/src/dark/core/network/fluid/NetworkFluidTiles.java b/src/dark/core/network/fluid/NetworkFluidTiles.java index 5cab228d..cf9d35cc 100644 --- a/src/dark/core/network/fluid/NetworkFluidTiles.java +++ b/src/dark/core/network/fluid/NetworkFluidTiles.java @@ -23,6 +23,7 @@ import dark.api.fluid.AdvancedFluidEvent.FluidMergeEvent; import dark.api.fluid.INetworkFluidPart; import dark.api.parts.INetworkPart; import dark.core.interfaces.ColorCode; +import dark.core.prefab.FluidSelectiveTank; import dark.core.prefab.helpers.FluidHelper; import dark.core.prefab.helpers.Pair; import dark.core.prefab.tilenetwork.NetworkTileEntities; @@ -132,7 +133,7 @@ public class NetworkFluidTiles extends NetworkTileEntities if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0) { //TODO change this to percent based system so tiles get volume that they can store - int volume = this.combinedStorage().getFluid().amount / this.networkMember.size(); + int vol = this.combinedStorage().getFluid().amount; int fluid = this.combinedStorage().getFluid().fluidID; NBTTagCompound tag = this.combinedStorage().getFluid().tag; @@ -140,9 +141,27 @@ public class NetworkFluidTiles extends NetworkTileEntities { if (par instanceof INetworkFluidPart) { + int fillVolume = this.combinedStorage().getFluid().amount / this.networkMember.size(); INetworkFluidPart part = ((INetworkFluidPart) par); - part.setTankContent(null); - part.setTankContent(new FluidStack(fluid, volume, tag)); + for (int tank = 0; tank < part.getNumberOfTanks(); tank++) + { + if (part.getTank(tank) != null) + { + if (part.getTank(tank) instanceof FluidSelectiveTank) + { + if (((FluidSelectiveTank) part.getTank(tank)).canAcceptFluid(FluidRegistry.getFluid(fluid))) + { + part.drainTankContent(tank, Integer.MAX_VALUE, true); + vol -= part.fillTankContent(tank, new FluidStack(fluid, fillVolume, tag), true); + } + } + else + { + part.setTankContent(tank, null); + part.setTankContent(tank, new FluidStack(fluid, volume, tag)); + } + } + } } } } diff --git a/src/dark/fluid/common/machines/TileEntityBoiler.java b/src/dark/fluid/common/machines/TileEntityBoiler.java index 89c5dc1e..d70bebf8 100644 --- a/src/dark/fluid/common/machines/TileEntityBoiler.java +++ b/src/dark/fluid/common/machines/TileEntityBoiler.java @@ -1,5 +1,7 @@ package dark.fluid.common.machines; +import java.util.List; + import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -7,11 +9,13 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.IFluidTank; +import dark.api.fluid.INetworkFluidPart; import dark.core.interfaces.ColorCode; -import dark.core.interfaces.ColorCode.IColorCoded; +import dark.core.prefab.tilenetwork.NetworkTileEntities; import dark.fluid.common.prefab.TileEntityFluidDevice; -public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHandler +public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHandler, INetworkFluidPart { public TileEntity[] connectedBlocks = new TileEntity[6]; @@ -70,7 +74,11 @@ public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHan @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - if(from == ForgeDirection.DOWN) + if (from == ForgeDirection.DOWN) + { + + } + else { } @@ -91,4 +99,87 @@ public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHan return null; } + @Override + public ColorCode getColor() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setColor(Object obj) + { + // TODO Auto-generated method stub + + } + + @Override + public List getNetworkConnections() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void refresh() + { + // TODO Auto-generated method stub + + } + + @Override + public NetworkTileEntities getTileNetwork() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setTileNetwork(NetworkTileEntities fluidNetwok) + { + // TODO Auto-generated method stub + + } + + @Override + public boolean mergeDamage(String result) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public IFluidTank getTank(int index) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public int fillTankContent(int index, FluidStack stack, boolean doFill) + { + if (this.getTank(index) != null) + { + return this.getTank(index).fill(stack, doFill); + } + return 0; + + } + + @Override + public FluidStack drainTankContent(int index, int volume, boolean doDrain) + { + if (this.getTank(index) != null) + { + return this.getTank(index).drain(volume, doDrain); + } + return null; + } + + @Override + public int getNumberOfTanks() + { + return 2; + } + } diff --git a/src/dark/fluid/common/machines/TileEntityTank.java b/src/dark/fluid/common/machines/TileEntityTank.java index ba209d53..d2fe0fe9 100644 --- a/src/dark/fluid/common/machines/TileEntityTank.java +++ b/src/dark/fluid/common/machines/TileEntityTank.java @@ -95,7 +95,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand { if (id == 0) { - this.getTank().setFluid(FluidStack.loadFluidStackFromNBT( PacketHandler.instance().readNBTTagCompound(dataStream))); + this.getTank().setFluid(FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(dataStream))); } else { @@ -126,7 +126,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand { stack = this.getTank().getFluid(); } - return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, stack != null ? 0 : 1, stack != null ? stack.writeToNBT(new NBTTagCompound()) : 1, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); + return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, stack != null ? 0 : 1, stack != null ? stack.writeToNBT(new NBTTagCompound()) : 1, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); } /** gets the current color mark of the pipe */ @@ -294,9 +294,23 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand } @Override - public void setTankContent(FluidStack stack) + public int fillTankContent(int index, FluidStack stack, boolean doFill) { - this.getTank().setFluid(stack); + if (this.getTank() != null) + { + return this.getTank().fill(stack, doFill); + } + return 0; + } + + @Override + public FluidStack drainTankContent(int index, int volume, boolean doDrain) + { + if (this.getTank(index) != null) + { + return this.getTank(index).drain(volume, doDrain); + } + return null; } public int getRedstoneLevel() @@ -332,4 +346,16 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand { return false; } + + @Override + public int getNumberOfTanks() + { + return 1; + } + + @Override + public IFluidTank getTank(int index) + { + return this.getTank(); + } } diff --git a/src/dark/fluid/common/pipes/BlockPipe.java b/src/dark/fluid/common/pipes/BlockPipe.java index d1addfd8..a427b777 100644 --- a/src/dark/fluid/common/pipes/BlockPipe.java +++ b/src/dark/fluid/common/pipes/BlockPipe.java @@ -116,7 +116,7 @@ public class BlockPipe extends BlockFM TileEntity entity = world.getBlockTileEntity(x, y, z); if (entity instanceof TileEntityPipe) { - IFluidTank tank = ((TileEntityPipe) entity).getTank(); + IFluidTank tank = ((TileEntityPipe) entity).getTank(0); if (tank != null && tank.getFluid() != null && tank.getFluid().getFluid() != null && tank.getFluid().amount > 0) { if (tank.getFluid().getFluid().getName().equalsIgnoreCase("water")) diff --git a/src/dark/fluid/common/pipes/TileEntityPipe.java b/src/dark/fluid/common/pipes/TileEntityPipe.java index 5a9ec98a..3285dd7f 100644 --- a/src/dark/fluid/common/pipes/TileEntityPipe.java +++ b/src/dark/fluid/common/pipes/TileEntityPipe.java @@ -130,7 +130,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, ((TileEntity) extention).updateEntity(); if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null) { - Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_UPDATE.ordinal(), ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote)); + Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_UPDATE.ordinal(), ForgeDirection.getOrientation(i), extention.getExtentionPacketData(!this.worldObj.isRemote)); PacketHandler.instance().sendPacketToClients(packet, worldObj, new Vector3(this), 50); } } @@ -170,7 +170,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, { System.out.println("Handling Packet for Pipe addon"); int side = dataStream.readInt(); - NBTTagCompound tag = PacketHandler.instance().readNBTTagCompound(dataStream); + NBTTagCompound tag = PacketHandler.instance().readNBTTagCompound(dataStream); this.loadOrCreateSubTile(side, tag); } @@ -194,7 +194,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, @Override public Packet getDescriptionPacket() { - return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); + return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.PIPE_CONNECTIONS.ordinal(), this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]); } /** Reads a tile entity from NBT. */ @@ -317,7 +317,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, if (tag != null && tag.hasKey("id")) { System.out.println("Sending TileEntity to Client"); - Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_CREATE.ordinal(), ForgeDirection.getOrientation(side), tag); + Packet packet = PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, PacketID.EXTENTION_CREATE.ordinal(), ForgeDirection.getOrientation(side), tag); PacketHandler.instance().sendPacketToClients(packet, this.worldObj, new Vector3(this), 50); } } @@ -414,7 +414,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, @Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { - return new FluidTankInfo[] { new FluidTankInfo(this.getTank()) }; + return new FluidTankInfo[] { new FluidTankInfo(this.getTank(0)) }; } /** Checks to make sure the connection is valid to the tileEntity @@ -567,7 +567,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, } @Override - public FluidTank getTank() + public FluidTank getTank(int index) { if (this.fakeTank == null) { @@ -577,9 +577,23 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, } @Override - public void setTankContent(FluidStack stack) + public int fillTankContent(int index, FluidStack stack, boolean doFill) { - this.getTank().setFluid(stack); + if (this.getTank(index) != null) + { + return this.getTank(index).fill(stack, doFill); + } + return 0; + } + + @Override + public FluidStack drainTankContent(int index, int volume, boolean doDrain) + { + if (this.getTank(index) != null) + { + return this.getTank(index).drain(volume, doDrain); + } + return null; } @Override @@ -609,4 +623,10 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, return false; } + @Override + public int getNumberOfTanks() + { + return 1; + } + }