638 lines
24 KiB
Java
Executable file
638 lines
24 KiB
Java
Executable file
package game.renderer;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.FloatBuffer;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.opengl.GL13;
|
|
|
|
import game.Game;
|
|
import game.block.Block;
|
|
import game.entity.npc.EntityNPC;
|
|
import game.entity.types.EntityLiving;
|
|
import game.item.Item;
|
|
import game.item.ItemAction;
|
|
import game.item.ItemStack;
|
|
import game.renderer.blockmodel.Transforms;
|
|
import game.renderer.entity.RenderItem;
|
|
import game.renderer.entity.RenderManager;
|
|
import game.renderer.entity.RenderNpc;
|
|
import game.renderer.texture.TextureAtlasSprite;
|
|
import game.renderer.texture.TextureMap;
|
|
import game.util.ExtMath;
|
|
import game.world.BlockPos;
|
|
import game.world.State;
|
|
import game.world.Vec3;
|
|
|
|
|
|
public class ItemRenderer
|
|
{
|
|
private static final FloatBuffer BUFFER = ByteBuffer.allocateDirect(16 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
private static final Vec3 LIGHT0_POS = (new Vec3(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize();
|
|
private static final Vec3 LIGHT1_POS = (new Vec3(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize();
|
|
|
|
/** A reference to the Game object. */
|
|
private final Game gm;
|
|
private ItemStack itemToRender;
|
|
|
|
/**
|
|
* How far the current item has been equipped (0 disequipped and 1 fully up)
|
|
*/
|
|
private float equippedProgress;
|
|
private float prevEquippedProgress;
|
|
private final RenderManager renderManager;
|
|
private final RenderItem itemRenderer;
|
|
|
|
/** The index of the currently held item (0-8, or -1 if not yet updated) */
|
|
private int equippedItemSlot = -1;
|
|
|
|
private static FloatBuffer setColorBuffer(float r, float g, float b, float a)
|
|
{
|
|
BUFFER.clear();
|
|
BUFFER.put(r).put(g).put(b).put(a);
|
|
BUFFER.flip();
|
|
return BUFFER;
|
|
}
|
|
|
|
public static void enableGUIStandardItemLighting()
|
|
{
|
|
GL11.glPushMatrix();
|
|
GL11.glRotatef(-30.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glRotatef(165.0F, 1.0F, 0.0F, 0.0F);
|
|
enableStandardItemLighting();
|
|
GL11.glPopMatrix();
|
|
}
|
|
|
|
public static void enableStandardItemLighting()
|
|
{
|
|
GlState.enableLighting();
|
|
GlState.enableLight(0);
|
|
GlState.enableLight(1);
|
|
GlState.enableColorMaterial();
|
|
GlState.colorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
|
|
float f = 0.4F;
|
|
float f1 = 0.6F;
|
|
float f2 = 0.0F;
|
|
GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_POSITION, setColorBuffer(
|
|
(float)LIGHT0_POS.xCoord, (float)LIGHT0_POS.yCoord, (float)LIGHT0_POS.zCoord, 0.0f));
|
|
GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, setColorBuffer(f1, f1, f1, 1.0F));
|
|
GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_AMBIENT, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
|
|
GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_SPECULAR, setColorBuffer(f2, f2, f2, 1.0F));
|
|
GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_POSITION, setColorBuffer(
|
|
(float)LIGHT1_POS.xCoord, (float)LIGHT1_POS.yCoord, (float)LIGHT1_POS.zCoord, 0.0f));
|
|
GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, setColorBuffer(f1, f1, f1, 1.0F));
|
|
GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_AMBIENT, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
|
|
GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_SPECULAR, setColorBuffer(f2, f2, f2, 1.0F));
|
|
GlState.shadeModel(GL11.GL_FLAT);
|
|
GL11.glLightModelfv(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(f, f, f, 1.0F));
|
|
}
|
|
|
|
public static void disableStandardItemLighting()
|
|
{
|
|
GlState.disableLighting();
|
|
GlState.disableLight(0);
|
|
GlState.disableLight(1);
|
|
GlState.disableColorMaterial();
|
|
}
|
|
|
|
public ItemRenderer(Game gmIn)
|
|
{
|
|
this.gm = gmIn;
|
|
this.renderManager = gmIn.getRenderManager();
|
|
this.itemRenderer = gmIn.getRenderItem();
|
|
}
|
|
|
|
public void renderItem(EntityLiving entityIn, ItemStack heldStack, Transforms.Camera transform)
|
|
{
|
|
if (heldStack != null)
|
|
{
|
|
Item item = heldStack.getItem();
|
|
if(item.isFirstPerson() || transform != Transforms.Camera.FIRST_PERSON) {
|
|
Block block = item.getBlock();
|
|
GL11.glPushMatrix();
|
|
|
|
if (this.itemRenderer.shouldRenderItemIn3D(heldStack))
|
|
{
|
|
GL11.glScalef(2.0F, 2.0F, 2.0F);
|
|
|
|
if (this.isBlockTranslucent(block))
|
|
{
|
|
GlState.depthMask(false);
|
|
}
|
|
}
|
|
|
|
this.itemRenderer.renderItemModelForEntity(heldStack, entityIn, transform);
|
|
|
|
if (this.isBlockTranslucent(block))
|
|
{
|
|
GlState.depthMask(true);
|
|
}
|
|
|
|
GL11.glPopMatrix();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true if given block is translucent
|
|
*/
|
|
private boolean isBlockTranslucent(Block blockIn)
|
|
{
|
|
return blockIn != null && blockIn.getBlockLayer() == BlockLayer.TRANSLUCENT;
|
|
}
|
|
|
|
/**
|
|
* Rotate the render around X and Y
|
|
*
|
|
* @param angleY The angle for the rotation arround Y
|
|
*/
|
|
private void rotateArroundXAndY(float angle, float angleY)
|
|
{
|
|
GL11.glPushMatrix();
|
|
GL11.glRotatef(angle, 1.0F, 0.0F, 0.0F);
|
|
GL11.glRotatef(angleY, 0.0F, 1.0F, 0.0F);
|
|
ItemRenderer.enableStandardItemLighting();
|
|
GL11.glPopMatrix();
|
|
}
|
|
|
|
/**
|
|
* Set the OpenGL LightMapTextureCoords based on the EntityNPCClient
|
|
*/
|
|
private void setLightMapFromPlayer(EntityNPC clientPlayer)
|
|
{
|
|
int i = this.gm.theWorld.getCombinedLight(new BlockPos(clientPlayer.posX, clientPlayer.posY + (double)clientPlayer.getEyeHeight(), clientPlayer.posZ), 0);
|
|
float f = (float)(i & 65535);
|
|
float f1 = (float)(i >> 16);
|
|
GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, f, f1);
|
|
}
|
|
|
|
/**
|
|
* Rotate the render according to the player's yaw and pitch
|
|
*/
|
|
private void rotateWithPlayerRotations(EntityNPC entityplayerspIn, float partialTicks)
|
|
{
|
|
float f = entityplayerspIn.prevRenderArmPitch + (entityplayerspIn.renderArmPitch - entityplayerspIn.prevRenderArmPitch) * partialTicks;
|
|
float f1 = entityplayerspIn.prevRenderArmYaw + (entityplayerspIn.renderArmYaw - entityplayerspIn.prevRenderArmYaw) * partialTicks;
|
|
GL11.glRotatef((entityplayerspIn.rotPitch - f) * 0.1F, 1.0F, 0.0F, 0.0F);
|
|
GL11.glRotatef((entityplayerspIn.rotYaw - f1) * 0.1F, 0.0F, 1.0F, 0.0F);
|
|
}
|
|
|
|
/**
|
|
* Return the angle to render the Map
|
|
*
|
|
* @param pitch The player's pitch
|
|
*/
|
|
private float getMapAngleFromPitch(float pitch)
|
|
{
|
|
float f = 1.0F - pitch / 45.0F + 0.1F;
|
|
f = ExtMath.clampf(f, 0.0F, 1.0F);
|
|
f = -ExtMath.cos(f * (float)Math.PI) * 0.5F + 0.5F;
|
|
return f;
|
|
}
|
|
|
|
// private void renderRightArm(RenderPlayer renderPlayerIn)
|
|
// {
|
|
// SKC.glPushMatrix();
|
|
// SKC.glRotatef(54.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(64.0F, 1.0F, 0.0F, 0.0F);
|
|
// SKC.glRotatef(-62.0F, 0.0F, 0.0F, 1.0F);
|
|
// SKC.glTranslatef(0.25F, -0.85F, 0.75F);
|
|
// renderPlayerIn.renderRightArm(this.gm.thePlayer);
|
|
// SKC.glPopMatrix();
|
|
// }
|
|
//
|
|
// private void renderLeftArm(RenderPlayer renderPlayerIn)
|
|
// {
|
|
// SKC.glPushMatrix();
|
|
// SKC.glRotatef(92.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(45.0F, 1.0F, 0.0F, 0.0F);
|
|
// SKC.glRotatef(41.0F, 0.0F, 0.0F, 1.0F);
|
|
// SKC.glTranslatef(-0.3F, -1.1F, 0.45F);
|
|
// renderPlayerIn.renderLeftArm(this.gm.thePlayer);
|
|
// SKC.glPopMatrix();
|
|
// }
|
|
|
|
// private void renderPlayerArms(EntityNPCClient clientPlayer)
|
|
// {
|
|
// this.gm.getTextureManager().bindTexture(clientPlayer.getLocationSkin());
|
|
// Render<EntityNPCClient> render = this.renderManager.<EntityNPCClient>getEntityRenderObject(this.gm.thePlayer);
|
|
// RenderPlayer renderplayer = (RenderPlayer)render;
|
|
//
|
|
// if (!clientPlayer.isInvisible())
|
|
// {
|
|
// GlState.disableCull();
|
|
// this.renderRightArm(renderplayer);
|
|
// this.renderLeftArm(renderplayer);
|
|
// GlState.enableCull();
|
|
// }
|
|
// }
|
|
|
|
// private void renderItemMap(EntityNPCClient clientPlayer, float pitch, float equipmentProgress, float swingProgress)
|
|
// {
|
|
// float f = -0.4F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
|
// float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI * 2.0F);
|
|
// float f2 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI);
|
|
// SKC.glTranslatef(f, f1, f2);
|
|
// float f3 = this.getMapAngleFromPitch(pitch);
|
|
// SKC.glTranslatef(0.0F, 0.04F, -0.72F);
|
|
// SKC.glTranslatef(0.0F, equipmentProgress * -1.2F, 0.0F);
|
|
// SKC.glTranslatef(0.0F, f3 * -0.5F, 0.0F);
|
|
// SKC.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(f3 * -85.0F, 0.0F, 0.0F, 1.0F);
|
|
// SKC.glRotatef(0.0F, 1.0F, 0.0F, 0.0F);
|
|
// this.renderPlayerArms(clientPlayer);
|
|
// float f4 = MathHelper.sin(swingProgress * swingProgress * (float)Math.PI);
|
|
// float f5 = MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
|
// SKC.glRotatef(f4 * -20.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(f5 * -20.0F, 0.0F, 0.0F, 1.0F);
|
|
// SKC.glRotatef(f5 * -80.0F, 1.0F, 0.0F, 0.0F);
|
|
// SKC.glScalef(0.38F, 0.38F, 0.38F);
|
|
// SKC.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
|
|
// SKC.glRotatef(0.0F, 1.0F, 0.0F, 0.0F);
|
|
// SKC.glTranslatef(-1.0F, -1.0F, 0.0F);
|
|
// SKC.glScalef(0.015625F, 0.015625F, 0.015625F);
|
|
// this.gm.getTextureManager().bindTexture(RES_MAP_BACKGROUND);
|
|
//// Tessellator tessellator = Tessellator.getInstance();
|
|
// RenderBuffer worldrenderer = Tessellator.getBuffer();
|
|
// SKC.glNormal3f(0.0F, 0.0F, -1.0F);
|
|
// worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
|
// worldrenderer.pos(-7.0D, 135.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
|
|
// worldrenderer.pos(135.0D, 135.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
|
|
// worldrenderer.pos(135.0D, -7.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
|
|
// worldrenderer.pos(-7.0D, -7.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
|
|
// Tessellator.draw();
|
|
// MapData mapdata = Items.filled_map.getMapData(this.itemToRender, this.gm.theWorld);
|
|
//
|
|
// if (mapdata != null)
|
|
// {
|
|
// this.gm.entityRenderer.getMapItemRenderer().renderMap(mapdata, false);
|
|
// }
|
|
// }
|
|
|
|
/**
|
|
* Render the player's arm
|
|
*
|
|
* @param equipProgress The progress of equiping the item
|
|
* @param swingProgress The swing movement progression
|
|
*/
|
|
private void renderPlayerArm(EntityNPC clientPlayer, float equipProgress, float swingProgress)
|
|
{
|
|
float f = -0.3F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI);
|
|
float f1 = 0.4F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI * 2.0F);
|
|
float f2 = -0.4F * ExtMath.sin(swingProgress * (float)Math.PI);
|
|
GL11.glTranslatef(f, f1, f2);
|
|
GL11.glTranslatef(0.64000005F, -0.6F, -0.71999997F);
|
|
GL11.glTranslatef(0.0F, equipProgress * -0.6F, 0.0F);
|
|
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
|
|
float f3 = ExtMath.sin(swingProgress * swingProgress * (float)Math.PI);
|
|
float f4 = ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI);
|
|
GL11.glRotatef(f4 * 70.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glRotatef(f3 * -20.0F, 0.0F, 0.0F, 1.0F);
|
|
this.gm.getTextureManager().bindTexture(clientPlayer.getLocationSkin());
|
|
GL11.glTranslatef(-1.0F, 3.6F, 3.5F);
|
|
GL11.glRotatef(120.0F, 0.0F, 0.0F, 1.0F);
|
|
GL11.glRotatef(200.0F, 1.0F, 0.0F, 0.0F);
|
|
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glScalef(1.0F, 1.0F, 1.0F);
|
|
GL11.glTranslatef(5.6F, 0.0F, 0.0F);
|
|
RenderNpc render = this.renderManager.getRenderObject(this.gm.thePlayer.getModel());
|
|
GlState.disableCull();
|
|
render.renderPlayerArm(this.gm.thePlayer);
|
|
GlState.enableCull();
|
|
}
|
|
|
|
/**
|
|
* Rotate and translate render to show item consumption
|
|
*
|
|
* @param swingProgress The swing movement progress
|
|
*/
|
|
private void doItemUsedTransformations(float swingProgress)
|
|
{
|
|
float f = -0.4F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI);
|
|
float f1 = 0.2F * ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI * 2.0F);
|
|
float f2 = -0.2F * ExtMath.sin(swingProgress * (float)Math.PI);
|
|
GL11.glTranslatef(f, f1, f2);
|
|
}
|
|
|
|
// /**
|
|
// * Perform the drinking animation movement
|
|
// *
|
|
// * @param partialTicks Partials ticks
|
|
// */
|
|
// private void performDrinking(EntityNPCSP clientPlayer, float partialTicks)
|
|
// {
|
|
// float f = (float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F;
|
|
// float f1 = f / (float)this.itemToRender.getMaxItemUseDuration();
|
|
// float f2 = ExtMath.absf(ExtMath.cos(f / 4.0F * (float)Math.PI) * 0.1F);
|
|
//
|
|
// if (f1 >= 0.8F)
|
|
// {
|
|
// f2 = 0.0F;
|
|
// }
|
|
//
|
|
// SKC.glTranslatef(0.0F, f2, 0.0F);
|
|
// float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
|
|
// SKC.glTranslatef(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F);
|
|
// SKC.glRotatef(f3 * 90.0F, 0.0F, 1.0F, 0.0F);
|
|
// SKC.glRotatef(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
|
|
// SKC.glRotatef(f3 * 30.0F, 0.0F, 0.0F, 1.0F);
|
|
// }
|
|
|
|
/**
|
|
* Performs transformations prior to the rendering of a held item in first person.
|
|
*/
|
|
private void transformFirstPersonItem(float equipProgress, float swingProgress)
|
|
{
|
|
GL11.glTranslatef(0.56F, -0.52F, -0.71999997F);
|
|
GL11.glTranslatef(0.0F, equipProgress * -0.6F, 0.0F);
|
|
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
|
|
float f = ExtMath.sin(swingProgress * swingProgress * (float)Math.PI);
|
|
float f1 = ExtMath.sin(ExtMath.sqrtf(swingProgress) * (float)Math.PI);
|
|
GL11.glRotatef(f * -20.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glRotatef(f1 * -20.0F, 0.0F, 0.0F, 1.0F);
|
|
GL11.glRotatef(f1 * -80.0F, 1.0F, 0.0F, 0.0F);
|
|
GL11.glScalef(0.4F, 0.4F, 0.4F);
|
|
}
|
|
|
|
/**
|
|
* Translate and rotate the render to look like holding a bow
|
|
*
|
|
* @param partialTicks Partial ticks
|
|
*/
|
|
private void doBowTransformations(float partialTicks, EntityNPC clientPlayer)
|
|
{
|
|
GL11.glRotatef(-18.0F, 0.0F, 0.0F, 1.0F);
|
|
GL11.glRotatef(-12.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glRotatef(-8.0F, 1.0F, 0.0F, 0.0F);
|
|
GL11.glTranslatef(-0.9F, 0.2F, 0.0F);
|
|
float f = (float)this.itemToRender.getMaxItemUseDuration() - ((float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F);
|
|
float f1 = f / 20.0F;
|
|
f1 = (f1 * f1 + f1 * 2.0F) / 3.0F;
|
|
|
|
if (f1 > 1.0F)
|
|
{
|
|
f1 = 1.0F;
|
|
}
|
|
|
|
if (f1 > 0.1F)
|
|
{
|
|
float f2 = ExtMath.sin((f - 0.1F) * 1.3F);
|
|
float f3 = f1 - 0.1F;
|
|
float f4 = f2 * f3;
|
|
GL11.glTranslatef(f4 * 0.0F, f4 * 0.01F, f4 * 0.0F);
|
|
}
|
|
|
|
GL11.glTranslatef(f1 * 0.0F, f1 * 0.0F, f1 * 0.1F);
|
|
GL11.glScalef(1.0F, 1.0F, 1.0F + f1 * 0.2F);
|
|
}
|
|
|
|
/**
|
|
* Translate and rotate the render for holding a block
|
|
*/
|
|
private void doBlockTransformations()
|
|
{
|
|
GL11.glTranslatef(-0.5F, 0.2F, 0.0F);
|
|
GL11.glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
|
|
GL11.glRotatef(-80.0F, 1.0F, 0.0F, 0.0F);
|
|
GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F);
|
|
}
|
|
|
|
/**
|
|
* Renders the active item in the player's hand when in first person mode. Args: partialTickTime
|
|
*/
|
|
public void renderItemInFirstPerson(float partialTicks)
|
|
{
|
|
float f = 1.0F - (this.prevEquippedProgress + (this.equippedProgress - this.prevEquippedProgress) * partialTicks);
|
|
EntityNPC clientplayer = this.gm.thePlayer;
|
|
float f1 = clientplayer.getSwingProgress(partialTicks);
|
|
float f2 = clientplayer.prevPitch + (clientplayer.rotPitch - clientplayer.prevPitch) * partialTicks;
|
|
float f3 = clientplayer.prevYaw + (clientplayer.rotYaw - clientplayer.prevYaw) * partialTicks;
|
|
this.rotateArroundXAndY(f2, f3);
|
|
this.setLightMapFromPlayer(clientplayer);
|
|
this.rotateWithPlayerRotations(clientplayer, partialTicks);
|
|
GlState.enableRescaleNormal();
|
|
GL11.glPushMatrix();
|
|
|
|
if (this.itemToRender != null)
|
|
{
|
|
// if (this.itemToRender.getItem() == Items.filled_map)
|
|
// {
|
|
// this.renderItemMap(clientplayer, f2, f, f1);
|
|
// }
|
|
// else
|
|
if (clientplayer.getItemInUseCount() > 0)
|
|
{
|
|
ItemAction enumaction = this.itemToRender.getItemUseAction();
|
|
|
|
switch (enumaction)
|
|
{
|
|
case NONE:
|
|
this.transformFirstPersonItem(f, 0.0F);
|
|
break;
|
|
|
|
case EAT:
|
|
case DRINK:
|
|
// this.performDrinking(clientplayer, partialTicks);
|
|
// this.transformFirstPersonItem(f, 0.0F);
|
|
// break;
|
|
|
|
case BLOCK:
|
|
this.transformFirstPersonItem(f, 0.0F);
|
|
this.doBlockTransformations();
|
|
break;
|
|
|
|
case AIM:
|
|
this.transformFirstPersonItem(f, 0.0F);
|
|
this.doBowTransformations(partialTicks, clientplayer);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.doItemUsedTransformations(f1);
|
|
this.transformFirstPersonItem(f, f1);
|
|
}
|
|
|
|
this.renderItem(clientplayer, this.itemToRender, Transforms.Camera.FIRST_PERSON);
|
|
}
|
|
else // if (!clientplayer.isInvisible())
|
|
{
|
|
this.renderPlayerArm(clientplayer, f, f1);
|
|
}
|
|
|
|
GL11.glPopMatrix();
|
|
GlState.disableRescaleNormal();
|
|
ItemRenderer.disableStandardItemLighting();
|
|
}
|
|
|
|
/**
|
|
* Renders all the overlays that are in first person mode. Args: partialTickTime
|
|
*/
|
|
public void renderOverlays(float partialTicks)
|
|
{
|
|
GlState.disableAlpha();
|
|
|
|
if (this.gm.thePlayer.isEntityInsideOpaqueBlock())
|
|
{
|
|
State iblockstate = this.gm.theWorld.getState(new BlockPos(this.gm.thePlayer));
|
|
EntityNPC entityplayer = this.gm.thePlayer;
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
{
|
|
double d0 = entityplayer.posX + (double)(((float)((i >> 0) % 2) - 0.5F) * entityplayer.width * 0.8F);
|
|
double d1 = entityplayer.posY + (double)(((float)((i >> 1) % 2) - 0.5F) * 0.1F);
|
|
double d2 = entityplayer.posZ + (double)(((float)((i >> 2) % 2) - 0.5F) * entityplayer.width * 0.8F);
|
|
BlockPos blockpos = new BlockPos(d0, d1 + (double)entityplayer.getEyeHeight(), d2);
|
|
State iblockstate1 = this.gm.theWorld.getState(blockpos);
|
|
|
|
if (iblockstate1.getBlock().isVisuallyOpaque())
|
|
{
|
|
iblockstate = iblockstate1;
|
|
}
|
|
}
|
|
|
|
if (iblockstate.getBlock().getRenderType() != -1)
|
|
{
|
|
this.renderBlockInHand(partialTicks, this.gm.getBlockRendererDispatcher().getModelManager().getTexture(iblockstate));
|
|
}
|
|
}
|
|
|
|
if(this.gm.thePlayer.isBurning()) {
|
|
this.renderFireInFirstPerson(partialTicks);
|
|
}
|
|
|
|
GlState.enableAlpha();
|
|
}
|
|
|
|
/**
|
|
* Render the block in the player's hand
|
|
*
|
|
* @param partialTicks Partial ticks
|
|
* @param atlas The TextureAtlasSprite to render
|
|
*/
|
|
private void renderBlockInHand(float partialTicks, TextureAtlasSprite atlas)
|
|
{
|
|
this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
|
// Tessellator tessellator = Tessellator.getInstance();
|
|
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
|
float f = 0.1F;
|
|
GlState.color(0.1F, 0.1F, 0.1F, 0.5F);
|
|
GL11.glPushMatrix();
|
|
float f1 = -1.0F;
|
|
float f2 = 1.0F;
|
|
float f3 = -1.0F;
|
|
float f4 = 1.0F;
|
|
float f5 = -0.5F;
|
|
float f6 = atlas.getMinU();
|
|
float f7 = atlas.getMaxU();
|
|
float f8 = atlas.getMinV();
|
|
float f9 = atlas.getMaxV();
|
|
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
|
worldrenderer.pos(-1.0D, -1.0D, -0.5D).tex((double)f7, (double)f9).endVertex();
|
|
worldrenderer.pos(1.0D, -1.0D, -0.5D).tex((double)f6, (double)f9).endVertex();
|
|
worldrenderer.pos(1.0D, 1.0D, -0.5D).tex((double)f6, (double)f8).endVertex();
|
|
worldrenderer.pos(-1.0D, 1.0D, -0.5D).tex((double)f7, (double)f8).endVertex();
|
|
Tessellator.draw();
|
|
GL11.glPopMatrix();
|
|
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
/**
|
|
* Renders the fire on the screen for first person mode. Arg: partialTickTime
|
|
*
|
|
* @param partialTicks Partial ticks
|
|
*/
|
|
private void renderFireInFirstPerson(float partialTicks)
|
|
{
|
|
// Tessellator tessellator = Tessellator.getInstance();
|
|
RenderBuffer worldrenderer = Tessellator.getBuffer();
|
|
GlState.color(1.0F, 1.0F, 1.0F, 0.9F);
|
|
GlState.depthFunc(GL11.GL_ALWAYS);
|
|
GlState.depthMask(false);
|
|
GlState.enableBlend();
|
|
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
|
float f = 1.0F;
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
GL11.glPushMatrix();
|
|
TextureAtlasSprite textureatlassprite = this.gm.getTextureMapBlocks().getAtlasSprite("blocks/fire_layer_1");
|
|
this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
|
float f1 = textureatlassprite.getMinU();
|
|
float f2 = textureatlassprite.getMaxU();
|
|
float f3 = textureatlassprite.getMinV();
|
|
float f4 = textureatlassprite.getMaxV();
|
|
float f5 = (0.0F - f) / 2.0F;
|
|
float f6 = f5 + f;
|
|
float f7 = 0.0F - f / 2.0F;
|
|
float f8 = f7 + f;
|
|
float f9 = -0.5F;
|
|
GL11.glTranslatef((float)(-(i * 2 - 1)) * 0.24F, -0.3F, 0.0F);
|
|
GL11.glRotatef((float)(i * 2 - 1) * 10.0F, 0.0F, 1.0F, 0.0F);
|
|
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
|
worldrenderer.pos((double)f5, (double)f7, (double)f9).tex((double)f2, (double)f4).endVertex();
|
|
worldrenderer.pos((double)f6, (double)f7, (double)f9).tex((double)f1, (double)f4).endVertex();
|
|
worldrenderer.pos((double)f6, (double)f8, (double)f9).tex((double)f1, (double)f3).endVertex();
|
|
worldrenderer.pos((double)f5, (double)f8, (double)f9).tex((double)f2, (double)f3).endVertex();
|
|
Tessellator.draw();
|
|
GL11.glPopMatrix();
|
|
}
|
|
|
|
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
|
GlState.disableBlend();
|
|
GlState.depthMask(true);
|
|
GlState.depthFunc(GL11.GL_LEQUAL);
|
|
}
|
|
|
|
public void updateEquippedItem()
|
|
{
|
|
this.prevEquippedProgress = this.equippedProgress;
|
|
EntityNPC entityplayer = this.gm.thePlayer;
|
|
ItemStack itemstack = entityplayer.inventory.getCurrentItem();
|
|
boolean flag = false;
|
|
|
|
if (this.itemToRender != null && itemstack != null)
|
|
{
|
|
if (!this.itemToRender.getIsItemStackEqual(itemstack))
|
|
{
|
|
flag = true;
|
|
}
|
|
}
|
|
else if (this.itemToRender == null && itemstack == null)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
|
|
float f = 0.4F;
|
|
float f1 = flag ? 0.0F : 1.0F;
|
|
float f2 = ExtMath.clampf(f1 - this.equippedProgress, -f, f);
|
|
this.equippedProgress += f2;
|
|
|
|
if (this.equippedProgress < 0.1F)
|
|
{
|
|
this.itemToRender = itemstack;
|
|
this.equippedItemSlot = entityplayer.inventory.currentItem;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Resets equippedProgress
|
|
*/
|
|
public void resetEquippedProgress()
|
|
{
|
|
this.equippedProgress = 0.0F;
|
|
}
|
|
|
|
/**
|
|
* Resets equippedProgress
|
|
*/
|
|
public void resetEquippedProgress2()
|
|
{
|
|
this.equippedProgress = 0.0F;
|
|
}
|
|
}
|