Advertisement
Guest User

fffff

a guest
Sep 17th, 2014
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.03 KB | None | 0 0
  1. package net.minecraftforge.client;
  2.  
  3. import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.*;
  4.  
  5. import java.awt.Color;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.client.gui.FontRenderer;
  12. import net.minecraft.client.gui.Gui;
  13. import net.minecraft.client.gui.GuiIngame;
  14. import net.minecraft.client.gui.GuiPlayerInfo;
  15. import net.minecraft.client.gui.ScaledResolution;
  16. import net.minecraft.client.network.NetHandlerPlayClient;
  17. import net.minecraft.client.renderer.OpenGlHelper;
  18. import net.minecraft.client.renderer.RenderHelper;
  19. import net.minecraft.client.resources.I18n;
  20. import net.minecraft.entity.Entity;
  21. import net.minecraft.entity.EntityLivingBase;
  22. import net.minecraft.entity.SharedMonsterAttributes;
  23. import net.minecraft.entity.ai.attributes.IAttributeInstance;
  24. import net.minecraft.entity.player.InventoryPlayer;
  25. import net.minecraft.init.Blocks;
  26. import net.minecraft.item.Item;
  27. import net.minecraft.item.ItemStack;
  28. import net.minecraft.potion.Potion;
  29. import net.minecraft.scoreboard.Score;
  30. import net.minecraft.scoreboard.ScoreObjective;
  31. import net.minecraft.scoreboard.ScorePlayerTeam;
  32. import net.minecraft.util.Direction;
  33. import net.minecraft.util.EnumChatFormatting;
  34. import net.minecraft.util.FoodStats;
  35. import net.minecraft.util.MathHelper;
  36. import net.minecraft.util.ResourceLocation;
  37. import net.minecraft.util.StringUtils;
  38. import net.minecraft.world.EnumSkyBlock;
  39. import net.minecraft.world.chunk.Chunk;
  40. import net.minecraftforge.client.event.RenderGameOverlayEvent;
  41. import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
  42. import net.minecraftforge.common.ForgeHooks;
  43. import net.minecraftforge.common.MinecraftForge;
  44.  
  45. import org.lwjgl.opengl.GL11;
  46. import org.lwjgl.opengl.GL12;
  47.  
  48. import cpw.mods.fml.common.FMLCommonHandler;
  49.  
  50. public class GuiIngameForge extends GuiIngame
  51. {
  52. //private static final ResourceLocation VIGNETTE = new ResourceLocation("textures/misc/vignette.png");
  53. private static final ResourceLocation WIDGITS = new ResourceLocation("textures/gui/widgets.png");
  54. //private static final ResourceLocation PUMPKIN_BLUR = new ResourceLocation("textures/misc/pumpkinblur.png");
  55.  
  56. private static final int WHITE = 0xFFFFFF;
  57.  
  58. //Flags to toggle the rendering of certain aspects of the HUD, valid conditions
  59. //must be met for them to render normally. If those conditions are met, but this flag
  60. //is false, they will not be rendered.
  61. public static boolean renderHelmet = true;
  62. public static boolean renderPortal = true;
  63. public static boolean renderHotbar = true;
  64. public static boolean renderCrosshairs = true;
  65. public static boolean renderBossHealth = true;
  66. public static boolean renderHealth = true;
  67. public static boolean renderArmor = true;
  68. public static boolean renderFood = true;
  69. public static boolean renderHealthMount = true;
  70. public static boolean renderAir = true;
  71. public static boolean renderExperiance = true;
  72. public static boolean renderJumpBar = true;
  73. public static boolean renderObjective = true;
  74. protected String msgPlaying = "";
  75. protected int msgPlayingUpFor = 0;
  76. protected boolean msgIsPlaying = false;
  77.  
  78. public static int left_height = 39;
  79. public static int right_height = 39;
  80.  
  81. private ScaledResolution res = null;
  82. private FontRenderer fontrenderer = null;
  83. private RenderGameOverlayEvent eventParent;
  84. private static final String MC_VERSION = MinecraftForge.MC_VERSION;
  85.  
  86. public GuiIngameForge(Minecraft mc)
  87. {
  88. super(mc);
  89. }
  90.  
  91. /**
  92. * Render the ingame overlay with quick icon bar, ...
  93. */
  94. @Override
  95. public void renderGameOverlay(float partialTicks, boolean hasScreen, int mouseX, int mouseY)
  96. {
  97. res = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
  98. eventParent = new RenderGameOverlayEvent(partialTicks, res, mouseX, mouseY);
  99. int width = res.getScaledWidth();
  100. int height = res.getScaledHeight();
  101. renderHealthMount = mc.thePlayer.ridingEntity instanceof EntityLivingBase;
  102. renderFood = mc.thePlayer.ridingEntity == null;
  103. renderJumpBar = mc.thePlayer.isRidingHorse();
  104.  
  105. right_height = 39;
  106. left_height = 39;
  107.  
  108. if (pre(ALL)) return;
  109.  
  110. fontrenderer = mc.fontRenderer;
  111. mc.entityRenderer.setupOverlayRendering();
  112. GL11.glEnable(GL11.GL_BLEND);
  113.  
  114. if (Minecraft.isFancyGraphicsEnabled())
  115. {
  116. renderVignette(mc.thePlayer.getBrightness(partialTicks), width, height);
  117. }
  118. else
  119. {
  120. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  121. }
  122.  
  123. if (renderHelmet) renderHelmet(res, partialTicks, hasScreen, mouseX, mouseY);
  124.  
  125. if (renderPortal && !mc.thePlayer.isPotionActive(Potion.confusion))
  126. {
  127. renderPortal(width, height, partialTicks);
  128. }
  129.  
  130. if (!mc.playerController.enableEverythingIsScrewedUpMode())
  131. {
  132. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  133. zLevel = -90.0F;
  134. rand.setSeed((long)(updateCounter * 312871));
  135.  
  136. if (renderCrosshairs) renderCrosshairs(width, height);
  137. if (renderBossHealth) renderBossHealth();
  138.  
  139. if (this.mc.playerController.shouldDrawHUD())
  140. {
  141. if (renderHealth) renderHealth(width, height);
  142. if (renderArmor) renderArmor(width, height);
  143. if (renderFood) renderFood(width, height);
  144. if (renderHealthMount) renderHealthMount(width, height);
  145. if (renderAir) renderAir(width, height);
  146. }
  147. if (renderHotbar) renderHotbar(width, height, partialTicks);
  148. }
  149.  
  150. if (renderJumpBar)
  151. {
  152. renderJumpBar(width, height);
  153. }
  154. else if (renderExperiance)
  155. {
  156. renderExperience(width, height);
  157. }
  158.  
  159. renderSleepFade(width, height);
  160. renderToolHightlight(width, height);
  161. renderHUDText(width, height);
  162. renderRecordOverlay(width, height, partialTicks);
  163. renderRecordOverlay(width, height, partialTicks);
  164. renderMsgOverlay(width, height, partialTicks);
  165.  
  166. ScoreObjective objective = mc.theWorld.getScoreboard().func_96539_a(1);
  167. if (renderObjective && objective != null)
  168. {
  169. this.func_96136_a(objective, height, width, fontrenderer);
  170. }
  171.  
  172. GL11.glEnable(GL11.GL_BLEND);
  173. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  174. GL11.glDisable(GL11.GL_ALPHA_TEST);
  175.  
  176. renderChat(width, height);
  177.  
  178. renderPlayerList(width, height);
  179.  
  180. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  181. GL11.glDisable(GL11.GL_LIGHTING);
  182. GL11.glEnable(GL11.GL_ALPHA_TEST);
  183.  
  184. post(ALL);
  185.  
  186. if (this.msgPlayingUpFor > 0)
  187. {
  188. mc.mcProfiler.startSection("overlayMessage");
  189. float hue = (float)this.msgPlayingUpFor - partialTicks;
  190. int opacity = (int)(hue * 256.0F / 20.0F);
  191. if (opacity > 255) opacity = 255;
  192.  
  193. if (opacity > 0)
  194. {
  195. GL11.glPushMatrix();
  196. GL11.glTranslatef((float)(width / 2), (float)(height - 48), 0.0F);
  197. GL11.glEnable(GL11.GL_BLEND);
  198. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  199. int color = (this.msgIsPlaying ? Color.HSBtoRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
  200. fontrenderer.drawString(recordPlaying, -fontrenderer.getStringWidth(msgPlaying) / 2, -200, color | (opacity << 24));
  201. GL11.glDisable(GL11.GL_BLEND);
  202. GL11.glPopMatrix();
  203. }
  204.  
  205. mc.mcProfiler.endSection();
  206. }
  207. }
  208.  
  209. public ScaledResolution getResolution()
  210. {
  211. return res;
  212. }
  213.  
  214. protected void renderHotbar(int width, int height, float partialTicks)
  215. {
  216. if (pre(HOTBAR)) return;
  217. mc.mcProfiler.startSection("actionBar");
  218.  
  219. GL11.glEnable(GL11.GL_BLEND);
  220. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  221. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  222. mc.renderEngine.bindTexture(WIDGITS);
  223.  
  224. InventoryPlayer inv = mc.thePlayer.inventory;
  225. drawTexturedModalRect(width / 2 - 91, height - 22, 0, 0, 182, 22);
  226. drawTexturedModalRect(width / 2 - 91 - 1 + inv.currentItem * 20, height - 22 - 1, 0, 22, 24, 22);
  227.  
  228. GL11.glDisable(GL11.GL_BLEND);
  229. GL11.glEnable(GL12.GL_RESCALE_NORMAL);
  230. RenderHelper.enableGUIStandardItemLighting();
  231.  
  232. for (int i = 0; i < 9; ++i)
  233. {
  234. int x = width / 2 - 90 + i * 20 + 2;
  235. int z = height - 16 - 3;
  236. renderInventorySlot(i, x, z, partialTicks);
  237. }
  238.  
  239. RenderHelper.disableStandardItemLighting();
  240. GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  241. mc.mcProfiler.endSection();
  242. post(HOTBAR);
  243. }
  244.  
  245. protected void renderCrosshairs(int width, int height)
  246. {
  247. if (pre(CROSSHAIRS)) return;
  248. bind(Gui.icons);
  249. GL11.glEnable(GL11.GL_BLEND);
  250. OpenGlHelper.glBlendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0);
  251. drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);
  252. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  253. GL11.glDisable(GL11.GL_BLEND);
  254. post(CROSSHAIRS);
  255. }
  256.  
  257. /**
  258. * Renders dragon's (boss) health on the HUD
  259. */
  260. @Override
  261. protected void renderBossHealth()
  262. {
  263. if (pre(BOSSHEALTH)) return;
  264. mc.mcProfiler.startSection("bossHealth");
  265. GL11.glEnable(GL11.GL_BLEND);
  266. super.renderBossHealth();
  267. GL11.glDisable(GL11.GL_BLEND);
  268. mc.mcProfiler.endSection();
  269. post(BOSSHEALTH);
  270. }
  271.  
  272. private void renderHelmet(ScaledResolution res, float partialTicks, boolean hasScreen, int mouseX, int mouseY)
  273. {
  274. if (pre(HELMET)) return;
  275.  
  276. ItemStack itemstack = this.mc.thePlayer.inventory.armorItemInSlot(3);
  277.  
  278. if (this.mc.gameSettings.thirdPersonView == 0 && itemstack != null && itemstack.getItem() != null)
  279. {
  280. if (itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin))
  281. {
  282. renderPumpkinBlur(res.getScaledWidth(), res.getScaledHeight());
  283. }
  284. else
  285. {
  286. itemstack.getItem().renderHelmetOverlay(itemstack, mc.thePlayer, res, partialTicks, hasScreen, mouseX, mouseY);
  287. }
  288. }
  289.  
  290. post(HELMET);
  291. }
  292.  
  293. protected void renderArmor(int width, int height)
  294. {
  295. if (pre(ARMOR)) return;
  296. mc.mcProfiler.startSection("armor");
  297.  
  298. GL11.glEnable(GL11.GL_BLEND);
  299. int left = width / 2 - 91;
  300. int top = height - left_height;
  301.  
  302. int level = ForgeHooks.getTotalArmorValue(mc.thePlayer);
  303. for (int i = 1; level > 0 && i < 20; i += 2)
  304. {
  305. if (i < level)
  306. {
  307. drawTexturedModalRect(left, top, 34, 9, 9, 9);
  308. }
  309. else if (i == level)
  310. {
  311. drawTexturedModalRect(left, top, 25, 9, 9, 9);
  312. }
  313. else if (i > level)
  314. {
  315. drawTexturedModalRect(left, top, 16, 9, 9, 9);
  316. }
  317. left += 8;
  318. }
  319. left_height += 10;
  320.  
  321. GL11.glDisable(GL11.GL_BLEND);
  322. mc.mcProfiler.endSection();
  323. post(ARMOR);
  324. }
  325.  
  326. protected void renderPortal(int width, int height, float partialTicks)
  327. {
  328. if (pre(PORTAL)) return;
  329.  
  330. float f1 = mc.thePlayer.prevTimeInPortal + (mc.thePlayer.timeInPortal - mc.thePlayer.prevTimeInPortal) * partialTicks;
  331.  
  332. if (f1 > 0.0F)
  333. {
  334. func_130015_b(f1, width, height);
  335. }
  336.  
  337. post(PORTAL);
  338. }
  339.  
  340. protected void renderAir(int width, int height)
  341. {
  342. if (pre(AIR)) return;
  343. mc.mcProfiler.startSection("air");
  344. GL11.glEnable(GL11.GL_BLEND);
  345. int left = width / 2 + 91;
  346. int top = height - right_height;
  347.  
  348. if (mc.thePlayer.isInsideOfMaterial(Material.water))
  349. {
  350. int air = mc.thePlayer.getAir();
  351. int full = MathHelper.ceiling_double_int((double)(air - 2) * 10.0D / 300.0D);
  352. int partial = MathHelper.ceiling_double_int((double)air * 10.0D / 300.0D) - full;
  353.  
  354. for (int i = 0; i < full + partial; ++i)
  355. {
  356. drawTexturedModalRect(left - i * 8 - 9, top, (i < full ? 16 : 25), 18, 9, 9);
  357. }
  358. right_height += 10;
  359. }
  360.  
  361. GL11.glDisable(GL11.GL_BLEND);
  362. mc.mcProfiler.endSection();
  363. post(AIR);
  364. }
  365.  
  366. public void renderHealth(int width, int height)
  367. {
  368. bind(icons);
  369. if (pre(HEALTH)) return;
  370. mc.mcProfiler.startSection("health");
  371. GL11.glEnable(GL11.GL_BLEND);
  372.  
  373. boolean highlight = mc.thePlayer.hurtResistantTime / 3 % 2 == 1;
  374.  
  375. if (mc.thePlayer.hurtResistantTime < 10)
  376. {
  377. highlight = false;
  378. }
  379.  
  380. IAttributeInstance attrMaxHealth = this.mc.thePlayer.getEntityAttribute(SharedMonsterAttributes.maxHealth);
  381. int health = MathHelper.ceiling_float_int(mc.thePlayer.getHealth());
  382. int healthLast = MathHelper.ceiling_float_int(mc.thePlayer.prevHealth);
  383. float healthMax = (float)attrMaxHealth.getAttributeValue();
  384. float absorb = this.mc.thePlayer.getAbsorptionAmount();
  385.  
  386. int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
  387. int rowHeight = Math.max(10 - (healthRows - 2), 3);
  388.  
  389. this.rand.setSeed((long)(updateCounter * 312871));
  390.  
  391. int left = width / 2 - 91;
  392. int top = height - left_height;
  393. left_height += (healthRows * rowHeight);
  394. if (rowHeight != 10) left_height += 10 - rowHeight;
  395.  
  396. int regen = -1;
  397. if (mc.thePlayer.isPotionActive(Potion.regeneration))
  398. {
  399. regen = updateCounter % 25;
  400. }
  401.  
  402. final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
  403. final int BACKGROUND = (highlight ? 25 : 16);
  404. int MARGIN = 16;
  405. if (mc.thePlayer.isPotionActive(Potion.poison)) MARGIN += 36;
  406. else if (mc.thePlayer.isPotionActive(Potion.wither)) MARGIN += 72;
  407. float absorbRemaining = absorb;
  408.  
  409. for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i)
  410. {
  411. //int b0 = (highlight ? 1 : 0);
  412. int row = MathHelper.ceiling_float_int((float)(i + 1) / 10.0F) - 1;
  413. int x = left + i % 10 * 8;
  414. int y = top - row * rowHeight;
  415.  
  416. if (health <= 4) y += rand.nextInt(2);
  417. if (i == regen) y -= 2;
  418.  
  419. drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);
  420.  
  421. if (highlight)
  422. {
  423. if (i * 2 + 1 < healthLast)
  424. drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9); //6
  425. else if (i * 2 + 1 == healthLast)
  426. drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9); //7
  427. }
  428.  
  429. if (absorbRemaining > 0.0F)
  430. {
  431. if (absorbRemaining == absorb && absorb % 2.0F == 1.0F)
  432. drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9); //17
  433. else
  434. drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9); //16
  435. absorbRemaining -= 2.0F;
  436. }
  437. else
  438. {
  439. if (i * 2 + 1 < health)
  440. drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9); //4
  441. else if (i * 2 + 1 == health)
  442. drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9); //5
  443. }
  444. }
  445.  
  446. GL11.glDisable(GL11.GL_BLEND);
  447. mc.mcProfiler.endSection();
  448. post(HEALTH);
  449. }
  450.  
  451. public void renderFood(int width, int height)
  452. {
  453. if (pre(FOOD)) return;
  454. mc.mcProfiler.startSection("food");
  455.  
  456. GL11.glEnable(GL11.GL_BLEND);
  457. int left = width / 2 + 91;
  458. int top = height - right_height;
  459. right_height += 10;
  460. boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic
  461.  
  462. FoodStats stats = mc.thePlayer.getFoodStats();
  463. int level = stats.getFoodLevel();
  464. int levelLast = stats.getPrevFoodLevel();
  465.  
  466. for (int i = 0; i < 10; ++i)
  467. {
  468. int idx = i * 2 + 1;
  469. int x = left - i * 8 - 9;
  470. int y = top;
  471. int icon = 16;
  472. byte backgound = 0;
  473.  
  474. if (mc.thePlayer.isPotionActive(Potion.hunger))
  475. {
  476. icon += 36;
  477. backgound = 13;
  478. }
  479. if (unused) backgound = 1; //Probably should be a += 1 but vanilla never uses this
  480.  
  481. if (mc.thePlayer.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0)
  482. {
  483. y = top + (rand.nextInt(3) - 1);
  484. }
  485.  
  486. drawTexturedModalRect(x, y, 16 + backgound * 9, 27, 9, 9);
  487.  
  488. if (unused)
  489. {
  490. if (idx < levelLast)
  491. drawTexturedModalRect(x, y, icon + 54, 27, 9, 9);
  492. else if (idx == levelLast)
  493. drawTexturedModalRect(x, y, icon + 63, 27, 9, 9);
  494. }
  495.  
  496. if (idx < level)
  497. drawTexturedModalRect(x, y, icon + 36, 27, 9, 9);
  498. else if (idx == level)
  499. drawTexturedModalRect(x, y, icon + 45, 27, 9, 9);
  500. }
  501. GL11.glDisable(GL11.GL_BLEND);
  502. mc.mcProfiler.endSection();
  503. post(FOOD);
  504. }
  505.  
  506. protected void renderSleepFade(int width, int height)
  507. {
  508. if (mc.thePlayer.getSleepTimer() > 0)
  509. {
  510. mc.mcProfiler.startSection("sleep");
  511. GL11.glDisable(GL11.GL_DEPTH_TEST);
  512. GL11.glDisable(GL11.GL_ALPHA_TEST);
  513. int sleepTime = mc.thePlayer.getSleepTimer();
  514. float opacity = (float)sleepTime / 100.0F;
  515.  
  516. if (opacity > 1.0F)
  517. {
  518. opacity = 1.0F - (float)(sleepTime - 100) / 10.0F;
  519. }
  520.  
  521. int color = (int)(220.0F * opacity) << 24 | 1052704;
  522. drawRect(0, 0, width, height, color);
  523. GL11.glEnable(GL11.GL_ALPHA_TEST);
  524. GL11.glEnable(GL11.GL_DEPTH_TEST);
  525. mc.mcProfiler.endSection();
  526. }
  527. }
  528.  
  529. protected void renderExperience(int width, int height)
  530. {
  531. bind(icons);
  532. if (pre(EXPERIENCE)) return;
  533. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  534.  
  535. if (mc.playerController.gameIsSurvivalOrAdventure())
  536. {
  537. mc.mcProfiler.startSection("expBar");
  538. int cap = this.mc.thePlayer.xpBarCap();
  539. int left = width / 2 - 91;
  540.  
  541. if (cap > 0)
  542. {
  543. short barWidth = 182;
  544. int filled = (int)(mc.thePlayer.experience * (float)(barWidth + 1));
  545. int top = height - 32 + 3;
  546. drawTexturedModalRect(left, top, 0, 64, barWidth, 5);
  547.  
  548. if (filled > 0)
  549. {
  550. drawTexturedModalRect(left, top, 0, 69, filled, 5);
  551. }
  552. }
  553.  
  554. this.mc.mcProfiler.endSection();
  555.  
  556.  
  557. if (mc.playerController.gameIsSurvivalOrAdventure() && mc.thePlayer.experienceLevel > 0)
  558. {
  559. mc.mcProfiler.startSection("expLevel");
  560. boolean flag1 = false;
  561. int color = flag1 ? 16777215 : 8453920;
  562. String text = "" + mc.thePlayer.experienceLevel;
  563. int x = (width - fontrenderer.getStringWidth(text)) / 2;
  564. int y = height - 31 - 4;
  565. fontrenderer.drawString(text, x + 1, y, 0);
  566. fontrenderer.drawString(text, x - 1, y, 0);
  567. fontrenderer.drawString(text, x, y + 1, 0);
  568. fontrenderer.drawString(text, x, y - 1, 0);
  569. fontrenderer.drawString(text, x, y, color);
  570. mc.mcProfiler.endSection();
  571. }
  572. }
  573. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  574.  
  575. post(EXPERIENCE);
  576. }
  577.  
  578. protected void renderJumpBar(int width, int height)
  579. {
  580. bind(icons);
  581. if (pre(JUMPBAR)) return;
  582. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  583.  
  584. mc.mcProfiler.startSection("jumpBar");
  585. float charge = mc.thePlayer.getHorseJumpPower();
  586. final int barWidth = 182;
  587. int x = (width / 2) - (barWidth / 2);
  588. int filled = (int)(charge * (float)(barWidth + 1));
  589. int top = height - 32 + 3;
  590.  
  591. drawTexturedModalRect(x, top, 0, 84, barWidth, 5);
  592.  
  593. if (filled > 0)
  594. {
  595. this.drawTexturedModalRect(x, top, 0, 89, filled, 5);
  596. }
  597.  
  598. mc.mcProfiler.endSection();
  599. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  600.  
  601. post(JUMPBAR);
  602. }
  603.  
  604. protected void renderToolHightlight(int width, int height)
  605. {
  606. if (this.mc.gameSettings.heldItemTooltips)
  607. {
  608. mc.mcProfiler.startSection("toolHighlight");
  609.  
  610. if (this.remainingHighlightTicks > 0 && this.highlightingItemStack != null)
  611. {
  612. String name = this.highlightingItemStack.getDisplayName();
  613.  
  614. int opacity = (int)((float)this.remainingHighlightTicks * 256.0F / 10.0F);
  615. if (opacity > 255) opacity = 255;
  616.  
  617. if (opacity > 0)
  618. {
  619. int y = height - 59;
  620. if (!mc.playerController.shouldDrawHUD()) y += 14;
  621.  
  622. GL11.glPushMatrix();
  623. GL11.glEnable(GL11.GL_BLEND);
  624. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  625. FontRenderer font = highlightingItemStack.getItem().getFontRenderer(highlightingItemStack);
  626. if (font != null)
  627. {
  628. int x = (width - font.getStringWidth(name)) / 2;
  629. font.drawStringWithShadow(name, x, y, WHITE | (opacity << 24));
  630. }
  631. else
  632. {
  633. int x = (width - fontrenderer.getStringWidth(name)) / 2;
  634. fontrenderer.drawStringWithShadow(name, x, y, WHITE | (opacity << 24));
  635. }
  636. GL11.glDisable(GL11.GL_BLEND);
  637. GL11.glPopMatrix();
  638. }
  639. }
  640.  
  641. mc.mcProfiler.endSection();
  642. }
  643. }
  644.  
  645. protected void renderHUDText(int width, int height)
  646. {
  647. mc.mcProfiler.startSection("forgeHudText");
  648. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  649. ArrayList<String> left = new ArrayList<String>();
  650. ArrayList<String> right = new ArrayList<String>();
  651.  
  652. if (mc.isDemo())
  653. {
  654. long time = mc.theWorld.getTotalWorldTime();
  655. if (time >= 120500L)
  656. {
  657. right.add(I18n.format("demo.demoExpired"));
  658. }
  659. else
  660. {
  661. right.add(I18n.format("demo.remainingTime", StringUtils.ticksToElapsedTime((int)(120500L - time))));
  662. }
  663. }
  664.  
  665.  
  666. if (this.mc.gameSettings.showDebugInfo && !pre(DEBUG))
  667. {
  668. mc.mcProfiler.startSection("debug");
  669. GL11.glPushMatrix();
  670. left.add("Mine " + MC_VERSION + " (" + this.mc.debug + ")");
  671. left.add(mc.debugInfoRenders());
  672. left.add(mc.getEntityDebug());
  673. left.add(mc.debugInfoEntities());
  674. left.add(mc.getWorldProviderName());
  675. left.add(null); //Spacer
  676.  
  677. long max = Runtime.getRuntime().maxMemory();
  678. long total = Runtime.getRuntime().totalMemory();
  679. long free = Runtime.getRuntime().freeMemory();
  680. long used = total - free;
  681.  
  682. right.add("Used memory: " + used * 100L / max + "% (" + used / 1024L / 1024L + "MB) of " + max / 1024L / 1024L + "MB");
  683. right.add("Allocated memory: " + total * 100L / max + "% (" + total / 1024L / 1024L + "MB)");
  684.  
  685. int x = MathHelper.floor_double(mc.thePlayer.posX);
  686. int y = MathHelper.floor_double(mc.thePlayer.posY);
  687. int z = MathHelper.floor_double(mc.thePlayer.posZ);
  688. float yaw = mc.thePlayer.rotationYaw;
  689. int heading = MathHelper.floor_double((double)(mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  690.  
  691. left.add(String.format("x: %.5f (%d) // c: %d (%d)", mc.thePlayer.posX, x, x >> 4, x & 15));
  692. left.add(String.format("y: %.3f (feet pos, %.3f eyes pos)", mc.thePlayer.boundingBox.minY, mc.thePlayer.posY));
  693. left.add(String.format("z: %.5f (%d) // c: %d (%d)", mc.thePlayer.posZ, z, z >> 4, z & 15));
  694. left.add(String.format("f: %d (%s) / %f", heading, Direction.directions[heading], MathHelper.wrapAngleTo180_float(yaw)));
  695.  
  696. if (mc.theWorld != null && mc.theWorld.blockExists(x, y, z))
  697. {
  698. Chunk chunk = this.mc.theWorld.getChunkFromBlockCoords(x, z);
  699. left.add(String.format("lc: %d b: %s bl: %d sl: %d rl: %d",
  700. chunk.getTopFilledSegment() + 15,
  701. chunk.getBiomeGenForWorldCoords(x & 15, z & 15, mc.theWorld.getWorldChunkManager()).biomeName,
  702. chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15),
  703. chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15),
  704. chunk.getBlockLightValue(x & 15, y, z & 15, 0)));
  705. }
  706. else
  707. {
  708. left.add(null);
  709. }
  710.  
  711. left.add(String.format("ws: %.3f, fs: %.3f, g: %b, fl: %d", mc.thePlayer.capabilities.getWalkSpeed(), mc.thePlayer.capabilities.getFlySpeed(), mc.thePlayer.onGround, mc.theWorld.getHeightValue(x, z)));
  712. if (mc.entityRenderer != null && mc.entityRenderer.isShaderActive())
  713. {
  714. left.add(String.format("shader: %s", mc.entityRenderer.getShaderGroup().getShaderGroupName()));
  715. }
  716.  
  717. right.add(null);
  718. for (String brand : FMLCommonHandler.instance().getBrandings(false))
  719. {
  720. right.add(brand);
  721. }
  722. GL11.glPopMatrix();
  723. mc.mcProfiler.endSection();
  724. post(DEBUG);
  725. }
  726.  
  727. RenderGameOverlayEvent.Text event = new RenderGameOverlayEvent.Text(eventParent, left, right);
  728. if (!MinecraftForge.EVENT_BUS.post(event))
  729. {
  730. for (int x = 0; x < left.size(); x++)
  731. {
  732. String msg = left.get(x);
  733. if (msg == null) continue;
  734. fontrenderer.drawStringWithShadow(msg, 2, 2 + x * 10, WHITE);
  735. }
  736.  
  737. for (int x = 0; x < right.size(); x++)
  738. {
  739. String msg = right.get(x);
  740. if (msg == null) continue;
  741. int w = fontrenderer.getStringWidth(msg);
  742. fontrenderer.drawStringWithShadow(msg, width - w - 10, 2 + x * 10, WHITE);
  743. }
  744. }
  745.  
  746. mc.mcProfiler.endSection();
  747. post(TEXT);
  748. }
  749.  
  750. protected void renderRecordOverlay(int width, int height, float partialTicks)
  751. {
  752. if (recordPlayingUpFor > 0)
  753. {
  754. mc.mcProfiler.startSection("overlayMessage");
  755. float hue = (float)recordPlayingUpFor - partialTicks;
  756. int opacity = (int)(hue * 256.0F / 20.0F);
  757. if (opacity > 255) opacity = 255;
  758.  
  759. if (opacity > 0)
  760. {
  761. GL11.glPushMatrix();
  762. GL11.glTranslatef((float)(width / 2), (float)(height - 48), 0.0F);
  763. GL11.glEnable(GL11.GL_BLEND);
  764. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  765. int color = (recordIsPlaying ? Color.HSBtoRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
  766. fontrenderer.drawString(recordPlaying, -fontrenderer.getStringWidth(recordPlaying) / 2, -4, color | (opacity << 24));
  767. GL11.glDisable(GL11.GL_BLEND);
  768. GL11.glPopMatrix();
  769. }
  770.  
  771. mc.mcProfiler.endSection();
  772. }
  773. }
  774.  
  775. protected void renderMsgOverlay(int width, int height, float partialTicks)
  776. {
  777. if (this.msgPlayingUpFor > 0)
  778. {
  779. mc.mcProfiler.startSection("overlayMessage");
  780. float hue = (float)this.msgPlayingUpFor - partialTicks;
  781. int opacity = (int)(hue * 256.0F / 20.0F);
  782. if (opacity > 255) opacity = 255;
  783.  
  784. if (opacity > 0)
  785. {
  786. GL11.glPushMatrix();
  787. GL11.glTranslatef((float)(width / 2), (float)(height - 48), 0.0F);
  788. GL11.glEnable(GL11.GL_BLEND);
  789. OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
  790. int color = (this.msgIsPlaying ? Color.HSBtoRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
  791. fontrenderer.drawString(recordPlaying, -fontrenderer.getStringWidth(msgPlaying) / 2, -200, color | (opacity << 24));
  792. GL11.glDisable(GL11.GL_BLEND);
  793. GL11.glPopMatrix();
  794. }
  795.  
  796. mc.mcProfiler.endSection();
  797. }
  798. }
  799.  
  800.  
  801. protected void renderChat(int width, int height)
  802. {
  803. mc.mcProfiler.startSection("chat");
  804.  
  805. RenderGameOverlayEvent.Chat event = new RenderGameOverlayEvent.Chat(eventParent, 0, height - 48);
  806. if (MinecraftForge.EVENT_BUS.post(event)) return;
  807.  
  808. GL11.glPushMatrix();
  809. GL11.glTranslatef((float)event.posX, (float)event.posY, 0.0F);
  810. persistantChatGUI.drawChat(updateCounter);
  811. GL11.glPopMatrix();
  812.  
  813. post(CHAT);
  814.  
  815. mc.mcProfiler.endSection();
  816. }
  817.  
  818. @SuppressWarnings("unchecked")
  819. protected void renderPlayerList(int width, int height)
  820. {
  821. ScoreObjective scoreobjective = this.mc.theWorld.getScoreboard().func_96539_a(0);
  822. NetHandlerPlayClient handler = mc.thePlayer.sendQueue;
  823.  
  824. if (mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && (!mc.isIntegratedServerRunning() || handler.playerInfoList.size() > 1 || scoreobjective != null))
  825. {
  826. if (pre(PLAYER_LIST)) return;
  827. this.mc.mcProfiler.startSection("playerList");
  828. List<GuiPlayerInfo> players = (List<GuiPlayerInfo>)handler.playerInfoList;
  829. int maxPlayers = handler.currentServerMaxPlayers;
  830. int rows = maxPlayers;
  831. int columns = 1;
  832.  
  833. for (columns = 1; rows > 20; rows = (maxPlayers + columns - 1) / columns)
  834. {
  835. columns++;
  836. }
  837.  
  838. int columnWidth = 300 / columns;
  839.  
  840. if (columnWidth > 150)
  841. {
  842. columnWidth = 150;
  843. }
  844.  
  845. int left = (width - columns * columnWidth) / 2;
  846. byte border = 10;
  847. drawRect(left - 1, border - 1, left + columnWidth * columns, border + 9 * rows, Integer.MIN_VALUE);
  848.  
  849. for (int i = 0; i < maxPlayers; i++)
  850. {
  851. int xPos = left + i % columns * columnWidth;
  852. int yPos = border + i / columns * 9;
  853. drawRect(xPos, yPos, xPos + columnWidth - 1, yPos + 8, 553648127);
  854. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  855. GL11.glEnable(GL11.GL_ALPHA_TEST);
  856.  
  857. if (i < players.size())
  858. {
  859. GuiPlayerInfo player = (GuiPlayerInfo)players.get(i);
  860. ScorePlayerTeam team = mc.theWorld.getScoreboard().getPlayersTeam(player.name);
  861. String displayName = ScorePlayerTeam.formatPlayerName(team, player.name);
  862. fontrenderer.drawStringWithShadow(displayName, xPos, yPos, 16777215);
  863.  
  864. if (scoreobjective != null)
  865. {
  866. int endX = xPos + fontrenderer.getStringWidth(displayName) + 5;
  867. int maxX = xPos + columnWidth - 12 - 5;
  868.  
  869. if (maxX - endX > 5)
  870. {
  871. Score score = scoreobjective.getScoreboard().func_96529_a(player.name, scoreobjective);
  872. String scoreDisplay = EnumChatFormatting.YELLOW + "" + score.getScorePoints();
  873. fontrenderer.drawStringWithShadow(scoreDisplay, maxX - fontrenderer.getStringWidth(scoreDisplay), yPos, 16777215);
  874. }
  875. }
  876.  
  877. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  878.  
  879. mc.getTextureManager().bindTexture(Gui.icons);
  880. int pingIndex = 4;
  881. int ping = player.responseTime;
  882. if (ping < 0) pingIndex = 5;
  883. else if (ping < 150) pingIndex = 0;
  884. else if (ping < 300) pingIndex = 1;
  885. else if (ping < 600) pingIndex = 2;
  886. else if (ping < 1000) pingIndex = 3;
  887.  
  888. zLevel += 100.0F;
  889. drawTexturedModalRect(xPos + columnWidth - 12, yPos, 0, 176 + pingIndex * 8, 10, 8);
  890. zLevel -= 100.0F;
  891. }
  892. }
  893. post(PLAYER_LIST);
  894. }
  895. }
  896.  
  897. protected void renderHealthMount(int width, int height)
  898. {
  899. Entity tmp = mc.thePlayer.ridingEntity;
  900. if (!(tmp instanceof EntityLivingBase)) return;
  901.  
  902. bind(icons);
  903.  
  904. if (pre(HEALTHMOUNT)) return;
  905.  
  906. boolean unused = false;
  907. int left_align = width / 2 + 91;
  908.  
  909. mc.mcProfiler.endStartSection("mountHealth");
  910. GL11.glEnable(GL11.GL_BLEND);
  911. EntityLivingBase mount = (EntityLivingBase)tmp;
  912. int health = (int)Math.ceil((double)mount.getHealth());
  913. float healthMax = mount.getMaxHealth();
  914. int hearts = (int)(healthMax + 0.5F) / 2;
  915.  
  916. if (hearts > 30) hearts = 30;
  917.  
  918. final int MARGIN = 52;
  919. final int BACKGROUND = MARGIN + (unused ? 1 : 0);
  920. final int HALF = MARGIN + 45;
  921. final int FULL = MARGIN + 36;
  922.  
  923. for (int heart = 0; hearts > 0; heart += 20)
  924. {
  925. int top = height - right_height;
  926.  
  927. int rowCount = Math.min(hearts, 10);
  928. hearts -= rowCount;
  929.  
  930. for (int i = 0; i < rowCount; ++i)
  931. {
  932. int x = left_align - i * 8 - 9;
  933. drawTexturedModalRect(x, top, BACKGROUND, 9, 9, 9);
  934.  
  935. if (i * 2 + 1 + heart < health)
  936. drawTexturedModalRect(x, top, FULL, 9, 9, 9);
  937. else if (i * 2 + 1 + heart == health)
  938. drawTexturedModalRect(x, top, HALF, 9, 9, 9);
  939. }
  940.  
  941. right_height += 10;
  942. }
  943. GL11.glDisable(GL11.GL_BLEND);
  944. post(HEALTHMOUNT);
  945. }
  946.  
  947. public void updateTick()
  948. {
  949. if (this.msgPlayingUpFor > 0)
  950. {
  951. --this.msgPlayingUpFor;
  952. }
  953. }
  954.  
  955. //Helper macros
  956. private boolean pre(ElementType type)
  957. {
  958. return MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Pre(eventParent, type));
  959. }
  960. private void post(ElementType type)
  961. {
  962. MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(eventParent, type));
  963. }
  964. private void bind(ResourceLocation res)
  965. {
  966. mc.getTextureManager().bindTexture(res);
  967. }
  968.  
  969. public void renderMsg(String message)
  970. {
  971. this.msgPlaying = message;
  972. this.msgPlayingUpFor = 60;
  973. this.msgIsPlaying = true;
  974. }
  975. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement