More work to fix issues with tanks being filled by a bucket

This commit is contained in:
Robert S 2014-05-16 14:41:11 -04:00
parent 0e5633fcd0
commit ae3cba60f6
3 changed files with 135 additions and 127 deletions

View file

@ -5,7 +5,6 @@ import java.util.LinkedList;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import resonant.lib.utility.FluidUtility;
import resonantinduction.core.fluid.FluidDistributionetwork; import resonantinduction.core.fluid.FluidDistributionetwork;
import resonantinduction.core.fluid.IFluidDistribution; import resonantinduction.core.fluid.IFluidDistribution;
@ -23,22 +22,30 @@ public class TankNetwork extends FluidDistributionetwork
@Override @Override
public void update() public void update()
{ {
System.out.println("\nTankNetwork>Tank: " + getTank());
System.out.println("TankNetwork>Fluid: " + getTank().getFluid());
System.out.println("TankNetwork>Tank: " + getTank().getFluidAmount());
final FluidStack networkTankFluid = getTank().getFluid(); final FluidStack networkTankFluid = getTank().getFluid();
int lowestY = 255; int lowestY = 255;
int highestY = 0; int highestY = 0;
int connectorCount = 0; int connectorCount = 0;
int totalFluid = networkTankFluid != null ? networkTankFluid.amount : 0; int totalFluid = networkTankFluid != null ? networkTankFluid.amount : 0;
boolean didChange = false;
//If we only have one tank only fill one tank //If we only have one tank only fill one tank
if (getConnectors().size() == 1)
if (getConnectors().size() > 0)
{ {
IFluidDistribution tank = ((IFluidDistribution) getConnectors().toArray()[0]); IFluidDistribution tank = ((IFluidDistribution) getConnectors().toArray()[0]);
tank.getInternalTank().setFluid(networkTankFluid); if (!((TileEntity) tank).getWorldObj().isRemote)
tank.onFluidChanged(); System.out.println(this.toString());
} if (getConnectors().size() == 1)
else if (getConnectors().size() > 0) {
{ tank.getInternalTank().setFluid(networkTankFluid);
tank.onFluidChanged();
needsUpdate = false;
return;
}
if (networkTankFluid != null) if (networkTankFluid != null)
{ {
//If fluid is gaseous fill all tanks equally //If fluid is gaseous fill all tanks equally
@ -97,7 +104,8 @@ public class TankNetwork extends FluidDistributionetwork
if (connectorCount <= 0) if (connectorCount <= 0)
continue; continue;
if (!((TileEntity) tank).getWorldObj().isRemote)
System.out.println("Filling Y: " + yLevel + " Tanks: " + connectorCount);
//Loop threw tanks in each level //Loop threw tanks in each level
for (IFluidDistribution connector : heightMap.get(yLevel)) for (IFluidDistribution connector : heightMap.get(yLevel))
{ {
@ -133,8 +141,8 @@ public class TankNetwork extends FluidDistributionetwork
connector.onFluidChanged(); connector.onFluidChanged();
} }
} }
needsUpdate = false;
} }
needsUpdate = false;
} }
@Override @Override

View file

@ -9,133 +9,133 @@ import universalelectricity.api.net.IUpdate;
import universalelectricity.core.net.NetworkTickHandler; import universalelectricity.core.net.NetworkTickHandler;
import universalelectricity.core.net.NodeNetwork; import universalelectricity.core.net.NodeNetwork;
/** /** The fluid network for instantaneous equal distribution between all nodes. Used for tanks.
* The fluid network for instantaneous equal distribution between all nodes. Used for tanks.
* *
* @author DarkCow, Calclavia * @author DarkCow, Calclavia */
*
*/
public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistributionetwork, IFluidDistribution, IFluidHandler> implements IUpdate public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistributionetwork, IFluidDistribution, IFluidHandler> implements IUpdate
{ {
protected FluidTank tank = new FluidTank(0); protected FluidTank tank = new FluidTank(0);
public boolean needsUpdate = false; public boolean needsUpdate = false;
public FluidDistributionetwork() public FluidDistributionetwork()
{ {
super(IFluidDistribution.class); super(IFluidDistribution.class);
} }
@Override @Override
public void addConnector(IFluidDistribution connector) public void addConnector(IFluidDistribution connector)
{ {
super.addConnector(connector); super.addConnector(connector);
NetworkTickHandler.addNetwork(this); NetworkTickHandler.addNetwork(this);
} }
@Override @Override
public boolean canUpdate() public boolean canUpdate()
{ {
return needsUpdate && getConnectors().size() > 0; return needsUpdate && getConnectors().size() > 0;
} }
@Override @Override
public boolean continueUpdate() public boolean continueUpdate()
{ {
return canUpdate(); return canUpdate();
} }
@Override @Override
public void reconstruct() public void reconstruct()
{ {
this.tank = new FluidTank(0); this.tank.setCapacity(0);
super.reconstruct(); this.tank.setFluid(null);
needsUpdate = true; super.reconstruct();
NetworkTickHandler.addNetwork(this); needsUpdate = true;
} NetworkTickHandler.addNetwork(this);
}
@Override @Override
public void reconstructConnector(IFluidDistribution connector) public void reconstructConnector(IFluidDistribution connector)
{ {
if (connector.getNetwork() instanceof FluidDistributionetwork) if (connector.getNetwork() instanceof FluidDistributionetwork)
connector.setNetwork(this); connector.setNetwork(this);
FluidTank connectorTank = connector.getInternalTank(); FluidTank connectorTank = connector.getInternalTank();
if (connectorTank != null) if (connectorTank != null)
{ {
tank.setCapacity(tank.getCapacity() + connectorTank.getCapacity()); tank.setCapacity(tank.getCapacity() + connectorTank.getCapacity());
if (connectorTank.getFluid() != null) if (connectorTank.getFluid() != null)
{ {
if (tank.getFluid() == null) if (tank.getFluid() == null)
{ {
tank.setFluid(connectorTank.getFluid().copy()); tank.setFluid(connectorTank.getFluid().copy());
} }
else if (tank.getFluid().isFluidEqual(connectorTank.getFluid())) else if (tank.getFluid().isFluidEqual(connectorTank.getFluid()))
{ {
tank.getFluid().amount += connectorTank.getFluidAmount(); tank.getFluid().amount += connectorTank.getFluidAmount();
} }
else if (tank.getFluid() != null) else if (tank.getFluid() != null)
{ {
// TODO: Cause a mixing event // TODO: Cause a mixing event
} }
} }
} }
} }
public int fill(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doFill) public int fill(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doFill)
{ {
int fill = this.getTank().fill(resource.copy(), doFill); System.out.println("FluidDistributionNetwork: Filling " + resource + " Tank: " + this.getTank().getFluidAmount());
needsUpdate = true; System.out.println("FluidDistributionNetwork: Tank Contains Fluid: " + getTank().getFluid() + " Tank: " + this.getTank().getFluidAmount());
NetworkTickHandler.addNetwork(this); int fill = this.getTank().fill(resource.copy(), doFill);
return fill; System.out.println("FluidDistributionNetwork: Filled " + fill + " Tank: " + this.getTank().getFluidAmount());
} needsUpdate = true;
NetworkTickHandler.addNetwork(this);
return fill;
}
public FluidStack drain(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doDrain) public FluidStack drain(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doDrain)
{ {
if (resource != null && resource.isFluidEqual(getTank().getFluid())) if (resource != null && resource.isFluidEqual(getTank().getFluid()))
{ {
FluidStack drain = getTank().drain(resource.amount, doDrain); FluidStack drain = getTank().drain(resource.amount, doDrain);
needsUpdate = true; needsUpdate = true;
NetworkTickHandler.addNetwork(this); NetworkTickHandler.addNetwork(this);
return drain; return drain;
} }
return null; return null;
} }
public FluidStack drain(IFluidDistribution source, ForgeDirection from, int resource, boolean doDrain) public FluidStack drain(IFluidDistribution source, ForgeDirection from, int resource, boolean doDrain)
{ {
FluidStack drain = getTank().drain(resource, doDrain); FluidStack drain = getTank().drain(resource, doDrain);
needsUpdate = true; needsUpdate = true;
NetworkTickHandler.addNetwork(this); NetworkTickHandler.addNetwork(this);
return drain; return drain;
} }
public FluidTank getTank() public FluidTank getTank()
{ {
if (this.tank == null) if (this.tank == null)
{ {
this.tank = new FluidTank(0); this.tank = new FluidTank(0);
} }
return this.tank;
}
return this.tank; @Override
} public Class getConnectorClass()
{
return IFluidDistribution.class;
}
@Override public FluidTankInfo[] getTankInfo()
public Class getConnectorClass() {
{ return new FluidTankInfo[] { getTank().getInfo() };
return IFluidDistribution.class; }
}
public FluidTankInfo[] getTankInfo() @Override
{ public String toString()
return new FluidTankInfo[] { getTank().getInfo() }; {
} return super.toString() + " Volume: " + this.tank.getFluidAmount();
}
@Override
public String toString()
{
return super.toString() + " Volume: " + this.tank.getFluidAmount();
}
} }

View file

@ -14,29 +14,28 @@ import universalelectricity.api.vector.Vector3;
* @author DarkGuardsman */ * @author DarkGuardsman */
public abstract class TileFluidDistribution extends TileFluidNode implements IFluidDistribution public abstract class TileFluidDistribution extends TileFluidNode implements IFluidDistribution
{ {
public TileFluidDistribution(Material material, int tankSize)
{
super(material, tankSize);
}
protected Object[] connectedBlocks = new Object[6]; protected Object[] connectedBlocks = new Object[6];
/** Network used to link all parts together */ /** Network used to link all parts together */
protected FluidDistributionetwork network; protected FluidDistributionetwork network;
public TileFluidDistribution(Material material, int tankSize)
{
super(material, tankSize);
}
@Override @Override
public void initiate() public void initiate()
{ {
super.initiate(); super.initiate();
refresh(); refresh();
getNetwork().reconstruct();
} }
@Override @Override
protected void onNeighborChanged() protected void onNeighborChanged()
{ {
refresh(); refresh();
getNetwork().reconstruct();
} }
@Override @Override
@ -104,8 +103,9 @@ public abstract class TileFluidDistribution extends TileFluidNode implements IFl
/** Only send packet updates if visuallyConnected changed. */ /** Only send packet updates if visuallyConnected changed. */
if (previousConnections != renderSides) if (previousConnections != renderSides)
{ {
sendRenderUpdate(); getNetwork().update();
getNetwork().reconstruct(); getNetwork().reconstruct();
sendRenderUpdate();
} }
} }