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