Fixed gutter fluid attempting to flow back up

This commit is contained in:
Calclavia 2014-12-10 22:26:58 +08:00
parent fbcdbbca4d
commit 1b1a295513
4 changed files with 80 additions and 53 deletions

View file

@ -22,11 +22,16 @@ class NodeFluidGravity(parent: TileFluidProvider, volume: Int = FluidContainerRe
var quantity = 0
if (dir == ForgeDirection.DOWN)
{
quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else amountA, amountA)
else if (nodeB.isInstanceOf[NodeFluidGravity])
quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else Math.min((amountA - amountB) / 2, flowRate), Math.min((amountA - amountB) / 2, flowRate))
else
quantity = if (pressureA > pressureB) (pressureA - pressureB) * flowRate else 0
}
else if (dir != ForgeDirection.UP)
{
if (nodeB.isInstanceOf[NodeFluidGravity])
quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else Math.min((amountA - amountB) / 2, flowRate), Math.min((amountA - amountB) / 2, flowRate))
else
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)

View file

@ -17,6 +17,7 @@ import net.minecraftforge.fluids._
import org.lwjgl.opengl.GL11
import resonant.api.recipe.{MachineRecipes, RecipeResource}
import resonant.content.factory.resources.RecipeType
import resonant.lib.grid.UpdateTicker
import resonant.lib.prefab.fluid.NodeFluid
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
import resonant.lib.transform.region.Cuboid
@ -46,6 +47,15 @@ object TileGutter
class TileGutter extends TileFluidProvider(Material.rock)
{
fluidNode = new NodeGutter(this)
fluidNode.onFluidChanged = () =>
{
if (!world.isRemote)
{
//TODO: Check if this is very costly
// UpdateTicker.world.enqueue(checkFluidAbove)
sendPacket(0)
}
}
textureName = "material_wood_surface"
isOpaqueCube = false
@ -114,10 +124,23 @@ class TileGutter extends TileFluidProvider(Material.rock)
}
}
/**
* Called when the block is first added to the world
*/
override def onWorldJoin()
{
super.onWorldJoin()
checkFluidAbove()
}
override def onNeighborChanged(block: Block)
{
super.onNeighborChanged(block)
checkFluidAbove()
}
def checkFluidAbove()
{
if (!world.isRemote)
{
val posAbove = toVectorWorld + new Vector3(0, 1, 0)
@ -274,8 +297,7 @@ class TileGutter extends TileFluidProvider(Material.rock)
class NodeGutter(parent: TileFluidProvider) extends NodeFluidGravity(parent)
{
override def canConnect[B <: IFluidHandler](other: B, from: ForgeDirection) : Boolean =
override def canConnect[B <: IFluidHandler](other: B, from: ForgeDirection): Boolean =
{
if (other.isInstanceOf[NodeFluid] && other.asInstanceOf[NodeFluid].parent.isInstanceOf[TileTank])
return false

View file

@ -6,7 +6,6 @@ import resonant.api.IUpdate
import resonant.api.tile.INodeProvider
import resonant.lib.grid.UpdateTicker
import resonant.lib.prefab.fluid.NodeFluid
import resonantinduction.archaic.fluid.gutter.NodeFluidGravity
import scala.collection.convert.wrapAll._
@ -43,68 +42,71 @@ class NodeFluidPressure(parent: INodeProvider, volume: Int = FluidContainerRegis
{
val flowRate = (maxFlowRate * deltaTime).toInt
directionMap.foreach
directionMap synchronized
{
case (handler: IFluidHandler, dir: ForgeDirection) =>
directionMap.foreach
{
if (handler.isInstanceOf[NodeFluidPressure])
case (handler: IFluidHandler, dir: ForgeDirection) =>
{
//"A" is this node. "B" is the other node
//It's another pressure node
val otherNode = handler.asInstanceOf[NodeFluidPressure]
val pressureA = pressure(dir)
val pressureB = otherNode.pressure(dir.getOpposite)
//High pressure to low
if (pressureA >= pressureB)
if (handler.isInstanceOf[NodeFluidPressure])
{
val tankA = getPrimaryTank
//"A" is this node. "B" is the other node
//It's another pressure node
val otherNode = handler.asInstanceOf[NodeFluidPressure]
val pressureA = pressure(dir)
val pressureB = otherNode.pressure(dir.getOpposite)
if (tankA != null)
//High pressure to low
if (pressureA >= pressureB)
{
val fluidA = tankA.getFluid
val tankA = getPrimaryTank
if (fluidA != null)
if (tankA != null)
{
val amountA = fluidA.amount
val fluidA = tankA.getFluid
if (amountA > 0)
if (fluidA != null)
{
val tankB = otherNode.getPrimaryTank
val amountA = fluidA.amount
if (tankB != null)
if (amountA > 0)
{
doDistribute(dir, this, otherNode, flowRate)
val tankB = otherNode.getPrimaryTank
if (tankB != null)
{
doDistribute(dir, this, otherNode, flowRate)
}
}
}
}
}
}
}
else
{
//It's a fluid handler.
val pressure = this.pressure(dir)
val tankPressure = 0
val sourceTank = getPrimaryTank
val transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * flowRate
else
{
//It's a fluid handler.
val pressure = this.pressure(dir)
val tankPressure = 0
val sourceTank = getPrimaryTank
val transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * flowRate
if (pressure > tankPressure)
{
if (sourceTank.getFluidAmount > 0 && transferAmount > 0)
if (pressure > tankPressure)
{
val drainStack = drain(dir.getOpposite, transferAmount, false)
drain(dir.getOpposite, handler.fill(dir.getOpposite, drainStack, true), true)
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
val drainStack = handler.drain(dir.getOpposite, transferAmount, false)
if (drainStack != null)
if (sourceTank.getFluidAmount > 0 && transferAmount > 0)
{
handler.drain(dir.getOpposite, fill(dir.getOpposite, drainStack, true), true)
val drainStack = drain(dir.getOpposite, transferAmount, false)
drain(dir.getOpposite, handler.fill(dir.getOpposite, drainStack, true), true)
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
val drainStack = handler.drain(dir.getOpposite, transferAmount, false)
if (drainStack != null)
{
handler.drain(dir.getOpposite, fill(dir.getOpposite, drainStack, true), true)
}
}
}
}

View file

@ -79,15 +79,13 @@ object ElectricalContent extends ContentHolder
{
super.init()
RICreativeTab.itemStack(new ItemStack(ElectricalContent.itemTransformer))
OreDictionary.registerOre("wire", ElectricalContent.itemWire)
OreDictionary.registerOre("motor", ElectricalContent.blockMotor)
OreDictionary.registerOre("battery", ItemBlockBattery.setTier(new ItemStack(ElectricalContent.blockBattery, 1, 0), 0.asInstanceOf[Byte]))
OreDictionary.registerOre("batteryBox", ItemBlockBattery.setTier(new ItemStack(ElectricalContent.blockBattery, 1, 0), 0.asInstanceOf[Byte]))
}
override def postInit
override def postInit()
{
recipes += shaped(blockTesla, "WEW", " C ", "DID", 'W', "wire", 'E', Items.ender_eye, 'C', UniversalRecipe.BATTERY.get, 'D', Items.diamond, 'I', UniversalRecipe.PRIMARY_PLATE.get)
recipes += shaped(itemMultimeter, "WWW", "ICI", 'W', "wire", 'C', UniversalRecipe.BATTERY.get, 'I', UniversalRecipe.PRIMARY_METAL.get)
@ -141,7 +139,7 @@ object ElectricalContent extends ContentHolder
@SideOnly(Side.CLIENT)
def preTextureHook(event: TextureStitchEvent.Pre)
{
if (event.map.getTextureType() == 0)
if (event.map.getTextureType == 0)
{
RenderFlatWire.wireIcon = event.map.registerIcon(Reference.prefix + "models/flatWire")
RenderFramedWire.wireIcon = event.map.registerIcon(Reference.prefix + "models/wire")