    001    package net.minecraft.src;
    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 org.lwjgl.opengl.GL11;
    009
    010    @SideOnly(Side.CLIENT)
    011    public class RenderManager
    012    {
    013        /** A map of entity classes and the associated renderer. */
    014        public Map entityRenderMap = new HashMap();
    015
    016        /** The static instance of RenderManager. */
    017        public static RenderManager instance = new RenderManager();
    018
    019        /** Renders fonts */
    020        private FontRenderer fontRenderer;
    021        public static double renderPosX;
    022        public static double renderPosY;
    023        public static double renderPosZ;
    024        public RenderEngine renderEngine;
    025        public ItemRenderer itemRenderer;
    026
    027        /** Reference to the World object. */
    028        public World worldObj;
    029
    030        /** Rendermanager's variable for the player */
    031        public EntityLiving livingPlayer;
    032        public float playerViewY;
    033        public float playerViewX;
    034
    035        /** Reference to the GameSettings object. */
    036        public GameSettings options;
    037        public double viewerPosX;
    038        public double viewerPosY;
    039        public double viewerPosZ;
    040        public static boolean field_85095_o = false;
    041
    042        private RenderManager()
    043        {
    044            this.entityRenderMap.put(EntitySpider.class, new RenderSpider());
    045            this.entityRenderMap.put(EntityCaveSpider.class, new RenderSpider());
    046            this.entityRenderMap.put(EntityPig.class, new RenderPig(new ModelPig(), new ModelPig(0.5F), 0.7F));
    047            this.entityRenderMap.put(EntitySheep.class, new RenderSheep(new ModelSheep2(), new ModelSheep1(), 0.7F));
    048            this.entityRenderMap.put(EntityCow.class, new RenderCow(new ModelCow(), 0.7F));
    049            this.entityRenderMap.put(EntityMooshroom.class, new RenderMooshroom(new ModelCow(), 0.7F));
    050            this.entityRenderMap.put(EntityWolf.class, new RenderWolf(new ModelWolf(), new ModelWolf(), 0.5F));
    051            this.entityRenderMap.put(EntityChicken.class, new RenderChicken(new ModelChicken(), 0.3F));
    052            this.entityRenderMap.put(EntityOcelot.class, new RenderOcelot(new ModelOcelot(), 0.4F));
    053            this.entityRenderMap.put(EntitySilverfish.class, new RenderSilverfish());
    054            this.entityRenderMap.put(EntityCreeper.class, new RenderCreeper());
    055            this.entityRenderMap.put(EntityEnderman.class, new RenderEnderman());
    056            this.entityRenderMap.put(EntitySnowman.class, new RenderSnowMan());
    057            this.entityRenderMap.put(EntitySkeleton.class, new RenderSkeleton());
    058            this.entityRenderMap.put(EntityWitch.class, new RenderWitch());
    059            this.entityRenderMap.put(EntityBlaze.class, new RenderBlaze());
    060            this.entityRenderMap.put(EntityZombie.class, new RenderZombie());
    061            this.entityRenderMap.put(EntitySlime.class, new RenderSlime(new ModelSlime(16), new ModelSlime(0), 0.25F));
    062            this.entityRenderMap.put(EntityMagmaCube.class, new RenderMagmaCube());
    063            this.entityRenderMap.put(EntityPlayer.class, new RenderPlayer());
    064            this.entityRenderMap.put(EntityGiantZombie.class, new RenderGiantZombie(new ModelZombie(), 0.5F, 6.0F));
    065            this.entityRenderMap.put(EntityGhast.class, new RenderGhast());
    066            this.entityRenderMap.put(EntitySquid.class, new RenderSquid(new ModelSquid(), 0.7F));
    067            this.entityRenderMap.put(EntityVillager.class, new RenderVillager());
    068            this.entityRenderMap.put(EntityIronGolem.class, new RenderIronGolem());
    069            this.entityRenderMap.put(EntityLiving.class, new RenderLiving(new ModelBiped(), 0.5F));
    070            this.entityRenderMap.put(EntityBat.class, new RenderBat());
    071            this.entityRenderMap.put(EntityDragon.class, new RenderDragon());
    072            this.entityRenderMap.put(EntityEnderCrystal.class, new RenderEnderCrystal());
    073            this.entityRenderMap.put(EntityWither.class, new RenderWither());
    074            this.entityRenderMap.put(Entity.class, new RenderEntity());
    075            this.entityRenderMap.put(EntityPainting.class, new RenderPainting());
    076            this.entityRenderMap.put(EntityItemFrame.class, new RenderItemFrame());
    077            this.entityRenderMap.put(EntityArrow.class, new RenderArrow());
    078            this.entityRenderMap.put(EntitySnowball.class, new RenderSnowball(Item.snowball.getIconFromDamage(0)));
    079            this.entityRenderMap.put(EntityEnderPearl.class, new RenderSnowball(Item.enderPearl.getIconFromDamage(0)));
    080            this.entityRenderMap.put(EntityEnderEye.class, new RenderSnowball(Item.eyeOfEnder.getIconFromDamage(0)));
    081            this.entityRenderMap.put(EntityEgg.class, new RenderSnowball(Item.egg.getIconFromDamage(0)));
    082            this.entityRenderMap.put(EntityPotion.class, new RenderSnowball(154));
    083            this.entityRenderMap.put(EntityExpBottle.class, new RenderSnowball(Item.expBottle.getIconFromDamage(0)));
    084            this.entityRenderMap.put(EntityLargeFireball.class, new RenderFireball(2.0F));
    085            this.entityRenderMap.put(EntitySmallFireball.class, new RenderFireball(0.5F));
    086            this.entityRenderMap.put(EntityWitherSkull.class, new RenderWitherSkull());
    087            this.entityRenderMap.put(EntityItem.class, new RenderItem());
    088            this.entityRenderMap.put(EntityXPOrb.class, new RenderXPOrb());
    089            this.entityRenderMap.put(EntityTNTPrimed.class, new RenderTNTPrimed());
    090            this.entityRenderMap.put(EntityFallingSand.class, new RenderFallingSand());
    091            this.entityRenderMap.put(EntityMinecart.class, new RenderMinecart());
    092            this.entityRenderMap.put(EntityBoat.class, new RenderBoat());
    093            this.entityRenderMap.put(EntityFishHook.class, new RenderFish());
    094            this.entityRenderMap.put(EntityLightningBolt.class, new RenderLightningBolt());
    095            Iterator var1 = this.entityRenderMap.values().iterator();
    096
    097            while (var1.hasNext())
    098            {
    099                Render var2 = (Render)var1.next();
    100                var2.setRenderManager(this);
    101            }
    102        }
    103
    104        public Render getEntityClassRenderObject(Class par1Class)
    105        {
    106            Render var2 = (Render)this.entityRenderMap.get(par1Class);
    107
    108            if (var2 == null && par1Class != Entity.class)
    109            {
    110                var2 = this.getEntityClassRenderObject(par1Class.getSuperclass());
    111                this.entityRenderMap.put(par1Class, var2);
    112            }
    113
    114            return var2;
    115        }
    116
    117        public Render getEntityRenderObject(Entity par1Entity)
    118        {
    119            return this.getEntityClassRenderObject(par1Entity.getClass());
    120        }
    121
    122        /**
    123         * Caches the current frame's active render info, including the current World, RenderEngine, GameSettings and
    124         * FontRenderer settings, as well as interpolated player position, pitch and yaw.
    125         */
    126        public void cacheActiveRenderInfo(World par1World, RenderEngine par2RenderEngine, FontRenderer par3FontRenderer, EntityLiving par4EntityLiving, GameSettings par5GameSettings, float par6)
    127        {
    128            this.worldObj = par1World;
    129            this.renderEngine = par2RenderEngine;
    130            this.options = par5GameSettings;
    131            this.livingPlayer = par4EntityLiving;
    132            this.fontRenderer = par3FontRenderer;
    133
    134            if (par4EntityLiving.isPlayerSleeping())
    135            {
    136                int x = MathHelper.floor_double(par4EntityLiving.posX);
    137                int y = MathHelper.floor_double(par4EntityLiving.posY);
    138                int z = MathHelper.floor_double(par4EntityLiving.posZ);
    139                Block block = Block.blocksList[par1World.getBlockId(x, y, z)];
    140
    141                if (block != null && block.isBed(par1World, x, y, z, par4EntityLiving))
    142                {
    143                    int var9 = block.getBedDirection(par1World, x, y, z);;
    144                    this.playerViewY = (float)(var9 * 90 + 180);
    145                    this.playerViewX = 0.0F;
    146                }
    147            }
    148            else
    149            {
    150                this.playerViewY = par4EntityLiving.prevRotationYaw + (par4EntityLiving.rotationYaw - par4EntityLiving.prevRotationYaw) * par6;
    151                this.playerViewX = par4EntityLiving.prevRotationPitch + (par4EntityLiving.rotationPitch - par4EntityLiving.prevRotationPitch) * par6;
    152            }
    153
    154            if (par5GameSettings.thirdPersonView == 2)
    155            {
    156                this.playerViewY += 180.0F;
    157            }
    158
    159            this.viewerPosX = par4EntityLiving.lastTickPosX + (par4EntityLiving.posX - par4EntityLiving.lastTickPosX) * (double)par6;
    160            this.viewerPosY = par4EntityLiving.lastTickPosY + (par4EntityLiving.posY - par4EntityLiving.lastTickPosY) * (double)par6;
    161            this.viewerPosZ = par4EntityLiving.lastTickPosZ + (par4EntityLiving.posZ - par4EntityLiving.lastTickPosZ) * (double)par6;
    162        }
    163
    164        /**
    165         * Will render the specified entity at the specified partial tick time. Args: entity, partialTickTime
    166         */
    167        public void renderEntity(Entity par1Entity, float par2)
    168        {
    169            double var3 = par1Entity.lastTickPosX + (par1Entity.posX - par1Entity.lastTickPosX) * (double)par2;
    170            double var5 = par1Entity.lastTickPosY + (par1Entity.posY - par1Entity.lastTickPosY) * (double)par2;
    171            double var7 = par1Entity.lastTickPosZ + (par1Entity.posZ - par1Entity.lastTickPosZ) * (double)par2;
    172            float var9 = par1Entity.prevRotationYaw + (par1Entity.rotationYaw - par1Entity.prevRotationYaw) * par2;
    173            int var10 = par1Entity.getBrightnessForRender(par2);
    174
    175            if (par1Entity.isBurning())
    176            {
    177                var10 = 15728880;
    178            }
    179
    180            int var11 = var10 % 65536;
    181            int var12 = var10 / 65536;
    182            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var11 / 1.0F, (float)var12 / 1.0F);
    183            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    184            this.renderEntityWithPosYaw(par1Entity, var3 - renderPosX, var5 - renderPosY, var7 - renderPosZ, var9, par2);
    185        }
    186
    187        /**
    188         * Renders the specified entity with the passed in position, yaw, and partialTickTime. Args: entity, x, y, z, yaw,
    189         * partialTickTime
    190         */
    191        public void renderEntityWithPosYaw(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    192        {
    193            Render var10 = this.getEntityRenderObject(par1Entity);
    194
    195            if (var10 != null && this.renderEngine != null)
    196            {
    197                if (field_85095_o)
    198                {
    199                    this.func_85094_b(par1Entity, par2, par4, par6, par8, par9);
    200                }
    201
    202                var10.doRender(par1Entity, par2, par4, par6, par8, par9);
    203                var10.doRenderShadowAndFire(par1Entity, par2, par4, par6, par8, par9);
    204            }
    205        }
    206
    207        private void func_85094_b(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    208        {
    209            GL11.glDepthMask(false);
    210            GL11.glDisable(GL11.GL_TEXTURE_2D);
    211            GL11.glDisable(GL11.GL_LIGHTING);
    212            GL11.glDisable(GL11.GL_CULL_FACE);
    213            GL11.glDisable(GL11.GL_BLEND);
    214            GL11.glPushMatrix();
    215            Tessellator var10 = Tessellator.instance;
    216            var10.startDrawingQuads();
    217            var10.setColorRGBA(255, 255, 255, 32);
    218            double var11 = (double)(-par1Entity.width / 2.0F);
    219            double var13 = (double)(-par1Entity.width / 2.0F);
    220            double var15 = (double)(par1Entity.width / 2.0F);
    221            double var17 = (double)(-par1Entity.width / 2.0F);
    222            double var19 = (double)(-par1Entity.width / 2.0F);
    223            double var21 = (double)(par1Entity.width / 2.0F);
    224            double var23 = (double)(par1Entity.width / 2.0F);
    225            double var25 = (double)(par1Entity.width / 2.0F);
    226            double var27 = (double)par1Entity.height;
    227            var10.addVertex(par2 + var11, par4 + var27, par6 + var13);
    228            var10.addVertex(par2 + var11, par4, par6 + var13);
    229            var10.addVertex(par2 + var15, par4, par6 + var17);
    230            var10.addVertex(par2 + var15, par4 + var27, par6 + var17);
    231            var10.addVertex(par2 + var23, par4 + var27, par6 + var25);
    232            var10.addVertex(par2 + var23, par4, par6 + var25);
    233            var10.addVertex(par2 + var19, par4, par6 + var21);
    234            var10.addVertex(par2 + var19, par4 + var27, par6 + var21);
    235            var10.addVertex(par2 + var15, par4 + var27, par6 + var17);
    236            var10.addVertex(par2 + var15, par4, par6 + var17);
    237            var10.addVertex(par2 + var23, par4, par6 + var25);
    238            var10.addVertex(par2 + var23, par4 + var27, par6 + var25);
    239            var10.addVertex(par2 + var19, par4 + var27, par6 + var21);
    240            var10.addVertex(par2 + var19, par4, par6 + var21);
    241            var10.addVertex(par2 + var11, par4, par6 + var13);
    242            var10.addVertex(par2 + var11, par4 + var27, par6 + var13);
    243            var10.draw();
    244            GL11.glPopMatrix();
    245            GL11.glEnable(GL11.GL_TEXTURE_2D);
    246            GL11.glEnable(GL11.GL_LIGHTING);
    247            GL11.glEnable(GL11.GL_CULL_FACE);
    248            GL11.glDisable(GL11.GL_BLEND);
    249            GL11.glDepthMask(true);
    250        }
    251
    252        /**
    253         * World sets this RenderManager's worldObj to the world provided
    254         */
    255        public void set(World par1World)
    256        {
    257            this.worldObj = par1World;
    258        }
    259
    260        public double getDistanceToCamera(double par1, double par3, double par5)
    261        {
    262            double var7 = par1 - this.viewerPosX;
    263            double var9 = par3 - this.viewerPosY;
    264            double var11 = par5 - this.viewerPosZ;
    265            return var7 * var7 + var9 * var9 + var11 * var11;
    266        }
    267
    268        /**
    269         * Returns the font renderer
    270         */
    271        public FontRenderer getFontRenderer()
    272        {
    273            return this.fontRenderer;
    274        }
    275    }