    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
    041        private RenderManager()
    042        {
    043            this.entityRenderMap.put(EntitySpider.class, new RenderSpider());
    044            this.entityRenderMap.put(EntityCaveSpider.class, new RenderSpider());
    045            this.entityRenderMap.put(EntityPig.class, new RenderPig(new ModelPig(), new ModelPig(0.5F), 0.7F));
    046            this.entityRenderMap.put(EntitySheep.class, new RenderSheep(new ModelSheep2(), new ModelSheep1(), 0.7F));
    047            this.entityRenderMap.put(EntityCow.class, new RenderCow(new ModelCow(), 0.7F));
    048            this.entityRenderMap.put(EntityMooshroom.class, new RenderMooshroom(new ModelCow(), 0.7F));
    049            this.entityRenderMap.put(EntityWolf.class, new RenderWolf(new ModelWolf(), 0.5F));
    050            this.entityRenderMap.put(EntityChicken.class, new RenderChicken(new ModelChicken(), 0.3F));
    051            this.entityRenderMap.put(EntityOcelot.class, new RenderOcelot(new ModelOcelot(), 0.4F));
    052            this.entityRenderMap.put(EntitySilverfish.class, new RenderSilverfish());
    053            this.entityRenderMap.put(EntityCreeper.class, new RenderCreeper());
    054            this.entityRenderMap.put(EntityEnderman.class, new RenderEnderman());
    055            this.entityRenderMap.put(EntitySnowman.class, new RenderSnowMan());
    056            this.entityRenderMap.put(EntitySkeleton.class, new RenderBiped(new ModelSkeleton(), 0.5F));
    057            this.entityRenderMap.put(EntityBlaze.class, new RenderBlaze());
    058            this.entityRenderMap.put(EntityZombie.class, new RenderBiped(new ModelZombie(), 0.5F));
    059            this.entityRenderMap.put(EntitySlime.class, new RenderSlime(new ModelSlime(16), new ModelSlime(0), 0.25F));
    060            this.entityRenderMap.put(EntityMagmaCube.class, new RenderMagmaCube());
    061            this.entityRenderMap.put(EntityPlayer.class, new RenderPlayer());
    062            this.entityRenderMap.put(EntityGiantZombie.class, new RenderGiantZombie(new ModelZombie(), 0.5F, 6.0F));
    063            this.entityRenderMap.put(EntityGhast.class, new RenderGhast());
    064            this.entityRenderMap.put(EntitySquid.class, new RenderSquid(new ModelSquid(), 0.7F));
    065            this.entityRenderMap.put(EntityVillager.class, new RenderVillager());
    066            this.entityRenderMap.put(EntityIronGolem.class, new RenderIronGolem());
    067            this.entityRenderMap.put(EntityLiving.class, new RenderLiving(new ModelBiped(), 0.5F));
    068            this.entityRenderMap.put(EntityDragon.class, new RenderDragon());
    069            this.entityRenderMap.put(EntityEnderCrystal.class, new RenderEnderCrystal());
    070            this.entityRenderMap.put(Entity.class, new RenderEntity());
    071            this.entityRenderMap.put(EntityPainting.class, new RenderPainting());
    072            this.entityRenderMap.put(EntityArrow.class, new RenderArrow());
    073            this.entityRenderMap.put(EntitySnowball.class, new RenderSnowball(Item.snowball.getIconFromDamage(0)));
    074            this.entityRenderMap.put(EntityEnderPearl.class, new RenderSnowball(Item.enderPearl.getIconFromDamage(0)));
    075            this.entityRenderMap.put(EntityEnderEye.class, new RenderSnowball(Item.eyeOfEnder.getIconFromDamage(0)));
    076            this.entityRenderMap.put(EntityEgg.class, new RenderSnowball(Item.egg.getIconFromDamage(0)));
    077            this.entityRenderMap.put(EntityPotion.class, new RenderSnowball(154));
    078            this.entityRenderMap.put(EntityExpBottle.class, new RenderSnowball(Item.expBottle.getIconFromDamage(0)));
    079            this.entityRenderMap.put(EntityFireball.class, new RenderFireball(2.0F));
    080            this.entityRenderMap.put(EntitySmallFireball.class, new RenderFireball(0.5F));
    081            this.entityRenderMap.put(EntityItem.class, new RenderItem());
    082            this.entityRenderMap.put(EntityXPOrb.class, new RenderXPOrb());
    083            this.entityRenderMap.put(EntityTNTPrimed.class, new RenderTNTPrimed());
    084            this.entityRenderMap.put(EntityFallingSand.class, new RenderFallingSand());
    085            this.entityRenderMap.put(EntityMinecart.class, new RenderMinecart());
    086            this.entityRenderMap.put(EntityBoat.class, new RenderBoat());
    087            this.entityRenderMap.put(EntityFishHook.class, new RenderFish());
    088            this.entityRenderMap.put(EntityLightningBolt.class, new RenderLightningBolt());
    089            Iterator var1 = this.entityRenderMap.values().iterator();
    090
    091            while (var1.hasNext())
    092            {
    093                Render var2 = (Render)var1.next();
    094                var2.setRenderManager(this);
    095            }
    096        }
    097
    098        public Render getEntityClassRenderObject(Class par1Class)
    099        {
    100            Render var2 = (Render)this.entityRenderMap.get(par1Class);
    101
    102            if (var2 == null && par1Class != Entity.class)
    103            {
    104                var2 = this.getEntityClassRenderObject(par1Class.getSuperclass());
    105                this.entityRenderMap.put(par1Class, var2);
    106            }
    107
    108            return var2;
    109        }
    110
    111        public Render getEntityRenderObject(Entity par1Entity)
    112        {
    113            return this.getEntityClassRenderObject(par1Entity.getClass());
    114        }
    115
    116        /**
    117         * Caches the current frame's active render info, including the current World, RenderEngine, GameSettings and
    118         * FontRenderer settings, as well as interpolated player position, pitch and yaw.
    119         */
    120        public void cacheActiveRenderInfo(World par1World, RenderEngine par2RenderEngine, FontRenderer par3FontRenderer, EntityLiving par4EntityLiving, GameSettings par5GameSettings, float par6)
    121        {
    122            this.worldObj = par1World;
    123            this.renderEngine = par2RenderEngine;
    124            this.options = par5GameSettings;
    125            this.livingPlayer = par4EntityLiving;
    126            this.fontRenderer = par3FontRenderer;
    127
    128            if (par4EntityLiving.isPlayerSleeping())
    129            {
    130                int x = MathHelper.floor_double(par4EntityLiving.posX);
    131                int y = MathHelper.floor_double(par4EntityLiving.posY);
    132                int z = MathHelper.floor_double(par4EntityLiving.posZ);
    133                Block block = Block.blocksList[par1World.getBlockId(x, y, z)];
    134
    135                if (block != null && block.isBed(par1World, x, y, z, par4EntityLiving))
    136                {
    137                    int var9 = block.getBedDirection(par1World, x, y, z);;
    138                    this.playerViewY = (float)(var9 * 90 + 180);
    139                    this.playerViewX = 0.0F;
    140                }
    141            }
    142            else
    143            {
    144                this.playerViewY = par4EntityLiving.prevRotationYaw + (par4EntityLiving.rotationYaw - par4EntityLiving.prevRotationYaw) * par6;
    145                this.playerViewX = par4EntityLiving.prevRotationPitch + (par4EntityLiving.rotationPitch - par4EntityLiving.prevRotationPitch) * par6;
    146            }
    147
    148            if (par5GameSettings.thirdPersonView == 2)
    149            {
    150                this.playerViewY += 180.0F;
    151            }
    152
    153            this.viewerPosX = par4EntityLiving.lastTickPosX + (par4EntityLiving.posX - par4EntityLiving.lastTickPosX) * (double)par6;
    154            this.viewerPosY = par4EntityLiving.lastTickPosY + (par4EntityLiving.posY - par4EntityLiving.lastTickPosY) * (double)par6;
    155            this.viewerPosZ = par4EntityLiving.lastTickPosZ + (par4EntityLiving.posZ - par4EntityLiving.lastTickPosZ) * (double)par6;
    156        }
    157
    158        /**
    159         * Will render the specified entity at the specified partial tick time. Args: entity, partialTickTime
    160         */
    161        public void renderEntity(Entity par1Entity, float par2)
    162        {
    163            double var3 = par1Entity.lastTickPosX + (par1Entity.posX - par1Entity.lastTickPosX) * (double)par2;
    164            double var5 = par1Entity.lastTickPosY + (par1Entity.posY - par1Entity.lastTickPosY) * (double)par2;
    165            double var7 = par1Entity.lastTickPosZ + (par1Entity.posZ - par1Entity.lastTickPosZ) * (double)par2;
    166            float var9 = par1Entity.prevRotationYaw + (par1Entity.rotationYaw - par1Entity.prevRotationYaw) * par2;
    167            int var10 = par1Entity.getBrightnessForRender(par2);
    168
    169            if (par1Entity.isBurning())
    170            {
    171                var10 = 15728880;
    172            }
    173
    174            int var11 = var10 % 65536;
    175            int var12 = var10 / 65536;
    176            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var11 / 1.0F, (float)var12 / 1.0F);
    177            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    178            this.renderEntityWithPosYaw(par1Entity, var3 - renderPosX, var5 - renderPosY, var7 - renderPosZ, var9, par2);
    179        }
    180
    181        /**
    182         * Renders the specified entity with the passed in position, yaw, and partialTickTime. Args: entity, x, y, z, yaw,
    183         * partialTickTime
    184         */
    185        public void renderEntityWithPosYaw(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    186        {
    187            Render var10 = this.getEntityRenderObject(par1Entity);
    188
    189            if (var10 != null)
    190            {
    191                var10.doRender(par1Entity, par2, par4, par6, par8, par9);
    192                var10.doRenderShadowAndFire(par1Entity, par2, par4, par6, par8, par9);
    193            }
    194        }
    195
    196        /**
    197         * World sets this RenderManager's worldObj to the world provided
    198         */
    199        public void set(World par1World)
    200        {
    201            this.worldObj = par1World;
    202        }
    203
    204        public double getDistanceToCamera(double par1, double par3, double par5)
    205        {
    206            double var7 = par1 - this.viewerPosX;
    207            double var9 = par3 - this.viewerPosY;
    208            double var11 = par5 - this.viewerPosZ;
    209            return var7 * var7 + var9 * var9 + var11 * var11;
    210        }
    211
    212        /**
    213         * Returns the font renderer
    214         */
    215        public FontRenderer getFontRenderer()
    216        {
    217            return this.fontRenderer;
    218        }
    219    }