Stradaa_

EntityRenderer.java

Mar 30th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.38 KB | None | 0 0
  1. package net.minecraft.client.renderer;
  2.  
  3. import com.google.common.base.Predicate;
  4. import com.google.common.base.Predicates;
  5. import com.google.gson.JsonSyntaxException;
  6. import java.io.IOException;
  7. import java.nio.FloatBuffer;
  8. import java.util.List;
  9. import java.util.Random;
  10. import java.util.concurrent.Callable;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.BlockBed;
  13. import net.minecraft.block.material.Material;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.client.Minecraft;
  16. import net.minecraft.client.entity.AbstractClientPlayer;
  17. import net.minecraft.client.gui.MapItemRenderer;
  18. import net.minecraft.client.gui.ScaledResolution;
  19. import net.minecraft.client.particle.EffectRenderer;
  20. import net.minecraft.client.renderer.culling.ClippingHelperImpl;
  21. import net.minecraft.client.renderer.culling.Frustum;
  22. import net.minecraft.client.renderer.culling.ICamera;
  23. import net.minecraft.client.renderer.texture.DynamicTexture;
  24. import net.minecraft.client.renderer.texture.TextureMap;
  25. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  26. import net.minecraft.client.resources.IResourceManager;
  27. import net.minecraft.client.resources.IResourceManagerReloadListener;
  28. import net.minecraft.client.shader.ShaderGroup;
  29. import net.minecraft.client.shader.ShaderLinkHelper;
  30. import net.minecraft.crash.CrashReport;
  31. import net.minecraft.crash.CrashReportCategory;
  32. import net.minecraft.enchantment.EnchantmentHelper;
  33. import net.minecraft.entity.Entity;
  34. import net.minecraft.entity.EntityLivingBase;
  35. import net.minecraft.entity.boss.BossStatus;
  36. import net.minecraft.entity.item.EntityItemFrame;
  37. import net.minecraft.entity.monster.EntityCreeper;
  38. import net.minecraft.entity.monster.EntityEnderman;
  39. import net.minecraft.entity.monster.EntitySpider;
  40. import net.minecraft.entity.passive.EntityAnimal;
  41. import net.minecraft.entity.player.EntityPlayer;
  42. import net.minecraft.init.Blocks;
  43. import net.minecraft.inventory.IInventory;
  44. import net.minecraft.item.ItemStack;
  45. import net.minecraft.potion.Potion;
  46. import net.minecraft.util.AxisAlignedBB;
  47. import net.minecraft.util.BlockPos;
  48. import net.minecraft.util.EntitySelectors;
  49. import net.minecraft.util.EnumFacing;
  50. import net.minecraft.util.EnumParticleTypes;
  51. import net.minecraft.util.EnumWorldBlockLayer;
  52. import net.minecraft.util.MathHelper;
  53. import net.minecraft.util.MouseFilter;
  54. import net.minecraft.util.MovingObjectPosition;
  55. import net.minecraft.util.ReportedException;
  56. import net.minecraft.util.ResourceLocation;
  57. import net.minecraft.util.Vec3;
  58. import net.minecraft.world.World;
  59. import net.minecraft.world.WorldSettings;
  60. import net.minecraft.world.biome.BiomeGenBase;
  61. import org.apache.logging.log4j.LogManager;
  62. import org.apache.logging.log4j.Logger;
  63. import org.lwjgl.input.Mouse;
  64. import org.lwjgl.opengl.Display;
  65. import org.lwjgl.opengl.GL11;
  66. import org.lwjgl.opengl.GLContext;
  67. import org.lwjgl.util.glu.Project;
  68.  
  69. public class EntityRenderer implements IResourceManagerReloadListener
  70. {
  71. private static final Logger logger = LogManager.getLogger();
  72. private static final ResourceLocation locationRainPng = new ResourceLocation("textures/environment/rain.png");
  73. private static final ResourceLocation locationSnowPng = new ResourceLocation("textures/environment/snow.png");
  74. public static boolean anaglyphEnable;
  75.  
  76. /** Anaglyph field (0=R, 1=GB) */
  77. public static int anaglyphField;
  78.  
  79. /** A reference to the Minecraft object. */
  80. private Minecraft mc;
  81. private final IResourceManager resourceManager;
  82. private Random random = new Random();
  83. private float farPlaneDistance;
  84. public final ItemRenderer itemRenderer;
  85. private final MapItemRenderer theMapItemRenderer;
  86.  
  87. /** Entity renderer update count */
  88. private int rendererUpdateCount;
  89.  
  90. /** Pointed entity */
  91. private Entity pointedEntity;
  92. private MouseFilter mouseFilterXAxis = new MouseFilter();
  93. private MouseFilter mouseFilterYAxis = new MouseFilter();
  94. private float thirdPersonDistance = 4.0F;
  95.  
  96. /** Third person distance temp */
  97. private float thirdPersonDistanceTemp = 4.0F;
  98.  
  99. /** Smooth cam yaw */
  100. private float smoothCamYaw;
  101.  
  102. /** Smooth cam pitch */
  103. private float smoothCamPitch;
  104.  
  105. /** Smooth cam filter X */
  106. private float smoothCamFilterX;
  107.  
  108. /** Smooth cam filter Y */
  109. private float smoothCamFilterY;
  110.  
  111. /** Smooth cam partial ticks */
  112. private float smoothCamPartialTicks;
  113.  
  114. /** FOV modifier hand */
  115. private float fovModifierHand;
  116.  
  117. /** FOV modifier hand prev */
  118. private float fovModifierHandPrev;
  119. private float bossColorModifier;
  120. private float bossColorModifierPrev;
  121.  
  122. /** Cloud fog mode */
  123. private boolean cloudFog;
  124. private boolean renderHand = true;
  125. private boolean drawBlockOutline = true;
  126.  
  127. /** Previous frame time in milliseconds */
  128. private long prevFrameTime = Minecraft.getSystemTime();
  129.  
  130. /** End time of last render (ns) */
  131. private long renderEndNanoTime;
  132.  
  133. /**
  134. * The texture id of the blocklight/skylight texture used for lighting effects
  135. */
  136. private final DynamicTexture lightmapTexture;
  137.  
  138. /**
  139. * Colors computed in updateLightmap() and loaded into the lightmap emptyTexture
  140. */
  141. private final int[] lightmapColors;
  142. private final ResourceLocation locationLightMap;
  143.  
  144. /**
  145. * Is set, updateCameraAndRender() calls updateLightmap(); set by updateTorchFlicker()
  146. */
  147. private boolean lightmapUpdateNeeded;
  148.  
  149. /** Torch flicker X */
  150. private float torchFlickerX;
  151. private float torchFlickerDX;
  152.  
  153. /** Rain sound counter */
  154. private int rainSoundCounter;
  155. private float[] rainXCoords = new float[1024];
  156. private float[] rainYCoords = new float[1024];
  157.  
  158. /** Fog color buffer */
  159. private FloatBuffer fogColorBuffer = GLAllocation.createDirectFloatBuffer(16);
  160. private float fogColorRed;
  161. private float fogColorGreen;
  162. private float fogColorBlue;
  163.  
  164. /** Fog color 2 */
  165. private float fogColor2;
  166.  
  167. /** Fog color 1 */
  168. private float fogColor1;
  169. private int debugViewDirection = 0;
  170. private boolean debugView = false;
  171. private double cameraZoom = 1.0D;
  172. private double cameraYaw;
  173. private double cameraPitch;
  174. private ShaderGroup theShaderGroup;
  175. private static final ResourceLocation[] shaderResourceLocations = new ResourceLocation[] {new ResourceLocation("shaders/post/notch.json"), new ResourceLocation("shaders/post/fxaa.json"), new ResourceLocation("shaders/post/art.json"), new ResourceLocation("shaders/post/bumpy.json"), new ResourceLocation("shaders/post/blobs2.json"), new ResourceLocation("shaders/post/pencil.json"), new ResourceLocation("shaders/post/color_convolve.json"), new ResourceLocation("shaders/post/deconverge.json"), new ResourceLocation("shaders/post/flip.json"), new ResourceLocation("shaders/post/invert.json"), new ResourceLocation("shaders/post/ntsc.json"), new ResourceLocation("shaders/post/outline.json"), new ResourceLocation("shaders/post/phosphor.json"), new ResourceLocation("shaders/post/scan_pincushion.json"), new ResourceLocation("shaders/post/sobel.json"), new ResourceLocation("shaders/post/bits.json"), new ResourceLocation("shaders/post/desaturate.json"), new ResourceLocation("shaders/post/green.json"), new ResourceLocation("shaders/post/blur.json"), new ResourceLocation("shaders/post/wobble.json"), new ResourceLocation("shaders/post/blobs.json"), new ResourceLocation("shaders/post/antialias.json"), new ResourceLocation("shaders/post/creeper.json"), new ResourceLocation("shaders/post/spider.json")};
  176. public static final int shaderCount = shaderResourceLocations.length;
  177. private int shaderIndex;
  178. private boolean useShader;
  179. private int frameCount;
  180.  
  181. public EntityRenderer(Minecraft mcIn, IResourceManager resourceManagerIn)
  182. {
  183. this.shaderIndex = shaderCount;
  184. this.useShader = false;
  185. this.frameCount = 0;
  186. this.mc = mcIn;
  187. this.resourceManager = resourceManagerIn;
  188. this.itemRenderer = mcIn.getItemRenderer();
  189. this.theMapItemRenderer = new MapItemRenderer(mcIn.getTextureManager());
  190. this.lightmapTexture = new DynamicTexture(16, 16);
  191. this.locationLightMap = mcIn.getTextureManager().getDynamicTextureLocation("lightMap", this.lightmapTexture);
  192. this.lightmapColors = this.lightmapTexture.getTextureData();
  193. this.theShaderGroup = null;
  194.  
  195. for (int i = 0; i < 32; ++i)
  196. {
  197. for (int j = 0; j < 32; ++j)
  198. {
  199. float f = (float)(j - 16);
  200. float f1 = (float)(i - 16);
  201. float f2 = MathHelper.sqrt_float(f * f + f1 * f1);
  202. this.rainXCoords[i << 5 | j] = -f1 / f2;
  203. this.rainYCoords[i << 5 | j] = f / f2;
  204. }
  205. }
  206. }
  207.  
  208. public boolean isShaderActive()
  209. {
  210. return OpenGlHelper.shadersSupported && this.theShaderGroup != null;
  211. }
  212.  
  213. public void func_181022_b()
  214. {
  215. if (this.theShaderGroup != null)
  216. {
  217. this.theShaderGroup.deleteShaderGroup();
  218. }
  219.  
  220. this.theShaderGroup = null;
  221. this.shaderIndex = shaderCount;
  222. }
  223.  
  224. public void switchUseShader()
  225. {
  226. this.useShader = !this.useShader;
  227. }
  228.  
  229. /**
  230. * What shader to use when spectating this entity
  231. */
  232. public void loadEntityShader(Entity entityIn)
  233. {
  234. if (OpenGlHelper.shadersSupported)
  235. {
  236. if (this.theShaderGroup != null)
  237. {
  238. this.theShaderGroup.deleteShaderGroup();
  239. }
  240.  
  241. this.theShaderGroup = null;
  242.  
  243. if (entityIn instanceof EntityCreeper)
  244. {
  245. this.loadShader(new ResourceLocation("shaders/post/creeper.json"));
  246. }
  247. else if (entityIn instanceof EntitySpider)
  248. {
  249. this.loadShader(new ResourceLocation("shaders/post/spider.json"));
  250. }
  251. else if (entityIn instanceof EntityEnderman)
  252. {
  253. this.loadShader(new ResourceLocation("shaders/post/invert.json"));
  254. }
  255. }
  256. }
  257.  
  258. public void activateNextShader()
  259. {
  260. if (OpenGlHelper.shadersSupported)
  261. {
  262. if (this.mc.getRenderViewEntity() instanceof EntityPlayer)
  263. {
  264. if (this.theShaderGroup != null)
  265. {
  266. this.theShaderGroup.deleteShaderGroup();
  267. }
  268.  
  269. this.shaderIndex = (this.shaderIndex + 1) % (shaderResourceLocations.length + 1);
  270.  
  271. if (this.shaderIndex != shaderCount)
  272. {
  273. this.loadShader(shaderResourceLocations[this.shaderIndex]);
  274. }
  275. else
  276. {
  277. this.theShaderGroup = null;
  278. }
  279. }
  280. }
  281. }
  282.  
  283. private void loadShader(ResourceLocation resourceLocationIn)
  284. {
  285. try
  286. {
  287. this.theShaderGroup = new ShaderGroup(this.mc.getTextureManager(), this.resourceManager, this.mc.getFramebuffer(), resourceLocationIn);
  288. this.theShaderGroup.createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
  289. this.useShader = true;
  290. }
  291. catch (IOException ioexception)
  292. {
  293. logger.warn((String)("Failed to load shader: " + resourceLocationIn), (Throwable)ioexception);
  294. this.shaderIndex = shaderCount;
  295. this.useShader = false;
  296. }
  297. catch (JsonSyntaxException jsonsyntaxexception)
  298. {
  299. logger.warn((String)("Failed to load shader: " + resourceLocationIn), (Throwable)jsonsyntaxexception);
  300. this.shaderIndex = shaderCount;
  301. this.useShader = false;
  302. }
  303. }
  304.  
  305. public void onResourceManagerReload(IResourceManager resourceManager)
  306. {
  307. if (this.theShaderGroup != null)
  308. {
  309. this.theShaderGroup.deleteShaderGroup();
  310. }
  311.  
  312. this.theShaderGroup = null;
  313.  
  314. if (this.shaderIndex != shaderCount)
  315. {
  316. this.loadShader(shaderResourceLocations[this.shaderIndex]);
  317. }
  318. else
  319. {
  320. this.loadEntityShader(this.mc.getRenderViewEntity());
  321. }
  322. }
  323.  
  324. /**
  325. * Updates the entity renderer
  326. */
  327. public void updateRenderer()
  328. {
  329. if (OpenGlHelper.shadersSupported && ShaderLinkHelper.getStaticShaderLinkHelper() == null)
  330. {
  331. ShaderLinkHelper.setNewStaticShaderLinkHelper();
  332. }
  333.  
  334. this.updateFovModifierHand();
  335. this.updateTorchFlicker();
  336. this.fogColor2 = this.fogColor1;
  337. this.thirdPersonDistanceTemp = this.thirdPersonDistance;
  338.  
  339. if (this.mc.gameSettings.smoothCamera)
  340. {
  341. float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
  342. float f1 = f * f * f * 8.0F;
  343. this.smoothCamFilterX = this.mouseFilterXAxis.smooth(this.smoothCamYaw, 0.05F * f1);
  344. this.smoothCamFilterY = this.mouseFilterYAxis.smooth(this.smoothCamPitch, 0.05F * f1);
  345. this.smoothCamPartialTicks = 0.0F;
  346. this.smoothCamYaw = 0.0F;
  347. this.smoothCamPitch = 0.0F;
  348. }
  349. else
  350. {
  351. this.smoothCamFilterX = 0.0F;
  352. this.smoothCamFilterY = 0.0F;
  353. this.mouseFilterXAxis.reset();
  354. this.mouseFilterYAxis.reset();
  355. }
  356.  
  357. if (this.mc.getRenderViewEntity() == null)
  358. {
  359. this.mc.setRenderViewEntity(this.mc.thePlayer);
  360. }
  361.  
  362. float f3 = this.mc.theWorld.getLightBrightness(new BlockPos(this.mc.getRenderViewEntity()));
  363. float f4 = (float)this.mc.gameSettings.renderDistanceChunks / 32.0F;
  364. float f2 = f3 * (1.0F - f4) + f4;
  365. this.fogColor1 += (f2 - this.fogColor1) * 0.1F;
  366. ++this.rendererUpdateCount;
  367. this.itemRenderer.updateEquippedItem();
  368. this.addRainParticles();
  369. this.bossColorModifierPrev = this.bossColorModifier;
  370.  
  371. if (BossStatus.hasColorModifier)
  372. {
  373. this.bossColorModifier += 0.05F;
  374.  
  375. if (this.bossColorModifier > 1.0F)
  376. {
  377. this.bossColorModifier = 1.0F;
  378. }
  379.  
  380. BossStatus.hasColorModifier = false;
  381. }
  382. else if (this.bossColorModifier > 0.0F)
  383. {
  384. this.bossColorModifier -= 0.0125F;
  385. }
  386. }
  387.  
  388. public ShaderGroup getShaderGroup()
  389. {
  390. return this.theShaderGroup;
  391. }
  392.  
  393. public void updateShaderGroupSize(int width, int height)
  394. {
  395. if (OpenGlHelper.shadersSupported)
  396. {
  397. if (this.theShaderGroup != null)
  398. {
  399. this.theShaderGroup.createBindFramebuffers(width, height);
  400. }
  401.  
  402. this.mc.renderGlobal.createBindEntityOutlineFbs(width, height);
  403. }
  404. }
  405.  
  406. /**
  407. * Finds what block or object the mouse is over at the specified partial tick time. Args: partialTickTime
  408. */
  409. public void getMouseOver(float partialTicks)
  410. {
  411. Entity entity = this.mc.getRenderViewEntity();
  412.  
  413. if (entity != null)
  414. {
  415. if (this.mc.theWorld != null)
  416. {
  417. this.mc.mcProfiler.startSection("pick");
  418. this.mc.pointedEntity = null;
  419. double d0 = (double)this.mc.playerController.getBlockReachDistance();
  420. this.mc.objectMouseOver = entity.rayTrace(d0, partialTicks);
  421. double d1 = d0;
  422. Vec3 vec3 = entity.getPositionEyes(partialTicks);
  423. boolean flag = false;
  424. int i = 3;
  425.  
  426. if (this.mc.playerController.extendedReach())
  427. {
  428. d0 = 6.0D;
  429. d1 = 6.0D;
  430. }
  431. else
  432. {
  433. if (d0 > 3.0D)
  434. {
  435. flag = true;
  436. }
  437. }
  438.  
  439. if (this.mc.objectMouseOver != null)
  440. {
  441. d1 = this.mc.objectMouseOver.hitVec.distanceTo(vec3);
  442. }
  443.  
  444. Vec3 vec31 = entity.getLook(partialTicks);
  445. Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
  446. this.pointedEntity = null;
  447. Vec3 vec33 = null;
  448. float f = 1.0F;
  449. List<Entity> list = this.mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand((double)f, (double)f, (double)f), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
  450. {
  451. public boolean apply(Entity p_apply_1_)
  452. {
  453. return p_apply_1_.canBeCollidedWith();
  454. }
  455. }));
  456. double d2 = d1;
  457.  
  458. for (int j = 0; j < list.size(); ++j)
  459. {
  460. Entity entity1 = (Entity)list.get(j);
  461. float f1 = entity1.getCollisionBorderSize();
  462. AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1);
  463. MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
  464.  
  465. if (axisalignedbb.isVecInside(vec3))
  466. {
  467. if (d2 >= 0.0D)
  468. {
  469. this.pointedEntity = entity1;
  470. vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
  471. d2 = 0.0D;
  472. }
  473. }
  474. else if (movingobjectposition != null)
  475. {
  476. double d3 = vec3.distanceTo(movingobjectposition.hitVec);
  477.  
  478. if (d3 < d2 || d2 == 0.0D)
  479. {
  480. if (entity1 == entity.ridingEntity)
  481. {
  482. if (d2 == 0.0D)
  483. {
  484. this.pointedEntity = entity1;
  485. vec33 = movingobjectposition.hitVec;
  486. }
  487. }
  488. else
  489. {
  490. this.pointedEntity = entity1;
  491. vec33 = movingobjectposition.hitVec;
  492. d2 = d3;
  493. }
  494. }
  495. }
  496. }
  497.  
  498. if (this.pointedEntity != null && flag && vec3.distanceTo(vec33) > 3.0D)
  499. {
  500. this.pointedEntity = null;
  501. this.mc.objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, (EnumFacing)null, new BlockPos(vec33));
  502. }
  503.  
  504. if (this.pointedEntity != null && (d2 < d1 || this.mc.objectMouseOver == null))
  505. {
  506. this.mc.objectMouseOver = new MovingObjectPosition(this.pointedEntity, vec33);
  507.  
  508. if (this.pointedEntity instanceof EntityLivingBase || this.pointedEntity instanceof EntityItemFrame)
  509. {
  510. this.mc.pointedEntity = this.pointedEntity;
  511. }
  512. }
  513.  
  514. this.mc.mcProfiler.endSection();
  515. }
  516. }
  517. }
  518.  
  519. /**
  520. * Update FOV modifier hand
  521. */
  522. private void updateFovModifierHand()
  523. {
  524. float f = 1.0F;
  525.  
  526. if (this.mc.getRenderViewEntity() instanceof AbstractClientPlayer)
  527. {
  528. AbstractClientPlayer abstractclientplayer = (AbstractClientPlayer)this.mc.getRenderViewEntity();
  529. f = abstractclientplayer.getFovModifier();
  530. }
  531.  
  532. this.fovModifierHandPrev = this.fovModifierHand;
  533. this.fovModifierHand += (f - this.fovModifierHand) * 0.5F;
  534.  
  535. if (this.fovModifierHand > 1.5F)
  536. {
  537. this.fovModifierHand = 1.5F;
  538. }
  539.  
  540. if (this.fovModifierHand < 0.1F)
  541. {
  542. this.fovModifierHand = 0.1F;
  543. }
  544. }
  545.  
  546. /**
  547. * Changes the field of view of the player depending on if they are underwater or not
  548. */
  549. private float getFOVModifier(float partialTicks, boolean p_78481_2_)
  550. {
  551. if (this.debugView)
  552. {
  553. return 90.0F;
  554. }
  555. else
  556. {
  557. Entity entity = this.mc.getRenderViewEntity();
  558. float f = 70.0F;
  559.  
  560. if (p_78481_2_)
  561. {
  562. f = this.mc.gameSettings.fovSetting;
  563. f = f * (this.fovModifierHandPrev + (this.fovModifierHand - this.fovModifierHandPrev) * partialTicks);
  564. }
  565.  
  566. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getHealth() <= 0.0F)
  567. {
  568. float f1 = (float)((EntityLivingBase)entity).deathTime + partialTicks;
  569. f /= (1.0F - 500.0F / (f1 + 500.0F)) * 2.0F + 1.0F;
  570. }
  571.  
  572. Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.mc.theWorld, entity, partialTicks);
  573.  
  574. if (block.getMaterial() == Material.water)
  575. {
  576. f = f * 60.0F / 70.0F;
  577. }
  578.  
  579. return f;
  580. }
  581. }
  582.  
  583. private void hurtCameraEffect(float partialTicks)
  584. {
  585. if (this.mc.getRenderViewEntity() instanceof EntityLivingBase)
  586. {
  587. EntityLivingBase entitylivingbase = (EntityLivingBase)this.mc.getRenderViewEntity();
  588. float f = (float)entitylivingbase.hurtTime - partialTicks;
  589.  
  590. if (entitylivingbase.getHealth() <= 0.0F)
  591. {
  592. float f1 = (float)entitylivingbase.deathTime + partialTicks;
  593. GlStateManager.rotate(40.0F - 8000.0F / (f1 + 200.0F), 0.0F, 0.0F, 1.0F);
  594. }
  595.  
  596. if (f < 0.0F)
  597. {
  598. return;
  599. }
  600.  
  601. f = f / (float)entitylivingbase.maxHurtTime;
  602. f = MathHelper.sin(f * f * f * f * (float)Math.PI);
  603. float f2 = entitylivingbase.attackedAtYaw;
  604. GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
  605. GlStateManager.rotate(-f * 14.0F, 0.0F, 0.0F, 1.0F);
  606. GlStateManager.rotate(f2, 0.0F, 1.0F, 0.0F);
  607. }
  608. }
  609.  
  610. /**
  611. * Setups all the GL settings for view bobbing. Args: partialTickTime
  612. */
  613. private void setupViewBobbing(float partialTicks)
  614. {
  615. if (this.mc.getRenderViewEntity() instanceof EntityPlayer)
  616. {
  617. EntityPlayer entityplayer = (EntityPlayer)this.mc.getRenderViewEntity();
  618. float f = entityplayer.distanceWalkedModified - entityplayer.prevDistanceWalkedModified;
  619. float f1 = -(entityplayer.distanceWalkedModified + f * partialTicks);
  620. float f2 = entityplayer.prevCameraYaw + (entityplayer.cameraYaw - entityplayer.prevCameraYaw) * partialTicks;
  621. float f3 = entityplayer.prevCameraPitch + (entityplayer.cameraPitch - entityplayer.prevCameraPitch) * partialTicks;
  622. GlStateManager.translate(MathHelper.sin(f1 * (float)Math.PI) * f2 * 0.5F, -Math.abs(MathHelper.cos(f1 * (float)Math.PI) * f2), 0.0F);
  623. GlStateManager.rotate(MathHelper.sin(f1 * (float)Math.PI) * f2 * 3.0F, 0.0F, 0.0F, 1.0F);
  624. GlStateManager.rotate(Math.abs(MathHelper.cos(f1 * (float)Math.PI - 0.2F) * f2) * 5.0F, 1.0F, 0.0F, 0.0F);
  625. GlStateManager.rotate(f3, 1.0F, 0.0F, 0.0F);
  626. }
  627. }
  628.  
  629. /**
  630. * sets up player's eye (or camera in third person mode)
  631. */
  632. private void orientCamera(float partialTicks)
  633. {
  634. Entity entity = this.mc.getRenderViewEntity();
  635. float f = entity.getEyeHeight();
  636. double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)partialTicks;
  637. double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)partialTicks + (double)f;
  638. double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)partialTicks;
  639.  
  640. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPlayerSleeping())
  641. {
  642. f = (float)((double)f + 1.0D);
  643. GlStateManager.translate(0.0F, 0.3F, 0.0F);
  644.  
  645. if (!this.mc.gameSettings.debugCamEnable)
  646. {
  647. BlockPos blockpos = new BlockPos(entity);
  648. IBlockState iblockstate = this.mc.theWorld.getBlockState(blockpos);
  649. Block block = iblockstate.getBlock();
  650.  
  651. if (block == Blocks.bed)
  652. {
  653. int j = ((EnumFacing)iblockstate.getValue(BlockBed.FACING)).getHorizontalIndex();
  654. GlStateManager.rotate((float)(j * 90), 0.0F, 1.0F, 0.0F);
  655. }
  656.  
  657. GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
  658. GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
  659. }
  660. }
  661. else if (this.mc.gameSettings.thirdPersonView > 0)
  662. {
  663. double d3 = (double)(this.thirdPersonDistanceTemp + (this.thirdPersonDistance - this.thirdPersonDistanceTemp) * partialTicks);
  664.  
  665. if (this.mc.gameSettings.debugCamEnable)
  666. {
  667. GlStateManager.translate(0.0F, 0.0F, (float)(-d3));
  668. }
  669. else
  670. {
  671. float f1 = entity.rotationYaw;
  672. float f2 = entity.rotationPitch;
  673.  
  674. if (this.mc.gameSettings.thirdPersonView == 2)
  675. {
  676. f2 += 180.0F;
  677. }
  678.  
  679. double d4 = (double)(-MathHelper.sin(f1 / 180.0F * (float)Math.PI) * MathHelper.cos(f2 / 180.0F * (float)Math.PI)) * d3;
  680. double d5 = (double)(MathHelper.cos(f1 / 180.0F * (float)Math.PI) * MathHelper.cos(f2 / 180.0F * (float)Math.PI)) * d3;
  681. double d6 = (double)(-MathHelper.sin(f2 / 180.0F * (float)Math.PI)) * d3;
  682.  
  683. for (int i = 0; i < 8; ++i)
  684. {
  685. float f3 = (float)((i & 1) * 2 - 1);
  686. float f4 = (float)((i >> 1 & 1) * 2 - 1);
  687. float f5 = (float)((i >> 2 & 1) * 2 - 1);
  688. f3 = f3 * 0.1F;
  689. f4 = f4 * 0.1F;
  690. f5 = f5 * 0.1F;
  691. MovingObjectPosition movingobjectposition = this.mc.theWorld.rayTraceBlocks(new Vec3(d0 + (double)f3, d1 + (double)f4, d2 + (double)f5), new Vec3(d0 - d4 + (double)f3 + (double)f5, d1 - d6 + (double)f4, d2 - d5 + (double)f5));
  692.  
  693. if (movingobjectposition != null)
  694. {
  695. double d7 = movingobjectposition.hitVec.distanceTo(new Vec3(d0, d1, d2));
  696.  
  697. if (d7 < d3)
  698. {
  699. d3 = d7;
  700. }
  701. }
  702. }
  703.  
  704. if (this.mc.gameSettings.thirdPersonView == 2)
  705. {
  706. GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
  707. }
  708.  
  709. GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
  710. GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
  711. GlStateManager.translate(0.0F, 0.0F, (float)(-d3));
  712. GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
  713. GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
  714. }
  715. }
  716. else
  717. {
  718. GlStateManager.translate(0.0F, 0.0F, -0.1F);
  719. }
  720.  
  721. if (!this.mc.gameSettings.debugCamEnable)
  722. {
  723. GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 1.0F, 0.0F, 0.0F);
  724.  
  725. if (entity instanceof EntityAnimal)
  726. {
  727. EntityAnimal entityanimal = (EntityAnimal)entity;
  728. GlStateManager.rotate(entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F);
  729. }
  730. else
  731. {
  732. GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F);
  733. }
  734. }
  735.  
  736. GlStateManager.translate(0.0F, -f, 0.0F);
  737. d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)partialTicks;
  738. d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)partialTicks + (double)f;
  739. d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)partialTicks;
  740. this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
  741. }
  742.  
  743. /**
  744. * sets up projection, view effects, camera position/rotation
  745. */
  746. private void setupCameraTransform(float partialTicks, int pass)
  747. {
  748. this.farPlaneDistance = (float)(this.mc.gameSettings.renderDistanceChunks * 16);
  749. GlStateManager.matrixMode(5889);
  750. GlStateManager.loadIdentity();
  751. float f = 0.07F;
  752.  
  753. if (this.mc.gameSettings.anaglyph)
  754. {
  755. GlStateManager.translate((float)(-(pass * 2 - 1)) * f, 0.0F, 0.0F);
  756. }
  757.  
  758. if (this.cameraZoom != 1.0D)
  759. {
  760. GlStateManager.translate((float)this.cameraYaw, (float)(-this.cameraPitch), 0.0F);
  761. GlStateManager.scale(this.cameraZoom, this.cameraZoom, 1.0D);
  762. }
  763.  
  764. Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * MathHelper.SQRT_2);
  765. GlStateManager.matrixMode(5888);
  766. GlStateManager.loadIdentity();
  767.  
  768. if (this.mc.gameSettings.anaglyph)
  769. {
  770. GlStateManager.translate((float)(pass * 2 - 1) * 0.1F, 0.0F, 0.0F);
  771. }
  772.  
  773. this.hurtCameraEffect(partialTicks);
  774.  
  775. if (this.mc.gameSettings.viewBobbing)
  776. {
  777. this.setupViewBobbing(partialTicks);
  778. }
  779.  
  780. float f1 = this.mc.thePlayer.prevTimeInPortal + (this.mc.thePlayer.timeInPortal - this.mc.thePlayer.prevTimeInPortal) * partialTicks;
  781.  
  782. if (f1 > 0.0F)
  783. {
  784. int i = 20;
  785.  
  786. if (this.mc.thePlayer.isPotionActive(Potion.confusion))
  787. {
  788. i = 7;
  789. }
  790.  
  791. float f2 = 5.0F / (f1 * f1 + 5.0F) - f1 * 0.04F;
  792. f2 = f2 * f2;
  793. GlStateManager.rotate(((float)this.rendererUpdateCount + partialTicks) * (float)i, 0.0F, 1.0F, 1.0F);
  794. GlStateManager.scale(1.0F / f2, 1.0F, 1.0F);
  795. GlStateManager.rotate(-((float)this.rendererUpdateCount + partialTicks) * (float)i, 0.0F, 1.0F, 1.0F);
  796. }
  797.  
  798. this.orientCamera(partialTicks);
  799.  
  800. if (this.debugView)
  801. {
  802. switch (this.debugViewDirection)
  803. {
  804. case 0:
  805. GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
  806. break;
  807.  
  808. case 1:
  809. GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
  810. break;
  811.  
  812. case 2:
  813. GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
  814. break;
  815.  
  816. case 3:
  817. GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
  818. break;
  819.  
  820. case 4:
  821. GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
  822. }
  823. }
  824. }
  825.  
  826. /**
  827. * Render player hand
  828. */
  829. private void renderHand(float partialTicks, int xOffset)
  830. {
  831. if (!this.debugView)
  832. {
  833. GlStateManager.matrixMode(5889);
  834. GlStateManager.loadIdentity();
  835. float f = 0.07F;
  836.  
  837. if (this.mc.gameSettings.anaglyph)
  838. {
  839. GlStateManager.translate((float)(-(xOffset * 2 - 1)) * f, 0.0F, 0.0F);
  840. }
  841.  
  842. Project.gluPerspective(this.getFOVModifier(partialTicks, false), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 2.0F);
  843. GlStateManager.matrixMode(5888);
  844. GlStateManager.loadIdentity();
  845.  
  846. if (this.mc.gameSettings.anaglyph)
  847. {
  848. GlStateManager.translate((float)(xOffset * 2 - 1) * 0.1F, 0.0F, 0.0F);
  849. }
  850.  
  851. GlStateManager.pushMatrix();
  852. this.hurtCameraEffect(partialTicks);
  853.  
  854. if (this.mc.gameSettings.viewBobbing)
  855. {
  856. this.setupViewBobbing(partialTicks);
  857. }
  858.  
  859. boolean flag = this.mc.getRenderViewEntity() instanceof EntityLivingBase && ((EntityLivingBase)this.mc.getRenderViewEntity()).isPlayerSleeping();
  860.  
  861. if (this.mc.gameSettings.thirdPersonView == 0 && !flag && !this.mc.gameSettings.hideGUI && !this.mc.playerController.isSpectator())
  862. {
  863. this.enableLightmap();
  864. this.itemRenderer.renderItemInFirstPerson(partialTicks);
  865. this.disableLightmap();
  866. }
  867.  
  868. GlStateManager.popMatrix();
  869.  
  870. if (this.mc.gameSettings.thirdPersonView == 0 && !flag)
  871. {
  872. this.itemRenderer.renderOverlays(partialTicks);
  873. this.hurtCameraEffect(partialTicks);
  874. }
  875.  
  876. if (this.mc.gameSettings.viewBobbing)
  877. {
  878. this.setupViewBobbing(partialTicks);
  879. }
  880. }
  881. }
  882.  
  883. public void disableLightmap()
  884. {
  885. GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
  886. GlStateManager.disableTexture2D();
  887. GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
  888. }
  889.  
  890. public void enableLightmap()
  891. {
  892. GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
  893. GlStateManager.matrixMode(5890);
  894. GlStateManager.loadIdentity();
  895. float f = 0.00390625F;
  896. GlStateManager.scale(f, f, f);
  897. GlStateManager.translate(8.0F, 8.0F, 8.0F);
  898. GlStateManager.matrixMode(5888);
  899. this.mc.getTextureManager().bindTexture(this.locationLightMap);
  900. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
  901. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
  902. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
  903. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
  904. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  905. GlStateManager.enableTexture2D();
  906. GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
  907. }
  908.  
  909. /**
  910. * Recompute a random value that is applied to block color in updateLightmap()
  911. */
  912. private void updateTorchFlicker()
  913. {
  914. this.torchFlickerDX = (float)((double)this.torchFlickerDX + (Math.random() - Math.random()) * Math.random() * Math.random());
  915. this.torchFlickerDX = (float)((double)this.torchFlickerDX * 0.9D);
  916. this.torchFlickerX += (this.torchFlickerDX - this.torchFlickerX) * 1.0F;
  917. this.lightmapUpdateNeeded = true;
  918. }
  919.  
  920. private void updateLightmap(float partialTicks)
  921. {
  922. if (this.lightmapUpdateNeeded)
  923. {
  924. this.mc.mcProfiler.startSection("lightTex");
  925. World world = this.mc.theWorld;
  926.  
  927. if (world != null)
  928. {
  929. float f = world.getSunBrightness(1.0F);
  930. float f1 = f * 0.95F + 0.05F;
  931.  
  932. for (int i = 0; i < 256; ++i)
  933. {
  934. float f2 = world.provider.getLightBrightnessTable()[i / 16] * f1;
  935. float f3 = world.provider.getLightBrightnessTable()[i % 16] * (this.torchFlickerX * 0.1F + 1.5F);
  936.  
  937. if (world.getLastLightningBolt() > 0)
  938. {
  939. f2 = world.provider.getLightBrightnessTable()[i / 16];
  940. }
  941.  
  942. float f4 = f2 * (f * 0.65F + 0.35F);
  943. float f5 = f2 * (f * 0.65F + 0.35F);
  944. float f6 = f3 * ((f3 * 0.6F + 0.4F) * 0.6F + 0.4F);
  945. float f7 = f3 * (f3 * f3 * 0.6F + 0.4F);
  946. float f8 = f4 + f3;
  947. float f9 = f5 + f6;
  948. float f10 = f2 + f7;
  949. f8 = f8 * 0.96F + 0.03F;
  950. f9 = f9 * 0.96F + 0.03F;
  951. f10 = f10 * 0.96F + 0.03F;
  952.  
  953. if (this.bossColorModifier > 0.0F)
  954. {
  955. float f11 = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * partialTicks;
  956. f8 = f8 * (1.0F - f11) + f8 * 0.7F * f11;
  957. f9 = f9 * (1.0F - f11) + f9 * 0.6F * f11;
  958. f10 = f10 * (1.0F - f11) + f10 * 0.6F * f11;
  959. }
  960.  
  961. if (world.provider.getDimensionId() == 1)
  962. {
  963. f8 = 0.22F + f3 * 0.75F;
  964. f9 = 0.28F + f6 * 0.75F;
  965. f10 = 0.25F + f7 * 0.75F;
  966. }
  967.  
  968. if (this.mc.thePlayer.isPotionActive(Potion.nightVision))
  969. {
  970. float f15 = this.getNightVisionBrightness(this.mc.thePlayer, partialTicks);
  971. float f12 = 1.0F / f8;
  972.  
  973. if (f12 > 1.0F / f9)
  974. {
  975. f12 = 1.0F / f9;
  976. }
  977.  
  978. if (f12 > 1.0F / f10)
  979. {
  980. f12 = 1.0F / f10;
  981. }
  982.  
  983. f8 = f8 * (1.0F - f15) + f8 * f12 * f15;
  984. f9 = f9 * (1.0F - f15) + f9 * f12 * f15;
  985. f10 = f10 * (1.0F - f15) + f10 * f12 * f15;
  986. }
  987.  
  988. if (f8 > 1.0F)
  989. {
  990. f8 = 1.0F;
  991. }
  992.  
  993. if (f9 > 1.0F)
  994. {
  995. f9 = 1.0F;
  996. }
  997.  
  998. if (f10 > 1.0F)
  999. {
  1000. f10 = 1.0F;
  1001. }
  1002.  
  1003. float f16 = this.mc.gameSettings.gammaSetting;
  1004. float f17 = 1.0F - f8;
  1005. float f13 = 1.0F - f9;
  1006. float f14 = 1.0F - f10;
  1007. f17 = 1.0F - f17 * f17 * f17 * f17;
  1008. f13 = 1.0F - f13 * f13 * f13 * f13;
  1009. f14 = 1.0F - f14 * f14 * f14 * f14;
  1010. f8 = f8 * (1.0F - f16) + f17 * f16;
  1011. f9 = f9 * (1.0F - f16) + f13 * f16;
  1012. f10 = f10 * (1.0F - f16) + f14 * f16;
  1013. f8 = f8 * 0.96F + 0.03F;
  1014. f9 = f9 * 0.96F + 0.03F;
  1015. f10 = f10 * 0.96F + 0.03F;
  1016.  
  1017. if (f8 > 1.0F)
  1018. {
  1019. f8 = 1.0F;
  1020. }
  1021.  
  1022. if (f9 > 1.0F)
  1023. {
  1024. f9 = 1.0F;
  1025. }
  1026.  
  1027. if (f10 > 1.0F)
  1028. {
  1029. f10 = 1.0F;
  1030. }
  1031.  
  1032. if (f8 < 0.0F)
  1033. {
  1034. f8 = 0.0F;
  1035. }
  1036.  
  1037. if (f9 < 0.0F)
  1038. {
  1039. f9 = 0.0F;
  1040. }
  1041.  
  1042. if (f10 < 0.0F)
  1043. {
  1044. f10 = 0.0F;
  1045. }
  1046.  
  1047. int j = 255;
  1048. int k = (int)(f8 * 255.0F);
  1049. int l = (int)(f9 * 255.0F);
  1050. int i1 = (int)(f10 * 255.0F);
  1051. this.lightmapColors[i] = j << 24 | k << 16 | l << 8 | i1;
  1052. }
  1053.  
  1054. this.lightmapTexture.updateDynamicTexture();
  1055. this.lightmapUpdateNeeded = false;
  1056. this.mc.mcProfiler.endSection();
  1057. }
  1058. }
  1059. }
  1060.  
  1061. private float getNightVisionBrightness(EntityLivingBase entitylivingbaseIn, float partialTicks)
  1062. {
  1063. int i = entitylivingbaseIn.getActivePotionEffect(Potion.nightVision).getDuration();
  1064. return i > 200 ? 1.0F : 0.7F + MathHelper.sin(((float)i - partialTicks) * (float)Math.PI * 0.2F) * 0.3F;
  1065. }
  1066.  
  1067. public void func_181560_a(float p_181560_1_, long p_181560_2_)
  1068. {
  1069. boolean flag = Display.isActive();
  1070.  
  1071. if (!flag && this.mc.gameSettings.pauseOnLostFocus && (!this.mc.gameSettings.touchscreen || !Mouse.isButtonDown(1)))
  1072. {
  1073. if (Minecraft.getSystemTime() - this.prevFrameTime > 500L)
  1074. {
  1075. this.mc.displayInGameMenu();
  1076. }
  1077. }
  1078. else
  1079. {
  1080. this.prevFrameTime = Minecraft.getSystemTime();
  1081. }
  1082.  
  1083. this.mc.mcProfiler.startSection("mouse");
  1084.  
  1085. if (flag && Minecraft.isRunningOnMac && this.mc.inGameHasFocus && !Mouse.isInsideWindow())
  1086. {
  1087. Mouse.setGrabbed(false);
  1088. Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
  1089. Mouse.setGrabbed(true);
  1090. }
  1091.  
  1092. if (this.mc.inGameHasFocus && flag)
  1093. {
  1094. this.mc.mouseHelper.mouseXYChange();
  1095. float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
  1096. float f1 = f * f * f * 8.0F;
  1097. float f2 = (float)this.mc.mouseHelper.deltaX * f1;
  1098. float f3 = (float)this.mc.mouseHelper.deltaY * f1;
  1099. int i = 1;
  1100.  
  1101. if (this.mc.gameSettings.invertMouse)
  1102. {
  1103. i = -1;
  1104. }
  1105.  
  1106. if (this.mc.gameSettings.smoothCamera)
  1107. {
  1108. this.smoothCamYaw += f2;
  1109. this.smoothCamPitch += f3;
  1110. float f4 = p_181560_1_ - this.smoothCamPartialTicks;
  1111. this.smoothCamPartialTicks = p_181560_1_;
  1112. f2 = this.smoothCamFilterX * f4;
  1113. f3 = this.smoothCamFilterY * f4;
  1114. this.mc.thePlayer.setAngles(f2, f3 * (float)i);
  1115. }
  1116. else
  1117. {
  1118. this.smoothCamYaw = 0.0F;
  1119. this.smoothCamPitch = 0.0F;
  1120. this.mc.thePlayer.setAngles(f2, f3 * (float)i);
  1121. }
  1122. }
  1123.  
  1124. this.mc.mcProfiler.endSection();
  1125.  
  1126. if (!this.mc.skipRenderWorld)
  1127. {
  1128. anaglyphEnable = this.mc.gameSettings.anaglyph;
  1129. final ScaledResolution scaledresolution = new ScaledResolution(this.mc);
  1130. int i1 = scaledresolution.getScaledWidth();
  1131. int j1 = scaledresolution.getScaledHeight();
  1132. final int k1 = Mouse.getX() * i1 / this.mc.displayWidth;
  1133. final int l1 = j1 - Mouse.getY() * j1 / this.mc.displayHeight - 1;
  1134. int i2 = this.mc.gameSettings.limitFramerate;
  1135.  
  1136. if (this.mc.theWorld != null)
  1137. {
  1138. this.mc.mcProfiler.startSection("level");
  1139. int j = Math.min(Minecraft.getDebugFPS(), i2);
  1140. j = Math.max(j, 60);
  1141. long k = System.nanoTime() - p_181560_2_;
  1142. long l = Math.max((long)(1000000000 / j / 4) - k, 0L);
  1143. this.renderWorld(p_181560_1_, System.nanoTime() + l);
  1144.  
  1145. if (OpenGlHelper.shadersSupported)
  1146. {
  1147. this.mc.renderGlobal.renderEntityOutlineFramebuffer();
  1148.  
  1149. if (this.theShaderGroup != null && this.useShader)
  1150. {
  1151. GlStateManager.matrixMode(5890);
  1152. GlStateManager.pushMatrix();
  1153. GlStateManager.loadIdentity();
  1154. this.theShaderGroup.loadShaderGroup(p_181560_1_);
  1155. GlStateManager.popMatrix();
  1156. }
  1157.  
  1158. this.mc.getFramebuffer().bindFramebuffer(true);
  1159. }
  1160.  
  1161. this.renderEndNanoTime = System.nanoTime();
  1162. this.mc.mcProfiler.endStartSection("gui");
  1163.  
  1164. if (!this.mc.gameSettings.hideGUI || this.mc.currentScreen != null)
  1165. {
  1166. GlStateManager.alphaFunc(516, 0.1F);
  1167. this.mc.ingameGUI.renderGameOverlay(p_181560_1_);
  1168. }
  1169.  
  1170. this.mc.mcProfiler.endSection();
  1171. }
  1172. else
  1173. {
  1174. GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
  1175. GlStateManager.matrixMode(5889);
  1176. GlStateManager.loadIdentity();
  1177. GlStateManager.matrixMode(5888);
  1178. GlStateManager.loadIdentity();
  1179. this.setupOverlayRendering();
  1180. this.renderEndNanoTime = System.nanoTime();
  1181. }
  1182.  
  1183. if (this.mc.currentScreen != null)
  1184. {
  1185. GlStateManager.clear(256);
  1186.  
  1187. try
  1188. {
  1189. this.mc.currentScreen.drawScreen(k1, l1, p_181560_1_);
  1190. }
  1191. catch (Throwable throwable)
  1192. {
  1193. CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Rendering screen");
  1194. CrashReportCategory crashreportcategory = crashreport.makeCategory("Screen render details");
  1195. crashreportcategory.addCrashSectionCallable("Screen name", new Callable<String>()
  1196. {
  1197. public String call() throws Exception
  1198. {
  1199. return EntityRenderer.this.mc.currentScreen.getClass().getCanonicalName();
  1200. }
  1201. });
  1202. crashreportcategory.addCrashSectionCallable("Mouse location", new Callable<String>()
  1203. {
  1204. public String call() throws Exception
  1205. {
  1206. return String.format("Scaled: (%d, %d). Absolute: (%d, %d)", new Object[] {Integer.valueOf(k1), Integer.valueOf(l1), Integer.valueOf(Mouse.getX()), Integer.valueOf(Mouse.getY())});
  1207. }
  1208. });
  1209. crashreportcategory.addCrashSectionCallable("Screen size", new Callable<String>()
  1210. {
  1211. public String call() throws Exception
  1212. {
  1213. return String.format("Scaled: (%d, %d). Absolute: (%d, %d). Scale factor of %d", new Object[] {Integer.valueOf(scaledresolution.getScaledWidth()), Integer.valueOf(scaledresolution.getScaledHeight()), Integer.valueOf(EntityRenderer.this.mc.displayWidth), Integer.valueOf(EntityRenderer.this.mc.displayHeight), Integer.valueOf(scaledresolution.getScaleFactor())});
  1214. }
  1215. });
  1216. throw new ReportedException(crashreport);
  1217. }
  1218. }
  1219. }
  1220. }
  1221.  
  1222. public void renderStreamIndicator(float partialTicks)
  1223. {
  1224. this.setupOverlayRendering();
  1225. this.mc.ingameGUI.renderStreamIndicator(new ScaledResolution(this.mc));
  1226. }
  1227.  
  1228. private boolean isDrawBlockOutline()
  1229. {
  1230. if (!this.drawBlockOutline)
  1231. {
  1232. return false;
  1233. }
  1234. else
  1235. {
  1236. Entity entity = this.mc.getRenderViewEntity();
  1237. boolean flag = entity instanceof EntityPlayer && !this.mc.gameSettings.hideGUI;
  1238.  
  1239. if (flag && !((EntityPlayer)entity).capabilities.allowEdit)
  1240. {
  1241. ItemStack itemstack = ((EntityPlayer)entity).getCurrentEquippedItem();
  1242.  
  1243. if (this.mc.objectMouseOver != null && this.mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
  1244. {
  1245. BlockPos blockpos = this.mc.objectMouseOver.getBlockPos();
  1246. Block block = this.mc.theWorld.getBlockState(blockpos).getBlock();
  1247.  
  1248. if (this.mc.playerController.getCurrentGameType() == WorldSettings.GameType.SPECTATOR)
  1249. {
  1250. flag = block.hasTileEntity() && this.mc.theWorld.getTileEntity(blockpos) instanceof IInventory;
  1251. }
  1252. else
  1253. {
  1254. flag = itemstack != null && (itemstack.canDestroy(block) || itemstack.canPlaceOn(block));
  1255. }
  1256. }
  1257. }
  1258.  
  1259. return flag;
  1260. }
  1261. }
  1262.  
  1263. private void renderWorldDirections(float partialTicks)
  1264. {
  1265. if (this.mc.gameSettings.showDebugInfo && !this.mc.gameSettings.hideGUI && !this.mc.thePlayer.hasReducedDebug() && !this.mc.gameSettings.reducedDebugInfo)
  1266. {
  1267. Entity entity = this.mc.getRenderViewEntity();
  1268. GlStateManager.enableBlend();
  1269. GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  1270. GL11.glLineWidth(1.0F);
  1271. GlStateManager.disableTexture2D();
  1272. GlStateManager.depthMask(false);
  1273. GlStateManager.pushMatrix();
  1274. GlStateManager.matrixMode(5888);
  1275. GlStateManager.loadIdentity();
  1276. this.orientCamera(partialTicks);
  1277. GlStateManager.translate(0.0F, entity.getEyeHeight(), 0.0F);
  1278. RenderGlobal.func_181563_a(new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.005D, 1.0E-4D, 1.0E-4D), 255, 0, 0, 255);
  1279. RenderGlobal.func_181563_a(new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0E-4D, 1.0E-4D, 0.005D), 0, 0, 255, 255);
  1280. RenderGlobal.func_181563_a(new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0E-4D, 0.0033D, 1.0E-4D), 0, 255, 0, 255);
  1281. GlStateManager.popMatrix();
  1282. GlStateManager.depthMask(true);
  1283. GlStateManager.enableTexture2D();
  1284. GlStateManager.disableBlend();
  1285. }
  1286. }
  1287.  
  1288. public void renderWorld(float partialTicks, long finishTimeNano)
  1289. {
  1290. this.updateLightmap(partialTicks);
  1291.  
  1292. if (this.mc.getRenderViewEntity() == null)
  1293. {
  1294. this.mc.setRenderViewEntity(this.mc.thePlayer);
  1295. }
  1296.  
  1297. this.getMouseOver(partialTicks);
  1298. GlStateManager.enableDepth();
  1299. GlStateManager.enableAlpha();
  1300. GlStateManager.alphaFunc(516, 0.5F);
  1301. this.mc.mcProfiler.startSection("center");
  1302.  
  1303. if (this.mc.gameSettings.anaglyph)
  1304. {
  1305. anaglyphField = 0;
  1306. GlStateManager.colorMask(false, true, true, false);
  1307. this.renderWorldPass(0, partialTicks, finishTimeNano);
  1308. anaglyphField = 1;
  1309. GlStateManager.colorMask(true, false, false, false);
  1310. this.renderWorldPass(1, partialTicks, finishTimeNano);
  1311. GlStateManager.colorMask(true, true, true, false);
  1312. }
  1313. else
  1314. {
  1315. this.renderWorldPass(2, partialTicks, finishTimeNano);
  1316. }
  1317.  
  1318. this.mc.mcProfiler.endSection();
  1319. }
  1320.  
  1321. private void renderWorldPass(int pass, float partialTicks, long finishTimeNano)
  1322. {
  1323. RenderGlobal renderglobal = this.mc.renderGlobal;
  1324. EffectRenderer effectrenderer = this.mc.effectRenderer;
  1325. boolean flag = this.isDrawBlockOutline();
  1326. GlStateManager.enableCull();
  1327. this.mc.mcProfiler.endStartSection("clear");
  1328. GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
  1329. this.updateFogColor(partialTicks);
  1330. GlStateManager.clear(16640);
  1331. this.mc.mcProfiler.endStartSection("camera");
  1332. this.setupCameraTransform(partialTicks, pass);
  1333. ActiveRenderInfo.updateRenderInfo(this.mc.thePlayer, this.mc.gameSettings.thirdPersonView == 2);
  1334. this.mc.mcProfiler.endStartSection("frustum");
  1335. ClippingHelperImpl.getInstance();
  1336. this.mc.mcProfiler.endStartSection("culling");
  1337. ICamera icamera = new Frustum();
  1338. Entity entity = this.mc.getRenderViewEntity();
  1339. double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;
  1340. double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks;
  1341. double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;
  1342. icamera.setPosition(d0, d1, d2);
  1343.  
  1344. if (this.mc.gameSettings.renderDistanceChunks >= 4)
  1345. {
  1346. this.setupFog(-1, partialTicks);
  1347. this.mc.mcProfiler.endStartSection("sky");
  1348. GlStateManager.matrixMode(5889);
  1349. GlStateManager.loadIdentity();
  1350. Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 2.0F);
  1351. GlStateManager.matrixMode(5888);
  1352. renderglobal.renderSky(partialTicks, pass);
  1353. GlStateManager.matrixMode(5889);
  1354. GlStateManager.loadIdentity();
  1355. Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * MathHelper.SQRT_2);
  1356. GlStateManager.matrixMode(5888);
  1357. }
  1358.  
  1359. this.setupFog(0, partialTicks);
  1360. GlStateManager.shadeModel(7425);
  1361.  
  1362. if (entity.posY + (double)entity.getEyeHeight() < 128.0D)
  1363. {
  1364. this.renderCloudsCheck(renderglobal, partialTicks, pass);
  1365. }
  1366.  
  1367. this.mc.mcProfiler.endStartSection("prepareterrain");
  1368. this.setupFog(0, partialTicks);
  1369. this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
  1370. RenderHelper.disableStandardItemLighting();
  1371. this.mc.mcProfiler.endStartSection("terrain_setup");
  1372. renderglobal.setupTerrain(entity, (double)partialTicks, icamera, this.frameCount++, this.mc.thePlayer.isSpectator());
  1373.  
  1374. if (pass == 0 || pass == 2)
  1375. {
  1376. this.mc.mcProfiler.endStartSection("updatechunks");
  1377. this.mc.renderGlobal.updateChunks(finishTimeNano);
  1378. }
  1379.  
  1380. this.mc.mcProfiler.endStartSection("terrain");
  1381. GlStateManager.matrixMode(5888);
  1382. GlStateManager.pushMatrix();
  1383. GlStateManager.disableAlpha();
  1384. renderglobal.renderBlockLayer(EnumWorldBlockLayer.SOLID, (double)partialTicks, pass, entity);
  1385. GlStateManager.enableAlpha();
  1386. renderglobal.renderBlockLayer(EnumWorldBlockLayer.CUTOUT_MIPPED, (double)partialTicks, pass, entity);
  1387. this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false);
  1388. renderglobal.renderBlockLayer(EnumWorldBlockLayer.CUTOUT, (double)partialTicks, pass, entity);
  1389. this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap();
  1390. GlStateManager.shadeModel(7424);
  1391. GlStateManager.alphaFunc(516, 0.1F);
  1392.  
  1393. if (!this.debugView)
  1394. {
  1395. GlStateManager.matrixMode(5888);
  1396. GlStateManager.popMatrix();
  1397. GlStateManager.pushMatrix();
  1398. RenderHelper.enableStandardItemLighting();
  1399. this.mc.mcProfiler.endStartSection("entities");
  1400. renderglobal.renderEntities(entity, icamera, partialTicks);
  1401. RenderHelper.disableStandardItemLighting();
  1402. this.disableLightmap();
  1403. GlStateManager.matrixMode(5888);
  1404. GlStateManager.popMatrix();
  1405. GlStateManager.pushMatrix();
  1406.  
  1407. if (this.mc.objectMouseOver != null && entity.isInsideOfMaterial(Material.water) && flag)
  1408. {
  1409. EntityPlayer entityplayer = (EntityPlayer)entity;
  1410. GlStateManager.disableAlpha();
  1411. this.mc.mcProfiler.endStartSection("outline");
  1412. renderglobal.drawSelectionBox(entityplayer, this.mc.objectMouseOver, 0, partialTicks);
  1413. GlStateManager.enableAlpha();
  1414. }
  1415. }
  1416.  
  1417. GlStateManager.matrixMode(5888);
  1418. GlStateManager.popMatrix();
  1419.  
  1420. if (flag && this.mc.objectMouseOver != null && !entity.isInsideOfMaterial(Material.water))
  1421. {
  1422. EntityPlayer entityplayer1 = (EntityPlayer)entity;
  1423. GlStateManager.disableAlpha();
  1424. this.mc.mcProfiler.endStartSection("outline");
  1425. renderglobal.drawSelectionBox(entityplayer1, this.mc.objectMouseOver, 0, partialTicks);
  1426. GlStateManager.enableAlpha();
  1427. }
  1428.  
  1429. this.mc.mcProfiler.endStartSection("destroyProgress");
  1430. GlStateManager.enableBlend();
  1431. GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0);
  1432. this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false);
  1433. renderglobal.drawBlockDamageTexture(Tessellator.getInstance(), Tessellator.getInstance().getWorldRenderer(), entity, partialTicks);
  1434. this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap();
  1435. GlStateManager.disableBlend();
  1436.  
  1437. if (!this.debugView)
  1438. {
  1439. this.enableLightmap();
  1440. this.mc.mcProfiler.endStartSection("litParticles");
  1441. effectrenderer.renderLitParticles(entity, partialTicks);
  1442. RenderHelper.disableStandardItemLighting();
  1443. this.setupFog(0, partialTicks);
  1444. this.mc.mcProfiler.endStartSection("particles");
  1445. effectrenderer.renderParticles(entity, partialTicks);
  1446. this.disableLightmap();
  1447. }
  1448.  
  1449. GlStateManager.depthMask(false);
  1450. GlStateManager.enableCull();
  1451. this.mc.mcProfiler.endStartSection("weather");
  1452. this.renderRainSnow(partialTicks);
  1453. GlStateManager.depthMask(true);
  1454. renderglobal.renderWorldBorder(entity, partialTicks);
  1455. GlStateManager.disableBlend();
  1456. GlStateManager.enableCull();
  1457. GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  1458. GlStateManager.alphaFunc(516, 0.1F);
  1459. this.setupFog(0, partialTicks);
  1460. GlStateManager.enableBlend();
  1461. GlStateManager.depthMask(false);
  1462. this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
  1463. GlStateManager.shadeModel(7425);
  1464. this.mc.mcProfiler.endStartSection("translucent");
  1465. renderglobal.renderBlockLayer(EnumWorldBlockLayer.TRANSLUCENT, (double)partialTicks, pass, entity);
  1466. GlStateManager.shadeModel(7424);
  1467. GlStateManager.depthMask(true);
  1468. GlStateManager.enableCull();
  1469. GlStateManager.disableBlend();
  1470. GlStateManager.disableFog();
  1471.  
  1472. if (entity.posY + (double)entity.getEyeHeight() >= 128.0D)
  1473. {
  1474. this.mc.mcProfiler.endStartSection("aboveClouds");
  1475. this.renderCloudsCheck(renderglobal, partialTicks, pass);
  1476. }
  1477.  
  1478. this.mc.mcProfiler.endStartSection("hand");
  1479.  
  1480. if (this.renderHand)
  1481. {
  1482. GlStateManager.clear(256);
  1483. this.renderHand(partialTicks, pass);
  1484. this.renderWorldDirections(partialTicks);
  1485. }
  1486. }
  1487.  
  1488. private void renderCloudsCheck(RenderGlobal renderGlobalIn, float partialTicks, int pass)
  1489. {
  1490. if (this.mc.gameSettings.func_181147_e() != 0)
  1491. {
  1492. this.mc.mcProfiler.endStartSection("clouds");
  1493. GlStateManager.matrixMode(5889);
  1494. GlStateManager.loadIdentity();
  1495. Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 4.0F);
  1496. GlStateManager.matrixMode(5888);
  1497. GlStateManager.pushMatrix();
  1498. this.setupFog(0, partialTicks);
  1499. renderGlobalIn.renderClouds(partialTicks, pass);
  1500. GlStateManager.disableFog();
  1501. GlStateManager.popMatrix();
  1502. GlStateManager.matrixMode(5889);
  1503. GlStateManager.loadIdentity();
  1504. Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * MathHelper.SQRT_2);
  1505. GlStateManager.matrixMode(5888);
  1506. }
  1507. }
  1508.  
  1509. private void addRainParticles()
  1510. {
  1511. float f = this.mc.theWorld.getRainStrength(1.0F);
  1512.  
  1513. if (!this.mc.gameSettings.fancyGraphics)
  1514. {
  1515. f /= 2.0F;
  1516. }
  1517.  
  1518. if (f != 0.0F)
  1519. {
  1520. this.random.setSeed((long)this.rendererUpdateCount * 312987231L);
  1521. Entity entity = this.mc.getRenderViewEntity();
  1522. World world = this.mc.theWorld;
  1523. BlockPos blockpos = new BlockPos(entity);
  1524. int i = 10;
  1525. double d0 = 0.0D;
  1526. double d1 = 0.0D;
  1527. double d2 = 0.0D;
  1528. int j = 0;
  1529. int k = (int)(100.0F * f * f);
  1530.  
  1531. if (this.mc.gameSettings.particleSetting == 1)
  1532. {
  1533. k >>= 1;
  1534. }
  1535. else if (this.mc.gameSettings.particleSetting == 2)
  1536. {
  1537. k = 0;
  1538. }
  1539.  
  1540. for (int l = 0; l < k; ++l)
  1541. {
  1542. BlockPos blockpos1 = world.getPrecipitationHeight(blockpos.add(this.random.nextInt(i) - this.random.nextInt(i), 0, this.random.nextInt(i) - this.random.nextInt(i)));
  1543. BiomeGenBase biomegenbase = world.getBiomeGenForCoords(blockpos1);
  1544. BlockPos blockpos2 = blockpos1.down();
  1545. Block block = world.getBlockState(blockpos2).getBlock();
  1546.  
  1547. if (blockpos1.getY() <= blockpos.getY() + i && blockpos1.getY() >= blockpos.getY() - i && biomegenbase.canSpawnLightningBolt() && biomegenbase.getFloatTemperature(blockpos1) >= 0.15F)
  1548. {
  1549. double d3 = this.random.nextDouble();
  1550. double d4 = this.random.nextDouble();
  1551.  
  1552. if (block.getMaterial() == Material.lava)
  1553. {
  1554. this.mc.theWorld.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)blockpos1.getX() + d3, (double)((float)blockpos1.getY() + 0.1F) - block.getBlockBoundsMinY(), (double)blockpos1.getZ() + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  1555. }
  1556. else if (block.getMaterial() != Material.air)
  1557. {
  1558. block.setBlockBoundsBasedOnState(world, blockpos2);
  1559. ++j;
  1560.  
  1561. if (this.random.nextInt(j) == 0)
  1562. {
  1563. d0 = (double)blockpos2.getX() + d3;
  1564. d1 = (double)((float)blockpos2.getY() + 0.1F) + block.getBlockBoundsMaxY() - 1.0D;
  1565. d2 = (double)blockpos2.getZ() + d4;
  1566. }
  1567.  
  1568. this.mc.theWorld.spawnParticle(EnumParticleTypes.WATER_DROP, (double)blockpos2.getX() + d3, (double)((float)blockpos2.getY() + 0.1F) + block.getBlockBoundsMaxY(), (double)blockpos2.getZ() + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  1569. }
  1570. }
  1571. }
  1572.  
  1573. if (j > 0 && this.random.nextInt(3) < this.rainSoundCounter++)
  1574. {
  1575. this.rainSoundCounter = 0;
  1576.  
  1577. if (d1 > (double)(blockpos.getY() + 1) && world.getPrecipitationHeight(blockpos).getY() > MathHelper.floor_float((float)blockpos.getY()))
  1578. {
  1579. this.mc.theWorld.playSound(d0, d1, d2, "ambient.weather.rain", 0.1F, 0.5F, false);
  1580. }
  1581. else
  1582. {
  1583. this.mc.theWorld.playSound(d0, d1, d2, "ambient.weather.rain", 0.2F, 1.0F, false);
  1584. }
  1585. }
  1586. }
  1587. }
  1588.  
  1589. /**
  1590. * Render rain and snow
  1591. */
  1592. protected void renderRainSnow(float partialTicks)
  1593. {
  1594. float f = this.mc.theWorld.getRainStrength(partialTicks);
  1595.  
  1596. if (f > 0.0F)
  1597. {
  1598. this.enableLightmap();
  1599. Entity entity = this.mc.getRenderViewEntity();
  1600. World world = this.mc.theWorld;
  1601. int i = MathHelper.floor_double(entity.posX);
  1602. int j = MathHelper.floor_double(entity.posY);
  1603. int k = MathHelper.floor_double(entity.posZ);
  1604. Tessellator tessellator = Tessellator.getInstance();
  1605. WorldRenderer worldrenderer = tessellator.getWorldRenderer();
  1606. GlStateManager.disableCull();
  1607. GL11.glNormal3f(0.0F, 1.0F, 0.0F);
  1608. GlStateManager.enableBlend();
  1609. GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  1610. GlStateManager.alphaFunc(516, 0.1F);
  1611. double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;
  1612. double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks;
  1613. double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;
  1614. int l = MathHelper.floor_double(d1);
  1615. int i1 = 5;
  1616.  
  1617. if (this.mc.gameSettings.fancyGraphics)
  1618. {
  1619. i1 = 10;
  1620. }
  1621.  
  1622. int j1 = -1;
  1623. float f1 = (float)this.rendererUpdateCount + partialTicks;
  1624. worldrenderer.setTranslation(-d0, -d1, -d2);
  1625. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  1626. BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
  1627.  
  1628. for (int k1 = k - i1; k1 <= k + i1; ++k1)
  1629. {
  1630. for (int l1 = i - i1; l1 <= i + i1; ++l1)
  1631. {
  1632. int i2 = (k1 - k + 16) * 32 + l1 - i + 16;
  1633. double d3 = (double)this.rainXCoords[i2] * 0.5D;
  1634. double d4 = (double)this.rainYCoords[i2] * 0.5D;
  1635. blockpos$mutableblockpos.func_181079_c(l1, 0, k1);
  1636. BiomeGenBase biomegenbase = world.getBiomeGenForCoords(blockpos$mutableblockpos);
  1637.  
  1638. if (biomegenbase.canSpawnLightningBolt() || biomegenbase.getEnableSnow())
  1639. {
  1640. int j2 = world.getPrecipitationHeight(blockpos$mutableblockpos).getY();
  1641. int k2 = j - i1;
  1642. int l2 = j + i1;
  1643.  
  1644. if (k2 < j2)
  1645. {
  1646. k2 = j2;
  1647. }
  1648.  
  1649. if (l2 < j2)
  1650. {
  1651. l2 = j2;
  1652. }
  1653.  
  1654. int i3 = j2;
  1655.  
  1656. if (j2 < l)
  1657. {
  1658. i3 = l;
  1659. }
  1660.  
  1661. if (k2 != l2)
  1662. {
  1663. this.random.setSeed((long)(l1 * l1 * 3121 + l1 * 45238971 ^ k1 * k1 * 418711 + k1 * 13761));
  1664. blockpos$mutableblockpos.func_181079_c(l1, k2, k1);
  1665. float f2 = biomegenbase.getFloatTemperature(blockpos$mutableblockpos);
  1666.  
  1667. if (world.getWorldChunkManager().getTemperatureAtHeight(f2, j2) >= 0.15F)
  1668. {
  1669. if (j1 != 0)
  1670. {
  1671. if (j1 >= 0)
  1672. {
  1673. tessellator.draw();
  1674. }
  1675.  
  1676. j1 = 0;
  1677. this.mc.getTextureManager().bindTexture(locationRainPng);
  1678. worldrenderer.begin(7, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
  1679. }
  1680.  
  1681. double d5 = ((double)(this.rendererUpdateCount + l1 * l1 * 3121 + l1 * 45238971 + k1 * k1 * 418711 + k1 * 13761 & 31) + (double)partialTicks) / 32.0D * (3.0D + this.random.nextDouble());
  1682. double d6 = (double)((float)l1 + 0.5F) - entity.posX;
  1683. double d7 = (double)((float)k1 + 0.5F) - entity.posZ;
  1684. float f3 = MathHelper.sqrt_double(d6 * d6 + d7 * d7) / (float)i1;
  1685. float f4 = ((1.0F - f3 * f3) * 0.5F + 0.5F) * f;
  1686. blockpos$mutableblockpos.func_181079_c(l1, i3, k1);
  1687. int j3 = world.getCombinedLight(blockpos$mutableblockpos, 0);
  1688. int k3 = j3 >> 16 & 65535;
  1689. int l3 = j3 & 65535;
  1690. worldrenderer.pos((double)l1 - d3 + 0.5D, (double)k2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex();
  1691. worldrenderer.pos((double)l1 + d3 + 0.5D, (double)k2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)k2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex();
  1692. worldrenderer.pos((double)l1 + d3 + 0.5D, (double)l2, (double)k1 + d4 + 0.5D).tex(1.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex();
  1693. worldrenderer.pos((double)l1 - d3 + 0.5D, (double)l2, (double)k1 - d4 + 0.5D).tex(0.0D, (double)l2 * 0.25D + d5).color(1.0F, 1.0F, 1.0F, f4).lightmap(k3, l3).endVertex();
  1694. }
  1695. else
  1696. {
  1697. if (j1 != 1)
  1698. {
  1699. if (j1 >= 0)
  1700. {
  1701. tessellator.draw();
  1702. }
  1703.  
  1704. j1 = 1;
  1705. this.mc.getTextureManager().bindTexture(locationSnowPng);
  1706. worldrenderer.begin(7, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
  1707. }
  1708.  
  1709. double d8 = (double)(((float)(this.rendererUpdateCount & 511) + partialTicks) / 512.0F);
  1710. double d9 = this.random.nextDouble() + (double)f1 * 0.01D * (double)((float)this.random.nextGaussian());
  1711. double d10 = this.random.nextDouble() + (double)(f1 * (float)this.random.nextGaussian()) * 0.001D;
  1712. double d11 = (double)((float)l1 + 0.5F) - entity.posX;
  1713. double d12 = (double)((float)k1 + 0.5F) - entity.posZ;
  1714. float f6 = MathHelper.sqrt_double(d11 * d11 + d12 * d12) / (float)i1;
  1715. float f5 = ((1.0F - f6 * f6) * 0.3F + 0.5F) * f;
  1716. blockpos$mutableblockpos.func_181079_c(l1, i3, k1);
  1717. int i4 = (world.getCombinedLight(blockpos$mutableblockpos, 0) * 3 + 15728880) / 4;
  1718. int j4 = i4 >> 16 & 65535;
  1719. int k4 = i4 & 65535;
  1720. worldrenderer.pos((double)l1 - d3 + 0.5D, (double)k2, (double)k1 - d4 + 0.5D).tex(0.0D + d9, (double)k2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex();
  1721. worldrenderer.pos((double)l1 + d3 + 0.5D, (double)k2, (double)k1 + d4 + 0.5D).tex(1.0D + d9, (double)k2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex();
  1722. worldrenderer.pos((double)l1 + d3 + 0.5D, (double)l2, (double)k1 + d4 + 0.5D).tex(1.0D + d9, (double)l2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex();
  1723. worldrenderer.pos((double)l1 - d3 + 0.5D, (double)l2, (double)k1 - d4 + 0.5D).tex(0.0D + d9, (double)l2 * 0.25D + d8 + d10).color(1.0F, 1.0F, 1.0F, f5).lightmap(j4, k4).endVertex();
  1724. }
  1725. }
  1726. }
  1727. }
  1728. }
  1729.  
  1730. if (j1 >= 0)
  1731. {
  1732. tessellator.draw();
  1733. }
  1734.  
  1735. worldrenderer.setTranslation(0.0D, 0.0D, 0.0D);
  1736. GlStateManager.enableCull();
  1737. GlStateManager.disableBlend();
  1738. GlStateManager.alphaFunc(516, 0.1F);
  1739. this.disableLightmap();
  1740. }
  1741. }
  1742.  
  1743. /**
  1744. * Setup orthogonal projection for rendering GUI screen overlays
  1745. */
  1746. public void setupOverlayRendering()
  1747. {
  1748. ScaledResolution scaledresolution = new ScaledResolution(this.mc);
  1749. GlStateManager.clear(256);
  1750. GlStateManager.matrixMode(5889);
  1751. GlStateManager.loadIdentity();
  1752. GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D);
  1753. GlStateManager.matrixMode(5888);
  1754. GlStateManager.loadIdentity();
  1755. GlStateManager.translate(0.0F, 0.0F, -2000.0F);
  1756. }
  1757.  
  1758. /**
  1759. * calculates fog and calls glClearColor
  1760. */
  1761. private void updateFogColor(float partialTicks)
  1762. {
  1763. World world = this.mc.theWorld;
  1764. Entity entity = this.mc.getRenderViewEntity();
  1765. float f = 0.25F + 0.75F * (float)this.mc.gameSettings.renderDistanceChunks / 32.0F;
  1766. f = 1.0F - (float)Math.pow((double)f, 0.25D);
  1767. Vec3 vec3 = world.getSkyColor(this.mc.getRenderViewEntity(), partialTicks);
  1768. float f1 = (float)vec3.xCoord;
  1769. float f2 = (float)vec3.yCoord;
  1770. float f3 = (float)vec3.zCoord;
  1771. Vec3 vec31 = world.getFogColor(partialTicks);
  1772. this.fogColorRed = (float)vec31.xCoord;
  1773. this.fogColorGreen = (float)vec31.yCoord;
  1774. this.fogColorBlue = (float)vec31.zCoord;
  1775.  
  1776. if (this.mc.gameSettings.renderDistanceChunks >= 4)
  1777. {
  1778. double d0 = -1.0D;
  1779. Vec3 vec32 = MathHelper.sin(world.getCelestialAngleRadians(partialTicks)) > 0.0F ? new Vec3(d0, 0.0D, 0.0D) : new Vec3(1.0D, 0.0D, 0.0D);
  1780. float f5 = (float)entity.getLook(partialTicks).dotProduct(vec32);
  1781.  
  1782. if (f5 < 0.0F)
  1783. {
  1784. f5 = 0.0F;
  1785. }
  1786.  
  1787. if (f5 > 0.0F)
  1788. {
  1789. float[] afloat = world.provider.calcSunriseSunsetColors(world.getCelestialAngle(partialTicks), partialTicks);
  1790.  
  1791. if (afloat != null)
  1792. {
  1793. f5 = f5 * afloat[3];
  1794. this.fogColorRed = this.fogColorRed * (1.0F - f5) + afloat[0] * f5;
  1795. this.fogColorGreen = this.fogColorGreen * (1.0F - f5) + afloat[1] * f5;
  1796. this.fogColorBlue = this.fogColorBlue * (1.0F - f5) + afloat[2] * f5;
  1797. }
  1798. }
  1799. }
  1800.  
  1801. this.fogColorRed += (f1 - this.fogColorRed) * f;
  1802. this.fogColorGreen += (f2 - this.fogColorGreen) * f;
  1803. this.fogColorBlue += (f3 - this.fogColorBlue) * f;
  1804. float f8 = world.getRainStrength(partialTicks);
  1805.  
  1806. if (f8 > 0.0F)
  1807. {
  1808. float f4 = 1.0F - f8 * 0.5F;
  1809. float f10 = 1.0F - f8 * 0.4F;
  1810. this.fogColorRed *= f4;
  1811. this.fogColorGreen *= f4;
  1812. this.fogColorBlue *= f10;
  1813. }
  1814.  
  1815. float f9 = world.getThunderStrength(partialTicks);
  1816.  
  1817. if (f9 > 0.0F)
  1818. {
  1819. float f11 = 1.0F - f9 * 0.5F;
  1820. this.fogColorRed *= f11;
  1821. this.fogColorGreen *= f11;
  1822. this.fogColorBlue *= f11;
  1823. }
  1824.  
  1825. Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.mc.theWorld, entity, partialTicks);
  1826.  
  1827. if (this.cloudFog)
  1828. {
  1829. Vec3 vec33 = world.getCloudColour(partialTicks);
  1830. this.fogColorRed = (float)vec33.xCoord;
  1831. this.fogColorGreen = (float)vec33.yCoord;
  1832. this.fogColorBlue = (float)vec33.zCoord;
  1833. }
  1834. else if (block.getMaterial() == Material.water)
  1835. {
  1836. float f12 = (float)EnchantmentHelper.getRespiration(entity) * 0.2F;
  1837.  
  1838. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.waterBreathing))
  1839. {
  1840. f12 = f12 * 0.3F + 0.6F;
  1841. }
  1842.  
  1843. this.fogColorRed = 0.02F + f12;
  1844. this.fogColorGreen = 0.02F + f12;
  1845. this.fogColorBlue = 0.2F + f12;
  1846. }
  1847. else if (block.getMaterial() == Material.lava)
  1848. {
  1849. this.fogColorRed = 0.6F;
  1850. this.fogColorGreen = 0.1F;
  1851. this.fogColorBlue = 0.0F;
  1852. }
  1853.  
  1854. float f13 = this.fogColor2 + (this.fogColor1 - this.fogColor2) * partialTicks;
  1855. this.fogColorRed *= f13;
  1856. this.fogColorGreen *= f13;
  1857. this.fogColorBlue *= f13;
  1858. double d1 = (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks) * world.provider.getVoidFogYFactor();
  1859.  
  1860. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.blindness))
  1861. {
  1862. int i = ((EntityLivingBase)entity).getActivePotionEffect(Potion.blindness).getDuration();
  1863.  
  1864. if (i < 20)
  1865. {
  1866. d1 *= (double)(1.0F - (float)i / 20.0F);
  1867. }
  1868. else
  1869. {
  1870. d1 = 0.0D;
  1871. }
  1872. }
  1873.  
  1874. if (d1 < 1.0D)
  1875. {
  1876. if (d1 < 0.0D)
  1877. {
  1878. d1 = 0.0D;
  1879. }
  1880.  
  1881. d1 = d1 * d1;
  1882. this.fogColorRed = (float)((double)this.fogColorRed * d1);
  1883. this.fogColorGreen = (float)((double)this.fogColorGreen * d1);
  1884. this.fogColorBlue = (float)((double)this.fogColorBlue * d1);
  1885. }
  1886.  
  1887. if (this.bossColorModifier > 0.0F)
  1888. {
  1889. float f14 = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * partialTicks;
  1890. this.fogColorRed = this.fogColorRed * (1.0F - f14) + this.fogColorRed * 0.7F * f14;
  1891. this.fogColorGreen = this.fogColorGreen * (1.0F - f14) + this.fogColorGreen * 0.6F * f14;
  1892. this.fogColorBlue = this.fogColorBlue * (1.0F - f14) + this.fogColorBlue * 0.6F * f14;
  1893. }
  1894.  
  1895. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.nightVision))
  1896. {
  1897. float f15 = this.getNightVisionBrightness((EntityLivingBase)entity, partialTicks);
  1898. float f6 = 1.0F / this.fogColorRed;
  1899.  
  1900. if (f6 > 1.0F / this.fogColorGreen)
  1901. {
  1902. f6 = 1.0F / this.fogColorGreen;
  1903. }
  1904.  
  1905. if (f6 > 1.0F / this.fogColorBlue)
  1906. {
  1907. f6 = 1.0F / this.fogColorBlue;
  1908. }
  1909.  
  1910. this.fogColorRed = this.fogColorRed * (1.0F - f15) + this.fogColorRed * f6 * f15;
  1911. this.fogColorGreen = this.fogColorGreen * (1.0F - f15) + this.fogColorGreen * f6 * f15;
  1912. this.fogColorBlue = this.fogColorBlue * (1.0F - f15) + this.fogColorBlue * f6 * f15;
  1913. }
  1914.  
  1915. if (this.mc.gameSettings.anaglyph)
  1916. {
  1917. float f16 = (this.fogColorRed * 30.0F + this.fogColorGreen * 59.0F + this.fogColorBlue * 11.0F) / 100.0F;
  1918. float f17 = (this.fogColorRed * 30.0F + this.fogColorGreen * 70.0F) / 100.0F;
  1919. float f7 = (this.fogColorRed * 30.0F + this.fogColorBlue * 70.0F) / 100.0F;
  1920. this.fogColorRed = f16;
  1921. this.fogColorGreen = f17;
  1922. this.fogColorBlue = f7;
  1923. }
  1924.  
  1925. GlStateManager.clearColor(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 0.0F);
  1926. }
  1927.  
  1928. /**
  1929. * Sets up the fog to be rendered. If the arg passed in is -1 the fog starts at 0 and goes to 80% of far plane
  1930. * distance and is used for sky rendering.
  1931. */
  1932. private void setupFog(int p_78468_1_, float partialTicks)
  1933. {
  1934. Entity entity = this.mc.getRenderViewEntity();
  1935. boolean flag = false;
  1936.  
  1937. if (entity instanceof EntityPlayer)
  1938. {
  1939. flag = ((EntityPlayer)entity).capabilities.isCreativeMode;
  1940. }
  1941.  
  1942. GL11.glFog(GL11.GL_FOG_COLOR, (FloatBuffer)this.setFogColorBuffer(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 1.0F));
  1943. GL11.glNormal3f(0.0F, -1.0F, 0.0F);
  1944. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  1945. Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.mc.theWorld, entity, partialTicks);
  1946.  
  1947. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.blindness))
  1948. {
  1949. float f1 = 5.0F;
  1950. int i = ((EntityLivingBase)entity).getActivePotionEffect(Potion.blindness).getDuration();
  1951.  
  1952. if (i < 20)
  1953. {
  1954. f1 = 5.0F + (this.farPlaneDistance - 5.0F) * (1.0F - (float)i / 20.0F);
  1955. }
  1956.  
  1957. GlStateManager.setFog(9729);
  1958.  
  1959. if (p_78468_1_ == -1)
  1960. {
  1961. GlStateManager.setFogStart(0.0F);
  1962. GlStateManager.setFogEnd(f1 * 0.8F);
  1963. }
  1964. else
  1965. {
  1966. GlStateManager.setFogStart(f1 * 0.25F);
  1967. GlStateManager.setFogEnd(f1);
  1968. }
  1969.  
  1970. if (GLContext.getCapabilities().GL_NV_fog_distance)
  1971. {
  1972. GL11.glFogi(34138, 34139);
  1973. }
  1974. }
  1975. else if (this.cloudFog)
  1976. {
  1977. GlStateManager.setFog(2048);
  1978. GlStateManager.setFogDensity(0.1F);
  1979. }
  1980. else if (block.getMaterial() == Material.water)
  1981. {
  1982. GlStateManager.setFog(2048);
  1983.  
  1984. if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(Potion.waterBreathing))
  1985. {
  1986. GlStateManager.setFogDensity(0.01F);
  1987. }
  1988. else
  1989. {
  1990. GlStateManager.setFogDensity(0.1F - (float)EnchantmentHelper.getRespiration(entity) * 0.03F);
  1991. }
  1992. }
  1993. else if (block.getMaterial() == Material.lava)
  1994. {
  1995. GlStateManager.setFog(2048);
  1996. GlStateManager.setFogDensity(2.0F);
  1997. }
  1998. else
  1999. {
  2000. float f = this.farPlaneDistance;
  2001. GlStateManager.setFog(9729);
  2002.  
  2003. if (p_78468_1_ == -1)
  2004. {
  2005. GlStateManager.setFogStart(0.0F);
  2006. GlStateManager.setFogEnd(f);
  2007. }
  2008. else
  2009. {
  2010. GlStateManager.setFogStart(f * 0.75F);
  2011. GlStateManager.setFogEnd(f);
  2012. }
  2013.  
  2014. if (GLContext.getCapabilities().GL_NV_fog_distance)
  2015. {
  2016. GL11.glFogi(34138, 34139);
  2017. }
  2018.  
  2019. if (this.mc.theWorld.provider.doesXZShowFog((int)entity.posX, (int)entity.posZ))
  2020. {
  2021. GlStateManager.setFogStart(f * 0.05F);
  2022. GlStateManager.setFogEnd(Math.min(f, 192.0F) * 0.5F);
  2023. }
  2024. }
  2025.  
  2026. GlStateManager.enableColorMaterial();
  2027. GlStateManager.enableFog();
  2028. GlStateManager.colorMaterial(1028, 4608);
  2029. }
  2030.  
  2031. /**
  2032. * Update and return fogColorBuffer with the RGBA values passed as arguments
  2033. */
  2034. private FloatBuffer setFogColorBuffer(float red, float green, float blue, float alpha)
  2035. {
  2036. this.fogColorBuffer.clear();
  2037. this.fogColorBuffer.put(red).put(green).put(blue).put(alpha);
  2038. this.fogColorBuffer.flip();
  2039. return this.fogColorBuffer;
  2040. }
  2041.  
  2042. public MapItemRenderer getMapItemRenderer()
  2043. {
  2044. return this.theMapItemRenderer;
  2045. }
  2046. }
Advertisement
Add Comment
Please, Sign In to add comment