2014-09-27 20:58:24 +02:00
|
|
|
package resonantinduction.mechanical.fluid.transport
|
|
|
|
|
2014-11-08 17:39:13 +01:00
|
|
|
import java.util.{ArrayList, List}
|
|
|
|
|
2014-09-27 20:58:24 +02:00
|
|
|
import net.minecraft.block.material.Material
|
|
|
|
import net.minecraft.tileentity.TileEntity
|
2014-11-08 17:39:13 +01:00
|
|
|
import net.minecraft.util.ResourceLocation
|
|
|
|
import net.minecraftforge.client.model.AdvancedModelLoader
|
2014-09-27 20:58:24 +02:00
|
|
|
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
|
2014-09-27 20:58:24 +02:00
|
|
|
import resonant.api.IRotatable
|
2014-10-27 18:31:42 +01:00
|
|
|
import resonant.api.grid.INode
|
2014-11-08 17:39:13 +01:00
|
|
|
import resonant.lib.render.RenderUtility
|
|
|
|
import resonant.lib.transform.vector.Vector3
|
|
|
|
import resonantinduction.core.Reference
|
2014-11-02 13:51:56 +01:00
|
|
|
import resonantinduction.mechanical.mech.TileMechanical
|
2014-09-27 20:58:24 +02:00
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2014-09-27 20:58:24 +02:00
|
|
|
class TilePump extends TileMechanical(Material.iron) with IRotatable with IFluidHandler
|
|
|
|
{
|
2014-11-09 06:28:58 +01:00
|
|
|
val pressureNode = new PumpNode(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-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
|
|
|
|
|
|
|
if (!worldObj.isRemote && mechanicalNode.getPower > 0)
|
2014-09-27 20:58:24 +02:00
|
|
|
{
|
2014-11-08 13:58:31 +01:00
|
|
|
val tileIn: TileEntity = toVector3.add(getDirection.getOpposite).getTileEntity(this.worldObj)
|
2014-11-02 13:51:56 +01:00
|
|
|
if (tileIn.isInstanceOf[IFluidHandler])
|
|
|
|
{
|
|
|
|
val drain: FluidStack = (tileIn.asInstanceOf[IFluidHandler]).drain(getDirection, pressureNode.getCapacity, false)
|
|
|
|
if (drain != null)
|
2014-09-27 20:58:24 +02:00
|
|
|
{
|
2014-11-02 13:51:56 +01:00
|
|
|
(tileIn.asInstanceOf[IFluidHandler]).drain(getDirection, fill(getDirection.getOpposite, drain, true), true)
|
2014-09-27 20:58:24 +02:00
|
|
|
}
|
2014-11-02 13:51:56 +01:00
|
|
|
}
|
2014-09-27 20:58:24 +02:00
|
|
|
}
|
2014-11-02 13:51:56 +01:00
|
|
|
}
|
2014-09-27 20:58:24 +02:00
|
|
|
|
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]
|
|
|
|
|
|
|
|
GL11.glPushMatrix
|
2014-11-09 06:55:01 +01:00
|
|
|
GL11.glRotated(Math.toDegrees(mechanicalNode.angle.asInstanceOf[Float]), 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-02 13:51:56 +01:00
|
|
|
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
|
|
|
|
{
|
|
|
|
if (from eq getDirection.getOpposite)
|
2014-09-27 20:58:24 +02:00
|
|
|
{
|
2014-11-08 13:58:31 +01:00
|
|
|
val tileOut: TileEntity = toVector3.add(from.getOpposite).getTileEntity(this.worldObj)
|
2014-11-02 13:51:56 +01:00
|
|
|
if (tileOut.isInstanceOf[IFluidHandler]) return (tileOut.asInstanceOf[IFluidHandler]).fill(from, resource, doFill)
|
2014-09-27 20:58:24 +02:00
|
|
|
}
|
2014-11-02 13:51:56 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
|
|
|
|
{
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
|
|
|
|
{
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
|
|
|
|
{
|
|
|
|
return from eq this.getDirection.getOpposite
|
|
|
|
}
|
|
|
|
|
|
|
|
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
|
|
|
|
{
|
|
|
|
return from eq this.getDirection
|
|
|
|
}
|
|
|
|
|
|
|
|
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
|
|
|
|
{
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
|
|
|
|
{
|
|
|
|
if (nodeType.isAssignableFrom(pressureNode.getClass))
|
|
|
|
return pressureNode.asInstanceOf[N]
|
|
|
|
|
|
|
|
return null.asInstanceOf[N]
|
|
|
|
}
|
2014-09-27 20:58:24 +02:00
|
|
|
}
|