Settup fluid network building
This commit is contained in:
parent
c5335008ec
commit
1438e5eda7
3 changed files with 73 additions and 13 deletions
|
@ -10,19 +10,24 @@ import resonantinduction.api.fluid.IFluidPart;
|
|||
import universalelectricity.api.net.IConnector;
|
||||
import universalelectricity.core.net.ConnectionPathfinder;
|
||||
import universalelectricity.core.net.Network;
|
||||
import universalelectricity.core.net.NetworkTickHandler;
|
||||
import calclavia.lib.utility.FluidHelper;
|
||||
|
||||
public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork
|
||||
{
|
||||
protected FluidTank tank;
|
||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||
protected boolean loadPart = false;
|
||||
protected long ticks = 0;
|
||||
|
||||
public FluidNetwork()
|
||||
{
|
||||
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
public FluidNetwork(IFluidPart... parts)
|
||||
{
|
||||
this();
|
||||
for (IFluidPart part : parts)
|
||||
{
|
||||
this.addConnector(part);
|
||||
|
@ -32,8 +37,32 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
this.tank = new FluidTank(0);
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
this.buildPart(part);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildPart(IFluidPart part)
|
||||
{
|
||||
FluidTank tank = part.getInternalTank();
|
||||
if (tank != null)
|
||||
{
|
||||
this.tank.setCapacity(this.tank.getCapacity() + tank.getCapacity());
|
||||
if (this.tank.getFluid() == null)
|
||||
{
|
||||
this.tank.setFluid(tank.getFluid());
|
||||
}
|
||||
else if (this.tank.getFluid().isFluidEqual(tank.getFluid()))
|
||||
{
|
||||
this.tank.getFluid().amount += tank.getFluidAmount();
|
||||
}
|
||||
else if (tank.getFluid() != null)
|
||||
{
|
||||
//TODO cause a mixing event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rebuildTank()
|
||||
|
@ -51,8 +80,13 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
@Override
|
||||
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
int prev = this.getTank().getFluidAmount();
|
||||
int fill = this.getTank().fill(resource, doFill);
|
||||
if (prev != fill)
|
||||
{
|
||||
this.loadPart = true;
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,28 +99,52 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
@Override
|
||||
public FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
if (this.getTank().getFluid() != null)
|
||||
{
|
||||
return this.drain(source, from, FluidHelper.getStack(this.getTank().getFluid(), resource), doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
this.ticks++;
|
||||
if (ticks >= Long.MAX_VALUE - 10)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
if (this.loadPart && ticks % 10 == 0)
|
||||
{
|
||||
this.loadPart = false;
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
|
||||
if (stack != null)
|
||||
{
|
||||
int parts = this.getConnectors().size();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
int fillPer = stack.amount / parts;
|
||||
part.getInternalTank().setFluid(null);
|
||||
part.getInternalTank().fill(FluidHelper.getStack(stack, fillPer), true);
|
||||
if (parts > 1)
|
||||
parts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,11 @@ import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
|||
public class PipeNetwork extends FluidNetwork
|
||||
{
|
||||
//TODO implements pressure for future hydraulic machines
|
||||
|
||||
public PipeNetwork()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public PipeNetwork(IFluidPipe... pipes)
|
||||
{
|
||||
super(pipes);
|
||||
|
|
|
@ -146,14 +146,12 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip
|
|||
@Override
|
||||
public int getMaxPressure()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFlowRate()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue