001package net.minecraft.client.renderer.entity; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.Random; 006import net.minecraft.block.Block; 007import net.minecraft.client.model.ModelEnderman; 008import net.minecraft.client.renderer.OpenGlHelper; 009import net.minecraft.entity.Entity; 010import net.minecraft.entity.EntityLiving; 011import net.minecraft.entity.monster.EntityEnderman; 012import org.lwjgl.opengl.GL11; 013import org.lwjgl.opengl.GL12; 014 015@SideOnly(Side.CLIENT) 016public class RenderEnderman extends RenderLiving 017{ 018 /** The model of the enderman */ 019 private ModelEnderman endermanModel; 020 private Random rnd = new Random(); 021 022 public RenderEnderman() 023 { 024 super(new ModelEnderman(), 0.5F); 025 this.endermanModel = (ModelEnderman)super.mainModel; 026 this.setRenderPassModel(this.endermanModel); 027 } 028 029 /** 030 * Renders the enderman 031 */ 032 public void renderEnderman(EntityEnderman par1EntityEnderman, double par2, double par4, double par6, float par8, float par9) 033 { 034 this.endermanModel.isCarrying = par1EntityEnderman.getCarried() > 0; 035 this.endermanModel.isAttacking = par1EntityEnderman.isScreaming(); 036 037 if (par1EntityEnderman.isScreaming()) 038 { 039 double d3 = 0.02D; 040 par2 += this.rnd.nextGaussian() * d3; 041 par6 += this.rnd.nextGaussian() * d3; 042 } 043 044 super.doRenderLiving(par1EntityEnderman, par2, par4, par6, par8, par9); 045 } 046 047 /** 048 * Render the block an enderman is carrying 049 */ 050 protected void renderCarrying(EntityEnderman par1EntityEnderman, float par2) 051 { 052 super.renderEquippedItems(par1EntityEnderman, par2); 053 054 if (par1EntityEnderman.getCarried() > 0) 055 { 056 GL11.glEnable(GL12.GL_RESCALE_NORMAL); 057 GL11.glPushMatrix(); 058 float f1 = 0.5F; 059 GL11.glTranslatef(0.0F, 0.6875F, -0.75F); 060 f1 *= 1.0F; 061 GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F); 062 GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F); 063 GL11.glScalef(-f1, -f1, f1); 064 int i = par1EntityEnderman.getBrightnessForRender(par2); 065 int j = i % 65536; 066 int k = i / 65536; 067 OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F); 068 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 069 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 070 this.loadTexture("/terrain.png"); 071 this.renderBlocks.renderBlockAsItem(Block.blocksList[par1EntityEnderman.getCarried()], par1EntityEnderman.getCarryingData(), 1.0F); 072 GL11.glPopMatrix(); 073 GL11.glDisable(GL12.GL_RESCALE_NORMAL); 074 } 075 } 076 077 /** 078 * Render the endermans eyes 079 */ 080 protected int renderEyes(EntityEnderman par1EntityEnderman, int par2, float par3) 081 { 082 if (par2 != 0) 083 { 084 return -1; 085 } 086 else 087 { 088 this.loadTexture("/mob/enderman_eyes.png"); 089 float f1 = 1.0F; 090 GL11.glEnable(GL11.GL_BLEND); 091 GL11.glDisable(GL11.GL_ALPHA_TEST); 092 GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); 093 GL11.glDisable(GL11.GL_LIGHTING); 094 095 if (par1EntityEnderman.getHasActivePotion()) 096 { 097 GL11.glDepthMask(false); 098 } 099 else 100 { 101 GL11.glDepthMask(true); 102 } 103 104 char c0 = 61680; 105 int j = c0 % 65536; 106 int k = c0 / 65536; 107 OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F); 108 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 109 GL11.glEnable(GL11.GL_LIGHTING); 110 GL11.glColor4f(1.0F, 1.0F, 1.0F, f1); 111 return 1; 112 } 113 } 114 115 /** 116 * Queries whether should render the specified pass or not. 117 */ 118 protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3) 119 { 120 return this.renderEyes((EntityEnderman)par1EntityLiving, par2, par3); 121 } 122 123 protected void renderEquippedItems(EntityLiving par1EntityLiving, float par2) 124 { 125 this.renderCarrying((EntityEnderman)par1EntityLiving, par2); 126 } 127 128 public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9) 129 { 130 this.renderEnderman((EntityEnderman)par1EntityLiving, par2, par4, par6, par8, par9); 131 } 132 133 /** 134 * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then 135 * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic 136 * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1, 137 * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that. 138 */ 139 public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) 140 { 141 this.renderEnderman((EntityEnderman)par1Entity, par2, par4, par6, par8, par9); 142 } 143}