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.api.net.IConnector;
|
||||||
import universalelectricity.core.net.ConnectionPathfinder;
|
import universalelectricity.core.net.ConnectionPathfinder;
|
||||||
import universalelectricity.core.net.Network;
|
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
|
public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandler> implements IFluidNetwork
|
||||||
{
|
{
|
||||||
protected FluidTank tank;
|
protected FluidTank tank;
|
||||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||||
|
protected boolean loadPart = false;
|
||||||
|
protected long ticks = 0;
|
||||||
|
|
||||||
public FluidNetwork()
|
public FluidNetwork()
|
||||||
{
|
{
|
||||||
|
NetworkTickHandler.addNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluidNetwork(IFluidPart... parts)
|
public FluidNetwork(IFluidPart... parts)
|
||||||
{
|
{
|
||||||
|
this();
|
||||||
for (IFluidPart part : parts)
|
for (IFluidPart part : parts)
|
||||||
{
|
{
|
||||||
this.addConnector(part);
|
this.addConnector(part);
|
||||||
|
@ -32,8 +37,32 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
||||||
@Override
|
@Override
|
||||||
public void reconstruct()
|
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()
|
public void rebuildTank()
|
||||||
|
@ -51,8 +80,13 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
||||||
@Override
|
@Override
|
||||||
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
|
public int fill(IFluidPart source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
int prev = this.getTank().getFluidAmount();
|
||||||
return 0;
|
int fill = this.getTank().fill(resource, doFill);
|
||||||
|
if (prev != fill)
|
||||||
|
{
|
||||||
|
this.loadPart = true;
|
||||||
|
}
|
||||||
|
return fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,28 +99,52 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
||||||
@Override
|
@Override
|
||||||
public FluidStack drain(IFluidPart source, ForgeDirection from, int resource, boolean doDrain)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUpdate()
|
public boolean canUpdate()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean continueUpdate()
|
public boolean continueUpdate()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
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,6 +7,10 @@ import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||||
public class PipeNetwork extends FluidNetwork
|
public class PipeNetwork extends FluidNetwork
|
||||||
{
|
{
|
||||||
//TODO implements pressure for future hydraulic machines
|
//TODO implements pressure for future hydraulic machines
|
||||||
|
public PipeNetwork()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public PipeNetwork(IFluidPipe... pipes)
|
public PipeNetwork(IFluidPipe... pipes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -146,14 +146,12 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip
|
||||||
@Override
|
@Override
|
||||||
public int getMaxPressure()
|
public int getMaxPressure()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
return 10000;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFlowRate()
|
public int getMaxFlowRate()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
return 1000;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue