    001    package net.minecraft.client.renderer.entity;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.HashMap;
    006    import java.util.Iterator;
    007    import java.util.Map;
    008    import net.minecraft.block.Block;
    009    import net.minecraft.client.gui.FontRenderer;
    010    import net.minecraft.client.model.ModelBiped;
    011    import net.minecraft.client.model.ModelChicken;
    012    import net.minecraft.client.model.ModelCow;
    013    import net.minecraft.client.model.ModelOcelot;
    014    import net.minecraft.client.model.ModelPig;
    015    import net.minecraft.client.model.ModelSheep1;
    016    import net.minecraft.client.model.ModelSheep2;
    017    import net.minecraft.client.model.ModelSlime;
    018    import net.minecraft.client.model.ModelSquid;
    019    import net.minecraft.client.model.ModelWolf;
    020    import net.minecraft.client.model.ModelZombie;
    021    import net.minecraft.client.renderer.ItemRenderer;
    022    import net.minecraft.client.renderer.OpenGlHelper;
    023    import net.minecraft.client.renderer.RenderEngine;
    024    import net.minecraft.client.renderer.Tessellator;
    025    import net.minecraft.client.renderer.tileentity.RenderEnderCrystal;
    026    import net.minecraft.client.renderer.tileentity.RenderItemFrame;
    027    import net.minecraft.client.renderer.tileentity.RenderWitherSkull;
    028    import net.minecraft.client.settings.GameSettings;
    029    import net.minecraft.crash.CrashReport;
    030    import net.minecraft.crash.CrashReportCategory;
    031    import net.minecraft.entity.Entity;
    032    import net.minecraft.entity.EntityLiving;
    033    import net.minecraft.entity.boss.EntityDragon;
    034    import net.minecraft.entity.boss.EntityWither;
    035    import net.minecraft.entity.effect.EntityLightningBolt;
    036    import net.minecraft.entity.item.EntityBoat;
    037    import net.minecraft.entity.item.EntityEnderCrystal;
    038    import net.minecraft.entity.item.EntityEnderEye;
    039    import net.minecraft.entity.item.EntityEnderPearl;
    040    import net.minecraft.entity.item.EntityExpBottle;
    041    import net.minecraft.entity.item.EntityFallingSand;
    042    import net.minecraft.entity.item.EntityItem;
    043    import net.minecraft.entity.item.EntityItemFrame;
    044    import net.minecraft.entity.item.EntityMinecart;
    045    import net.minecraft.entity.item.EntityPainting;
    046    import net.minecraft.entity.item.EntityTNTPrimed;
    047    import net.minecraft.entity.item.EntityXPOrb;
    048    import net.minecraft.entity.monster.EntityBlaze;
    049    import net.minecraft.entity.monster.EntityCaveSpider;
    050    import net.minecraft.entity.monster.EntityCreeper;
    051    import net.minecraft.entity.monster.EntityEnderman;
    052    import net.minecraft.entity.monster.EntityGhast;
    053    import net.minecraft.entity.monster.EntityGiantZombie;
    054    import net.minecraft.entity.monster.EntityIronGolem;
    055    import net.minecraft.entity.monster.EntityMagmaCube;
    056    import net.minecraft.entity.monster.EntitySilverfish;
    057    import net.minecraft.entity.monster.EntitySkeleton;
    058    import net.minecraft.entity.monster.EntitySlime;
    059    import net.minecraft.entity.monster.EntitySnowman;
    060    import net.minecraft.entity.monster.EntitySpider;
    061    import net.minecraft.entity.monster.EntityWitch;
    062    import net.minecraft.entity.monster.EntityZombie;
    063    import net.minecraft.entity.passive.EntityBat;
    064    import net.minecraft.entity.passive.EntityChicken;
    065    import net.minecraft.entity.passive.EntityCow;
    066    import net.minecraft.entity.passive.EntityMooshroom;
    067    import net.minecraft.entity.passive.EntityOcelot;
    068    import net.minecraft.entity.passive.EntityPig;
    069    import net.minecraft.entity.passive.EntitySheep;
    070    import net.minecraft.entity.passive.EntitySquid;
    071    import net.minecraft.entity.passive.EntityVillager;
    072    import net.minecraft.entity.passive.EntityWolf;
    073    import net.minecraft.entity.player.EntityPlayer;
    074    import net.minecraft.entity.projectile.EntityArrow;
    075    import net.minecraft.entity.projectile.EntityEgg;
    076    import net.minecraft.entity.projectile.EntityFishHook;
    077    import net.minecraft.entity.projectile.EntityLargeFireball;
    078    import net.minecraft.entity.projectile.EntityPotion;
    079    import net.minecraft.entity.projectile.EntitySmallFireball;
    080    import net.minecraft.entity.projectile.EntitySnowball;
    081    import net.minecraft.entity.projectile.EntityWitherSkull;
    082    import net.minecraft.item.Item;
    083    import net.minecraft.util.MathHelper;
    084    import net.minecraft.util.ReportedException;
    085    import net.minecraft.world.World;
    086    import org.lwjgl.opengl.GL11;
    087
    088    @SideOnly(Side.CLIENT)
    089    public class RenderManager
    090    {
    091        /** A map of entity classes and the associated renderer. */
    092        public Map entityRenderMap = new HashMap();
    093
    094        /** The static instance of RenderManager. */
    095        public static RenderManager instance = new RenderManager();
    096
    097        /** Renders fonts */
    098        private FontRenderer fontRenderer;
    099        public static double renderPosX;
    100        public static double renderPosY;
    101        public static double renderPosZ;
    102        public RenderEngine renderEngine;
    103        public ItemRenderer itemRenderer;
    104
    105        /** Reference to the World object. */
    106        public World worldObj;
    107
    108        /** Rendermanager's variable for the player */
    109        public EntityLiving livingPlayer;
    110        public float playerViewY;
    111        public float playerViewX;
    112
    113        /** Reference to the GameSettings object. */
    114        public GameSettings options;
    115        public double viewerPosX;
    116        public double viewerPosY;
    117        public double viewerPosZ;
    118        public static boolean field_85095_o = false;
    119
    120        private RenderManager()
    121        {
    122            this.entityRenderMap.put(EntitySpider.class, new RenderSpider());
    123            this.entityRenderMap.put(EntityCaveSpider.class, new RenderSpider());
    124            this.entityRenderMap.put(EntityPig.class, new RenderPig(new ModelPig(), new ModelPig(0.5F), 0.7F));
    125            this.entityRenderMap.put(EntitySheep.class, new RenderSheep(new ModelSheep2(), new ModelSheep1(), 0.7F));
    126            this.entityRenderMap.put(EntityCow.class, new RenderCow(new ModelCow(), 0.7F));
    127            this.entityRenderMap.put(EntityMooshroom.class, new RenderMooshroom(new ModelCow(), 0.7F));
    128            this.entityRenderMap.put(EntityWolf.class, new RenderWolf(new ModelWolf(), new ModelWolf(), 0.5F));
    129            this.entityRenderMap.put(EntityChicken.class, new RenderChicken(new ModelChicken(), 0.3F));
    130            this.entityRenderMap.put(EntityOcelot.class, new RenderOcelot(new ModelOcelot(), 0.4F));
    131            this.entityRenderMap.put(EntitySilverfish.class, new RenderSilverfish());
    132            this.entityRenderMap.put(EntityCreeper.class, new RenderCreeper());
    133            this.entityRenderMap.put(EntityEnderman.class, new RenderEnderman());
    134            this.entityRenderMap.put(EntitySnowman.class, new RenderSnowMan());
    135            this.entityRenderMap.put(EntitySkeleton.class, new RenderSkeleton());
    136            this.entityRenderMap.put(EntityWitch.class, new RenderWitch());
    137            this.entityRenderMap.put(EntityBlaze.class, new RenderBlaze());
    138            this.entityRenderMap.put(EntityZombie.class, new RenderZombie());
    139            this.entityRenderMap.put(EntitySlime.class, new RenderSlime(new ModelSlime(16), new ModelSlime(0), 0.25F));
    140            this.entityRenderMap.put(EntityMagmaCube.class, new RenderMagmaCube());
    141            this.entityRenderMap.put(EntityPlayer.class, new RenderPlayer());
    142            this.entityRenderMap.put(EntityGiantZombie.class, new RenderGiantZombie(new ModelZombie(), 0.5F, 6.0F));
    143            this.entityRenderMap.put(EntityGhast.class, new RenderGhast());
    144            this.entityRenderMap.put(EntitySquid.class, new RenderSquid(new ModelSquid(), 0.7F));
    145            this.entityRenderMap.put(EntityVillager.class, new RenderVillager());
    146            this.entityRenderMap.put(EntityIronGolem.class, new RenderIronGolem());
    147            this.entityRenderMap.put(EntityLiving.class, new RenderLiving(new ModelBiped(), 0.5F));
    148            this.entityRenderMap.put(EntityBat.class, new RenderBat());
    149            this.entityRenderMap.put(EntityDragon.class, new RenderDragon());
    150            this.entityRenderMap.put(EntityEnderCrystal.class, new RenderEnderCrystal());
    151            this.entityRenderMap.put(EntityWither.class, new RenderWither());
    152            this.entityRenderMap.put(Entity.class, new RenderEntity());
    153            this.entityRenderMap.put(EntityPainting.class, new RenderPainting());
    154            this.entityRenderMap.put(EntityItemFrame.class, new RenderItemFrame());
    155            this.entityRenderMap.put(EntityArrow.class, new RenderArrow());
    156            this.entityRenderMap.put(EntitySnowball.class, new RenderSnowball(Item.snowball.getIconFromDamage(0)));
    157            this.entityRenderMap.put(EntityEnderPearl.class, new RenderSnowball(Item.enderPearl.getIconFromDamage(0)));
    158            this.entityRenderMap.put(EntityEnderEye.class, new RenderSnowball(Item.eyeOfEnder.getIconFromDamage(0)));
    159            this.entityRenderMap.put(EntityEgg.class, new RenderSnowball(Item.egg.getIconFromDamage(0)));
    160            this.entityRenderMap.put(EntityPotion.class, new RenderSnowball(154));
    161            this.entityRenderMap.put(EntityExpBottle.class, new RenderSnowball(Item.expBottle.getIconFromDamage(0)));
    162            this.entityRenderMap.put(EntityLargeFireball.class, new RenderFireball(2.0F));
    163            this.entityRenderMap.put(EntitySmallFireball.class, new RenderFireball(0.5F));
    164            this.entityRenderMap.put(EntityWitherSkull.class, new RenderWitherSkull());
    165            this.entityRenderMap.put(EntityItem.class, new RenderItem());
    166            this.entityRenderMap.put(EntityXPOrb.class, new RenderXPOrb());
    167            this.entityRenderMap.put(EntityTNTPrimed.class, new RenderTNTPrimed());
    168            this.entityRenderMap.put(EntityFallingSand.class, new RenderFallingSand());
    169            this.entityRenderMap.put(EntityMinecart.class, new RenderMinecart());
    170            this.entityRenderMap.put(EntityBoat.class, new RenderBoat());
    171            this.entityRenderMap.put(EntityFishHook.class, new RenderFish());
    172            this.entityRenderMap.put(EntityLightningBolt.class, new RenderLightningBolt());
    173            Iterator var1 = this.entityRenderMap.values().iterator();
    174
    175            while (var1.hasNext())
    176            {
    177                Render var2 = (Render)var1.next();
    178                var2.setRenderManager(this);
    179            }
    180        }
    181
    182        public Render getEntityClassRenderObject(Class par1Class)
    183        {
    184            Render var2 = (Render)this.entityRenderMap.get(par1Class);
    185
    186            if (var2 == null && par1Class != Entity.class)
    187            {
    188                var2 = this.getEntityClassRenderObject(par1Class.getSuperclass());
    189                this.entityRenderMap.put(par1Class, var2);
    190            }
    191
    192            return var2;
    193        }
    194
    195        public Render getEntityRenderObject(Entity par1Entity)
    196        {
    197            return this.getEntityClassRenderObject(par1Entity.getClass());
    198        }
    199
    200        /**
    201         * Caches the current frame's active render info, including the current World, RenderEngine, GameSettings and
    202         * FontRenderer settings, as well as interpolated player position, pitch and yaw.
    203         */
    204        public void cacheActiveRenderInfo(World par1World, RenderEngine par2RenderEngine, FontRenderer par3FontRenderer, EntityLiving par4EntityLiving, GameSettings par5GameSettings, float par6)
    205        {
    206            this.worldObj = par1World;
    207            this.renderEngine = par2RenderEngine;
    208            this.options = par5GameSettings;
    209            this.livingPlayer = par4EntityLiving;
    210            this.fontRenderer = par3FontRenderer;
    211
    212            if (par4EntityLiving.isPlayerSleeping())
    213            {
    214                int x = MathHelper.floor_double(par4EntityLiving.posX);
    215                int y = MathHelper.floor_double(par4EntityLiving.posY);
    216                int z = MathHelper.floor_double(par4EntityLiving.posZ);
    217                Block block = Block.blocksList[par1World.getBlockId(x, y, z)];
    218
    219                if (block != null && block.isBed(par1World, x, y, z, par4EntityLiving))
    220                {
    221                    int var9 = block.getBedDirection(par1World, x, y, z);;
    222                    this.playerViewY = (float)(var9 * 90 + 180);
    223                    this.playerViewX = 0.0F;
    224                }
    225            }
    226            else
    227            {
    228                this.playerViewY = par4EntityLiving.prevRotationYaw + (par4EntityLiving.rotationYaw - par4EntityLiving.prevRotationYaw) * par6;
    229                this.playerViewX = par4EntityLiving.prevRotationPitch + (par4EntityLiving.rotationPitch - par4EntityLiving.prevRotationPitch) * par6;
    230            }
    231
    232            if (par5GameSettings.thirdPersonView == 2)
    233            {
    234                this.playerViewY += 180.0F;
    235            }
    236
    237            this.viewerPosX = par4EntityLiving.lastTickPosX + (par4EntityLiving.posX - par4EntityLiving.lastTickPosX) * (double)par6;
    238            this.viewerPosY = par4EntityLiving.lastTickPosY + (par4EntityLiving.posY - par4EntityLiving.lastTickPosY) * (double)par6;
    239            this.viewerPosZ = par4EntityLiving.lastTickPosZ + (par4EntityLiving.posZ - par4EntityLiving.lastTickPosZ) * (double)par6;
    240        }
    241
    242        /**
    243         * Will render the specified entity at the specified partial tick time. Args: entity, partialTickTime
    244         */
    245        public void renderEntity(Entity par1Entity, float par2)
    246        {
    247            if (par1Entity.ticksExisted == 0)
    248            {
    249                par1Entity.lastTickPosX = par1Entity.posX;
    250                par1Entity.lastTickPosY = par1Entity.posY;
    251                par1Entity.lastTickPosZ = par1Entity.posZ;
    252            }
    253
    254            double var3 = par1Entity.lastTickPosX + (par1Entity.posX - par1Entity.lastTickPosX) * (double)par2;
    255            double var5 = par1Entity.lastTickPosY + (par1Entity.posY - par1Entity.lastTickPosY) * (double)par2;
    256            double var7 = par1Entity.lastTickPosZ + (par1Entity.posZ - par1Entity.lastTickPosZ) * (double)par2;
    257            float var9 = par1Entity.prevRotationYaw + (par1Entity.rotationYaw - par1Entity.prevRotationYaw) * par2;
    258            int var10 = par1Entity.getBrightnessForRender(par2);
    259
    260            if (par1Entity.isBurning())
    261            {
    262                var10 = 15728880;
    263            }
    264
    265            int var11 = var10 % 65536;
    266            int var12 = var10 / 65536;
    267            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var11 / 1.0F, (float)var12 / 1.0F);
    268            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    269            this.renderEntityWithPosYaw(par1Entity, var3 - renderPosX, var5 - renderPosY, var7 - renderPosZ, var9, par2);
    270        }
    271
    272        /**
    273         * Renders the specified entity with the passed in position, yaw, and partialTickTime. Args: entity, x, y, z, yaw,
    274         * partialTickTime
    275         */
    276        public void renderEntityWithPosYaw(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    277        {
    278            Render var10 = null;
    279
    280            try
    281            {
    282                var10 = this.getEntityRenderObject(par1Entity);
    283
    284                if (var10 != null && this.renderEngine != null)
    285                {
    286                    if (field_85095_o)
    287                    {
    288                        try
    289                        {
    290                            this.func_85094_b(par1Entity, par2, par4, par6, par8, par9);
    291                        }
    292                        catch (Throwable var17)
    293                        {
    294                            throw new ReportedException(CrashReport.func_85055_a(var17, "Rendering entity hitbox in world"));
    295                        }
    296                    }
    297
    298                    try
    299                    {
    300                        var10.doRender(par1Entity, par2, par4, par6, par8, par9);
    301                    }
    302                    catch (Throwable var16)
    303                    {
    304                        throw new ReportedException(CrashReport.func_85055_a(var16, "Rendering entity in world"));
    305                    }
    306
    307                    try
    308                    {
    309                        var10.doRenderShadowAndFire(par1Entity, par2, par4, par6, par8, par9);
    310                    }
    311                    catch (Throwable var15)
    312                    {
    313                        throw new ReportedException(CrashReport.func_85055_a(var15, "Post-rendering entity in world"));
    314                    }
    315                }
    316            }
    317            catch (Throwable var18)
    318            {
    319                CrashReport var12 = CrashReport.func_85055_a(var18, "Rendering entity in world");
    320                CrashReportCategory var13 = var12.func_85058_a("Entity being rendered");
    321                par1Entity.func_85029_a(var13);
    322                CrashReportCategory var14 = var12.func_85058_a("Renderer details");
    323                var14.addCrashSection("Assigned renderer", var10);
    324                var14.addCrashSection("Location", CrashReportCategory.func_85074_a(par2, par4, par6));
    325                var14.addCrashSection("Rotation", Float.valueOf(par8));
    326                var14.addCrashSection("Delta", Float.valueOf(par9));
    327                throw new ReportedException(var12);
    328            }
    329        }
    330
    331        private void func_85094_b(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    332        {
    333            GL11.glDepthMask(false);
    334            GL11.glDisable(GL11.GL_TEXTURE_2D);
    335            GL11.glDisable(GL11.GL_LIGHTING);
    336            GL11.glDisable(GL11.GL_CULL_FACE);
    337            GL11.glDisable(GL11.GL_BLEND);
    338            GL11.glPushMatrix();
    339            Tessellator var10 = Tessellator.instance;
    340            var10.startDrawingQuads();
    341            var10.setColorRGBA(255, 255, 255, 32);
    342            double var11 = (double)(-par1Entity.width / 2.0F);
    343            double var13 = (double)(-par1Entity.width / 2.0F);
    344            double var15 = (double)(par1Entity.width / 2.0F);
    345            double var17 = (double)(-par1Entity.width / 2.0F);
    346            double var19 = (double)(-par1Entity.width / 2.0F);
    347            double var21 = (double)(par1Entity.width / 2.0F);
    348            double var23 = (double)(par1Entity.width / 2.0F);
    349            double var25 = (double)(par1Entity.width / 2.0F);
    350            double var27 = (double)par1Entity.height;
    351            var10.addVertex(par2 + var11, par4 + var27, par6 + var13);
    352            var10.addVertex(par2 + var11, par4, par6 + var13);
    353            var10.addVertex(par2 + var15, par4, par6 + var17);
    354            var10.addVertex(par2 + var15, par4 + var27, par6 + var17);
    355            var10.addVertex(par2 + var23, par4 + var27, par6 + var25);
    356            var10.addVertex(par2 + var23, par4, par6 + var25);
    357            var10.addVertex(par2 + var19, par4, par6 + var21);
    358            var10.addVertex(par2 + var19, par4 + var27, par6 + var21);
    359            var10.addVertex(par2 + var15, par4 + var27, par6 + var17);
    360            var10.addVertex(par2 + var15, par4, par6 + var17);
    361            var10.addVertex(par2 + var23, par4, par6 + var25);
    362            var10.addVertex(par2 + var23, par4 + var27, par6 + var25);
    363            var10.addVertex(par2 + var19, par4 + var27, par6 + var21);
    364            var10.addVertex(par2 + var19, par4, par6 + var21);
    365            var10.addVertex(par2 + var11, par4, par6 + var13);
    366            var10.addVertex(par2 + var11, par4 + var27, par6 + var13);
    367            var10.draw();
    368            GL11.glPopMatrix();
    369            GL11.glEnable(GL11.GL_TEXTURE_2D);
    370            GL11.glEnable(GL11.GL_LIGHTING);
    371            GL11.glEnable(GL11.GL_CULL_FACE);
    372            GL11.glDisable(GL11.GL_BLEND);
    373            GL11.glDepthMask(true);
    374        }
    375
    376        /**
    377         * World sets this RenderManager's worldObj to the world provided
    378         */
    379        public void set(World par1World)
    380        {
    381            this.worldObj = par1World;
    382        }
    383
    384        public double getDistanceToCamera(double par1, double par3, double par5)
    385        {
    386            double var7 = par1 - this.viewerPosX;
    387            double var9 = par3 - this.viewerPosY;
    388            double var11 = par5 - this.viewerPosZ;
    389            return var7 * var7 + var9 * var9 + var11 * var11;
    390        }
    391
    392        /**
    393         * Returns the font renderer
    394         */
    395        public FontRenderer getFontRenderer()
    396        {
    397            return this.fontRenderer;
    398        }
    399    }