Improved gravity handling in NodePressureGravity
This commit is contained in:
parent
427f2ba132
commit
523f37508b
|
@ -10,17 +10,34 @@ import resonantinduction.core.prefab.node.{NodePressure, TileFluidProvider}
|
|||
*/
|
||||
class NodePressureGravity(parent: TileFluidProvider, volume: Int = FluidContainerRegistry.BUCKET_VOLUME) extends NodePressure(parent, volume)
|
||||
{
|
||||
override def pressure(dir: ForgeDirection): Int =
|
||||
override protected def doDistribute(dir: ForgeDirection, nodeA: NodePressure, nodeB: NodePressure, flowRate: Int)
|
||||
{
|
||||
if (dir == ForgeDirection.UP)
|
||||
{
|
||||
return -2
|
||||
}
|
||||
if (dir == ForgeDirection.DOWN)
|
||||
{
|
||||
return 2
|
||||
val tankA = nodeA.getPrimaryTank
|
||||
val tankB = nodeB.getPrimaryTank
|
||||
val pressureA = nodeA.pressure(dir)
|
||||
val pressureB = nodeB.pressure(dir.getOpposite)
|
||||
val amountA = tankA.getFluidAmount
|
||||
val amountB = tankB.getFluidAmount
|
||||
|
||||
var quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else amountA, amountA)
|
||||
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
|
||||
|
||||
if (quantity > 0)
|
||||
{
|
||||
val drainStack = drain(dir.getOpposite, quantity, false)
|
||||
if (drainStack != null && drainStack.amount > 0)
|
||||
{
|
||||
drain(dir.getOpposite, nodeB.fill(dir, drainStack, true), true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (dir != ForgeDirection.UP)
|
||||
{
|
||||
super.doDistribute(dir, nodeA, nodeB, flowRate)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
|
||||
|
|
|
@ -29,7 +29,6 @@ import resonantinduction.core.prefab.node.TileFluidProvider
|
|||
*/
|
||||
class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with RenderConnectedTexture
|
||||
{
|
||||
|
||||
edgeTexture = Reference.prefix + "tankEdge"
|
||||
isOpaqueCube = false
|
||||
normalRender = false
|
||||
|
@ -45,8 +44,6 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
|
|||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
//TODO: Somehow, the connections are not updating until manual triggers
|
||||
println(fluidNode.connections.size())
|
||||
fluidNode.reconstruct()
|
||||
return FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side)
|
||||
}
|
||||
|
|
|
@ -68,18 +68,7 @@ class NodePressure(parent: INodeProvider, volume: Int = FluidContainerRegistry.B
|
|||
|
||||
if (tankB != null)
|
||||
{
|
||||
val amountB = tankB.getFluidAmount
|
||||
var quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else Math.min((amountA - amountB) / 2, flowRate), Math.min((amountA - amountB) / 2, flowRate))
|
||||
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
|
||||
|
||||
if (quantity > 0)
|
||||
{
|
||||
val drainStack = drain(dir.getOpposite, quantity, false)
|
||||
if (drainStack != null && drainStack.amount > 0)
|
||||
{
|
||||
drain(dir.getOpposite, otherNode.fill(dir, drainStack, true), true)
|
||||
}
|
||||
}
|
||||
doDistribute(dir, this, otherNode, flowRate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +107,28 @@ class NodePressure(parent: INodeProvider, volume: Int = FluidContainerRegistry.B
|
|||
}
|
||||
}
|
||||
|
||||
protected def doDistribute(dir: ForgeDirection, nodeA: NodePressure, nodeB: NodePressure, flowRate: Int)
|
||||
{
|
||||
val tankA = nodeA.getPrimaryTank
|
||||
val tankB = nodeB.getPrimaryTank
|
||||
val pressureA = nodeA.pressure(dir)
|
||||
val pressureB = nodeB.pressure(dir.getOpposite)
|
||||
val amountA = tankA.getFluidAmount
|
||||
val amountB = tankB.getFluidAmount
|
||||
|
||||
var quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else Math.min((amountA - amountB) / 2, flowRate), Math.min((amountA - amountB) / 2, flowRate))
|
||||
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
|
||||
|
||||
if (quantity > 0)
|
||||
{
|
||||
val drainStack = drain(dir.getOpposite, quantity, false)
|
||||
if (drainStack != null && drainStack.amount > 0)
|
||||
{
|
||||
drain(dir.getOpposite, nodeB.fill(dir, drainStack, true), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected def updatePressure()
|
||||
{
|
||||
var totalPressure = 0
|
||||
|
|
Loading…
Reference in a new issue