Fixed tank network
This commit is contained in:
parent
b7c711f8c5
commit
67df03b32e
6 changed files with 84 additions and 78 deletions
|
@ -25,18 +25,10 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
public FluidNetwork(IFluidPart... parts)
|
||||
{
|
||||
this();
|
||||
for (IFluidPart part : parts)
|
||||
{
|
||||
this.addConnector(part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
System.out.println("Rebuilding network");
|
||||
if (this.reloadTanks)
|
||||
{
|
||||
this.reloadTanks();
|
||||
|
@ -44,6 +36,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
this.tank = new FluidTank(0);
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
part.setNetwork(this);
|
||||
this.buildPart(part);
|
||||
}
|
||||
this.rebuildTank();
|
||||
|
@ -65,7 +58,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
{
|
||||
this.tank.getFluid().amount += tank.getFluidAmount();
|
||||
}
|
||||
else if (tank.getFluid() != null)
|
||||
else if (this.tank.getFluid() != null)
|
||||
{
|
||||
//TODO cause a mixing event
|
||||
}
|
||||
|
@ -88,6 +81,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
@Override
|
||||
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
System.out.println("Filling network tank");
|
||||
int prev = this.getTank().getFluidAmount();
|
||||
int fill = this.getTank().fill(resource, doFill);
|
||||
if (prev != this.getTank().getFluid().amount)
|
||||
|
@ -100,6 +94,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
System.out.println("Draining network tank");
|
||||
if (resource != null && resource.isFluidEqual(this.getTank().getFluid()))
|
||||
{
|
||||
FluidStack before = this.getTank().getFluid();
|
||||
|
@ -153,15 +148,22 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
|
||||
public void reloadTanks()
|
||||
{
|
||||
FluidStack stack = this.getTank().getFluid().copy();
|
||||
this.reloadTanks = false;
|
||||
System.out.println("Reloading fluids");
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
|
||||
if (stack != null)
|
||||
{
|
||||
int parts = this.getConnectors().size();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
stack = stack.copy();
|
||||
}
|
||||
int parts = this.getConnectors().size();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (stack != null)
|
||||
{
|
||||
int fillPer = stack.amount / parts;
|
||||
part.getInternalTank().setFluid(null);
|
||||
part.getInternalTank().fill(FluidHelper.getStack(stack, fillPer), true);
|
||||
part.onFluidChanged();
|
||||
if (parts > 1)
|
||||
|
@ -174,7 +176,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
public IFluidNetwork merge(IFluidNetwork network)
|
||||
{
|
||||
FluidNetwork newNetwork = null;
|
||||
if (network != null && network.getClass().equals(this.getClass()) && network != this)
|
||||
if (network != null && network.getClass().isAssignableFrom(this.getClass()) && network != this)
|
||||
{
|
||||
|
||||
try
|
||||
|
@ -306,4 +308,10 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
return tankInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString() + " Vol:" + this.tank.getFluidAmount();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
package resonantinduction.mechanical.fluid.pipe;
|
||||
|
||||
import resonantinduction.api.fluid.IFluidPipe;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
|
||||
/** @author DarkGuardsman */
|
||||
public class PipeNetwork extends FluidNetwork
|
||||
{
|
||||
//TODO implements pressure for future hydraulic machines
|
||||
public PipeNetwork()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public PipeNetwork(IFluidPipe... pipes)
|
||||
{
|
||||
super(pipes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -99,9 +99,10 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip
|
|||
@Override
|
||||
public PipeNetwork getNetwork()
|
||||
{
|
||||
if (!(this.network instanceof PipeNetwork))
|
||||
if (this.network == null)
|
||||
{
|
||||
this.setNetwork(new PipeNetwork(this));
|
||||
this.network = new PipeNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return (PipeNetwork) this.network;
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip
|
|||
public void onWrongPressure(ForgeDirection side, int pressure)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -236,7 +236,8 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar
|
|||
{
|
||||
if (this.network != null)
|
||||
{
|
||||
this.network = new FluidNetwork(this);
|
||||
this.network = new FluidNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return this.network;
|
||||
}
|
||||
|
|
|
@ -14,20 +14,11 @@ import calclavia.lib.utility.FluidHelper;
|
|||
* @author DarkGuardsman */
|
||||
public class TankNetwork extends FluidNetwork
|
||||
{
|
||||
public TankNetwork()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public TankNetwork(TileTank... tanks)
|
||||
{
|
||||
super(tanks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadTanks()
|
||||
{
|
||||
FluidStack fillStack = this.getTank().getFluid().copy();
|
||||
FluidStack fillStack = this.getTank().getFluid();
|
||||
int lowestY = 255, highestY = 0;
|
||||
|
||||
if (fillStack == null || fillStack.getFluid().isGaseous())
|
||||
|
@ -36,6 +27,7 @@ public class TankNetwork extends FluidNetwork
|
|||
}
|
||||
else if (this.getNodes().size() > 0)
|
||||
{
|
||||
fillStack = fillStack.copy();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
|
|
|
@ -1,53 +1,66 @@
|
|||
package resonantinduction.mechanical.fluid.tank;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.api.IReadOut;
|
||||
import resonantinduction.api.fluid.IFluidNetwork;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
|
||||
|
||||
public class TileTank extends TileFluidNetwork
|
||||
public class TileTank extends TileFluidNetwork implements IReadOut
|
||||
{
|
||||
public static final int VOLUME = 16;
|
||||
public static final int VOLUME = 16;
|
||||
|
||||
public TileTank()
|
||||
{
|
||||
super(VOLUME);
|
||||
}
|
||||
public TileTank()
|
||||
{
|
||||
super(VOLUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankNetwork getNetwork()
|
||||
{
|
||||
if (!(this.network instanceof TankNetwork))
|
||||
{
|
||||
this.setNetwork(new TankNetwork(this));
|
||||
}
|
||||
return (TankNetwork) this.network;
|
||||
}
|
||||
@Override
|
||||
public TankNetwork getNetwork()
|
||||
{
|
||||
if (this.network == null)
|
||||
{
|
||||
this.network = new TankNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return (TankNetwork) this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IFluidNetwork network)
|
||||
{
|
||||
if (network instanceof TankNetwork)
|
||||
{
|
||||
this.network = (TankNetwork) network;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setNetwork(IFluidNetwork network)
|
||||
{
|
||||
if (network instanceof TankNetwork)
|
||||
{
|
||||
this.network = (TankNetwork) network;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (tileEntity instanceof TileTank)
|
||||
{
|
||||
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
|
||||
{
|
||||
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
|
||||
this.setRenderSide(side, true);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (tileEntity instanceof TileTank)
|
||||
{
|
||||
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
|
||||
{
|
||||
this.getNetwork().merge(((IFluidPart) tileEntity).getNetwork());
|
||||
this.setRenderSide(side, true);
|
||||
connectedBlocks[side.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
if (tool == EnumTools.PIPE_GUAGE)
|
||||
{
|
||||
return this.getNetwork().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue