Fixed tank network and improved fluid network
This commit is contained in:
parent
19f7aac383
commit
29b59d88e0
5 changed files with 38 additions and 31 deletions
|
@ -1,5 +1,7 @@
|
|||
package resonantinduction.mechanical.fluid.network;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
@ -147,20 +149,19 @@ public class FluidNetwork extends Network<IFluidNetwork, IFluidPart, IFluidHandl
|
|||
{
|
||||
this.reloadTanks = false;
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
this.fillTankSet(stack != null ? stack.copy() : null, this.getConnectors());
|
||||
}
|
||||
|
||||
if (stack != null)
|
||||
public void fillTankSet(FluidStack stack, Set<IFluidPart> tankList)
|
||||
{
|
||||
int parts = tankList.size();
|
||||
for (IFluidPart part : tankList)
|
||||
{
|
||||
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().fill(FluidUtility.getStack(stack, fillPer), true);
|
||||
stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true);
|
||||
part.onFluidChanged();
|
||||
if (parts > 1)
|
||||
parts--;
|
||||
|
|
|
@ -12,6 +12,7 @@ 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 */
|
||||
|
@ -19,6 +20,11 @@ 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()
|
||||
{
|
||||
|
@ -64,13 +70,13 @@ public class PipeNetwork extends FluidNetwork
|
|||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return super.canUpdate() || this.getTank().getFluid() != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return super.canUpdate() || this.getTank().getFluid() != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,7 +92,7 @@ public class PipeNetwork extends FluidNetwork
|
|||
super.buildPart(part);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (part.getConnections()[i] instanceof IFluidHandler)
|
||||
if (part.getConnections()[i] instanceof IFluidHandler && !(part.getConnections()[i] instanceof IFluidPipe))
|
||||
{
|
||||
EnumSet<ForgeDirection> set = this.connectionMap.get(part.getConnections()[i]);
|
||||
if (set == null)
|
||||
|
|
|
@ -111,11 +111,11 @@ public class TilePipe extends TileFluidNetwork implements IColorCoded, IFluidPip
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendTankUpdate(int index)
|
||||
public void sendTankUpdate()
|
||||
{
|
||||
if (this.getBlockMetadata() == FluidContainerMaterial.WOOD.ordinal() || this.getBlockMetadata() == FluidContainerMaterial.STONE.ordinal())
|
||||
{
|
||||
super.sendTankUpdate(index);
|
||||
super.sendTankUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar
|
|||
{
|
||||
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
||||
{
|
||||
this.sendTankUpdate(0);
|
||||
this.sendTankUpdate();
|
||||
}
|
||||
|
||||
this.prevStack = this.tank.getFluid();
|
||||
|
@ -298,9 +298,9 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar
|
|||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
|
||||
}
|
||||
|
||||
public void sendTankUpdate(int index)
|
||||
public void sendTankUpdate()
|
||||
{
|
||||
if (this.getInternalTank() != null && index == 0)
|
||||
if (this.getInternalTank() != null)
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package resonantinduction.mechanical.fluid.tank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import resonantinduction.api.fluid.IFluidPart;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
import universalelectricity.core.net.NetworkTickHandler;
|
||||
import calclavia.lib.utility.FluidUtility;
|
||||
|
||||
/** Network that handles connected tanks
|
||||
|
@ -14,18 +15,24 @@ import calclavia.lib.utility.FluidUtility;
|
|||
* @author DarkGuardsman */
|
||||
public class TankNetwork extends FluidNetwork
|
||||
{
|
||||
public TankNetwork()
|
||||
{
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadTanks()
|
||||
{
|
||||
System.out.println("TankNetwork: Balancing fluid");
|
||||
FluidStack fillStack = this.getTank().getFluid();
|
||||
int lowestY = 255, highestY = 0;
|
||||
|
||||
if (fillStack == null || fillStack.getFluid().isGaseous())
|
||||
{
|
||||
System.out.println("TankNetwork: Stack is null or a gas");
|
||||
super.reloadTanks();
|
||||
}
|
||||
else if (this.getNodes().size() > 0)
|
||||
else if (this.getConnectors().size() > 0)
|
||||
{
|
||||
fillStack = fillStack.copy();
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
|
@ -43,9 +50,9 @@ public class TankNetwork extends FluidNetwork
|
|||
|
||||
//TODO Add path finder to prevent filling when tanks are only connected at the top
|
||||
for (int y = lowestY; y <= highestY; y++)
|
||||
{
|
||||
List<IFluidPart> parts = new ArrayList<IFluidPart>();
|
||||
|
||||
{
|
||||
Set<IFluidPart> parts = new LinkedHashSet<IFluidPart>();
|
||||
|
||||
for (IFluidPart part : this.getConnectors())
|
||||
{
|
||||
if (part instanceof IFluidPart && ((TileEntity) part).yCoord == y)
|
||||
|
@ -55,15 +62,8 @@ public class TankNetwork extends FluidNetwork
|
|||
}
|
||||
if (!parts.isEmpty())
|
||||
{
|
||||
//TODO change this to use a percent system for even filling
|
||||
int partCount = parts.size();
|
||||
for (IFluidPart part : parts)
|
||||
{
|
||||
fillStack.amount -= part.getInternalTank().fill(FluidUtility.getStack(fillStack, fillStack.amount / partCount), true);
|
||||
part.onFluidChanged();
|
||||
if (partCount > 1)
|
||||
partCount--;
|
||||
}
|
||||
System.out.println("TankNetwork: balancing level: " + y);
|
||||
this.fillTankSet(fillStack, parts);
|
||||
}
|
||||
|
||||
if (fillStack == null || fillStack.amount <= 0)
|
||||
|
|
Loading…
Reference in a new issue