Attempted to fix pipe network filling tanks

This commit is contained in:
DarkGuardsman 2014-01-15 12:07:25 -05:00
parent ec0c06dc48
commit b53678a432
4 changed files with 19 additions and 19 deletions

View file

@ -3,6 +3,9 @@ package resonantinduction.mechanical.fluid.network;
import java.util.Set;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent.Save;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
@ -25,6 +28,7 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
public FluidNetwork()
{
NetworkTickHandler.addNetwork(this);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
@ -140,11 +144,16 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
}
if (this.reloadTanks && ticks % 10 == 0)
{
this.reloadTanks = false;
this.reloadTanks();
}
}
@ForgeSubscribe
public void onWorldSave(Save event)
{
this.reloadTanks();
}
public void reloadTanks()
{
this.reloadTanks = false;

View file

@ -12,7 +12,6 @@ import resonantinduction.api.fluid.IFluidPart;
import resonantinduction.api.fluid.IFluidPipe;
import resonantinduction.mechanical.fluid.network.FluidNetwork;
import universalelectricity.api.vector.Vector3;
import universalelectricity.core.net.NetworkTickHandler;
import calclavia.lib.utility.FluidUtility;
/** @author DarkGuardsman */
@ -20,14 +19,12 @@ public class PipeNetwork extends FluidNetwork
{
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> connectionMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
public PipeNetwork()
{
NetworkTickHandler.addNetwork(this);
}
@Override
public void update()
{
System.out.println("PipeNetwork:" + this.toString());
System.out.println("FluidVol: " + this.getTank().getFluidAmount());
super.update();
//Slight delay to allow visual effect to take place before draining the pipe's internal tank
if (this.ticks % 2 == 0 && this.getTank().getFluidAmount() > 0)
@ -36,23 +33,20 @@ public class PipeNetwork extends FluidNetwork
int count = this.connectionMap.size();
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
{
int volPer = stack.amount / count;
int sideCount = entry.getValue().size();
for (ForgeDirection dir : entry.getValue())
{
int volPerSide = volPer / sideCount;
int volPer = (stack.amount / count) + (stack.amount % count);
int volPerSide = (volPer / sideCount) + (volPer % count);
int maxFill = 1000;
TileEntity entity = new Vector3((TileEntity) entry.getKey()).modifyPositionFromSide(dir).getTileEntity(((TileEntity) entry.getKey()).worldObj);
if (entity instanceof IFluidPipe)
{
maxFill = ((IFluidPipe) entity).getMaxFlowRate();
}
int fill = entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
volPer -= fill;
stack.amount -= fill;
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
if (sideCount > 1)
--sideCount;
if (volPer <= 0)
break;
}
@ -76,7 +70,7 @@ public class PipeNetwork extends FluidNetwork
@Override
public boolean continueUpdate()
{
return true;
return this.getConnectors().size() > 0;
}
@Override

View file

@ -162,6 +162,7 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar
if (previousConnections != renderSides)
{
this.sendRenderUpdate();
this.getNetwork().reconstruct();
}
}

View file

@ -13,11 +13,7 @@ import universalelectricity.core.net.NetworkTickHandler;
*
* @author DarkGuardsman */
public class TankNetwork extends FluidNetwork
{
public TankNetwork()
{
NetworkTickHandler.addNetwork(this);
}
{
@Override
public void reloadTanks()