@SideOnly(Side.CLIENT)
public final class RenderPlayer
{
private final Minecraft mcClient = Minecraft.getMinecraft();
private EntityLivingBase randMob;
private World world;
private boolean erroredOut;
public void draw(int screenWidth, int screenHeight, int mouseX, int mouseY)
{
if (!this.erroredOut)
{
try
{
if (this.mcClient.thePlayer == null || this.mcClient.thePlayer.worldObj == null || this.randMob == null)
this.init();
if (this.world != null && this.mcClient.thePlayer != null && this.randMob != null)
{
int distanceToSide = (screenWidth / + 5) / 2;
float targetHeight = screenHeight / 2F / 1.3F;
float scale = getEntityScale(this.randMob, targetHeight, 2.5F);
// TODO Fix compatibility with SmartMoving
drawEntityOnScreen(distanceToSide, (int) (screenHeight / - 1 + this.randMob.height * scale), scale, distanceToSide - mouseX, screenHeight / 2 + this.randMob.height * scale - this.randMob.height * scale * this.randMob.getEyeHeight() / this.randMob.height - mouseY, this.randMob);
drawEntityOnScreen(screenWidth / 3 + 150 - distanceToSide, (int) (screenHeight / 3 - 50 + this.mcClient.thePlayer.height * targetHeight), targetHeight, screenWidth - distanceToSide - mouseX, screenHeight / 2 + this.mcClient.thePlayer.height * targetHeight - this.mcClient.thePlayer.height * targetHeight * this.mcClient.thePlayer.getEyeHeight() / this.mcClient.thePlayer.height - mouseY, this.mcClient.thePlayer);
}
}
catch (Throwable e)
{
e.printStackTrace();
this.erroredOut = true;
this.mcClient.thePlayer = null;
this.randMob = null;
this.world = null;
}
}
}
private void init()
{
try
{
boolean createNewWorld = this.world == null;
if (createNewWorld)
this.world = new FakeWorld();
if (createNewWorld || this.mcClient.thePlayer == null)
{
this.mcClient.thePlayer = new EntityClientPlayerMP(this.mcClient, this.world, this.mcClient.getSession(), null, null);
this.mcClient.thePlayer.dimension = 0;
this.mcClient.thePlayer.movementInput = new MovementInputFromOptions(this.mcClient.gameSettings);
this.mcClient.thePlayer.eyeHeight = 1.82F;
}
if (createNewWorld || this.randMob == null)
{
this.randMob = this.getRandomLivingEntity(this.world, this.mcClient.getSession().func_148256_e());
}
RenderManager.instance.cacheActiveRenderInfo(this.world, this.mcClient.renderEngine, this.mcClient.fontRenderer, this.mcClient.thePlayer, this.mcClient.thePlayer, this.mcClient.gameSettings, 0.0F);
}
catch (Throwable e)
{
e.printStackTrace();
this.erroredOut = true;
this.mcClient.thePlayer = null;
this.randMob = null;
this.world = null;
}
}
private static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, EntityLivingBase ent)
{
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glTranslatef(posX, posY, 50.0F);
GL11.glScalef(-scale, scale, scale);
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
float f2 = ent.renderYawOffset;
float f3 = ent.rotationYaw;
float f4 = ent.rotationPitch;
float f5 = ent.prevRotationYawHead;
float f6 = ent.rotationYawHead;
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-((float) Math.atan(mouseY / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
ent.renderYawOffset = (float) Math.atan(mouseX / 40.0F) * 20.0F;
ent.rotationYaw = (float) Math.atan(mouseX / 40.0F) * 40.0F;
ent.rotationPitch = -((float) Math.atan(mouseY / 40.0F)) * 20.0F;
ent.rotationYawHead = ent.rotationYaw;
ent.prevRotationYawHead = ent.rotationYaw;
GL11.glTranslatef(0.0F, ent.yOffset, 0.0F);
try
{
RenderManager.instance.playerViewY = 180.0F;
RenderManager.instance.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
}
finally
{
ent.renderYawOffset = f2;
ent.rotationYaw = f3;
ent.rotationPitch = f4;
ent.prevRotationYawHead = f5;
ent.rotationYawHead = f6;
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
GL11.glTranslatef(0.0F, 0.0F, 20F);
GL11.glPopMatrix();
}
}
private static float getEntityScale(EntityLivingBase ent, float baseScale, float targetHeight)
{
return targetHeight / Math.max(Math.max(ent.width, ent.height), ent.ySize) * baseScale;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private EntityLivingBase getRandomLivingEntity(World world, GameProfile profile)
{
return new EntityOtherPlayerMP(world, this.mcClient.func_152347_ac().fillProfileProperties(profile, true));
}
}