2014-08-11 06:41:09 +02:00
|
|
|
package resonantinduction.archaic.fluid.tank
|
|
|
|
|
|
|
|
import java.awt.Color
|
|
|
|
import java.util.{ArrayList, List}
|
|
|
|
|
2014-11-04 03:45:29 +01:00
|
|
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
2014-08-11 06:41:09 +02:00
|
|
|
import net.minecraft.block.material.Material
|
|
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
|
|
import net.minecraft.world.IBlockAccess
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection
|
2014-11-07 03:08:34 +01:00
|
|
|
import net.minecraftforge.fluids.{FluidStack, FluidTank, IFluidTank}
|
2014-08-11 06:41:09 +02:00
|
|
|
import org.lwjgl.opengl.GL11
|
|
|
|
import resonant.api.IRemovable.ISneakPickup
|
2014-11-04 03:45:29 +01:00
|
|
|
import resonant.content.prefab.RenderConnectedTexture
|
2014-08-11 06:41:09 +02:00
|
|
|
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
|
2014-11-04 03:45:29 +01:00
|
|
|
import resonant.lib.transform.vector.Vector3
|
2014-08-11 06:41:09 +02:00
|
|
|
import resonant.lib.utility.FluidUtility
|
2014-10-05 02:14:55 +02:00
|
|
|
import resonantinduction.archaic.ArchaicContent
|
2014-08-11 06:41:09 +02:00
|
|
|
import resonantinduction.core.Reference
|
2014-11-06 16:11:08 +01:00
|
|
|
import resonantinduction.core.prefab.node.{NodePressure, TileFluidProvider}
|
2014-08-11 06:41:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tile/Block class for basic Dynamic tanks
|
|
|
|
*
|
|
|
|
* @author Darkguardsman
|
|
|
|
*/
|
2014-11-06 16:11:08 +01:00
|
|
|
class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with RenderConnectedTexture
|
2014-09-07 05:50:03 +02:00
|
|
|
{
|
2014-11-07 03:08:34 +01:00
|
|
|
override protected val fluidNode = new NodePressure(this)
|
|
|
|
|
2014-11-07 04:16:26 +01:00
|
|
|
edgeTexture = Reference.prefix + "tankEdge"
|
2014-11-04 03:45:29 +01:00
|
|
|
isOpaqueCube = false
|
|
|
|
normalRender = false
|
|
|
|
itemBlock = classOf[ItemBlockTank]
|
|
|
|
|
2014-11-07 04:16:26 +01:00
|
|
|
override def shouldSideBeRendered(access: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Boolean = new Vector3(x, y, z).getBlock(access) != block
|
2014-08-11 06:41:09 +02:00
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def use(player: EntityPlayer, side: Int, vector3: Vector3): Boolean =
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
2014-10-20 19:45:50 +02:00
|
|
|
return FluidUtility.playerActivatedFluidItem(world, xi, yi, zi, player, side)
|
2014-08-11 06:41:09 +02:00
|
|
|
}
|
2014-11-06 16:11:08 +01:00
|
|
|
|
2014-08-11 06:41:09 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
override def getLightValue(access: IBlockAccess): Int =
|
|
|
|
{
|
2014-10-25 15:36:07 +02:00
|
|
|
if (getFluid != null && getFluid.getFluid != null)
|
2014-09-07 05:50:03 +02:00
|
|
|
{
|
2014-08-11 06:41:09 +02:00
|
|
|
return getFluid.getFluid.getLuminosity
|
|
|
|
}
|
2014-11-06 16:11:08 +01:00
|
|
|
|
2014-08-11 06:41:09 +02:00
|
|
|
return super.getLightValue(access)
|
|
|
|
}
|
|
|
|
|
2014-11-04 03:45:29 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-09-07 05:50:03 +02:00
|
|
|
override def renderDynamic(position: Vector3, frame: Float, pass: Int)
|
|
|
|
{
|
2014-11-04 03:45:29 +01:00
|
|
|
renderTankFluid(position.x, position.y, position.z, getFluid)
|
2014-09-07 05:50:03 +02:00
|
|
|
}
|
|
|
|
|
2014-11-04 03:45:29 +01:00
|
|
|
/**
|
|
|
|
* Renders the fluid inside the tank
|
|
|
|
*/
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
def renderTankFluid(x: Double, y: Double, z: Double, fluid: FluidStack)
|
2014-09-07 05:50:03 +02:00
|
|
|
{
|
|
|
|
if (world != null)
|
|
|
|
{
|
2014-11-02 14:18:55 +01:00
|
|
|
GL11.glPushMatrix()
|
2014-08-11 06:41:09 +02:00
|
|
|
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
|
2014-09-07 05:50:03 +02:00
|
|
|
if (fluid != null)
|
|
|
|
{
|
2014-11-02 14:18:55 +01:00
|
|
|
GL11.glPushMatrix()
|
2014-09-07 05:50:03 +02:00
|
|
|
if (!fluid.getFluid.isGaseous)
|
|
|
|
{
|
2014-08-11 06:41:09 +02:00
|
|
|
GL11.glScaled(0.99, 0.99, 0.99)
|
2014-08-16 02:11:58 +02:00
|
|
|
val tank: IFluidTank = getTank
|
2014-11-07 04:16:26 +01:00
|
|
|
val percentageFilled: Double = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
|
2014-10-20 19:45:50 +02:00
|
|
|
val ySouthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.SOUTH, ForgeDirection.EAST)
|
|
|
|
val yNorthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.NORTH, ForgeDirection.EAST)
|
|
|
|
val ySouthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.SOUTH, ForgeDirection.WEST)
|
|
|
|
val yNorthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileTank], percentageFilled, world, asVector3, ForgeDirection.NORTH, ForgeDirection.WEST)
|
2014-08-11 06:41:09 +02:00
|
|
|
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
|
|
|
|
}
|
2014-11-02 14:18:55 +01:00
|
|
|
GL11.glPopMatrix()
|
2014-08-11 06:41:09 +02:00
|
|
|
}
|
2014-11-02 14:18:55 +01:00
|
|
|
GL11.glPopMatrix()
|
2014-08-11 06:41:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 03:45:29 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
override def renderInventory(itemStack: ItemStack)
|
|
|
|
{
|
|
|
|
super.renderInventory(itemStack)
|
|
|
|
|
|
|
|
GL11.glPushMatrix()
|
|
|
|
|
|
|
|
if (itemStack.getTagCompound != null && itemStack.getTagCompound.hasKey("fluid"))
|
|
|
|
{
|
2014-11-07 04:16:26 +01:00
|
|
|
renderInventoryFluid(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound.getCompoundTag("fluid")), fluidNode.getPrimaryTank.getCapacity)
|
2014-11-04 03:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glPopMatrix()
|
|
|
|
}
|
|
|
|
|
2014-11-07 04:16:26 +01:00
|
|
|
def renderInventoryFluid(x: Double, y: Double, z: Double, fluid: FluidStack, capacity: Int)
|
2014-11-04 03:45:29 +01:00
|
|
|
{
|
2014-11-07 04:16:26 +01:00
|
|
|
val tank = new FluidTank(fluid, capacity)
|
|
|
|
|
2014-11-04 03:45:29 +01:00
|
|
|
GL11.glPushMatrix()
|
|
|
|
GL11.glTranslated(0.02, 0.02, 0.02)
|
|
|
|
GL11.glScaled(0.92, 0.92, 0.92)
|
|
|
|
if (fluid != null)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix()
|
|
|
|
if (!fluid.getFluid.isGaseous)
|
|
|
|
{
|
2014-11-07 04:16:26 +01:00
|
|
|
val percentageFilled: Double = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
|
2014-11-04 03:45:29 +01:00
|
|
|
FluidRenderUtility.renderFluidTesselation(tank, percentageFilled, percentageFilled, percentageFilled, percentageFilled)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-07 04:16:26 +01:00
|
|
|
val filledPercentage: Double = fluid.amount.toDouble / capacity.toDouble
|
2014-11-04 03:45:29 +01:00
|
|
|
GL11.glPushAttrib(GL11.GL_ENABLE_BIT)
|
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE)
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING)
|
|
|
|
GL11.glEnable(GL11.GL_BLEND)
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
val color: Color = new Color(fluid.getFluid.getColor)
|
|
|
|
RenderUtility.enableBlending()
|
|
|
|
GL11.glColor4d(color.getRed / 255f, color.getGreen / 255f, color.getBlue / 255f, if (fluid.getFluid.isGaseous) filledPercentage else 1)
|
|
|
|
RenderUtility.bind(FluidRenderUtility.getFluidSheet(fluid))
|
|
|
|
FluidRenderUtility.renderFluidTesselation(tank, 1, 1, 1, 1)
|
|
|
|
RenderUtility.disableBlending()
|
|
|
|
GL11.glPopAttrib()
|
|
|
|
}
|
|
|
|
GL11.glPopMatrix()
|
|
|
|
}
|
|
|
|
GL11.glPopMatrix()
|
|
|
|
}
|
|
|
|
|
2014-09-07 05:50:03 +02:00
|
|
|
def getRemovedItems(entity: EntityPlayer): List[ItemStack] =
|
|
|
|
{
|
2014-11-02 14:18:55 +01:00
|
|
|
val drops = new ArrayList[ItemStack]
|
2014-10-05 02:14:55 +02:00
|
|
|
val itemStack: ItemStack = new ItemStack(ArchaicContent.blockTank, 1, 0)
|
2014-09-07 05:50:03 +02:00
|
|
|
if (itemStack != null)
|
|
|
|
{
|
|
|
|
if (getTank != null && getTank.getFluid != null)
|
|
|
|
{
|
2014-08-11 06:41:09 +02:00
|
|
|
val stack: FluidStack = getTank.getFluid
|
2014-09-07 05:50:03 +02:00
|
|
|
if (stack != null)
|
|
|
|
{
|
|
|
|
if (itemStack.getTagCompound == null)
|
|
|
|
{
|
2014-08-11 06:41:09 +02:00
|
|
|
itemStack.setTagCompound(new NBTTagCompound)
|
|
|
|
}
|
|
|
|
drain(ForgeDirection.UNKNOWN, stack.amount, false)
|
|
|
|
itemStack.getTagCompound.setTag("fluid", stack.writeToNBT(new NBTTagCompound))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drops.add(itemStack)
|
|
|
|
}
|
|
|
|
return drops
|
|
|
|
}
|
|
|
|
}
|