Using viscosity to calculate gravity flow rate
This commit is contained in:
parent
57fa0ab646
commit
9a9ec410ed
3 changed files with 19 additions and 7 deletions
|
@ -10,14 +10,15 @@ import net.minecraftforge.fluids.FluidContainerRegistry
|
||||||
*/
|
*/
|
||||||
class NodeFluidGravity(parent: TileFluidProvider, volume: Int = FluidContainerRegistry.BUCKET_VOLUME) extends NodeFluidPressure(parent, volume)
|
class NodeFluidGravity(parent: TileFluidProvider, volume: Int = FluidContainerRegistry.BUCKET_VOLUME) extends NodeFluidPressure(parent, volume)
|
||||||
{
|
{
|
||||||
override protected def doDistribute(dir: ForgeDirection, nodeA: NodeFluidPressure, nodeB: NodeFluidPressure, flowRate: Int)
|
override protected def doDistribute(deltaTime: Double, dir: ForgeDirection, nodeA: NodeFluidPressure, nodeB: NodeFluidPressure, flowRate: Int)
|
||||||
{
|
{
|
||||||
val tankA = nodeA.getPrimaryTank
|
val tankA = nodeA.getPrimaryTank
|
||||||
val tankB = nodeB.getPrimaryTank
|
val tankB = nodeB.getPrimaryTank
|
||||||
val pressureA = nodeA.pressure(dir)
|
val pressureA = nodeA.pressure(dir)
|
||||||
val pressureB = nodeB.pressure(dir.getOpposite)
|
val pressureB = nodeB.pressure(dir.getOpposite)
|
||||||
val amountA = tankA.getFluidAmount
|
val amountA = tankA.getFluidAmount
|
||||||
val amountB = tankB.getFluidAmount - nodeB.fill(dir, drain(dir.getOpposite, amountA, false), false)
|
val testDrain = drain(dir.getOpposite, amountA, false)
|
||||||
|
val amountB = tankB.getFluidAmount - nodeB.fill(dir, testDrain, false)
|
||||||
|
|
||||||
var quantity = 0
|
var quantity = 0
|
||||||
|
|
||||||
|
@ -33,8 +34,20 @@ class NodeFluidGravity(parent: TileFluidProvider, volume: Int = FluidContainerRe
|
||||||
quantity = if (pressureA > pressureB) (pressureA - pressureB) * flowRate else 0
|
quantity = if (pressureA > pressureB) (pressureA - pressureB) * flowRate else 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: There's a slight pressure backflow
|
/**
|
||||||
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
|
* Take account of viscosity. Fluid in Minecraft is measured in liters.
|
||||||
|
* 1L = 0.001 m^3
|
||||||
|
* Viscosity (m/s^2)
|
||||||
|
* Viscosity/1000 (convert to L/s^2)
|
||||||
|
*/
|
||||||
|
if (testDrain != null && testDrain.getFluid != null)
|
||||||
|
{
|
||||||
|
quantity = Math.max(quantity, (Math.pow(testDrain.getFluid.getViscosity(testDrain) / 1000, 3) * deltaTime).toInt)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
|
||||||
|
}
|
||||||
|
|
||||||
if (quantity > 0)
|
if (quantity > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,6 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
|
||||||
{
|
{
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
println(fluidNode.asInstanceOf[NodeFluidGravity].pressure)
|
|
||||||
return FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side)
|
return FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class NodeFluidPressure(parent: INodeProvider, volume: Int = FluidContainerRegis
|
||||||
|
|
||||||
if (tankB != null)
|
if (tankB != null)
|
||||||
{
|
{
|
||||||
doDistribute(dir, this, otherNode, flowRate)
|
doDistribute(deltaTime, dir, this, otherNode, flowRate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class NodeFluidPressure(parent: INodeProvider, volume: Int = FluidContainerRegis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def doDistribute(dir: ForgeDirection, nodeA: NodeFluidPressure, nodeB: NodeFluidPressure, flowRate: Int)
|
protected def doDistribute(deltaTime: Double, dir: ForgeDirection, nodeA: NodeFluidPressure, nodeB: NodeFluidPressure, flowRate: Int)
|
||||||
{
|
{
|
||||||
val tankA = nodeA.getPrimaryTank
|
val tankA = nodeA.getPrimaryTank
|
||||||
val tankB = nodeB.getPrimaryTank
|
val tankB = nodeB.getPrimaryTank
|
||||||
|
|
Loading…
Add table
Reference in a new issue