    001    package net.minecraft.client.renderer.entity;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.block.Block;
    006    import net.minecraft.client.model.ModelBase;
    007    import net.minecraft.client.model.ModelMinecart;
    008    import net.minecraft.client.renderer.RenderBlocks;
    009    import net.minecraft.entity.Entity;
    010    import net.minecraft.entity.item.EntityMinecart;
    011    import net.minecraft.util.MathHelper;
    012    import net.minecraft.util.Vec3;
    013    import org.lwjgl.opengl.GL11;
    014
    015    @SideOnly(Side.CLIENT)
    016    public class RenderMinecart extends Render
    017    {
    018        /** instance of ModelMinecart for rendering */
    019        protected ModelBase modelMinecart;
    020
    021        public RenderMinecart()
    022        {
    023            this.shadowSize = 0.5F;
    024            this.modelMinecart = new ModelMinecart();
    025        }
    026
    027        /**
    028         * Renders the Minecart.
    029         */
    030        public void renderTheMinecart(EntityMinecart par1EntityMinecart, double par2, double par4, double par6, float par8, float par9)
    031        {
    032            GL11.glPushMatrix();
    033            long var10 = (long)par1EntityMinecart.entityId * 493286711L;
    034            var10 = var10 * var10 * 4392167121L + var10 * 98761L;
    035            float var12 = (((float)(var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    036            float var13 = (((float)(var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    037            float var14 = (((float)(var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
    038            GL11.glTranslatef(var12, var13, var14);
    039            double var15 = par1EntityMinecart.lastTickPosX + (par1EntityMinecart.posX - par1EntityMinecart.lastTickPosX) * (double)par9;
    040            double var17 = par1EntityMinecart.lastTickPosY + (par1EntityMinecart.posY - par1EntityMinecart.lastTickPosY) * (double)par9;
    041            double var19 = par1EntityMinecart.lastTickPosZ + (par1EntityMinecart.posZ - par1EntityMinecart.lastTickPosZ) * (double)par9;
    042            double var21 = 0.30000001192092896D;
    043            Vec3 var23 = par1EntityMinecart.func_70489_a(var15, var17, var19);
    044            float var24 = par1EntityMinecart.prevRotationPitch + (par1EntityMinecart.rotationPitch - par1EntityMinecart.prevRotationPitch) * par9;
    045
    046            if (var23 != null)
    047            {
    048                Vec3 var25 = par1EntityMinecart.func_70495_a(var15, var17, var19, var21);
    049                Vec3 var26 = par1EntityMinecart.func_70495_a(var15, var17, var19, -var21);
    050
    051                if (var25 == null)
    052                {
    053                    var25 = var23;
    054                }
    055
    056                if (var26 == null)
    057                {
    058                    var26 = var23;
    059                }
    060
    061                par2 += var23.xCoord - var15;
    062                par4 += (var25.yCoord + var26.yCoord) / 2.0D - var17;
    063                par6 += var23.zCoord - var19;
    064                Vec3 var27 = var26.addVector(-var25.xCoord, -var25.yCoord, -var25.zCoord);
    065
    066                if (var27.lengthVector() != 0.0D)
    067                {
    068                    var27 = var27.normalize();
    069                    par8 = (float)(Math.atan2(var27.zCoord, var27.xCoord) * 180.0D / Math.PI);
    070                    var24 = (float)(Math.atan(var27.yCoord) * 73.0D);
    071                }
    072            }
    073
    074            GL11.glTranslatef((float)par2, (float)par4, (float)par6);
    075            GL11.glRotatef(180.0F - par8, 0.0F, 1.0F, 0.0F);
    076            GL11.glRotatef(-var24, 0.0F, 0.0F, 1.0F);
    077            float var28 = (float)par1EntityMinecart.func_70496_j() - par9;
    078            float var30 = (float)par1EntityMinecart.getDamage() - par9;
    079
    080            if (var30 < 0.0F)
    081            {
    082                var30 = 0.0F;
    083            }
    084
    085            if (var28 > 0.0F)
    086            {
    087                GL11.glRotatef(MathHelper.sin(var28) * var28 * var30 / 10.0F * (float)par1EntityMinecart.func_70493_k(), 1.0F, 0.0F, 0.0F);
    088            }
    089
    090            if (par1EntityMinecart.minecartType != 0)
    091            {
    092                this.loadTexture("/terrain.png");
    093                float var29 = 0.75F;
    094                GL11.glScalef(var29, var29, var29);
    095
    096                if (par1EntityMinecart.minecartType == 1)
    097                {
    098                    GL11.glTranslatef(0.0F, 0.5F, 0.0F);
    099                    (new RenderBlocks()).renderBlockAsItem(Block.chest, 0, par1EntityMinecart.getBrightness(par9));
    100                    GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
    101                    GL11.glTranslatef(0.5F, 0.0F, -0.5F);
    102                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    103                }
    104                else if (par1EntityMinecart.minecartType == 2)
    105                {
    106                    GL11.glTranslatef(0.0F, 0.3125F, 0.0F);
    107                    (new RenderBlocks()).renderBlockAsItem(Block.stoneOvenIdle, 0, par1EntityMinecart.getBrightness(par9));
    108                    GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
    109                    GL11.glTranslatef(0.0F, -0.3125F, 0.0F);
    110                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    111                }
    112
    113                GL11.glScalef(1.0F / var29, 1.0F / var29, 1.0F / var29);
    114            }
    115
    116            this.loadTexture("/item/cart.png");
    117            GL11.glScalef(-1.0F, -1.0F, 1.0F);
    118            this.modelMinecart.render(par1EntityMinecart, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    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    }