Advertisement
robin4002

Untitled

Nov 28th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.57 KB | None | 0 0
  1. package net.minecraft.client.renderer.entity;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.client.gui.FontRenderer;
  7. import net.minecraft.client.renderer.RenderBlocks;
  8. import net.minecraft.client.renderer.Tessellator;
  9. import net.minecraft.client.renderer.texture.IconRegister;
  10. import net.minecraft.client.renderer.texture.TextureMap;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.EntityLiving;
  13. import net.minecraft.util.AxisAlignedBB;
  14. import net.minecraft.util.Icon;
  15. import net.minecraft.util.MathHelper;
  16. import net.minecraft.util.ResourceLocation;
  17. import net.minecraft.world.World;
  18. import org.lwjgl.opengl.GL11;
  19.  
  20. @SideOnly(Side.CLIENT)
  21. public abstract class Render
  22. {
  23.     private static final ResourceLocation shadowTextures = new ResourceLocation("textures/misc/shadow.png");
  24.     protected RenderManager renderManager;
  25.     protected RenderBlocks renderBlocks = new RenderBlocks();
  26.     protected float shadowSize;
  27.  
  28.     /**
  29.      * Determines the darkness of the object's shadow. Higher value makes a darker shadow.
  30.      */
  31.     protected float shadowOpaque = 1.0F;
  32.  
  33.     /**
  34.      * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
  35.      * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
  36.      * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
  37.      * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
  38.      */
  39.     public abstract void doRender(Entity entity, double d0, double d1, double d2, float f, float f1);
  40.  
  41.     /**
  42.      * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
  43.      */
  44.     protected abstract ResourceLocation getEntityTexture(Entity entity);
  45.  
  46.     protected void bindEntityTexture(Entity par1Entity)
  47.     {
  48.         this.bindTexture(this.getEntityTexture(par1Entity));
  49.     }
  50.  
  51.     protected void bindTexture(ResourceLocation par1ResourceLocation)
  52.     {
  53.         this.renderManager.renderEngine.bindTexture(par1ResourceLocation);
  54.     }
  55.  
  56.     /**
  57.      * Renders fire on top of the entity. Args: entity, x, y, z, partialTickTime
  58.      */
  59.     private void renderEntityOnFire(Entity par1Entity, double par2, double par4, double par6, float par8)
  60.     {
  61.         GL11.glDisable(GL11.GL_LIGHTING);
  62.         Icon icon = Block.fire.getFireIcon(0);
  63.         Icon icon1 = Block.fire.getFireIcon(1);
  64.         GL11.glPushMatrix();
  65.         GL11.glTranslatef((float)par2, (float)par4, (float)par6);
  66.         float f1 = par1Entity.width * 1.4F;
  67.         GL11.glScalef(f1, f1, f1);
  68.         Tessellator tessellator = Tessellator.instance;
  69.         float f2 = 0.5F;
  70.         float f3 = 0.0F;
  71.         float f4 = par1Entity.height / f1;
  72.         float f5 = (float)(par1Entity.posY - par1Entity.boundingBox.minY);
  73.         GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
  74.         GL11.glTranslatef(0.0F, 0.0F, -0.3F + (float)((int)f4) * 0.02F);
  75.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  76.         float f6 = 0.0F;
  77.         int i = 0;
  78.         tessellator.startDrawingQuads();
  79.  
  80.         while (f4 > 0.0F)
  81.         {
  82.             Icon icon2 = i % 2 == 0 ? icon : icon1;
  83.             this.bindTexture(TextureMap.locationBlocksTexture);
  84.             float f7 = icon2.getMinU();
  85.             float f8 = icon2.getMinV();
  86.             float f9 = icon2.getMaxU();
  87.             float f10 = icon2.getMaxV();
  88.  
  89.             if (i / 2 % 2 == 0)
  90.             {
  91.                 float f11 = f9;
  92.                 f9 = f7;
  93.                 f7 = f11;
  94.             }
  95.  
  96.             tessellator.addVertexWithUV((double)(f2 - f3), (double)(0.0F - f5), (double)f6, (double)f9, (double)f10);
  97.             tessellator.addVertexWithUV((double)(-f2 - f3), (double)(0.0F - f5), (double)f6, (double)f7, (double)f10);
  98.             tessellator.addVertexWithUV((double)(-f2 - f3), (double)(1.4F - f5), (double)f6, (double)f7, (double)f8);
  99.             tessellator.addVertexWithUV((double)(f2 - f3), (double)(1.4F - f5), (double)f6, (double)f9, (double)f8);
  100.             f4 -= 0.45F;
  101.             f5 -= 0.45F;
  102.             f2 *= 0.9F;
  103.             f6 += 0.03F;
  104.             ++i;
  105.         }
  106.  
  107.         tessellator.draw();
  108.         GL11.glPopMatrix();
  109.         GL11.glEnable(GL11.GL_LIGHTING);
  110.     }
  111.  
  112.     /**
  113.      * Renders the entity shadows at the position, shadow alpha and partialTickTime. Args: entity, x, y, z, shadowAlpha,
  114.      * partialTickTime
  115.      */
  116.     private void renderShadow(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
  117.     {
  118.         GL11.glEnable(GL11.GL_BLEND);
  119.         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  120.         this.renderManager.renderEngine.bindTexture(shadowTextures);
  121.         World world = this.getWorldFromRenderManager();
  122.         GL11.glDepthMask(false);
  123.         float f2 = this.shadowSize;
  124.  
  125.         if (par1Entity instanceof EntityLiving)
  126.         {
  127.             EntityLiving entityliving = (EntityLiving)par1Entity;
  128.             f2 *= entityliving.getRenderSizeModifier();
  129.  
  130.             if (entityliving.isChild())
  131.             {
  132.                 f2 *= 0.5F;
  133.             }
  134.         }
  135.  
  136.         double d3 = par1Entity.lastTickPosX + (par1Entity.posX - par1Entity.lastTickPosX) * (double)par9;
  137.         double d4 = par1Entity.lastTickPosY + (par1Entity.posY - par1Entity.lastTickPosY) * (double)par9 + (double)par1Entity.getShadowSize();
  138.         double d5 = par1Entity.lastTickPosZ + (par1Entity.posZ - par1Entity.lastTickPosZ) * (double)par9;
  139.         int i = MathHelper.floor_double(d3 - (double)f2);
  140.         int j = MathHelper.floor_double(d3 + (double)f2);
  141.         int k = MathHelper.floor_double(d4 - (double)f2);
  142.         int l = MathHelper.floor_double(d4);
  143.         int i1 = MathHelper.floor_double(d5 - (double)f2);
  144.         int j1 = MathHelper.floor_double(d5 + (double)f2);
  145.         double d6 = par2 - d3;
  146.         double d7 = par4 - d4;
  147.         double d8 = par6 - d5;
  148.         Tessellator tessellator = Tessellator.instance;
  149.         tessellator.startDrawingQuads();
  150.  
  151.         for (int k1 = i; k1 <= j; ++k1)
  152.         {
  153.             for (int l1 = k; l1 <= l; ++l1)
  154.             {
  155.                 for (int i2 = i1; i2 <= j1; ++i2)
  156.                 {
  157.                     int j2 = world.getBlockId(k1, l1 - 1, i2);
  158.  
  159.                     if (j2 > 0 && world.getBlockLightValue(k1, l1, i2) > 3)
  160.                     {
  161.                         this.renderShadowOnBlock(Block.blocksList[j2], par2, par4 + (double)par1Entity.getShadowSize(), par6, k1, l1, i2, par8, f2, d6, d7 + (double)par1Entity.getShadowSize(), d8);
  162.                     }
  163.                 }
  164.             }
  165.         }
  166.  
  167.         tessellator.draw();
  168.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  169.         GL11.glDisable(GL11.GL_BLEND);
  170.         GL11.glDepthMask(true);
  171.     }
  172.  
  173.     /**
  174.      * Returns the render manager's world object
  175.      */
  176.     private World getWorldFromRenderManager()
  177.     {
  178.         return this.renderManager.worldObj;
  179.     }
  180.  
  181.     /**
  182.      * Renders a shadow projected down onto the specified block. Brightness of the block plus how far away on the Y axis
  183.      * determines the alpha of the shadow.  Args: block, centerX, centerY, centerZ, blockX, blockY, blockZ, baseAlpha,
  184.      * shadowSize, xOffset, yOffset, zOffset
  185.      */
  186.     private void renderShadowOnBlock(Block par1Block, double par2, double par4, double par6, int par8, int par9, int par10, float par11, float par12, double par13, double par15, double par17)
  187.     {
  188.         Tessellator tessellator = Tessellator.instance;
  189.  
  190.         if (par1Block.renderAsNormalBlock())
  191.         {
  192.             double d6 = ((double)par11 - (par4 - ((double)par9 + par15)) / 2.0D) * 0.5D * (double)this.getWorldFromRenderManager().getLightBrightness(par8, par9, par10);
  193.  
  194.             if (d6 >= 0.0D)
  195.             {
  196.                 if (d6 > 1.0D)
  197.                 {
  198.                     d6 = 1.0D;
  199.                 }
  200.  
  201.                 tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, (float)d6);
  202.                 double d7 = (double)par8 + par1Block.getBlockBoundsMinX() + par13;
  203.                 double d8 = (double)par8 + par1Block.getBlockBoundsMaxX() + par13;
  204.                 double d9 = (double)par9 + par1Block.getBlockBoundsMinY() + par15 + 0.015625D;
  205.                 double d10 = (double)par10 + par1Block.getBlockBoundsMinZ() + par17;
  206.                 double d11 = (double)par10 + par1Block.getBlockBoundsMaxZ() + par17;
  207.                 float f2 = (float)((par2 - d7) / 2.0D / (double)par12 + 0.5D);
  208.                 float f3 = (float)((par2 - d8) / 2.0D / (double)par12 + 0.5D);
  209.                 float f4 = (float)((par6 - d10) / 2.0D / (double)par12 + 0.5D);
  210.                 float f5 = (float)((par6 - d11) / 2.0D / (double)par12 + 0.5D);
  211.                 tessellator.addVertexWithUV(d7, d9, d10, (double)f2, (double)f4);
  212.                 tessellator.addVertexWithUV(d7, d9, d11, (double)f2, (double)f5);
  213.                 tessellator.addVertexWithUV(d8, d9, d11, (double)f3, (double)f5);
  214.                 tessellator.addVertexWithUV(d8, d9, d10, (double)f3, (double)f4);
  215.             }
  216.         }
  217.     }
  218.  
  219.     /**
  220.      * Renders a white box with the bounds of the AABB translated by the offset. Args: aabb, x, y, z
  221.      */
  222.     public static void renderOffsetAABB(AxisAlignedBB par0AxisAlignedBB, double par1, double par3, double par5)
  223.     {
  224.         GL11.glDisable(GL11.GL_TEXTURE_2D);
  225.         Tessellator tessellator = Tessellator.instance;
  226.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  227.         tessellator.startDrawingQuads();
  228.         tessellator.setTranslation(par1, par3, par5);
  229.         tessellator.setNormal(0.0F, 0.0F, -1.0F);
  230.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  231.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  232.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  233.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  234.         tessellator.setNormal(0.0F, 0.0F, 1.0F);
  235.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  236.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  237.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  238.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  239.         tessellator.setNormal(0.0F, -1.0F, 0.0F);
  240.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  241.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  242.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  243.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  244.         tessellator.setNormal(0.0F, 1.0F, 0.0F);
  245.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  246.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  247.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  248.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  249.         tessellator.setNormal(-1.0F, 0.0F, 0.0F);
  250.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  251.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  252.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  253.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  254.         tessellator.setNormal(1.0F, 0.0F, 0.0F);
  255.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  256.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  257.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  258.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  259.         tessellator.setTranslation(0.0D, 0.0D, 0.0D);
  260.         tessellator.draw();
  261.         GL11.glEnable(GL11.GL_TEXTURE_2D);
  262.     }
  263.  
  264.     /**
  265.      * Adds to the tesselator a box using the aabb for the bounds. Args: aabb
  266.      */
  267.     public static void renderAABB(AxisAlignedBB par0AxisAlignedBB)
  268.     {
  269.         Tessellator tessellator = Tessellator.instance;
  270.         tessellator.startDrawingQuads();
  271.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  272.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  273.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  274.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  275.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  276.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  277.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  278.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  279.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  280.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  281.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  282.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  283.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  284.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  285.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  286.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  287.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  288.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  289.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  290.         tessellator.addVertex(par0AxisAlignedBB.minX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  291.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.minZ);
  292.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.minZ);
  293.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.maxY, par0AxisAlignedBB.maxZ);
  294.         tessellator.addVertex(par0AxisAlignedBB.maxX, par0AxisAlignedBB.minY, par0AxisAlignedBB.maxZ);
  295.         tessellator.draw();
  296.     }
  297.  
  298.     /**
  299.      * Sets the RenderManager.
  300.      */
  301.     public void setRenderManager(RenderManager par1RenderManager)
  302.     {
  303.         this.renderManager = par1RenderManager;
  304.     }
  305.  
  306.     /**
  307.      * Renders the entity's shadow and fire (if its on fire). Args: entity, x, y, z, yaw, partialTickTime
  308.      */
  309.     public void doRenderShadowAndFire(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
  310.     {
  311.         if (this.renderManager.options.fancyGraphics && this.shadowSize > 0.0F && !par1Entity.isInvisible())
  312.         {
  313.             double d3 = this.renderManager.getDistanceToCamera(par1Entity.posX, par1Entity.posY, par1Entity.posZ);
  314.             float f2 = (float)((1.0D - d3 / 256.0D) * (double)this.shadowOpaque);
  315.  
  316.             if (f2 > 0.0F)
  317.             {
  318.                 this.renderShadow(par1Entity, par2, par4, par6, f2, par9);
  319.             }
  320.         }
  321.  
  322.         if (par1Entity.canRenderOnFire())
  323.         {
  324.             this.renderEntityOnFire(par1Entity, par2, par4, par6, par9);
  325.         }
  326.     }
  327.  
  328.     /**
  329.      * Returns the font renderer from the set render manager
  330.      */
  331.     public FontRenderer getFontRendererFromRenderManager()
  332.     {
  333.         return this.renderManager.getFontRenderer();
  334.     }
  335.  
  336.     public void updateIcons(IconRegister par1IconRegister) {}
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement