electrodynamics/src/main/scala/edx/mechanical/fluid/transport/TilePump.scala

100 lines
3.1 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.mechanical.fluid.transport
2015-01-14 12:06:03 +01:00
import edx.core.Reference
import edx.mechanical.mech.TileMechanical
import net.minecraft.block.material.Material
2014-11-08 17:39:13 +01:00
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{Fluid, FluidStack, FluidTankInfo, IFluidHandler}
2014-11-08 17:39:13 +01:00
import org.lwjgl.opengl.GL11
2015-01-26 12:40:32 +01:00
import resonantengine.api.tile.IRotatable
import resonantengine.lib.render.RenderUtility
import resonantengine.lib.transform.vector.Vector3
2014-11-08 17:39:13 +01:00
import scala.collection.mutable
object TilePump
{
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "pump.tcn"))
val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "pump.png")
}
class TilePump extends TileMechanical(Material.iron) with IRotatable with IFluidHandler
{
2014-12-10 15:28:54 +01:00
val pressureNode = new NodePump(this)
2014-11-02 13:51:56 +01:00
//Constructor
2014-11-08 17:39:13 +01:00
normalRender = false
isOpaqueCube = false
2014-11-02 13:51:56 +01:00
setTextureName("material_steel")
2014-11-11 14:09:30 +01:00
2014-11-09 08:09:59 +01:00
nodes.add(pressureNode)
2014-11-02 13:51:56 +01:00
2014-11-08 17:41:34 +01:00
override def update()
2014-11-02 13:51:56 +01:00
{
2014-11-08 17:41:34 +01:00
super.update()
2014-11-02 13:51:56 +01:00
2014-11-12 13:26:51 +01:00
if (!worldObj.isRemote && mechanicalNode.power > 0)
{
2014-11-11 14:09:30 +01:00
//Push fluid inside this block to its front
//TODO: Allow change of direction based on angular velocity
val drain = pressureNode.drain(getDirection, pressureNode.getCapacity, false)
2014-11-09 08:09:59 +01:00
2014-11-11 14:09:30 +01:00
if (drain != null)
2014-11-02 13:51:56 +01:00
{
2014-11-11 14:09:30 +01:00
pressureNode.drain(getDirection, fill(getDirection.getOpposite, drain, true), true)
2014-11-02 13:51:56 +01:00
}
2014-11-11 14:09:30 +01:00
2014-11-11 15:28:25 +01:00
pressureNode.maxFlowRate = Math.abs(mechanicalNode.angularVelocity * 2000).toInt
}
2014-11-02 13:51:56 +01:00
}
2015-01-14 12:06:03 +01:00
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
if (from == getDirection.getOpposite)
{
2021-04-05 14:41:30 +02:00
val tileOut = (toVectorWorld + from.getOpposite).getTileEntity
if (tileOut.isInstanceOf[IFluidHandler])
return (tileOut.asInstanceOf[IFluidHandler]).fill(from, resource, doFill)
2015-01-14 12:06:03 +01:00
}
return 0
}
2014-11-08 17:39:13 +01:00
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
{
GL11.glPushMatrix()
2014-11-08 17:41:34 +01:00
GL11.glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5)
2014-11-08 17:39:13 +01:00
GL11.glRotatef(-90, 0, 1, 0)
if (tile.getWorldObj != null) RenderUtility.rotateBlockBasedOnDirection(getDirection)
RenderUtility.bind(TilePump.texture)
val notRendered = mutable.Set.empty[String]
2014-11-09 08:09:59 +01:00
GL11.glPushMatrix()
GL11.glRotated(Math.toDegrees(mechanicalNode.angle), 0, 0, 1)
2014-11-08 17:39:13 +01:00
for (i <- 1 to 12)
{
val fin: String = "fin" + i
val innerFin: String = "innerFin" + i
notRendered.add(fin)
notRendered.add(innerFin)
TilePump.model.renderOnly(fin, innerFin)
}
GL11.glPopMatrix()
TilePump.model.renderAllExcept(notRendered.toArray[String]: _*)
GL11.glPopMatrix()
}
2014-11-09 08:09:59 +01:00
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack = null
2014-11-02 13:51:56 +01:00
2014-11-09 08:09:59 +01:00
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack = null
2014-11-02 13:51:56 +01:00
2014-11-11 14:09:30 +01:00
def canFill(from: ForgeDirection, fluid: Fluid): Boolean = from == getDirection.getOpposite
2014-11-02 13:51:56 +01:00
2014-11-11 14:09:30 +01:00
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = from == getDirection
2014-11-02 13:51:56 +01:00
2014-11-09 08:09:59 +01:00
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = null
2021-04-05 14:41:30 +02:00
}