| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.entity.AbstractClientPlayer;
|
| 8 | import net.minecraft.client.entity.EntityPlayerSP;
|
| 9 | import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
| 10 | import net.minecraft.client.renderer.entity.Render;
|
| 11 | import net.minecraft.client.renderer.entity.RenderItem;
|
| 12 | import net.minecraft.client.renderer.entity.RenderManager;
|
| 13 | import net.minecraft.client.renderer.entity.RenderPlayer;
|
| 14 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
| 15 | import net.minecraft.client.renderer.texture.TextureMap;
|
| 16 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 17 | import net.minecraft.entity.EntityLivingBase;
|
| 18 | import net.minecraft.entity.player.EntityPlayer;
|
| 19 | import net.minecraft.init.Items;
|
| 20 | import net.minecraft.item.EnumAction;
|
| 21 | import net.minecraft.item.Item;
|
| 22 | import net.minecraft.item.ItemStack;
|
| 23 | import net.minecraft.util.BlockPos;
|
| 24 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 25 | import net.minecraft.util.MathHelper;
|
| 26 | import net.minecraft.util.ResourceLocation;
|
| 27 | import net.minecraft.world.storage.MapData;
|
| 28 | import org.lwjgl.opengl.GL11;
|
| 29 |
|
| 30 | public class ItemRenderer
|
| 31 | {
|
| 32 | private static final ResourceLocation RES_MAP_BACKGROUND = new ResourceLocation("textures/map/map_background.png");
|
| 33 | private static final ResourceLocation RES_UNDERWATER_OVERLAY = new ResourceLocation("textures/misc/underwater.png");
|
| 34 |
|
| 35 | /** A reference to the Minecraft object. */
|
| 36 | private final Minecraft mc;
|
| 37 | private ItemStack itemToRender;
|
| 38 |
|
| 39 | /**
|
| 40 | * How far the current item has been equipped (0 disequipped and 1 fully up)
|
| 41 | */
|
| 42 | private float equippedProgress;
|
| 43 | private float prevEquippedProgress;
|
| 44 | private final RenderManager renderManager;
|
| 45 | private final RenderItem itemRenderer;
|
| 46 |
|
| 47 | /** The index of the currently held item (0-8, or -1 if not yet updated) */
|
| 48 | private int equippedItemSlot = -1;
|
| 49 |
|
| 50 | public ItemRenderer(Minecraft mcIn)
|
| 51 | {
|
| 52 | this.mc = mcIn;
|
| 53 | this.renderManager = mcIn.getRenderManager();
|
| 54 | this.itemRenderer = mcIn.getRenderItem();
|
| 55 | }
|
| 56 |
|
| 57 | public void renderItem(EntityLivingBase entityIn, ItemStack heldStack, ItemCameraTransforms.TransformType transform)
|
| 58 | {
|
| 59 | if (heldStack != null)
|
| 60 | {
|
| 61 | Item item = heldStack.getItem();
|
| 62 | Block block = Block.getBlockFromItem(item);
|
| 63 | GlStateManager.pushMatrix();
|
| 64 |
|
| 65 | if (this.itemRenderer.shouldRenderItemIn3D(heldStack))
|
| 66 | {
|
| 67 | GlStateManager.scale(2.0F, 2.0F, 2.0F);
|
| 68 |
|
| 69 | if (this.isBlockTranslucent(block))
|
| 70 | {
|
| 71 | GlStateManager.depthMask(false);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | this.itemRenderer.renderItemModelForEntity(heldStack, entityIn, transform);
|
| 76 |
|
| 77 | if (this.isBlockTranslucent(block))
|
| 78 | {
|
| 79 | GlStateManager.depthMask(true);
|
| 80 | }
|
| 81 |
|
| 82 | GlStateManager.popMatrix();
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Returns true if given block is translucent
|
| 88 | */
|
| 89 | private boolean isBlockTranslucent(Block blockIn)
|
| 90 | {
|
| 91 | return blockIn != null && blockIn.getBlockLayer() == EnumWorldBlockLayer.TRANSLUCENT;
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Rotate the render around X and Y
|
| 96 | *
|
| 97 | * @param angleY The angle for the rotation arround Y
|
| 98 | */
|
| 99 | private void rotateArroundXAndY(float angle, float angleY)
|
| 100 | {
|
| 101 | GlStateManager.pushMatrix();
|
| 102 | GlStateManager.rotate(angle, 1.0F, 0.0F, 0.0F);
|
| 103 | GlStateManager.rotate(angleY, 0.0F, 1.0F, 0.0F);
|
| 104 | RenderHelper.enableStandardItemLighting();
|
| 105 | GlStateManager.popMatrix();
|
| 106 | }
|
| 107 |
|
| 108 | /**
|
| 109 | * Set the OpenGL LightMapTextureCoords based on the AbstractClientPlayer
|
| 110 | */
|
| 111 | private void setLightMapFromPlayer(AbstractClientPlayer clientPlayer)
|
| 112 | {
|
| 113 | int i = this.mc.theWorld.getCombinedLight(new BlockPos(clientPlayer.posX, clientPlayer.posY + (double)clientPlayer.getEyeHeight(), clientPlayer.posZ), 0);
|
| 114 | float f = (float)(i & 65535);
|
| 115 | float f1 = (float)(i >> 16);
|
| 116 | OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, f, f1);
|
| 117 | }
|
| 118 |
|
| 119 | /**
|
| 120 | * Rotate the render according to the player's yaw and pitch
|
| 121 | */
|
| 122 | private void rotateWithPlayerRotations(EntityPlayerSP entityplayerspIn, float partialTicks)
|
| 123 | {
|
| 124 | float f = entityplayerspIn.prevRenderArmPitch + (entityplayerspIn.renderArmPitch - entityplayerspIn.prevRenderArmPitch) * partialTicks;
|
| 125 | float f1 = entityplayerspIn.prevRenderArmYaw + (entityplayerspIn.renderArmYaw - entityplayerspIn.prevRenderArmYaw) * partialTicks;
|
| 126 | GlStateManager.rotate((entityplayerspIn.rotationPitch - f) * 0.1F, 1.0F, 0.0F, 0.0F);
|
| 127 | GlStateManager.rotate((entityplayerspIn.rotationYaw - f1) * 0.1F, 0.0F, 1.0F, 0.0F);
|
| 128 | }
|
| 129 |
|
| 130 | /**
|
| 131 | * Return the angle to render the Map
|
| 132 | *
|
| 133 | * @param pitch The player's pitch
|
| 134 | */
|
| 135 | private float getMapAngleFromPitch(float pitch)
|
| 136 | {
|
| 137 | float f = 1.0F - pitch / 45.0F + 0.1F;
|
| 138 | f = MathHelper.clamp_float(f, 0.0F, 1.0F);
|
| 139 | f = -MathHelper.cos(f * (float)Math.PI) * 0.5F + 0.5F;
|
| 140 | return f;
|
| 141 | }
|
| 142 |
|
| 143 | private void renderRightArm(RenderPlayer renderPlayerIn)
|
| 144 | {
|
| 145 | GlStateManager.pushMatrix();
|
| 146 | GlStateManager.rotate(54.0F, 0.0F, 1.0F, 0.0F);
|
| 147 | GlStateManager.rotate(64.0F, 1.0F, 0.0F, 0.0F);
|
| 148 | GlStateManager.rotate(-62.0F, 0.0F, 0.0F, 1.0F);
|
| 149 | GlStateManager.translate(0.25F, -0.85F, 0.75F);
|
| 150 | renderPlayerIn.renderRightArm(this.mc.thePlayer);
|
| 151 | GlStateManager.popMatrix();
|
| 152 | }
|
| 153 |
|
| 154 | private void renderLeftArm(RenderPlayer renderPlayerIn)
|
| 155 | {
|
| 156 | GlStateManager.pushMatrix();
|
| 157 | GlStateManager.rotate(92.0F, 0.0F, 1.0F, 0.0F);
|
| 158 | GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
|
| 159 | GlStateManager.rotate(41.0F, 0.0F, 0.0F, 1.0F);
|
| 160 | GlStateManager.translate(-0.3F, -1.1F, 0.45F);
|
| 161 | renderPlayerIn.renderLeftArm(this.mc.thePlayer);
|
| 162 | GlStateManager.popMatrix();
|
| 163 | }
|
| 164 |
|
| 165 | private void renderPlayerArms(AbstractClientPlayer clientPlayer)
|
| 166 | {
|
| 167 | this.mc.getTextureManager().bindTexture(clientPlayer.getLocationSkin());
|
| 168 | Render<AbstractClientPlayer> render = this.renderManager.<AbstractClientPlayer>getEntityRenderObject(this.mc.thePlayer);
|
| 169 | RenderPlayer renderplayer = (RenderPlayer)render;
|
| 170 |
|
| 171 | if (!clientPlayer.isInvisible())
|
| 172 | {
|
| 173 | GlStateManager.disableCull();
|
| 174 | this.renderRightArm(renderplayer);
|
| 175 | this.renderLeftArm(renderplayer);
|
| 176 | GlStateManager.enableCull();
|
| 177 | }
|
| 178 | }
|
| 179 |
|
| 180 | private void renderItemMap(AbstractClientPlayer clientPlayer, float pitch, float equipmentProgress, float swingProgress)
|
| 181 | {
|
| 182 | float f = -0.4F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 183 | float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI * 2.0F);
|
| 184 | float f2 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI);
|
| 185 | GlStateManager.translate(f, f1, f2);
|
| 186 | float f3 = this.getMapAngleFromPitch(pitch);
|
| 187 | GlStateManager.translate(0.0F, 0.04F, -0.72F);
|
| 188 | GlStateManager.translate(0.0F, equipmentProgress * -1.2F, 0.0F);
|
| 189 | GlStateManager.translate(0.0F, f3 * -0.5F, 0.0F);
|
| 190 | GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
| 191 | GlStateManager.rotate(f3 * -85.0F, 0.0F, 0.0F, 1.0F);
|
| 192 | GlStateManager.rotate(0.0F, 1.0F, 0.0F, 0.0F);
|
| 193 | this.renderPlayerArms(clientPlayer);
|
| 194 | float f4 = MathHelper.sin(swingProgress * swingProgress * (float)Math.PI);
|
| 195 | float f5 = MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 196 | GlStateManager.rotate(f4 * -20.0F, 0.0F, 1.0F, 0.0F);
|
| 197 | GlStateManager.rotate(f5 * -20.0F, 0.0F, 0.0F, 1.0F);
|
| 198 | GlStateManager.rotate(f5 * -80.0F, 1.0F, 0.0F, 0.0F);
|
| 199 | GlStateManager.scale(0.38F, 0.38F, 0.38F);
|
| 200 | GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
| 201 | GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
|
| 202 | GlStateManager.rotate(0.0F, 1.0F, 0.0F, 0.0F);
|
| 203 | GlStateManager.translate(-1.0F, -1.0F, 0.0F);
|
| 204 | GlStateManager.scale(0.015625F, 0.015625F, 0.015625F);
|
| 205 | this.mc.getTextureManager().bindTexture(RES_MAP_BACKGROUND);
|
| 206 | Tessellator tessellator = Tessellator.getInstance();
|
| 207 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 208 | GL11.glNormal3f(0.0F, 0.0F, -1.0F);
|
| 209 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 210 | worldrenderer.pos(-7.0D, 135.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
|
| 211 | worldrenderer.pos(135.0D, 135.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
|
| 212 | worldrenderer.pos(135.0D, -7.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
|
| 213 | worldrenderer.pos(-7.0D, -7.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
|
| 214 | tessellator.draw();
|
| 215 | MapData mapdata = Items.filled_map.getMapData(this.itemToRender, this.mc.theWorld);
|
| 216 |
|
| 217 | if (mapdata != null)
|
| 218 | {
|
| 219 | this.mc.entityRenderer.getMapItemRenderer().renderMap(mapdata, false);
|
| 220 | }
|
| 221 | }
|
| 222 |
|
| 223 | /**
|
| 224 | * Render the player's arm
|
| 225 | *
|
| 226 | * @param equipProgress The progress of equiping the item
|
| 227 | * @param swingProgress The swing movement progression
|
| 228 | */
|
| 229 | private void renderPlayerArm(AbstractClientPlayer clientPlayer, float equipProgress, float swingProgress)
|
| 230 | {
|
| 231 | float f = -0.3F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 232 | float f1 = 0.4F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI * 2.0F);
|
| 233 | float f2 = -0.4F * MathHelper.sin(swingProgress * (float)Math.PI);
|
| 234 | GlStateManager.translate(f, f1, f2);
|
| 235 | GlStateManager.translate(0.64000005F, -0.6F, -0.71999997F);
|
| 236 | GlStateManager.translate(0.0F, equipProgress * -0.6F, 0.0F);
|
| 237 | GlStateManager.rotate(45.0F, 0.0F, 1.0F, 0.0F);
|
| 238 | float f3 = MathHelper.sin(swingProgress * swingProgress * (float)Math.PI);
|
| 239 | float f4 = MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 240 | GlStateManager.rotate(f4 * 70.0F, 0.0F, 1.0F, 0.0F);
|
| 241 | GlStateManager.rotate(f3 * -20.0F, 0.0F, 0.0F, 1.0F);
|
| 242 | this.mc.getTextureManager().bindTexture(clientPlayer.getLocationSkin());
|
| 243 | GlStateManager.translate(-1.0F, 3.6F, 3.5F);
|
| 244 | GlStateManager.rotate(120.0F, 0.0F, 0.0F, 1.0F);
|
| 245 | GlStateManager.rotate(200.0F, 1.0F, 0.0F, 0.0F);
|
| 246 | GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
|
| 247 | GlStateManager.scale(1.0F, 1.0F, 1.0F);
|
| 248 | GlStateManager.translate(5.6F, 0.0F, 0.0F);
|
| 249 | Render<AbstractClientPlayer> render = this.renderManager.<AbstractClientPlayer>getEntityRenderObject(this.mc.thePlayer);
|
| 250 | GlStateManager.disableCull();
|
| 251 | RenderPlayer renderplayer = (RenderPlayer)render;
|
| 252 | renderplayer.renderRightArm(this.mc.thePlayer);
|
| 253 | GlStateManager.enableCull();
|
| 254 | }
|
| 255 |
|
| 256 | /**
|
| 257 | * Rotate and translate render to show item consumption
|
| 258 | *
|
| 259 | * @param swingProgress The swing movement progress
|
| 260 | */
|
| 261 | private void doItemUsedTransformations(float swingProgress)
|
| 262 | {
|
| 263 | float f = -0.4F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 264 | float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI * 2.0F);
|
| 265 | float f2 = -0.2F * MathHelper.sin(swingProgress * (float)Math.PI);
|
| 266 | GlStateManager.translate(f, f1, f2);
|
| 267 | }
|
| 268 |
|
| 269 | /**
|
| 270 | * Perform the drinking animation movement
|
| 271 | *
|
| 272 | * @param partialTicks Partials ticks
|
| 273 | */
|
| 274 | private void performDrinking(AbstractClientPlayer clientPlayer, float partialTicks)
|
| 275 | {
|
| 276 | float f = (float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F;
|
| 277 | float f1 = f / (float)this.itemToRender.getMaxItemUseDuration();
|
| 278 | float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);
|
| 279 |
|
| 280 | if (f1 >= 0.8F)
|
| 281 | {
|
| 282 | f2 = 0.0F;
|
| 283 | }
|
| 284 |
|
| 285 | GlStateManager.translate(0.0F, f2, 0.0F);
|
| 286 | float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
|
| 287 | GlStateManager.translate(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F);
|
| 288 | GlStateManager.rotate(f3 * 90.0F, 0.0F, 1.0F, 0.0F);
|
| 289 | GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
|
| 290 | GlStateManager.rotate(f3 * 30.0F, 0.0F, 0.0F, 1.0F);
|
| 291 | }
|
| 292 |
|
| 293 | /**
|
| 294 | * Performs transformations prior to the rendering of a held item in first person.
|
| 295 | */
|
| 296 | private void transformFirstPersonItem(float equipProgress, float swingProgress)
|
| 297 | {
|
| 298 | GlStateManager.translate(0.56F, -0.52F, -0.71999997F);
|
| 299 | GlStateManager.translate(0.0F, equipProgress * -0.6F, 0.0F);
|
| 300 | GlStateManager.rotate(45.0F, 0.0F, 1.0F, 0.0F);
|
| 301 | float f = MathHelper.sin(swingProgress * swingProgress * (float)Math.PI);
|
| 302 | float f1 = MathHelper.sin(MathHelper.sqrt_float(swingProgress) * (float)Math.PI);
|
| 303 | GlStateManager.rotate(f * -20.0F, 0.0F, 1.0F, 0.0F);
|
| 304 | GlStateManager.rotate(f1 * -20.0F, 0.0F, 0.0F, 1.0F);
|
| 305 | GlStateManager.rotate(f1 * -80.0F, 1.0F, 0.0F, 0.0F);
|
| 306 | GlStateManager.scale(0.4F, 0.4F, 0.4F);
|
| 307 | }
|
| 308 |
|
| 309 | /**
|
| 310 | * Translate and rotate the render to look like holding a bow
|
| 311 | *
|
| 312 | * @param partialTicks Partial ticks
|
| 313 | */
|
| 314 | private void doBowTransformations(float partialTicks, AbstractClientPlayer clientPlayer)
|
| 315 | {
|
| 316 | GlStateManager.rotate(-18.0F, 0.0F, 0.0F, 1.0F);
|
| 317 | GlStateManager.rotate(-12.0F, 0.0F, 1.0F, 0.0F);
|
| 318 | GlStateManager.rotate(-8.0F, 1.0F, 0.0F, 0.0F);
|
| 319 | GlStateManager.translate(-0.9F, 0.2F, 0.0F);
|
| 320 | float f = (float)this.itemToRender.getMaxItemUseDuration() - ((float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F);
|
| 321 | float f1 = f / 20.0F;
|
| 322 | f1 = (f1 * f1 + f1 * 2.0F) / 3.0F;
|
| 323 |
|
| 324 | if (f1 > 1.0F)
|
| 325 | {
|
| 326 | f1 = 1.0F;
|
| 327 | }
|
| 328 |
|
| 329 | if (f1 > 0.1F)
|
| 330 | {
|
| 331 | float f2 = MathHelper.sin((f - 0.1F) * 1.3F);
|
| 332 | float f3 = f1 - 0.1F;
|
| 333 | float f4 = f2 * f3;
|
| 334 | GlStateManager.translate(f4 * 0.0F, f4 * 0.01F, f4 * 0.0F);
|
| 335 | }
|
| 336 |
|
| 337 | GlStateManager.translate(f1 * 0.0F, f1 * 0.0F, f1 * 0.1F);
|
| 338 | GlStateManager.scale(1.0F, 1.0F, 1.0F + f1 * 0.2F);
|
| 339 | }
|
| 340 |
|
| 341 | /**
|
| 342 | * Translate and rotate the render for holding a block
|
| 343 | */
|
| 344 | private void doBlockTransformations()
|
| 345 | {
|
| 346 | GlStateManager.translate(-0.5F, 0.2F, 0.0F);
|
| 347 | GlStateManager.rotate(30.0F, 0.0F, 1.0F, 0.0F);
|
| 348 | GlStateManager.rotate(-80.0F, 1.0F, 0.0F, 0.0F);
|
| 349 | GlStateManager.rotate(60.0F, 0.0F, 1.0F, 0.0F);
|
| 350 | }
|
| 351 |
|
| 352 | /**
|
| 353 | * Renders the active item in the player's hand when in first person mode. Args: partialTickTime
|
| 354 | */
|
| 355 | public void renderItemInFirstPerson(float partialTicks)
|
| 356 | {
|
| 357 | float f = 1.0F - (this.prevEquippedProgress + (this.equippedProgress - this.prevEquippedProgress) * partialTicks);
|
| 358 | AbstractClientPlayer abstractclientplayer = this.mc.thePlayer;
|
| 359 | float f1 = abstractclientplayer.getSwingProgress(partialTicks);
|
| 360 | float f2 = abstractclientplayer.prevRotationPitch + (abstractclientplayer.rotationPitch - abstractclientplayer.prevRotationPitch) * partialTicks;
|
| 361 | float f3 = abstractclientplayer.prevRotationYaw + (abstractclientplayer.rotationYaw - abstractclientplayer.prevRotationYaw) * partialTicks;
|
| 362 | this.rotateArroundXAndY(f2, f3);
|
| 363 | this.setLightMapFromPlayer(abstractclientplayer);
|
| 364 | this.rotateWithPlayerRotations((EntityPlayerSP)abstractclientplayer, partialTicks);
|
| 365 | GlStateManager.enableRescaleNormal();
|
| 366 | GlStateManager.pushMatrix();
|
| 367 |
|
| 368 | if (this.itemToRender != null)
|
| 369 | {
|
| 370 | if (this.itemToRender.getItem() == Items.filled_map)
|
| 371 | {
|
| 372 | this.renderItemMap(abstractclientplayer, f2, f, f1);
|
| 373 | }
|
| 374 | else if (abstractclientplayer.getItemInUseCount() > 0)
|
| 375 | {
|
| 376 | EnumAction enumaction = this.itemToRender.getItemUseAction();
|
| 377 |
|
| 378 | switch (enumaction)
|
| 379 | {
|
| 380 | case NONE:
|
| 381 | this.transformFirstPersonItem(f, 0.0F);
|
| 382 | break;
|
| 383 |
|
| 384 | case EAT:
|
| 385 | case DRINK:
|
| 386 | this.performDrinking(abstractclientplayer, partialTicks);
|
| 387 | this.transformFirstPersonItem(f, 0.0F);
|
| 388 | break;
|
| 389 |
|
| 390 | case BLOCK:
|
| 391 | this.transformFirstPersonItem(f, 0.0F);
|
| 392 | this.doBlockTransformations();
|
| 393 | break;
|
| 394 |
|
| 395 | case BOW:
|
| 396 | this.transformFirstPersonItem(f, 0.0F);
|
| 397 | this.doBowTransformations(partialTicks, abstractclientplayer);
|
| 398 | }
|
| 399 | }
|
| 400 | else
|
| 401 | {
|
| 402 | this.doItemUsedTransformations(f1);
|
| 403 | this.transformFirstPersonItem(f, f1);
|
| 404 | }
|
| 405 |
|
| 406 | this.renderItem(abstractclientplayer, this.itemToRender, ItemCameraTransforms.TransformType.FIRST_PERSON);
|
| 407 | }
|
| 408 | else if (!abstractclientplayer.isInvisible())
|
| 409 | {
|
| 410 | this.renderPlayerArm(abstractclientplayer, f, f1);
|
| 411 | }
|
| 412 |
|
| 413 | GlStateManager.popMatrix();
|
| 414 | GlStateManager.disableRescaleNormal();
|
| 415 | RenderHelper.disableStandardItemLighting();
|
| 416 | }
|
| 417 |
|
| 418 | /**
|
| 419 | * Renders all the overlays that are in first person mode. Args: partialTickTime
|
| 420 | */
|
| 421 | public void renderOverlays(float partialTicks)
|
| 422 | {
|
| 423 | GlStateManager.disableAlpha();
|
| 424 |
|
| 425 | if (this.mc.thePlayer.isEntityInsideOpaqueBlock())
|
| 426 | {
|
| 427 | IBlockState iblockstate = this.mc.theWorld.getBlockState(new BlockPos(this.mc.thePlayer));
|
| 428 | EntityPlayer entityplayer = this.mc.thePlayer;
|
| 429 |
|
| 430 | for (int i = 0; i < 8; ++i)
|
| 431 | {
|
| 432 | double d0 = entityplayer.posX + (double)(((float)((i >> 0) % 2) - 0.5F) * entityplayer.width * 0.8F);
|
| 433 | double d1 = entityplayer.posY + (double)(((float)((i >> 1) % 2) - 0.5F) * 0.1F);
|
| 434 | double d2 = entityplayer.posZ + (double)(((float)((i >> 2) % 2) - 0.5F) * entityplayer.width * 0.8F);
|
| 435 | BlockPos blockpos = new BlockPos(d0, d1 + (double)entityplayer.getEyeHeight(), d2);
|
| 436 | IBlockState iblockstate1 = this.mc.theWorld.getBlockState(blockpos);
|
| 437 |
|
| 438 | if (iblockstate1.getBlock().isVisuallyOpaque())
|
| 439 | {
|
| 440 | iblockstate = iblockstate1;
|
| 441 | }
|
| 442 | }
|
| 443 |
|
| 444 | if (iblockstate.getBlock().getRenderType() != -1)
|
| 445 | {
|
| 446 | this.renderBlockInHand(partialTicks, this.mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(iblockstate));
|
| 447 | }
|
| 448 | }
|
| 449 |
|
| 450 | if (!this.mc.thePlayer.isSpectator())
|
| 451 | {
|
| 452 | if (this.mc.thePlayer.isInsideOfMaterial(Material.water))
|
| 453 | {
|
| 454 | this.renderWaterOverlayTexture(partialTicks);
|
| 455 | }
|
| 456 |
|
| 457 | if (this.mc.thePlayer.isBurning())
|
| 458 | {
|
| 459 | this.renderFireInFirstPerson(partialTicks);
|
| 460 | }
|
| 461 | }
|
| 462 |
|
| 463 | GlStateManager.enableAlpha();
|
| 464 | }
|
| 465 |
|
| 466 | /**
|
| 467 | * Render the block in the player's hand
|
| 468 | *
|
| 469 | * @param partialTicks Partial ticks
|
| 470 | * @param atlas The TextureAtlasSprite to render
|
| 471 | */
|
| 472 | private void renderBlockInHand(float partialTicks, TextureAtlasSprite atlas)
|
| 473 | {
|
| 474 | this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
| 475 | Tessellator tessellator = Tessellator.getInstance();
|
| 476 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 477 | float f = 0.1F;
|
| 478 | GlStateManager.color(0.1F, 0.1F, 0.1F, 0.5F);
|
| 479 | GlStateManager.pushMatrix();
|
| 480 | float f1 = -1.0F;
|
| 481 | float f2 = 1.0F;
|
| 482 | float f3 = -1.0F;
|
| 483 | float f4 = 1.0F;
|
| 484 | float f5 = -0.5F;
|
| 485 | float f6 = atlas.getMinU();
|
| 486 | float f7 = atlas.getMaxU();
|
| 487 | float f8 = atlas.getMinV();
|
| 488 | float f9 = atlas.getMaxV();
|
| 489 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 490 | worldrenderer.pos(-1.0D, -1.0D, -0.5D).tex((double)f7, (double)f9).endVertex();
|
| 491 | worldrenderer.pos(1.0D, -1.0D, -0.5D).tex((double)f6, (double)f9).endVertex();
|
| 492 | worldrenderer.pos(1.0D, 1.0D, -0.5D).tex((double)f6, (double)f8).endVertex();
|
| 493 | worldrenderer.pos(-1.0D, 1.0D, -0.5D).tex((double)f7, (double)f8).endVertex();
|
| 494 | tessellator.draw();
|
| 495 | GlStateManager.popMatrix();
|
| 496 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 497 | }
|
| 498 |
|
| 499 | /**
|
| 500 | * Renders a texture that warps around based on the direction the player is looking. Texture needs to be bound
|
| 501 | * before being called. Used for the water overlay. Args: parialTickTime
|
| 502 | *
|
| 503 | * @param partialTicks Partial ticks
|
| 504 | */
|
| 505 | private void renderWaterOverlayTexture(float partialTicks)
|
| 506 | {
|
| 507 | this.mc.getTextureManager().bindTexture(RES_UNDERWATER_OVERLAY);
|
| 508 | Tessellator tessellator = Tessellator.getInstance();
|
| 509 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 510 | float f = this.mc.thePlayer.getBrightness(partialTicks);
|
| 511 | GlStateManager.color(f, f, f, 0.5F);
|
| 512 | GlStateManager.enableBlend();
|
| 513 | GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
| 514 | GlStateManager.pushMatrix();
|
| 515 | float f1 = 4.0F;
|
| 516 | float f2 = -1.0F;
|
| 517 | float f3 = 1.0F;
|
| 518 | float f4 = -1.0F;
|
| 519 | float f5 = 1.0F;
|
| 520 | float f6 = -0.5F;
|
| 521 | float f7 = -this.mc.thePlayer.rotationYaw / 64.0F;
|
| 522 | float f8 = this.mc.thePlayer.rotationPitch / 64.0F;
|
| 523 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 524 | worldrenderer.pos(-1.0D, -1.0D, -0.5D).tex((double)(4.0F + f7), (double)(4.0F + f8)).endVertex();
|
| 525 | worldrenderer.pos(1.0D, -1.0D, -0.5D).tex((double)(0.0F + f7), (double)(4.0F + f8)).endVertex();
|
| 526 | worldrenderer.pos(1.0D, 1.0D, -0.5D).tex((double)(0.0F + f7), (double)(0.0F + f8)).endVertex();
|
| 527 | worldrenderer.pos(-1.0D, 1.0D, -0.5D).tex((double)(4.0F + f7), (double)(0.0F + f8)).endVertex();
|
| 528 | tessellator.draw();
|
| 529 | GlStateManager.popMatrix();
|
| 530 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 531 | GlStateManager.disableBlend();
|
| 532 | }
|
| 533 |
|
| 534 | /**
|
| 535 | * Renders the fire on the screen for first person mode. Arg: partialTickTime
|
| 536 | *
|
| 537 | * @param partialTicks Partial ticks
|
| 538 | */
|
| 539 | private void renderFireInFirstPerson(float partialTicks)
|
| 540 | {
|
| 541 | Tessellator tessellator = Tessellator.getInstance();
|
| 542 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 543 | GlStateManager.color(1.0F, 1.0F, 1.0F, 0.9F);
|
| 544 | GlStateManager.depthFunc(519);
|
| 545 | GlStateManager.depthMask(false);
|
| 546 | GlStateManager.enableBlend();
|
| 547 | GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
| 548 | float f = 1.0F;
|
| 549 |
|
| 550 | for (int i = 0; i < 2; ++i)
|
| 551 | {
|
| 552 | GlStateManager.pushMatrix();
|
| 553 | TextureAtlasSprite textureatlassprite = this.mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_1");
|
| 554 | this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
|
| 555 | float f1 = textureatlassprite.getMinU();
|
| 556 | float f2 = textureatlassprite.getMaxU();
|
| 557 | float f3 = textureatlassprite.getMinV();
|
| 558 | float f4 = textureatlassprite.getMaxV();
|
| 559 | float f5 = (0.0F - f) / 2.0F;
|
| 560 | float f6 = f5 + f;
|
| 561 | float f7 = 0.0F - f / 2.0F;
|
| 562 | float f8 = f7 + f;
|
| 563 | float f9 = -0.5F;
|
| 564 | GlStateManager.translate((float)(-(i * 2 - 1)) * 0.24F, -0.3F, 0.0F);
|
| 565 | GlStateManager.rotate((float)(i * 2 - 1) * 10.0F, 0.0F, 1.0F, 0.0F);
|
| 566 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 567 | worldrenderer.pos((double)f5, (double)f7, (double)f9).tex((double)f2, (double)f4).endVertex();
|
| 568 | worldrenderer.pos((double)f6, (double)f7, (double)f9).tex((double)f1, (double)f4).endVertex();
|
| 569 | worldrenderer.pos((double)f6, (double)f8, (double)f9).tex((double)f1, (double)f3).endVertex();
|
| 570 | worldrenderer.pos((double)f5, (double)f8, (double)f9).tex((double)f2, (double)f3).endVertex();
|
| 571 | tessellator.draw();
|
| 572 | GlStateManager.popMatrix();
|
| 573 | }
|
| 574 |
|
| 575 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 576 | GlStateManager.disableBlend();
|
| 577 | GlStateManager.depthMask(true);
|
| 578 | GlStateManager.depthFunc(515);
|
| 579 | }
|
| 580 |
|
| 581 | public void updateEquippedItem()
|
| 582 | {
|
| 583 | this.prevEquippedProgress = this.equippedProgress;
|
| 584 | EntityPlayer entityplayer = this.mc.thePlayer;
|
| 585 | ItemStack itemstack = entityplayer.inventory.getCurrentItem();
|
| 586 | boolean flag = false;
|
| 587 |
|
| 588 | if (this.itemToRender != null && itemstack != null)
|
| 589 | {
|
| 590 | if (!this.itemToRender.getIsItemStackEqual(itemstack))
|
| 591 | {
|
| 592 | flag = true;
|
| 593 | }
|
| 594 | }
|
| 595 | else if (this.itemToRender == null && itemstack == null)
|
| 596 | {
|
| 597 | flag = false;
|
| 598 | }
|
| 599 | else
|
| 600 | {
|
| 601 | flag = true;
|
| 602 | }
|
| 603 |
|
| 604 | float f = 0.4F;
|
| 605 | float f1 = flag ? 0.0F : 1.0F;
|
| 606 | float f2 = MathHelper.clamp_float(f1 - this.equippedProgress, -f, f);
|
| 607 | this.equippedProgress += f2;
|
| 608 |
|
| 609 | if (this.equippedProgress < 0.1F)
|
| 610 | {
|
| 611 | this.itemToRender = itemstack;
|
| 612 | this.equippedItemSlot = entityplayer.inventory.currentItem;
|
| 613 | }
|
| 614 | }
|
| 615 |
|
| 616 | /**
|
| 617 | * Resets equippedProgress
|
| 618 | */
|
| 619 | public void resetEquippedProgress()
|
| 620 | {
|
| 621 | this.equippedProgress = 0.0F;
|
| 622 | }
|
| 623 |
|
| 624 | /**
|
| 625 | * Resets equippedProgress
|
| 626 | */
|
| 627 | public void resetEquippedProgress2()
|
| 628 | {
|
| 629 | this.equippedProgress = 0.0F;
|
| 630 | }
|
| 631 | }
|
| 632 |
|