Files
ForgeMultipart/codechicken/multipart/MultipartRenderer.scala
T
2013-05-20 17:09:57 +10:00

84 lines
3.0 KiB
Scala

package codechicken.multipart
import codechicken.core.lighting.LightMatrix
import codechicken.core.render.CCRenderState
import codechicken.core.vec.Cuboid6
import codechicken.core.vec.Vector3
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
import cpw.mods.fml.client.registry.RenderingRegistry
import net.minecraft.block.Block
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.world.IBlockAccess
import codechicken.core.vec.BlockCoord
import net.minecraft.world.IWorldAccess
import net.minecraft.util.MovingObjectPosition
import net.minecraft.client.Minecraft
import cpw.mods.fml.relauncher.SideOnly
import cpw.mods.fml.relauncher.Side
import codechicken.core.raytracer.ExtendedMOP
import codechicken.core.lighting.LazyLightMatrix
@SideOnly(Side.CLIENT)
object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRenderingHandler
{
TileMultipartObj.renderID = RenderingRegistry.getNextAvailableRenderId()
private val olm = new LazyLightMatrix
var pass:Int = 0
override def renderTileEntityAt(t:TileEntity, x:Double, y:Double, z:Double, f:Float)
{
var tmpart = t.asInstanceOf[TileMultipartClient]
if(tmpart.partList.isEmpty)
return
CCRenderState.reset()
CCRenderState.pullLightmap()
CCRenderState.useNormals(true)
val pos = new Vector3(x, y, z)
tmpart.renderDynamic(pos, f)
}
override def getRenderId = TileMultipartObj.renderID
override def renderWorldBlock(world:IBlockAccess, x:Int, y:Int, z:Int, block:Block, modelId:Int, renderer:RenderBlocks):Boolean =
{
var t = world.getBlockTileEntity(x, y, z)
if(!t.isInstanceOf[TileMultipartClient])
return false
var tmpart = t.asInstanceOf[TileMultipartClient]
if(tmpart.partList.isEmpty)
return false
if(renderer.hasOverrideBlockTexture())
{
val hit = Minecraft.getMinecraft().objectMouseOver
if(hit != null && hit.blockX == x && hit.blockY == y && hit.blockZ == z && ExtendedMOP.getData(hit).isInstanceOf[(_, _)])
{
val hitInfo:(Int, _) = ExtendedMOP.getData(hit)
if(hitInfo._1.isInstanceOf[Int] && hitInfo._1 >= 0 && hitInfo._1 < tmpart.partList.size)
tmpart.partList(hitInfo._1).drawBreaking(renderer)
}
return false
}
CCRenderState.reset()
CCRenderState.useModelColours(true)
val pos = new Vector3(x, y, z)
olm.setPos(world, x, y, z)
tmpart.renderStatic(pos, olm, pass)
return true
}
override def renderInventoryBlock(block:Block, meta:Int, modelId:Int, renderer:RenderBlocks)
{
//TODO: pass to the super renderer.
}
override def shouldRender3DInInventory = false
}