Fixed pipes

This commit is contained in:
Calclavia 2014-11-11 22:28:25 +08:00
parent 7f6e7be7d6
commit f6fd617794
9 changed files with 99 additions and 66 deletions

View file

@ -1,7 +1,7 @@
package resonantinduction.archaic.fluid.gutter
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{Fluid, FluidContainerRegistry, FluidStack}
import net.minecraftforge.fluids.FluidContainerRegistry
import resonantinduction.core.prefab.node.{NodePressure, TileFluidProvider}
/**
@ -12,50 +12,32 @@ class NodePressureGravity(parent: TileFluidProvider, volume: Int = FluidContaine
{
override 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 = 0
if (dir == ForgeDirection.DOWN)
quantity = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * flowRate else amountA, amountA)
else if (nodeB.isInstanceOf[NodePressureGravity])
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
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
if (quantity > 0)
{
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)
{
val drainStack = drain(dir.getOpposite, quantity, false)
if (drainStack != null && drainStack.amount > 0)
{
drain(dir.getOpposite, nodeB.fill(dir, drainStack, true), true)
}
drain(dir.getOpposite, nodeB.fill(dir, drainStack, true), true)
}
}
else if (dir != ForgeDirection.UP)
{
super.doDistribute(dir, nodeA, nodeB, flowRate)
}
}
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return from != ForgeDirection.UP && !fluid.isGaseous
}
override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return from != ForgeDirection.UP && !fluid.isGaseous
}
override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
if (!resource.getFluid.isGaseous)
{
return super.fill(from, resource, doFill)
}
return 0
}
}

View file

@ -12,7 +12,7 @@ import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidRegistry, FluidStack, IFluidTank}
import net.minecraftforge.fluids.{Fluid, FluidRegistry, FluidStack, IFluidTank}
import org.lwjgl.opengl.GL11
import resonant.api.recipe.{MachineRecipes, RecipeResource}
import resonant.content.factory.resources.RecipeType
@ -39,6 +39,26 @@ object TileGutter
class TileGutter extends TileFluidProvider(Material.rock)
{
fluidNode = new NodePressureGravity(this)
{
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return from != ForgeDirection.UP && !fluid.isGaseous
}
override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return from != ForgeDirection.UP && !fluid.isGaseous
}
override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
if (!resource.getFluid.isGaseous)
{
return super.fill(from, resource, doFill)
}
return 0
}
}
textureName = "material_wood_surface"
isOpaqueCube = false

View file

@ -51,7 +51,7 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
}
fluidNode.asInstanceOf[NodePressureGravity].maxFlowRate = FluidContainerRegistry.BUCKET_VOLUME
fluidNode.onFluidChanged = () => markUpdate()
fluidNode.onFluidChanged = () => if(!world.isRemote) sendPacket(0)
override def shouldSideBeRendered(access: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Boolean = new Vector3(x, y, z).getBlock(access) != block
@ -59,6 +59,7 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
{
if (!world.isRemote)
{
println(fluidNode.asInstanceOf[NodePressureGravity].pressure)
return FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side)
}
@ -106,10 +107,10 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
GL11.glScaled(0.99, 0.99, 0.99)
val tank: IFluidTank = fluidNode.getPrimaryTank
val percentageFilled: Double = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
val ySouthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.SOUTH, ForgeDirection.EAST)
val yNorthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.NORTH, ForgeDirection.EAST)
val ySouthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.SOUTH, ForgeDirection.WEST)
val yNorthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.NORTH, ForgeDirection.WEST)
val ySouthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.SOUTH, ForgeDirection.EAST)
val yNorthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.NORTH, ForgeDirection.EAST)
val ySouthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.SOUTH, ForgeDirection.WEST)
val yNorthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, toVector3, ForgeDirection.NORTH, ForgeDirection.WEST)
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
}
GL11.glPopMatrix()

View file

@ -5,6 +5,7 @@ import net.minecraftforge.fluids.{FluidContainerRegistry, IFluidHandler}
import resonant.api.grid.{INodeProvider, IUpdate}
import resonant.lib.grid.UpdateTicker
import resonant.lib.prefab.fluid.NodeFluid
import resonantinduction.archaic.fluid.gutter.NodePressureGravity
import scala.collection.convert.wrapAll._
@ -18,7 +19,7 @@ import scala.collection.convert.wrapAll._
*/
class NodePressure(parent: INodeProvider, volume: Int = FluidContainerRegistry.BUCKET_VOLUME) extends NodeFluid(parent, volume) with IUpdate
{
var maxFlowRate = 20
var maxFlowRate = 1000
var maxPressure = 100
private var _pressure: Int = 0
@ -120,7 +121,7 @@ class NodePressure(parent: INodeProvider, volume: Int = FluidContainerRegistry.B
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))
var quantity = if (pressureA > pressureB) (pressureA - pressureB) * flowRate else 0
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
if (quantity > 0)

View file

@ -8,8 +8,10 @@ import codechicken.lib.render.CCRenderState
import codechicken.lib.vec.{Cuboid6, Vector3}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.MovingObjectPosition
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.lib.`type`.EvictingList
@ -41,6 +43,7 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
material = PipeMaterials.ceramic
node.onConnectionChanged = () => sendPacket(0)
node.onFluidChanged = () => markPacket = true
override def getBounds: Cuboid6 = CuboidShapes.thickCenter
@ -78,6 +81,17 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
}
}
/**
* Changes the wire's color.
*/
override def activate(player: EntityPlayer, part: MovingObjectPosition, itemStack: ItemStack) : Boolean =
{
if(!world.isRemote)
println(node.pressure)
return super.activate(player, part, itemStack)
}
/**
* Packet Methods
*/

View file

@ -9,9 +9,12 @@ import net.minecraftforge.client.IItemRenderer.ItemRenderType
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.api.grid.INodeProvider
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
import resonant.lib.utility.WorldUtility
import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.{FluidUtility, WorldUtility}
import resonant.lib.wrapper.BitmaskWrapper._
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT)
@ -81,21 +84,27 @@ object RenderPipe extends ISimpleItemRenderer
GL11.glPushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
render(part.getMaterialID, if (part.getColor > 0) ItemDye.field_150922_c(part.getColor) else -1, part.clientRenderMask)
GL11.glPopMatrix()
GL11.glPushMatrix()
val fluid = part.tank.getFluid
val renderSides = part.clientRenderMask
val pos = new Vector3(x, y, z)
if (fluid != null && fluid.amount > 0)
{
GL11.glScaled(0.99, 0.99, 0.99)
val tank = part.tank
val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double]
val ySouthEast = percentageFilled
val yNorthEast = percentageFilled
val ySouthWest = percentageFilled
val yNorthWest = percentageFilled
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
ForgeDirection.VALID_DIRECTIONS.filter(d => part.clientRenderMask.mask(d.ordinal())).foreach(
dir =>
{
GL11.glPushMatrix()
GL11.glTranslated(dir.offsetX * 0.33, dir.offsetY * 0.33, dir.offsetZ * 0.33)
GL11.glScaled(0.33, 0.33, 0.33)
val tank = part.tank
val percentageFilled = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
val ySouthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[INodeProvider], percentageFilled, part.world, pos, ForgeDirection.SOUTH, ForgeDirection.EAST)
val yNorthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[INodeProvider], percentageFilled, part.world, pos, ForgeDirection.NORTH, ForgeDirection.EAST)
val ySouthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[INodeProvider], percentageFilled, part.world, pos, ForgeDirection.SOUTH, ForgeDirection.WEST)
val yNorthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[INodeProvider], percentageFilled, part.world, pos, ForgeDirection.NORTH, ForgeDirection.WEST)
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
GL11.glPopMatrix()
})
}
GL11.glPopMatrix()

View file

@ -15,12 +15,17 @@ class PumpNode(parent: INodeProvider) extends NodePressure(parent)
override def pressure(dir: ForgeDirection): Int =
{
if (dir == pump.getDirection)
if(pump.mechanicalNode.getPower > 0)
{
return Math.max(Math.abs(pump.mechanicalNode.torque / 8000d), 2) toInt
if (dir == pump.getDirection)
{
return Math.max(Math.log(Math.abs(pump.mechanicalNode.torque)), 2) toInt
}
return -Math.max(Math.log(Math.abs(pump.mechanicalNode.torque)), 2).toInt
}
return -Math.max(Math.abs(pump.mechanicalNode.torque / 8000d), 2).toInt
return 0
}
override def canConnect[B <: IFluidHandler](source: B, from: ForgeDirection): Boolean =

View file

@ -47,7 +47,7 @@ class TilePump extends TileMechanical(Material.iron) with IRotatable with IFluid
pressureNode.drain(getDirection, fill(getDirection.getOpposite, drain, true), true)
}
pressureNode.maxFlowRate = Math.abs(mechanicalNode.angularVelocity * 15).toInt
pressureNode.maxFlowRate = Math.abs(mechanicalNode.angularVelocity * 2000).toInt
}
}

View file

@ -53,7 +53,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
{
if (manualCrankTime > 0)
{
mechanicalNode.rotate(this, if (isClockwiseCrank) 15 else -15, if (isClockwiseCrank) 0.025f else -0.025f)
mechanicalNode.rotate(this, if (isClockwiseCrank) 50 else -50, if (isClockwiseCrank) 0.05f else -0.05f)
manualCrankTime -= 0.1
}
}
@ -71,8 +71,9 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
getMultiBlock.get.mechanicalNode.angularVelocity = -getMultiBlock.get.mechanicalNode.angularVelocity
return true
}
isClockwiseCrank = player.isSneaking
//TODO fix;
getMultiBlock.get.manualCrankTime = 2
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f)
player.addExhaustion(0.01f)