    001package net.minecraft.client.renderer.entity;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.block.Block;
    006import net.minecraft.client.model.ModelBase;
    007import net.minecraft.client.model.ModelMinecart;
    008import net.minecraft.client.renderer.RenderBlocks;
    009import net.minecraft.entity.Entity;
    010import net.minecraft.entity.item.EntityMinecart;
    011import net.minecraft.util.MathHelper;
    012import net.minecraft.util.Vec3;
    013import org.lwjgl.opengl.GL11;
    014
    015@SideOnly(Side.CLIENT)
    016public class RenderMinecart extends Render
    017{
    018    /** instance of ModelMinecart for rendering */
    019    protected ModelBase modelMinecart;
    020    protected final RenderBlocks field_94145_f;
    021
    022    public RenderMinecart()
    023    {
    024        this.shadowSize = 0.5F;
    025        this.modelMinecart = new ModelMinecart();
    026        this.field_94145_f = new RenderBlocks();
    027    }
    028
    029    /**
    030     * Renders the Minecart.
    031     */
    032    public void renderTheMinecart(EntityMinecart par1EntityMinecart, double par2, double par4, double par6, float par8, float par9)
    033    {
    034        GL11.glPushMatrix();
    035        long i = (long)par1EntityMinecart.entityId * 493286711L;
    036        i = i * i * 4392167121L + i * 98761L;
    037        float f2 = (((float)(i >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    038        float f3 = (((float)(i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    039        float f4 = (((float)(i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    040        GL11.glTranslatef(f2, f3, f4);
    041        double d3 = par1EntityMinecart.lastTickPosX + (par1EntityMinecart.posX - par1EntityMinecart.lastTickPosX) * (double)par9;
    042        double d4 = par1EntityMinecart.lastTickPosY + (par1EntityMinecart.posY - par1EntityMinecart.lastTickPosY) * (double)par9;
    043        double d5 = par1EntityMinecart.lastTickPosZ + (par1EntityMinecart.posZ - par1EntityMinecart.lastTickPosZ) * (double)par9;
    044        double d6 = 0.30000001192092896D;
    045        Vec3 vec3 = par1EntityMinecart.func_70489_a(d3, d4, d5);
    046        float f5 = par1EntityMinecart.prevRotationPitch + (par1EntityMinecart.rotationPitch - par1EntityMinecart.prevRotationPitch) * par9;
    047
    048        if (vec3 != null)
    049        {
    050            Vec3 vec31 = par1EntityMinecart.func_70495_a(d3, d4, d5, d6);
    051            Vec3 vec32 = par1EntityMinecart.func_70495_a(d3, d4, d5, -d6);
    052
    053            if (vec31 == null)
    054            {
    055                vec31 = vec3;
    056            }
    057
    058            if (vec32 == null)
    059            {
    060                vec32 = vec3;
    061            }
    062
    063            par2 += vec3.xCoord - d3;
    064            par4 += (vec31.yCoord + vec32.yCoord) / 2.0D - d4;
    065            par6 += vec3.zCoord - d5;
    066            Vec3 vec33 = vec32.addVector(-vec31.xCoord, -vec31.yCoord, -vec31.zCoord);
    067
    068            if (vec33.lengthVector() != 0.0D)
    069            {
    070                vec33 = vec33.normalize();
    071                par8 = (float)(Math.atan2(vec33.zCoord, vec33.xCoord) * 180.0D / Math.PI);
    072                f5 = (float)(Math.atan(vec33.yCoord) * 73.0D);
    073            }
    074        }
    075
    076        GL11.glTranslatef((float)par2, (float)par4, (float)par6);
    077        GL11.glRotatef(180.0F - par8, 0.0F, 1.0F, 0.0F);
    078        GL11.glRotatef(-f5, 0.0F, 0.0F, 1.0F);
    079        float f6 = (float)par1EntityMinecart.getRollingAmplitude() - par9;
    080        float f7 = (float)par1EntityMinecart.getDamage() - par9;
    081
    082        if (f7 < 0.0F)
    083        {
    084            f7 = 0.0F;
    085        }
    086
    087        if (f6 > 0.0F)
    088        {
    089            GL11.glRotatef(MathHelper.sin(f6) * f6 * f7 / 10.0F * (float)par1EntityMinecart.getRollingDirection(), 1.0F, 0.0F, 0.0F);
    090        }
    091
    092        int j = par1EntityMinecart.getDisplayTileOffset();
    093        Block block = par1EntityMinecart.getDisplayTile();
    094        int k = par1EntityMinecart.getDisplayTileData();
    095
    096        if (block != null)
    097        {
    098            GL11.glPushMatrix();
    099            this.loadTexture("/terrain.png");
    100            float f8 = 0.75F;
    101            GL11.glScalef(f8, f8, f8);
    102            GL11.glTranslatef(0.0F, (float)j / 16.0F, 0.0F);
    103            this.func_94144_a(par1EntityMinecart, par9, block, k);
    104            GL11.glPopMatrix();
    105            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    106        }
    107
    108        this.loadTexture("/item/cart.png");
    109        GL11.glScalef(-1.0F, -1.0F, 1.0F);
    110        this.modelMinecart.render(par1EntityMinecart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    111        GL11.glPopMatrix();
    112    }
    113
    114    protected void func_94144_a(EntityMinecart par1EntityMinecart, float par2, Block par3Block, int par4)
    115    {
    116        float f1 = par1EntityMinecart.getBrightness(par2);
    117        GL11.glPushMatrix();
    118        this.field_94145_f.renderBlockAsItem(par3Block, par4, f1);
    119        GL11.glPopMatrix();
    120    }
    121
    122    /**
    123     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    124     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    125     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    126     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    127     */
    128    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    129    {
    130        this.renderTheMinecart((EntityMinecart)par1Entity, par2, par4, par6, par8, par9);
    131    }
    132}