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