electrodynamics/src/main/scala/edx/quantum/machine/TileFunnel.scala

114 lines
2.9 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.quantum.machine
2015-01-09 05:10:44 +01:00
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.IIcon
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
2014-12-09 23:46:07 +01:00
import resonant.api.tile.IBoilHandler
2015-01-09 05:10:44 +01:00
import resonant.lib.prefab.tile.spatial.SpatialTile
/**
* Funnel for gas.
*/
object TileFunnel
{
2015-01-09 05:10:44 +01:00
private var iconTop: IIcon = null
}
2015-01-09 05:10:44 +01:00
class TileFunnel extends SpatialTile(Material.iron) with IBoilHandler
{
2015-01-09 05:10:44 +01:00
private final val tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 16)
2015-01-09 05:10:44 +01:00
override def getIcon(side: Int, meta: Int): IIcon =
{
return if (side == 1 || side == 0) TileFunnel.iconTop else super.getIcon(side, meta)
}
2015-01-09 05:10:44 +01:00
@SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister)
{
super.registerIcons(iconRegister)
TileFunnel.iconTop = iconRegister.registerIcon(getTextureName + "_top")
}
2015-01-09 05:10:44 +01:00
override def update
{
super.update
if (tank.getFluidAmount > 0)
{
2015-01-09 05:10:44 +01:00
val tileEntity: TileEntity = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord)
if (tileEntity.isInstanceOf[IFluidHandler])
{
val handler: IFluidHandler = tileEntity.asInstanceOf[IFluidHandler]
if (handler.canFill(ForgeDirection.DOWN, tank.getFluid.getFluid))
{
2015-01-09 05:10:44 +01:00
val drainedStack: FluidStack = tank.drain(tank.getCapacity, false)
if (drainedStack != null)
{
tank.drain(handler.fill(ForgeDirection.DOWN, drainedStack, true), true)
}
}
2015-01-09 05:10:44 +01:00
}
}
2015-01-09 05:10:44 +01:00
}
2015-01-09 05:10:44 +01:00
override def readFromNBT(tag: NBTTagCompound)
{
super.readFromNBT(tag)
tank.writeToNBT(tag)
}
2015-01-09 05:10:44 +01:00
override def writeToNBT(tag: NBTTagCompound)
{
super.writeToNBT(tag)
tank.readFromNBT(tag)
}
2015-01-09 05:10:44 +01:00
/**
* Tank Methods
*/
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
return tank.fill(resource, doFill)
}
2015-01-09 05:10:44 +01:00
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
return this.tank.drain(maxDrain, doDrain)
}
2015-01-09 05:10:44 +01:00
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
if (resource == null || !resource.isFluidEqual(tank.getFluid))
{
2015-01-09 05:10:44 +01:00
return null
}
2015-01-09 05:10:44 +01:00
return tank.drain(resource.amount, doDrain)
}
2015-01-09 05:10:44 +01:00
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
if (fluid.isGaseous && from == ForgeDirection.DOWN)
{
2015-01-09 05:10:44 +01:00
return true
}
2015-01-09 05:10:44 +01:00
return false
}
2015-01-09 05:10:44 +01:00
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
if (fluid.isGaseous && from == ForgeDirection.UP)
{
2015-01-09 05:10:44 +01:00
return true
}
2015-01-09 05:10:44 +01:00
return false
}
2015-01-09 05:10:44 +01:00
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](tank.getInfo)
}
}