Fixed tank render

This commit is contained in:
Calclavia 2014-11-07 11:16:26 +08:00
parent 77ddba7c89
commit 28fa18f809
3 changed files with 33 additions and 29 deletions

View file

@ -29,15 +29,13 @@ import resonantinduction.core.prefab.node.{NodePressure, TileFluidProvider}
class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with RenderConnectedTexture
{
override protected val fluidNode = new NodePressure(this)
override val edgeTexture = Reference.prefix + "tankEdge"
edgeTexture = Reference.prefix + "tankEdge"
isOpaqueCube = false
normalRender = false
forceStandardRender(true)
itemBlock = classOf[ItemBlockTank]
nodes.add(fluidNode)
override def shouldSideBeRendered(access: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Boolean = access.getBlock(x, y, z) != getBlockType
override def shouldSideBeRendered(access: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Boolean = new Vector3(x, y, z).getBlock(access) != block
override def use(player: EntityPlayer, side: Int, vector3: Vector3): Boolean =
{
@ -62,7 +60,6 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
@SideOnly(Side.CLIENT)
override def renderDynamic(position: Vector3, frame: Float, pass: Int)
{
super.renderDynamic(position, frame, pass)
renderTankFluid(position.x, position.y, position.z, getFluid)
}
@ -83,7 +80,7 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
{
GL11.glScaled(0.99, 0.99, 0.99)
val tank: IFluidTank = getTank
val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double]
val percentageFilled: Double = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
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)
@ -105,15 +102,16 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
if (itemStack.getTagCompound != null && itemStack.getTagCompound.hasKey("fluid"))
{
renderTank(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound.getCompoundTag("fluid")), fluidNode.getPrimaryTank.getCapacity)
renderInventoryFluid(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound.getCompoundTag("fluid")), fluidNode.getPrimaryTank.getCapacity)
}
GL11.glPopMatrix()
}
def renderTank(x: Double, y: Double, z: Double, fluid: FluidStack, capacity: Int)
def renderInventoryFluid(x: Double, y: Double, z: Double, fluid: FluidStack, capacity: Int)
{
val tank: FluidTank = new FluidTank(fluid, capacity)
val tank = new FluidTank(fluid, capacity)
GL11.glPushMatrix()
GL11.glTranslated(0.02, 0.02, 0.02)
GL11.glScaled(0.92, 0.92, 0.92)
@ -122,12 +120,12 @@ class TileTank extends TileFluidProvider(Material.iron) with ISneakPickup with R
GL11.glPushMatrix()
if (!fluid.getFluid.isGaseous)
{
val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double]
val percentageFilled: Double = tank.getFluidAmount.toDouble / tank.getCapacity.toDouble
FluidRenderUtility.renderFluidTesselation(tank, percentageFilled, percentageFilled, percentageFilled, percentageFilled)
}
else
{
val filledPercentage: Double = fluid.amount.asInstanceOf[Double] / capacity.asInstanceOf[Double]
val filledPercentage: Double = fluid.amount.toDouble / capacity.toDouble
GL11.glPushAttrib(GL11.GL_ENABLE_BIT)
GL11.glEnable(GL11.GL_CULL_FACE)
GL11.glDisable(GL11.GL_LIGHTING)

View file

@ -11,6 +11,7 @@ import resonant.lib.network.ByteBufWrapper._
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.fluid.NodeFluid
import resonant.lib.wrapper.BitmaskWrapper._
/**
* A prefab class for tiles that use the fluid network.
@ -21,11 +22,12 @@ abstract class TileFluidProvider(material: Material) extends TileAdvanced(materi
{
protected val fluidNode: NodeFluid
protected var colorID: Int = 0
protected var clientRenderMask = 0x00
protected var clientRenderMask = 0x3F
override def start()
{
fluidNode.onConnectionChanged = () => sendPacket(1)
fluidNode.onConnectionChanged = () => if(!isInvalid) sendPacket(1)
nodes.add(fluidNode)
super.start()
}
@ -35,18 +37,6 @@ abstract class TileFluidProvider(material: Material) extends TileAdvanced(materi
def getTank: IFluidTank = fluidNode
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
colorID = nbt.getInteger("colorID")
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("colorID", colorID)
}
override def write(buf: ByteBuf, id: Int)
{
super.write(buf, id)
@ -56,13 +46,13 @@ abstract class TileFluidProvider(material: Material) extends TileAdvanced(materi
case 0 =>
{
buf <<< colorID
buf <<< fluidNode.connectedBitmask
buf <<< fluidNode.connectedMask.invert
buf <<< fluidNode.getPrimaryTank
}
case 1 =>
{
buf <<< colorID
buf <<< fluidNode.connectedBitmask
buf <<< fluidNode.connectedMask.invert
}
}
}
@ -85,6 +75,22 @@ abstract class TileFluidProvider(material: Material) extends TileAdvanced(materi
clientRenderMask = buf.readInt()
}
}
markRender()
}
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
fluidNode.load(nbt)
colorID = nbt.getInteger("colorID")
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
fluidNode.save(nbt)
nbt.setInteger("colorID", colorID)
}
override def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack = fluidNode.drain(from, resource, doDrain)

View file

@ -7,8 +7,8 @@ import net.minecraft.util.IIcon
import resonant.content.prefab.RenderConnectedTexture
import resonant.content.spatial.block.SpatialBlock
import resonant.lib.content.prefab.java.TileElectric
import resonantinduction.core.{Reference, Settings}
import resonant.lib.transform.region.Cuboid
import resonantinduction.core.{Reference, Settings}
class TileSolarPanel extends TileElectric(Material.iron) with RenderConnectedTexture
{
@ -17,7 +17,7 @@ class TileSolarPanel extends TileElectric(Material.iron) with RenderConnectedTex
bounds = new Cuboid(0, 0, 0, 1, 0.3f, 1)
isOpaqueCube = false
override val edgeTexture = Reference.prefix + "tankEdge"
edgeTexture = Reference.prefix + "tankEdge"
@SideOnly(Side.CLIENT)
override def registerIcons(iconReg: IIconRegister)