From 523f37508bf1d97f25f8444e1636636b5fdd85b3 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 7 Nov 2014 12:41:07 +0800 Subject: [PATCH] Improved gravity handling in NodePressureGravity --- .../fluid/gutter/NodePressureGravity.scala | 31 ++++++++++++---- .../archaic/fluid/tank/TileTank.scala | 3 -- .../core/prefab/node/NodePressure.scala | 35 ++++++++++++------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/main/scala/resonantinduction/archaic/fluid/gutter/NodePressureGravity.scala b/src/main/scala/resonantinduction/archaic/fluid/gutter/NodePressureGravity.scala index 7997d90d3..afeba3eb7 100644 --- a/src/main/scala/resonantinduction/archaic/fluid/gutter/NodePressureGravity.scala +++ b/src/main/scala/resonantinduction/archaic/fluid/gutter/NodePressureGravity.scala @@ -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 = diff --git a/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala b/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala index 9a778f5ad..b9d5e22db 100644 --- a/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala +++ b/src/main/scala/resonantinduction/archaic/fluid/tank/TileTank.scala @@ -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) } diff --git a/src/main/scala/resonantinduction/core/prefab/node/NodePressure.scala b/src/main/scala/resonantinduction/core/prefab/node/NodePressure.scala index 3a10663f0..80269e6b1 100644 --- a/src/main/scala/resonantinduction/core/prefab/node/NodePressure.scala +++ b/src/main/scala/resonantinduction/core/prefab/node/NodePressure.scala @@ -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