Fluids in tank now have smooth animation
This commit is contained in:
parent
a353e01840
commit
fee28407d8
5 changed files with 61 additions and 127 deletions
|
@ -60,9 +60,8 @@ public class BlockTank extends BlockFluidNetwork
|
||||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
|
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
|
||||||
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
|
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package resonantinduction.archaic.fluid.tank;
|
package resonantinduction.archaic.fluid.tank;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
|
@ -10,6 +9,8 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
import resonantinduction.core.fluid.FluidDistributionetwork;
|
import resonantinduction.core.fluid.FluidDistributionetwork;
|
||||||
import resonantinduction.core.fluid.IFluidDistribution;
|
import resonantinduction.core.fluid.IFluidDistribution;
|
||||||
import calclavia.lib.utility.FluidUtility;
|
import calclavia.lib.utility.FluidUtility;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Network that handles connected tanks
|
* Network that handles connected tanks
|
||||||
|
@ -21,29 +22,16 @@ public class TankNetwork extends FluidDistributionetwork
|
||||||
public TankNetwork()
|
public TankNetwork()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
animateDistribution = true;
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
// if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
final FluidStack totalFluid = getTank().getFluid();
|
||||||
// distributeConnectors();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void distributeConnectors()
|
|
||||||
{
|
|
||||||
int animateRate = 0;
|
|
||||||
|
|
||||||
FluidStack totalFluid = getTank().getFluid();
|
|
||||||
int lowestY = 255, highestY = 0;
|
int lowestY = 255, highestY = 0;
|
||||||
|
|
||||||
if (totalFluid == null || totalFluid.getFluid().isGaseous())
|
if (totalFluid != null && getConnectors().size() > 0)
|
||||||
{
|
|
||||||
super.distributeConnectors();
|
|
||||||
}
|
|
||||||
else if (getConnectors().size() > 0)
|
|
||||||
{
|
{
|
||||||
FluidStack distributeFluid = totalFluid.copy();
|
FluidStack distributeFluid = totalFluid.copy();
|
||||||
HashMap<Integer, Integer> heightCount = new HashMap<Integer, Integer>();
|
HashMap<Integer, Integer> heightCount = new HashMap<Integer, Integer>();
|
||||||
|
@ -52,6 +40,9 @@ public class TankNetwork extends FluidDistributionetwork
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object a, Object b)
|
public int compare(Object a, Object b)
|
||||||
{
|
{
|
||||||
|
if (totalFluid.getFluid().isGaseous())
|
||||||
|
return 0;
|
||||||
|
|
||||||
TileEntity wa = (TileEntity) a;
|
TileEntity wa = (TileEntity) a;
|
||||||
TileEntity wb = (TileEntity) b;
|
TileEntity wb = (TileEntity) b;
|
||||||
return wa.yCoord - wb.yCoord;
|
return wa.yCoord - wb.yCoord;
|
||||||
|
@ -80,7 +71,7 @@ public class TankNetwork extends FluidDistributionetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean didChange = false;
|
boolean didChange = false;
|
||||||
//System.out.println("TANK UPDATE " + distributeFluid.amount);
|
|
||||||
while (!heightPriorityQueue.isEmpty())
|
while (!heightPriorityQueue.isEmpty())
|
||||||
{
|
{
|
||||||
IFluidDistribution distributeNode = heightPriorityQueue.poll();
|
IFluidDistribution distributeNode = heightPriorityQueue.poll();
|
||||||
|
@ -89,28 +80,30 @@ public class TankNetwork extends FluidDistributionetwork
|
||||||
|
|
||||||
if (distributeFluid == null || distributeFluid.amount <= 0)
|
if (distributeFluid == null || distributeFluid.amount <= 0)
|
||||||
{
|
{
|
||||||
break;
|
distributeNode.getInternalTank().setFluid(null);
|
||||||
|
distributeNode.onFluidChanged();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fluidPer = (distributeFluid.amount / connectorCount) + (distributeFluid.amount % connectorCount);
|
int fluidPer = distributeFluid.amount / connectorCount;
|
||||||
int deltaFluidAmount = (fluidPer - distributeNode.getInternalTank().getFluidAmount()) / 10;
|
int deltaFluidAmount = fluidPer - distributeNode.getInternalTank().getFluidAmount();
|
||||||
|
|
||||||
distributeNode.getInternalTank().setFluid(FluidUtility.getStack(distributeFluid, fluidPer));
|
int current = distributeNode.getInternalTank().getFluidAmount();
|
||||||
|
|
||||||
/*
|
|
||||||
* System.out.println(connectorCount + " : " + fluidPer);
|
|
||||||
|
|
||||||
if (deltaFluidAmount > 0)
|
if (deltaFluidAmount > 0)
|
||||||
{
|
{
|
||||||
distributeNode.getInternalTank().fill(FluidUtility.getStack(distributeFluid, deltaFluidAmount), true);
|
int filled = distributeNode.getInternalTank().fill(FluidUtility.getStack(distributeFluid, deltaFluidAmount), false);
|
||||||
|
distributeNode.getInternalTank().fill(FluidUtility.getStack(distributeFluid, deltaFluidAmount / 10), true);
|
||||||
|
distributeFluid.amount -= current + filled;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: This causes quite a lot of issues.
|
FluidStack drain = distributeNode.getInternalTank().drain(Math.abs(deltaFluidAmount), false);
|
||||||
FluidStack drained = distributeNode.getInternalTank().drain(Math.abs(deltaFluidAmount), true);
|
distributeNode.getInternalTank().drain(Math.abs(deltaFluidAmount / 10), true);
|
||||||
}*/
|
|
||||||
|
|
||||||
distributeFluid.amount -= distributeNode.getInternalTank().getFluidAmount();
|
if (drain != null)
|
||||||
|
distributeFluid.amount -= current - drain.amount;
|
||||||
|
}
|
||||||
|
|
||||||
if (deltaFluidAmount != 0)
|
if (deltaFluidAmount != 0)
|
||||||
didChange = true;
|
didChange = true;
|
||||||
|
@ -121,6 +114,9 @@ public class TankNetwork extends FluidDistributionetwork
|
||||||
heightCount.put(yCoord, connectorCount);
|
heightCount.put(yCoord, connectorCount);
|
||||||
distributeNode.onFluidChanged();
|
distributeNode.onFluidChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!didChange)
|
||||||
|
needsUpdate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,18 +18,6 @@ public class TileTank extends TileFluidDistribution implements IPressure
|
||||||
this.getInternalTank().setCapacity(VOLUME * FluidContainerRegistry.BUCKET_VOLUME);
|
this.getInternalTank().setCapacity(VOLUME * FluidContainerRegistry.BUCKET_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity()
|
|
||||||
{
|
|
||||||
super.updateEntity();
|
|
||||||
|
|
||||||
if (!worldObj.isRemote)
|
|
||||||
{
|
|
||||||
getNetwork().distributeConnectors();
|
|
||||||
sendTankUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidDistributionetwork getNetwork()
|
public FluidDistributionetwork getNetwork()
|
||||||
{
|
{
|
||||||
|
@ -73,7 +61,7 @@ public class TileTank extends TileFluidDistribution implements IPressure
|
||||||
@Override
|
@Override
|
||||||
public int getPressure(ForgeDirection dir)
|
public int getPressure(ForgeDirection dir)
|
||||||
{
|
{
|
||||||
return (getInternalTank().getCapacity() - getInternalTank().getFluidAmount()) / 10;
|
return 0;//(getInternalTank().getCapacity() - getInternalTank().getFluidAmount()) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,7 @@ import calclavia.lib.utility.FluidUtility;
|
||||||
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);
|
||||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
public boolean needsUpdate = false;
|
||||||
|
|
||||||
public boolean animateDistribution = false;
|
|
||||||
|
|
||||||
public FluidDistributionetwork()
|
public FluidDistributionetwork()
|
||||||
{
|
{
|
||||||
|
@ -40,7 +38,7 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
|
||||||
@Override
|
@Override
|
||||||
public boolean canUpdate()
|
public boolean canUpdate()
|
||||||
{
|
{
|
||||||
return animateDistribution && getConnectors().size() > 0;
|
return needsUpdate && getConnectors().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,11 +51,9 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
|
||||||
public void reconstruct()
|
public void reconstruct()
|
||||||
{
|
{
|
||||||
this.tank = new FluidTank(0);
|
this.tank = new FluidTank(0);
|
||||||
|
|
||||||
super.reconstruct();
|
super.reconstruct();
|
||||||
|
needsUpdate = true;
|
||||||
this.reconstructTankInfo();
|
NetworkTickHandler.addNetwork(this);
|
||||||
this.distributeConnectors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,51 +62,36 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
|
||||||
if (connector.getNetwork() instanceof FluidDistributionetwork)
|
if (connector.getNetwork() instanceof FluidDistributionetwork)
|
||||||
connector.setNetwork(this);
|
connector.setNetwork(this);
|
||||||
|
|
||||||
FluidTank tank = connector.getInternalTank();
|
FluidTank connectorTank = connector.getInternalTank();
|
||||||
|
|
||||||
if (tank != null)
|
if (connectorTank != null)
|
||||||
{
|
{
|
||||||
this.tank.setCapacity(this.tank.getCapacity() + tank.getCapacity());
|
tank.setCapacity(tank.getCapacity() + connectorTank.getCapacity());
|
||||||
if (this.tank.getFluid() == null)
|
|
||||||
|
if (connectorTank.getFluid() != null)
|
||||||
{
|
{
|
||||||
this.tank.setFluid(tank.getFluid());
|
if (tank.getFluid() == null)
|
||||||
}
|
{
|
||||||
else if (this.tank.getFluid().isFluidEqual(tank.getFluid()))
|
tank.setFluid(connectorTank.getFluid().copy());
|
||||||
{
|
}
|
||||||
this.tank.getFluid().amount += tank.getFluidAmount();
|
else if (tank.getFluid().isFluidEqual(connectorTank.getFluid()))
|
||||||
}
|
{
|
||||||
else if (this.tank.getFluid() != null)
|
tank.getFluid().amount += connectorTank.getFluidAmount();
|
||||||
{
|
}
|
||||||
// TODO cause a mixing event
|
else if (tank.getFluid() != null)
|
||||||
|
{
|
||||||
|
// TODO: Cause a mixing event
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reconstructTankInfo()
|
|
||||||
{
|
|
||||||
if (this.getTank() != null)
|
|
||||||
{
|
|
||||||
this.tankInfo[0] = this.getTank().getInfo();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.tankInfo[0] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
distributeConnectors();
|
|
||||||
NetworkTickHandler.addNetwork(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int fill(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doFill)
|
public int fill(IFluidDistribution source, ForgeDirection from, FluidStack resource, boolean doFill)
|
||||||
{
|
{
|
||||||
int prev = this.getTank().getFluidAmount();
|
int prev = this.getTank().getFluidAmount();
|
||||||
int fill = this.getTank().fill(resource, doFill);
|
int fill = this.getTank().fill(resource.copy(), doFill);
|
||||||
|
needsUpdate = true;
|
||||||
if (prev != this.getTank().getFluidAmount())
|
NetworkTickHandler.addNetwork(this);
|
||||||
{
|
|
||||||
reconstructTankInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
return fill;
|
return fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,58 +101,29 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
|
||||||
{
|
{
|
||||||
FluidStack before = this.getTank().getFluid();
|
FluidStack before = this.getTank().getFluid();
|
||||||
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
|
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
|
||||||
|
needsUpdate = true;
|
||||||
if (!FluidUtility.matchExact(before, drain))
|
NetworkTickHandler.addNetwork(this);
|
||||||
{
|
|
||||||
reconstructTankInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (getTank().getFluid() != null)
|
if (getTank().getFluid() != null)
|
||||||
{
|
|
||||||
return this.drain(source, from, FluidUtility.getStack(getTank().getFluid(), resource), doDrain);
|
return this.drain(source, from, FluidUtility.getStack(getTank().getFluid(), resource), doDrain);
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void distributeConnectors()
|
|
||||||
{
|
|
||||||
FluidStack stack = this.getTank().getFluid();
|
|
||||||
this.fillTankSet(stack != null ? stack.copy() : null, this.getConnectors());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillTankSet(FluidStack stack, Set<IFluidDistribution> connectors)
|
|
||||||
{
|
|
||||||
int connectorCount = connectors.size();
|
|
||||||
|
|
||||||
for (IFluidDistribution part : connectors)
|
|
||||||
{
|
|
||||||
part.getInternalTank().setFluid(null);
|
|
||||||
if (stack != null)
|
|
||||||
{
|
|
||||||
int fillPer = (stack.amount / connectorCount) + (stack.amount % connectorCount);
|
|
||||||
stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true);
|
|
||||||
|
|
||||||
if (connectorCount > 1)
|
|
||||||
connectorCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
part.onFluidChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +134,7 @@ public abstract class FluidDistributionetwork extends NodeNetwork<FluidDistribut
|
||||||
|
|
||||||
public FluidTankInfo[] getTankInfo()
|
public FluidTankInfo[] getTankInfo()
|
||||||
{
|
{
|
||||||
return tankInfo;
|
return new FluidTankInfo[] { getTank().getInfo() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -228,12 +228,11 @@ public abstract class TileFluidDistribution extends TileAdvanced implements IFlu
|
||||||
{
|
{
|
||||||
if (!worldObj.isRemote)
|
if (!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
if (!FluidUtility.matchExact(prevStack, getInternalTank().getFluid()))
|
||||||
{
|
{
|
||||||
sendTankUpdate();
|
sendTankUpdate();
|
||||||
|
prevStack = tank.getFluid() != null ? tank.getFluid().copy() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
prevStack = tank.getFluid();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue