Advertisement
Superloup10

Untitled

Sep 27th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.07 KB | None | 0 0
  1. package fr.mcnanotech.nhg.client;
  2.  
  3. import java.util.Iterator;
  4. import java.util.List;
  5.  
  6. import org.lwjgl.input.Keyboard;
  7.  
  8. import fr.mcnanotech.kevin_68.thespotlightmod.client.gui.GuiBooleanButton;
  9. import fr.mcnanotech.nhg.client.gui.NHGPanorama;
  10. import fr.mcnanotech.nhg.client.gui.replaced.NHGGuiIngameMenu;
  11. import fr.mcnanotech.nhg.common.ModNanotechHungerGames;
  12. import fr.mcnanotech.nhg.common.NHGCommon;
  13. import fr.mcnanotech.nhg.common.capabilities.INHGCapability;
  14. import fr.mcnanotech.nhg.common.kit.Kit;
  15. import fr.mcnanotech.nhg.common.network.NHGNetwork;
  16. import fr.mcnanotech.nhg.common.network.packets.PacketRequestCrafterGui;
  17. import net.minecraft.client.Minecraft;
  18. import net.minecraft.client.audio.PositionedSoundRecord;
  19. import net.minecraft.client.audio.SoundHandler;
  20. import net.minecraft.client.gui.*;
  21. import net.minecraft.client.gui.inventory.GuiInventory;
  22. import net.minecraft.client.multiplayer.GuiConnecting;
  23. import net.minecraft.client.renderer.BufferBuilder;
  24. import net.minecraft.client.renderer.GlStateManager;
  25. import net.minecraft.client.renderer.Tessellator;
  26. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  27. import net.minecraft.client.resources.I18n;
  28. import net.minecraft.client.settings.GameSettings;
  29. import net.minecraft.init.SoundEvents;
  30. import net.minecraft.network.NetworkManager;
  31. import net.minecraft.util.ResourceLocation;
  32. import net.minecraft.util.SoundCategory;
  33. import net.minecraft.util.TabCompleter;
  34. import net.minecraft.util.Timer;
  35. import net.minecraft.util.math.MathHelper;
  36. import net.minecraft.util.text.TextFormatting;
  37. import net.minecraftforge.client.event.GuiScreenEvent;
  38. import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
  39. import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
  40. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  41. import net.minecraftforge.fml.relauncher.Side;
  42. import net.minecraftforge.fml.relauncher.SideOnly;
  43.  
  44. @EventBusSubscriber(modid = ModNanotechHungerGames.MODID, value = Side.CLIENT)
  45. public class GuiEventHandler
  46. {
  47.     private static final ResourceLocation white = new ResourceLocation(ModNanotechHungerGames.MODID, "textures/gui/white.png");
  48.     private static Timer timer = null;
  49.  
  50.     @SideOnly(Side.CLIENT)
  51.     @SubscribeEvent
  52.     public static void onGuiInitPost(GuiScreenEvent.InitGuiEvent.Post event)
  53.     {
  54.         if(event.getGui().getClass().equals(GuiIngameMenu.class))
  55.         {
  56.             NHGClient.mc.displayGuiScreen(new NHGGuiIngameMenu());
  57.         }
  58.         else if(event.getGui().getClass().equals(GuiInventory.class))
  59.         {
  60.             if(NHGClient.hasGameStarted() && NHGClient.mc.player != null)
  61.             {
  62.                 if(NHGClient.mc.player.hasCapability(NHGCommon.NHG_CAP, null))
  63.                 {
  64.                     final INHGCapability cap = NHGClient.mc.player.getCapability(NHGCommon.NHG_CAP, null);
  65.  
  66.                     Kit kit = cap.getKit();
  67.                     if(kit.hasIntegratedCraft())
  68.                     {
  69.                         event.getButtonList().add(new GuiButton(200, event.getGui().width / 2 + 10, event.getGui().height / 2 - 21, 16, 16, "")
  70.                         {
  71.                             @SideOnly(Side.CLIENT)
  72.                             @Override
  73.                             public void drawButton(Minecraft mcIn, int mouseX, int mouseY, float partialTicks)
  74.                             {
  75.                                 if(this.visible)
  76.                                 {
  77.                                     mcIn.getTextureManager().bindTexture(new ResourceLocation("nhg", "textures/gui/buttons.png"));
  78.                                     GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  79.                                     int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  80.                                     this.hovered = mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + x + this.width && mouseY < this.y + this.height;
  81.                                     GlStateManager.enableBlend();
  82.                                     GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  83.                                     GlStateManager.blendFunc(770, 771);
  84.                                     this.drawTexturedModalRect(this.x + x, this.y, 0, 0, 16, 16);
  85.                                     this.mouseDragged(mcIn, mouseX, mouseY);
  86.                                 }
  87.                             }
  88.  
  89.                             @SideOnly(Side.CLIENT)
  90.                             @Override
  91.                             public boolean mousePressed(Minecraft mcIn, int mouseX, int mouseY)
  92.                             {
  93.                                 int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  94.                                 return this.enabled && this.visible && mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + this.width + x && mouseY < this.y + this.height;
  95.                             }
  96.                         });
  97.                         event.getButtonList().add(new GuiButton(201, event.getGui().width / 2 + 28, event.getGui().height / 2 - 21, 16, 16, "")
  98.                         {
  99.                             @SideOnly(Side.CLIENT)
  100.                             @Override
  101.                             public void drawButton(Minecraft mcIn, int mouseX, int mouseY, float partialTicks)
  102.                             {
  103.                                 if(this.visible)
  104.                                 {
  105.                                     mcIn.getTextureManager().bindTexture(new ResourceLocation("nhg", "textures/gui/buttons.png"));
  106.                                     GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  107.                                     int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  108.                                     this.hovered = mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + x + this.width && mouseY < this.y + this.height;
  109.                                     GlStateManager.enableBlend();
  110.                                     GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  111.                                     GlStateManager.blendFunc(770, 771);
  112.                                     this.drawTexturedModalRect(this.x + x, this.y, cap.getIntegratedFurnace().isBurning() ? 32 : 16, 0, 16, 16);
  113.                                     this.mouseDragged(mcIn, mouseX, mouseY);
  114.                                 }
  115.                             }
  116.  
  117.                             @SideOnly(Side.CLIENT)
  118.                             @Override
  119.                             public boolean mousePressed(Minecraft mcIn, int mouseX, int mouseY)
  120.                             {
  121.                                 int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  122.                                 return this.enabled && this.visible && mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + this.width + x && mouseY < this.y + this.height;
  123.                             }
  124.                         });
  125.                     }
  126.                     if(kit.hasIntegratedEnchantTable())
  127.                     {
  128.                         event.getButtonList().add(new GuiButton(202, event.getGui().width / 2 + 46, event.getGui().height / 2 - 21, 16, 16, "")
  129.                         {
  130.                             @SideOnly(Side.CLIENT)
  131.                             @Override
  132.                             public void drawButton(Minecraft mcIn, int mouseX, int mouseY, float partialTicks)
  133.                             {
  134.                                 if(this.visible)
  135.                                 {
  136.                                     mcIn.getTextureManager().bindTexture(new ResourceLocation("nhg", "textures/gui/buttons.png"));
  137.                                     GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  138.                                     int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  139.                                     this.hovered = mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + x + this.width && mouseY < this.y + this.height;
  140.                                     GlStateManager.enableBlend();
  141.                                     GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  142.                                     GlStateManager.blendFunc(770, 771);
  143.                                     this.drawTexturedModalRect(this.x + x, this.y, 16, 16, 16, 16);
  144.                                     this.mouseDragged(mcIn, mouseX, mouseY);
  145.                                 }
  146.                             }
  147.  
  148.                             @SideOnly(Side.CLIENT)
  149.                             @Override
  150.                             public boolean mousePressed(Minecraft mcIn, int mouseX, int mouseY)
  151.                             {
  152.                                 int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  153.                                 return this.enabled && this.visible && mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + this.width + x && mouseY < this.y + this.height;
  154.                             }
  155.                         });
  156.                     }
  157.                     if(kit.hasIntegratedAnvil())
  158.                     {
  159.                         event.getButtonList().add(new GuiButton(203, event.getGui().width / 2 + 64, event.getGui().height / 2 - 21, 16, 16, "")
  160.                         {
  161.                             @SideOnly(Side.CLIENT)
  162.                             @Override
  163.                             public void drawButton(Minecraft mcIn, int mouseX, int mouseY, float partialTicks)
  164.                             {
  165.                                 if(this.visible)
  166.                                 {
  167.                                     mcIn.getTextureManager().bindTexture(new ResourceLocation("nhg", "textures/gui/buttons.png"));
  168.                                     GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  169.                                     int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  170.                                     this.hovered = mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + x + this.width && mouseY < this.y + this.height;
  171.                                     GlStateManager.enableBlend();
  172.                                     GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  173.                                     GlStateManager.blendFunc(770, 771);
  174.                                     this.drawTexturedModalRect(this.x + x, this.y, 32, 16, 16, 16);
  175.                                     this.mouseDragged(mcIn, mouseX, mouseY);
  176.                                 }
  177.                             }
  178.  
  179.                             @SideOnly(Side.CLIENT)
  180.                             @Override
  181.                             public boolean mousePressed(Minecraft mcIn, int mouseX, int mouseY)
  182.                             {
  183.                                 int x = mcIn.player.getActivePotionEffects().isEmpty() ? 0 : 60;
  184.                                 return this.enabled && this.visible && mouseX >= this.x + x && mouseY >= this.y && mouseX < this.x + this.width + x && mouseY < this.y + this.height;
  185.                             }
  186.                         });
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.         else if(event.getGui().getClass().equals(GuiChat.class))
  192.         {
  193.             if(ClientEventHandler.INSTANCE.isTeamEnabled() && NHGClient.mc.player.hasCapability(NHGCommon.NHG_CAP, null))
  194.             {
  195.                 if(NHGClient.mc.player.getCapability(NHGCommon.NHG_CAP, null).hasTeam())
  196.                 {
  197.                     GuiBooleanButton teamButton = new GuiBooleanButton(150, event.getGui().width / 2 - 60, 10, 120, 20, "", NHGClient.teamChatOnly());
  198.                     teamButton.setTexts(I18n.format("gui.chat.team", TextFormatting.GREEN + I18n.format("gui.yes")), I18n.format("gui.chat.team", I18n.format("gui.no")));
  199.                     event.getButtonList().add(teamButton);
  200.                 }
  201.             }
  202.         }
  203.         else if(event.getGui().getClass().equals(GuiScreenOptionsSounds.class))
  204.         {
  205.             event.getButtonList().clear();
  206.  
  207.             int i = 0;
  208.             event.getButtonList().add(new SndButton(SoundCategory.MASTER.ordinal(), event.getGui().width / 2 - 155 + i % 2 * 160, event.getGui().height / 6 - 12 + 24 * (i >> 1), SoundCategory.MASTER, true));
  209.             i = i + 2;
  210.             for(SoundCategory soundcategory : SoundCategory.values())
  211.             {
  212.                 if(soundcategory != SoundCategory.MASTER)
  213.                 {
  214.                     event.getButtonList().add(new SndButton(soundcategory.ordinal(), event.getGui().width / 2 - 155 + i % 2 * 160, event.getGui().height / 6 - 12 + 24 * (i >> 1), soundcategory, false));
  215.                     ++i;
  216.                 }
  217.             }
  218.  
  219.             int j = event.getGui().width / 2 - 75;
  220.             int k = event.getGui().height / 6 - 12;
  221.             ++i;
  222.             event.getButtonList().add(new GuiOptionButton(201, j, k + 24 * (i >> 1), GameSettings.Options.SHOW_SUBTITLES, NHGClient.mc.gameSettings.getKeyBinding(GameSettings.Options.SHOW_SUBTITLES)));
  223.             event.getButtonList().add(new GuiButton(200, event.getGui().width / 2 - 100, event.getGui().height / 6 + 168, I18n.format("gui.done")));
  224.         }
  225.     }
  226.  
  227.     @SideOnly(Side.CLIENT)
  228.     @SubscribeEvent
  229.     public static void onActionPerformedPre(GuiScreenEvent.ActionPerformedEvent.Pre event)
  230.     {
  231.         if(event.getGui().getClass().equals(GuiInventory.class))
  232.         {
  233.             if(NHGClient.hasGameStarted() && NHGClient.mc.player != null)
  234.             {
  235.                 if(event.getButton().id == 200)
  236.                 {
  237.                     NHGNetwork.network.sendToServer(new PacketRequestCrafterGui(0));
  238.                 }
  239.                 else if(event.getButton().id == 201)
  240.                 {
  241.                     NHGNetwork.network.sendToServer(new PacketRequestCrafterGui(1));
  242.                 }
  243.                 else if(event.getButton().id == 202)
  244.                 {
  245.                     NHGNetwork.network.sendToServer(new PacketRequestCrafterGui(3));
  246.                 }
  247.                 else if(event.getButton().id == 203)
  248.                 {
  249.                     NHGNetwork.network.sendToServer(new PacketRequestCrafterGui(4));
  250.                 }
  251.             }
  252.         }
  253.         else if(event.getGui().getClass().equals(GuiChat.class))
  254.         {
  255.             if(event.getButton().id == 150)
  256.             {
  257.                 ((GuiBooleanButton)event.getButton()).toggle();
  258.                 NHGClient.toogleTeamChatOnly();
  259.             }
  260.         }
  261.     }
  262.  
  263.     @SideOnly(Side.CLIENT)
  264.     @SubscribeEvent
  265.     public static void onGuiKeyTyped(GuiScreenEvent.KeyboardInputEvent.Pre event)
  266.     {
  267.         if(event.getGui().getClass().equals(GuiChat.class) && ClientEventHandler.INSTANCE.isTeamEnabled())
  268.         {
  269.             if(NHGClient.mc.player.hasCapability(NHGCommon.NHG_CAP, null))
  270.             {
  271.                 if(NHGClient.mc.player.getCapability(NHGCommon.NHG_CAP, null).hasTeam())
  272.                 {
  273.                     char typedChar = Keyboard.getEventCharacter();
  274.                     if(Keyboard.getEventKey() == 0 && typedChar >= 32 || Keyboard.getEventKeyState())
  275.                     {
  276.                         event.setCanceled(true);
  277.                         TabCompleter tabCompleter = ObfuscationReflectionHelper.getPrivateValue(GuiChat.class, (GuiChat)event.getGui(), "tabCompleter", "field_184096_i");
  278.                         GuiTextField inputField = ObfuscationReflectionHelper.getPrivateValue(GuiChat.class, (GuiChat)event.getGui(), "inputField", "field_146415_a");
  279.                         int keyCode = Keyboard.getEventKey();
  280.  
  281.                         tabCompleter.resetRequested();
  282.  
  283.                         if(keyCode == 15)
  284.                         {
  285.                             tabCompleter.complete();
  286.                         }
  287.                         else
  288.                         {
  289.                             tabCompleter.resetDidComplete();
  290.                         }
  291.  
  292.                         if(keyCode == 1)
  293.                         {
  294.                             NHGClient.mc.displayGuiScreen(null);
  295.                         }
  296.                         else if(keyCode != 28 && keyCode != 156)
  297.                         {
  298.                             if(keyCode == 200)
  299.                             {
  300.                                 ((GuiChat)event.getGui()).getSentHistory(-1);
  301.                             }
  302.                             else if(keyCode == 208)
  303.                             {
  304.                                 ((GuiChat)event.getGui()).getSentHistory(1);
  305.                             }
  306.                             else if(keyCode == 201)
  307.                             {
  308.                                 NHGClient.mc.ingameGUI.getChatGUI().scroll(NHGClient.mc.ingameGUI.getChatGUI().getLineCount() - 1);
  309.                             }
  310.                             else if(keyCode == 209)
  311.                             {
  312.                                 NHGClient.mc.ingameGUI.getChatGUI().scroll(-NHGClient.mc.ingameGUI.getChatGUI().getLineCount() + 1);
  313.                             }
  314.                             else
  315.                             {
  316.                                 inputField.textboxKeyTyped(typedChar, keyCode);
  317.                             }
  318.                         }
  319.                         else
  320.                         {
  321.                             String s = inputField.getText().trim();
  322.  
  323.                             if(!s.isEmpty())
  324.                             {
  325.                                 if(ClientEventHandler.INSTANCE.isTeamEnabled() && NHGClient.mc.player.hasCapability(NHGCommon.getNHGCap(), null) && NHGClient.mc.player.getCapability(NHGCommon.getNHGCap(), null).hasTeam())
  326.                                 {
  327.                                     event.getGui().sendChatMessage((NHGClient.teamChatOnly() ? "{Team} " : "") + s);
  328.                                 }
  329.                                 else
  330.                                 {
  331.                                     event.getGui().sendChatMessage(s);
  332.                                 }
  333.                             }
  334.  
  335.                             NHGClient.mc.displayGuiScreen(null);
  336.                         }
  337.                     }
  338.                 }
  339.             }
  340.         }
  341.     }
  342.  
  343.     @SideOnly(Side.CLIENT)
  344.     @SubscribeEvent
  345.     public static void onPreDrawGui(GuiScreenEvent.DrawScreenEvent.Pre event)
  346.     {
  347.         if(event.getGui().getClass().equals(GuiMainMenu.class))
  348.         {
  349.             GlStateManager.color(1.0F, 1.0F, 1.0F);
  350.             NHGClient.mc.renderEngine.bindTexture(white);
  351.             Tessellator tessellator = Tessellator.getInstance();
  352.             BufferBuilder worldrenderer = tessellator.getBuffer();
  353.             worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
  354.             worldrenderer.pos(0.0D, event.getGui().height, 1000.0D).tex(0.0D, 1.0D).endVertex();
  355.             worldrenderer.pos(event.getGui().width, event.getGui().height, 1000.0D).tex(1.0D, 1.0D).endVertex();
  356.             worldrenderer.pos(event.getGui().width, 0.0D, 1000.0D).tex(1.0D, 0.0D).endVertex();
  357.             worldrenderer.pos(0.0D, 0.0D, 1000.0D).tex(0.0D, 0.0D).endVertex();
  358.             tessellator.draw();
  359.         }
  360.         else if(event.getGui().getClass().equals(GuiConnecting.class))
  361.         {
  362.             event.setCanceled(true);
  363.  
  364.             float zlevel = ObfuscationReflectionHelper.getPrivateValue(Gui.class, event.getGui(), "zLevel", "field_77023_b", "field_73735_i");
  365.             NHGPanorama.instance.draw(event.getRenderPartialTicks(), event.getGui().width, event.getGui().height, zlevel);
  366.  
  367.             NetworkManager networkManager = ObfuscationReflectionHelper.getPrivateValue(GuiConnecting.class, (GuiConnecting)event.getGui(), "networkManager", "field_146371_g", "field_147313_b", "field_147333_a", "field_147384_b", "field_147386_b", "field_147393_d", "field_151272_f");
  368.             if(networkManager == null)
  369.             {
  370.                 event.getGui().drawCenteredString(event.getGui().mc.fontRenderer, I18n.format("connect.connecting"), event.getGui().width / 2, event.getGui().height / 2 - 50, 16777215);
  371.             }
  372.             else
  373.             {
  374.                 event.getGui().drawCenteredString(event.getGui().mc.fontRenderer, I18n.format("connect.authorizing"), event.getGui().width / 2, event.getGui().height / 2 - 50, 16777215);
  375.             }
  376.  
  377.             List<GuiButton> buttonList = ObfuscationReflectionHelper.getPrivateValue(GuiScreen.class, event.getGui(), "buttonList", "field_146292_n");
  378.             buttonList.forEach(button -> button.drawButton(NHGClient.mc, event.getMouseX(), event.getMouseY(), 0.0F)); // TODO Change 0.0F
  379.  
  380.             List<GuiLabel> labelList = ObfuscationReflectionHelper.getPrivateValue(GuiScreen.class, event.getGui(), "labelList", "field_146293_o");
  381.             labelList.forEach(label -> label.drawLabel(NHGClient.mc, event.getMouseX(), event.getMouseY()));
  382.  
  383.         }
  384.         else if(event.getGui().getClass().equals(GuiDisconnected.class))
  385.         {
  386.             event.setCanceled(true);
  387.             float zlevel = ObfuscationReflectionHelper.getPrivateValue(Gui.class, event.getGui(), "zLevel", "field_77023_b", "field_73735_i");
  388.             NHGPanorama.instance.draw(event.getRenderPartialTicks(), event.getGui().width, event.getGui().height, zlevel);
  389.  
  390.             String reason = ObfuscationReflectionHelper.getPrivateValue(GuiDisconnected.class, (GuiDisconnected)event.getGui(), "reason", "field_73693_g", "field_146306_a", "field_149167_a", "field_149605_a");
  391.             int field_175353_i = ObfuscationReflectionHelper.getPrivateValue(GuiDisconnected.class, (GuiDisconnected)event.getGui(), "field_175353_i");
  392.             List<String> multilineMessage = ObfuscationReflectionHelper.getPrivateValue(GuiDisconnected.class, (GuiDisconnected)event.getGui(), "multilineMessage", "field_146305_g");
  393.             event.getGui().drawCenteredString(event.getGui().mc.fontRenderer, reason, event.getGui().width / 2, event.getGui().height / 2 - field_175353_i / 2 - event.getGui().mc.fontRenderer.FONT_HEIGHT * 2, 11184810);
  394.  
  395.             int k2 = event.getGui().height / 2 - field_175353_i / 2;
  396.  
  397.             if(multilineMessage != null)
  398.             {
  399.                 for(Iterator<String> iterator = multilineMessage.iterator(); iterator.hasNext(); k2 += event.getGui().mc.fontRenderer.FONT_HEIGHT)
  400.                 {
  401.                     String s = iterator.next();
  402.                     event.getGui().drawCenteredString(event.getGui().mc.fontRenderer, s, event.getGui().width / 2, k2, 16777215);
  403.                 }
  404.             }
  405.  
  406.             List<GuiButton> buttonList = ObfuscationReflectionHelper.getPrivateValue(GuiScreen.class, event.getGui(), "buttonList", "field_146292_n");
  407.             buttonList.forEach(button -> button.drawButton(NHGClient.mc, event.getMouseX(), event.getMouseY(), 0.0F)); // TODO Change 0.0F
  408.  
  409.             List<GuiLabel> labelList = ObfuscationReflectionHelper.getPrivateValue(GuiScreen.class, event.getGui(), "labelList", "field_146293_o");
  410.             labelList.forEach(label -> label.drawLabel(NHGClient.mc, event.getMouseX(), event.getMouseY()));
  411.         }
  412.     }
  413.  
  414.     @SideOnly(Side.CLIENT)
  415.     @SubscribeEvent
  416.     public static void onPostDrawGui(GuiScreenEvent.DrawScreenEvent.Post event)
  417.     {
  418.         if(ClientEventHandler.INSTANCE.cheatWarn)
  419.         {
  420.             event.getGui().drawString(NHGClient.mc.fontRenderer, I18n.format("gui.cheat", ClientEventHandler.INSTANCE.cheatTimer / 20), 20, 20, 0xFF5555);
  421.         }
  422.     }
  423.  
  424.     @SideOnly(Side.CLIENT)
  425.     @SubscribeEvent
  426.     public static void onDrawBackGround(GuiScreenEvent.BackgroundDrawnEvent event)
  427.     {
  428.         if(timer == null)
  429.         {
  430.             timer = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, NHGClient.mc, "timer", "field_71428_T");
  431.         }
  432.  
  433.         if(NHGClient.mc.world == null)
  434.         {
  435.             NHGPanorama.instance.draw(timer.renderPartialTicks, event.getGui().width, event.getGui().height, 0.00001F);
  436.         }
  437.     }
  438.  
  439.     /**
  440.      * Clone of GuiScreenOptionsSounds.Button
  441.      */
  442.     @SideOnly(Side.CLIENT)
  443.     public static class SndButton extends GuiButton
  444.     {
  445.         private static final ResourceLocation btnTexture = new ResourceLocation("nhg:textures/gui/buttons.png");
  446.         private final SoundCategory category;
  447.         private final String categoryName;
  448.         public float volume = 1.0F;
  449.         public boolean pressed;
  450.  
  451.         public SndButton(int id, int x, int y, SoundCategory categoryIn, boolean master)
  452.         {
  453.             super(id, x, y, master ? 310 : 150, 20, "");
  454.             this.category = categoryIn;
  455.             this.categoryName = I18n.format("soundCategory." + categoryIn.getName());
  456.             this.displayString = this.categoryName + ": " + getDisplayString(categoryIn);
  457.             this.volume = NHGClient.mc.gameSettings.getSoundLevel(categoryIn);
  458.         }
  459.  
  460.         /**
  461.          * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over this button.
  462.          */
  463.         @Override
  464.         protected int getHoverState(boolean mouseOver)
  465.         {
  466.             return 0;
  467.         }
  468.  
  469.         /**
  470.          * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
  471.          */
  472.         @Override
  473.         protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
  474.         {
  475.             if(this.visible)
  476.             {
  477.                 if(this.pressed)
  478.                 {
  479.                     this.volume = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
  480.                     this.volume = MathHelper.clamp(this.volume, 0.0F, 1.0F);
  481.                     mc.gameSettings.setSoundLevel(this.category, this.volume);
  482.                     mc.gameSettings.saveOptions();
  483.                     this.displayString = this.categoryName + ": " + getDisplayString(this.category);
  484.                 }
  485.                 // NHGPatch-----old
  486.                 // GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  487.                 // this.drawTexturedModalRect(this.xPosition + (int)(this.volume * (this.width - 8)), this.yPosition, 0, 66, 4, 20);
  488.                 // this.drawTexturedModalRect(this.xPosition + (int)(this.volume * (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
  489.                 // NHGPatch-----new
  490.                 mc.getTextureManager().bindTexture(btnTexture);
  491.                 this.drawTexturedModalRect(this.x + (int)(this.volume * (this.width - 8)), this.y, 200, 0, 8, 20);
  492.                 // NHGPatch-----end
  493.             }
  494.         }
  495.  
  496.         /**
  497.          * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent e).
  498.          */
  499.         @Override
  500.         public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
  501.         {
  502.             if(super.mousePressed(mc, mouseX, mouseY))
  503.             {
  504.                 this.volume = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
  505.                 this.volume = MathHelper.clamp(this.volume, 0.0F, 1.0F);
  506.                 mc.gameSettings.setSoundLevel(this.category, this.volume);
  507.                 mc.gameSettings.saveOptions();
  508.                 this.displayString = this.categoryName + ": " + getDisplayString(this.category);
  509.                 this.pressed = true;
  510.                 return true;
  511.             }
  512.             else
  513.             {
  514.                 return false;
  515.             }
  516.         }
  517.  
  518.         @Override
  519.         public void playPressSound(SoundHandler soundHandlerIn)
  520.         {}
  521.  
  522.         /**
  523.          * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
  524.          */
  525.         @Override
  526.         public void mouseReleased(int mouseX, int mouseY)
  527.         {
  528.             if(this.pressed)
  529.             {
  530.                 NHGClient.mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  531.             }
  532.  
  533.             this.pressed = false;
  534.         }
  535.  
  536.         public String getDisplayString(SoundCategory categoryIn)
  537.         {
  538.             float f = NHGClient.mc.gameSettings.getSoundLevel(categoryIn);
  539.             return f == 0.0F ? I18n.format("options.off") : (int)(f * 100.0F) + "%";
  540.         }
  541.     }
  542. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement