Advertisement
Alex2772

bee.class

Jun 19th, 2015
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 32.26 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.DataInputStream;
  6. import java.io.DataOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.io.OutputStream;
  11. import java.net.InetAddress;
  12. import java.net.InetSocketAddress;
  13. import java.net.Socket;
  14. import java.net.SocketAddress;
  15. import java.net.URI;
  16. import java.util.ArrayList;
  17. import java.util.Calendar;
  18. import java.util.Date;
  19. import java.util.Random;
  20.  
  21. import net.minecraft.client.Minecraft;
  22. import net.minecraft.client.multiplayer.GuiConnecting;
  23. import net.minecraft.client.multiplayer.ServerData;
  24. import net.minecraft.client.renderer.OpenGlHelper;
  25. import net.minecraft.client.renderer.Tessellator;
  26. import net.minecraft.client.renderer.texture.DynamicTexture;
  27. import net.minecraft.client.resources.I18n;
  28. import net.minecraft.realms.RealmsBridge;
  29. import net.minecraft.util.EnumChatFormatting;
  30. import net.minecraft.util.MathHelper;
  31. import net.minecraft.util.ResourceLocation;
  32. import net.minecraft.world.demo.DemoWorldServer;
  33. import net.minecraft.world.storage.ISaveFormat;
  34. import net.minecraft.world.storage.WorldInfo;
  35.  
  36. import org.apache.commons.io.Charsets;
  37. import org.apache.logging.log4j.LogManager;
  38. import org.apache.logging.log4j.Logger;
  39. import org.lwjgl.opengl.GL11;
  40. import org.lwjgl.opengl.GLContext;
  41. import org.lwjgl.util.glu.Project;
  42.  
  43. import com.google.gson.Gson;
  44. import com.google.gson.JsonElement;
  45. import com.google.gson.JsonObject;
  46. import com.google.gson.JsonParser;
  47.  
  48. import cpw.mods.fml.client.FMLClientHandler;
  49.  
  50. public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback
  51. {
  52.     static boolean loaded = false;
  53.     //Настройки
  54.    
  55.     public static String serverIp = "localhost"; //IP сервака
  56.     public static String serverPort = "25565"; //Порт сервака
  57.     public static String siteAddress = "http://mysuperproject.ru/"; //Адрес сайта (с протоколом!). Укадите "none", если Вам это не надо.
  58.     public static String forumAddress = "http://forum.mysuperproject.ru/"; //Адрес форума (с протоколом!). Укадите "none", если Вам это не надо.
  59.    
  60.     public static String joinToServer = "§bЗайти на сервер§3:"; //Текст для кнопки мультиплеера (если сервер онлайн)
  61.     public static String numberOfPlayersColor = "§a"; //Цвет значения количества человек на сервере
  62.     public static String dividerColor = "§2"; //Цвет слеша для разделения количества человек от маскимального количества человек
  63.     public static String serverIsNotResponding = "Сервер недоступен"; //Если сервер недоступен, мало ли у человека инет говно (или хост :D)
  64.     private String waitTime = "10"; //Каждые waitTime сек будет обновляться онлайн
  65.     public static String updating = "§7Обновление..."; //Обновление
  66.    
  67.     private String bottomLeftText = "Текст слева"; //Для удобства
  68.     private String bottomRightText = "Текст справа"; //Тоже для удобства
  69.     private String customSplash = "helloPlayer"; //Жёстко установить значение сплеша (пульсирующего жёлтого текста)
  70.     private String ourSite = "§aНаш сайт"; //Текст кнопки для сайта
  71.     private String ourForum = "§1Форум"; //Текст кнопки для форума
  72.    
  73.     private static final Logger logger = LogManager.getLogger();
  74.  
  75.     /** The RNG used by the Main Menu Screen. */
  76.     private static final Random rand = new Random();
  77.  
  78.     /** Counts the number of screen updates. */
  79.     private float updateCounter;
  80.  
  81.     /** The splash message. */
  82.     private String splashText;
  83.     private GuiButton buttonResetDemo;
  84.  
  85.     /** Timer used to rotate the panorama, increases every tick. */
  86.     private int panoramaTimer;
  87.  
  88.     /**
  89.      * Texture allocated for the current viewport of the main menu's panorama background.
  90.      */
  91.     private DynamicTexture viewportTexture;
  92.     private final Object field_104025_t = new Object();
  93.     private String field_92025_p;
  94.     private String field_146972_A;
  95.     private String field_104024_v;
  96.     private static final ResourceLocation splashTexts = new ResourceLocation("texts/splashes.txt");
  97.     private static final ResourceLocation minecraftTitleTextures = new ResourceLocation("textures/gui/title/minecraft.png");
  98.  
  99.     /** An array of all the paths to the panorama pictures. */
  100.     private static final ResourceLocation[] titlePanoramaPaths = new ResourceLocation[] {new ResourceLocation("textures/gui/title/background/panorama_0.png"), new ResourceLocation("textures/gui/title/background/panorama_1.png"), new ResourceLocation("textures/gui/title/background/panorama_2.png"), new ResourceLocation("textures/gui/title/background/panorama_3.png"), new ResourceLocation("textures/gui/title/background/panorama_4.png"), new ResourceLocation("textures/gui/title/background/panorama_5.png")};
  101.     public static final String field_96138_a = "Please click " + EnumChatFormatting.UNDERLINE + "here" + EnumChatFormatting.RESET + " for more information.";
  102.     private int field_92024_r;
  103.     private int field_92023_s;
  104.     private int field_92022_t;
  105.     private int field_92021_u;
  106.     private int field_92020_v;
  107.     private int field_92019_w;
  108.     private ResourceLocation field_110351_G;
  109.     private static final String __OBFID = "CL_00001154";
  110.     public GuiMainMenu()
  111.     {
  112.         this.field_146972_A = field_96138_a;
  113.         this.splashText = "missingno";
  114.         BufferedReader var1 = null;
  115.  
  116.         try
  117.         {
  118.             ArrayList var2 = new ArrayList();
  119.             var1 = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(splashTexts).getInputStream(), Charsets.UTF_8));
  120.             String var3;
  121.  
  122.             while ((var3 = var1.readLine()) != null)
  123.             {
  124.                 var3 = var3.trim();
  125.  
  126.                 if (!var3.isEmpty())
  127.                 {
  128.                     var2.add(var3);
  129.                 }
  130.             }
  131.  
  132.             if (!var2.isEmpty())
  133.             {
  134.                 do
  135.                 {
  136.                     this.splashText = (String)var2.get(rand.nextInt(var2.size()));
  137.                 }
  138.                 while (this.splashText.hashCode() == 125780783);
  139.             }
  140.         }
  141.         catch (IOException var12)
  142.         {
  143.             ;
  144.         }
  145.         finally
  146.         {
  147.             if (var1 != null)
  148.             {
  149.                 try
  150.                 {
  151.                     var1.close();
  152.                 }
  153.                 catch (IOException var11)
  154.                 {
  155.                     ;
  156.                 }
  157.             }
  158.         }
  159.  
  160.         this.updateCounter = rand.nextFloat();
  161.         this.field_92025_p = "";
  162.  
  163.         if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.func_153193_b())
  164.         {
  165.             this.field_92025_p = I18n.format("title.oldgl1", new Object[0]);
  166.             this.field_146972_A = I18n.format("title.oldgl2", new Object[0]);
  167.             this.field_104024_v = "https://help.mojang.com/customer/portal/articles/325948?ref=game";
  168.         }
  169.         FMLClientHandler.instance().setupServerList();
  170.     }
  171.  
  172.     /**
  173.      * Called from the main game loop to update the screen.
  174.      */
  175.     public void updateScreen()
  176.     {
  177.         ++this.panoramaTimer;
  178.     }
  179.  
  180.     /**
  181.      * Returns true if this GUI should pause the game when it is displayed in single-player
  182.      */
  183.     public boolean doesGuiPauseGame()
  184.     {
  185.         return false;
  186.     }
  187.  
  188.     /**
  189.      * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  190.      */
  191.     protected void keyTyped(char p_73869_1_, int p_73869_2_) {}
  192.  
  193.     /**
  194.      * Adds the buttons (and other controls) to the screen in question.
  195.      */
  196.     public void initGui()
  197.     {
  198.         this.viewportTexture = new DynamicTexture(256, 256);
  199.         this.field_110351_G = this.mc.getTextureManager().getDynamicTextureLocation("background", this.viewportTexture);
  200.         Calendar var1 = Calendar.getInstance();
  201.         var1.setTime(new Date());
  202.  
  203.         if (var1.get(2) + 1 == 11 && var1.get(5) == 9)
  204.         {
  205.             this.splashText = "С Днём рождения, ez!";
  206.         }
  207.         else if (var1.get(2) + 1 == 6 && var1.get(5) == 1)
  208.         {
  209.             this.splashText = "С Днём рождения, Notch!";
  210.         }
  211.         else if (var1.get(2) + 1 == 12 && var1.get(5) == 24)
  212.         {
  213.             this.splashText = "С Рождеством!";
  214.         }
  215.         else if (var1.get(2) + 1 == 12 && var1.get(5) == 31) {
  216.             this.splashText = "Скорее бы!";
  217.         }
  218.         else if (var1.get(2) + 1 == 1 && var1.get(5) == 1)
  219.         {
  220.             this.splashText = "С Новым годом!";
  221.         }
  222.         else if (var1.get(2) + 1 == 10 && var1.get(5) == 31)
  223.         {
  224.             this.splashText = "ОООоооООООоооо! Страшно!";
  225.         }
  226.         else if (var1.get(2) + 1 == 5 && var1.get(5) == 9)
  227.         {
  228.             this.splashText = "Слава ветеранам!";
  229.         }
  230.         else if (var1.get(2) + 1 == 6 && var1.get(5) == 12)
  231.         {
  232.             this.splashText = "Россия - наша держава!";
  233.         }
  234.         else if (var1.get(2) + 1 == 7 && var1.get(5) == 15)
  235.         {
  236.             this.splashText = "1-ая половина лета просрана успешно";
  237.         }
  238.         else if (var1.get(2) + 1 == 8 && var1.get(5) == 31)
  239.         {
  240.             this.splashText = "Завтра самый ужасный день :(";
  241.         }
  242.         else if (var1.get(2) + 1 == 9 && var1.get(5) == 1)
  243.         {
  244.             this.splashText = "Этот день настал D:";
  245.         }
  246.         else {
  247.             if (customSplash=="helloPlayer") {
  248.                 this.splashText = "Привет, " + this.mc.getSession().getUsername() + "!";
  249.             } else
  250.             this.splashText = customSplash;
  251.         }
  252.  
  253.         boolean var2 = true;
  254.         int var3 = this.height / 4 + 48;
  255.  
  256.         if (this.mc.isDemo())
  257.         {
  258.             this.addDemoButtons(var3, 24);
  259.         }
  260.         else
  261.         {
  262.             this.addSingleplayerMultiplayerButtons(var3, 24);
  263.         }
  264.  
  265.         this.buttonList.add(new GuiButton(0, this.width / 2 - 100, var3 + 72 + 12, 98, 20, I18n.format("menu.options", new Object[0])));
  266.         this.buttonList.add(new GuiButton(4, this.width / 2 + 2, var3 + 72 + 12, 98, 20, I18n.format("menu.quit", new Object[0])));
  267.         this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, var3 + 72 + 12));
  268.         Object var4 = this.field_104025_t;
  269.  
  270.         synchronized (this.field_104025_t)
  271.         {
  272.             this.field_92023_s = this.fontRendererObj.getStringWidth(this.field_92025_p);
  273.             this.field_92024_r = this.fontRendererObj.getStringWidth(this.field_146972_A);
  274.             int var5 = Math.max(this.field_92023_s, this.field_92024_r);
  275.             this.field_92022_t = (this.width - var5) / 2;
  276.             this.field_92021_u = ((GuiButton)this.buttonList.get(0)).field_146129_i - 24;
  277.             this.field_92020_v = this.field_92022_t + var5;
  278.             this.field_92019_w = this.field_92021_u + 24;
  279.         }
  280.     }
  281.  
  282.     /**
  283.      * Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game.
  284.      */
  285.     GuiButton mult;
  286.     int time = Integer.valueOf(waitTime);
  287.     boolean isTimerStarted = false;
  288.     private void addSingleplayerMultiplayerButtons(int p_73969_1_, int p_73969_2_)
  289.     {
  290.         this.buttonList.add(new GuiButton(1, this.width / 2 - 100, p_73969_1_, I18n.format("menu.singleplayer", new Object[0])));
  291.         mult = new GuiButton(2, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 1, I18n.format("menu.multiplayer", new Object[0]));
  292.         getOnlineMaxOnline(mult);
  293.         this.buttonList.add(mult);
  294.         if (siteAddress!="none" && forumAddress=="none") this.buttonList.add(new GuiButton(14, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 2, I18n.format(ourSite, new Object[0])));
  295.         else if (siteAddress!="none" && forumAddress!="none") {
  296.             this.buttonList.add(new GuiButton(14, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.format(ourSite, new Object[0])));
  297.             this.buttonList.add(new GuiButton(400, this.width / 2 + 2, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.format(ourForum, new Object[0])));
  298.         }
  299.         Thread timer = new Thread(new Runnable(){
  300.             @Override
  301.             public void run() {
  302.                 while (true) {
  303.                     for (int i=time; i>0; i--) {
  304.                         try {
  305.                             time = i;
  306.                             Thread.sleep(1000);
  307.                         } catch (InterruptedException e) {
  308.                             e.printStackTrace();
  309.                         }
  310.                     }
  311.                     loaded = false;
  312.                     time = Integer.valueOf(waitTime);
  313.                     getOnlineMaxOnline(mult);
  314.                 }
  315.             }
  316.         });
  317.         if (!isTimerStarted) {
  318.             timer.start();
  319.             isTimerStarted = true;
  320.         }
  321.     }
  322.  
  323.     /**
  324.      * Adds Demo buttons on Main Menu for players who are playing Demo.
  325.      */
  326.     private void addDemoButtons(int p_73972_1_, int p_73972_2_)
  327.     {
  328.         this.buttonList.add(new GuiButton(11, this.width / 2 - 100, p_73972_1_, I18n.format("menu.playdemo", new Object[0])));
  329.         this.buttonList.add(this.buttonResetDemo = new GuiButton(12, this.width / 2 - 100, p_73972_1_ + p_73972_2_ * 1, I18n.format("menu.resetdemo", new Object[0])));
  330.         ISaveFormat var3 = this.mc.getSaveLoader();
  331.         WorldInfo var4 = var3.getWorldInfo("Demo_World");
  332.  
  333.         if (var4 == null)
  334.         {
  335.             this.buttonResetDemo.enabled = false;
  336.         }
  337.     }
  338.  
  339.     protected void actionPerformed(GuiButton p_146284_1_)
  340.     {
  341.         if (p_146284_1_.id == 0)
  342.         {
  343.             this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
  344.         }
  345.  
  346.         if (p_146284_1_.id == 5)
  347.         {
  348.             this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings, this.mc.getLanguageManager()));
  349.         }
  350.  
  351.         if (p_146284_1_.id == 1)
  352.         {
  353.             this.mc.displayGuiScreen(new GuiSelectWorld(this));
  354.         }
  355.  
  356.         if (p_146284_1_.id == 2)
  357.         {
  358.             FMLClientHandler.instance().connectToServer(this, new ServerData("MySuperServer", serverIp+":"+serverPort));
  359.         }
  360.         if (p_146284_1_.id == 14)
  361.         {
  362.             try
  363.             {
  364.                 Class var3 = Class.forName("java.awt.Desktop");
  365.                 Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
  366.                 var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {new URI(siteAddress)});
  367.             }
  368.             catch (Throwable var5)
  369.             {
  370.                 logger.error("Couldn\'t open link", var5);
  371.             }
  372.         }
  373.         if (p_146284_1_.id == 400)
  374.         {
  375.             try
  376.             {
  377.                 Class var3 = Class.forName("java.awt.Desktop");
  378.                 Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
  379.                 var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {new URI(forumAddress)});
  380.             }
  381.             catch (Throwable var5)
  382.             {
  383.                 logger.error("Couldn\'t open link", var5);
  384.             }
  385.         }
  386.         if (p_146284_1_.id == 4)
  387.         {
  388.             this.mc.shutdown();
  389.         }
  390.  
  391.         if (p_146284_1_.id == 11)
  392.         {
  393.             this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings);
  394.         }
  395.  
  396.         if (p_146284_1_.id == 12)
  397.         {
  398.             ISaveFormat var2 = this.mc.getSaveLoader();
  399.             WorldInfo var3 = var2.getWorldInfo("Demo_World");
  400.  
  401.             if (var3 != null)
  402.             {
  403.                 GuiYesNo var4 = GuiSelectWorld.func_152129_a(this, var3.getWorldName(), 12);
  404.                 this.mc.displayGuiScreen(var4);
  405.             }
  406.         }
  407.     }
  408.  
  409.     private void func_140005_i()
  410.     {
  411.         RealmsBridge var1 = new RealmsBridge();
  412.         var1.switchToRealms(this);
  413.     }
  414.  
  415.     public void confirmClicked(boolean p_73878_1_, int p_73878_2_)
  416.     {
  417.         if (p_73878_1_ && p_73878_2_ == 12)
  418.         {
  419.             ISaveFormat var6 = this.mc.getSaveLoader();
  420.             var6.flushCache();
  421.             var6.deleteWorldDirectory("Demo_World");
  422.             this.mc.displayGuiScreen(this);
  423.         }
  424.         else if (p_73878_2_ == 13)
  425.         {
  426.             if (p_73878_1_)
  427.             {
  428.                 try
  429.                 {
  430.                     Class var3 = Class.forName("java.awt.Desktop");
  431.                     Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
  432.                     var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {new URI(this.field_104024_v)});
  433.                 }
  434.                 catch (Throwable var5)
  435.                 {
  436.                     logger.error("Couldn\'t open link", var5);
  437.                 }
  438.             }
  439.  
  440.             this.mc.displayGuiScreen(this);
  441.         }
  442.     }
  443.  
  444.     /**
  445.      * Draws the main menu panorama
  446.      */
  447.     private void drawPanorama(int p_73970_1_, int p_73970_2_, float p_73970_3_)
  448.     {
  449.         Tessellator var4 = Tessellator.instance;
  450.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  451.         GL11.glPushMatrix();
  452.         GL11.glLoadIdentity();
  453.         Project.gluPerspective(120.0F, 1.0F, 0.05F, 10.0F);
  454.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  455.         GL11.glPushMatrix();
  456.         GL11.glLoadIdentity();
  457.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  458.         GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
  459.         GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
  460.         GL11.glEnable(GL11.GL_BLEND);
  461.         GL11.glDisable(GL11.GL_ALPHA_TEST);
  462.         GL11.glDisable(GL11.GL_CULL_FACE);
  463.         GL11.glDepthMask(false);
  464.         OpenGlHelper.glBlendFunc(770, 771, 1, 0);
  465.         byte var5 = 8;
  466.  
  467.         for (int var6 = 0; var6 < var5 * var5; ++var6)
  468.         {
  469.             GL11.glPushMatrix();
  470.             float var7 = ((float)(var6 % var5) / (float)var5 - 0.5F) / 64.0F;
  471.             float var8 = ((float)(var6 / var5) / (float)var5 - 0.5F) / 64.0F;
  472.             float var9 = 0.0F;
  473.             GL11.glTranslatef(var7, var8, var9);
  474.             GL11.glRotatef(MathHelper.sin(((float)this.panoramaTimer + p_73970_3_) / 400.0F) * 25.0F + 20.0F, 1.0F, 0.0F, 0.0F);
  475.             GL11.glRotatef(-((float)this.panoramaTimer + p_73970_3_) * 0.1F, 0.0F, 1.0F, 0.0F);
  476.  
  477.             for (int var10 = 0; var10 < 6; ++var10)
  478.             {
  479.                 GL11.glPushMatrix();
  480.  
  481.                 if (var10 == 1)
  482.                 {
  483.                     GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
  484.                 }
  485.  
  486.                 if (var10 == 2)
  487.                 {
  488.                     GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
  489.                 }
  490.  
  491.                 if (var10 == 3)
  492.                 {
  493.                     GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
  494.                 }
  495.  
  496.                 if (var10 == 4)
  497.                 {
  498.                     GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
  499.                 }
  500.  
  501.                 if (var10 == 5)
  502.                 {
  503.                     GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
  504.                 }
  505.  
  506.                 this.mc.getTextureManager().bindTexture(titlePanoramaPaths[var10]);
  507.                 var4.startDrawingQuads();
  508.                 var4.setColorRGBA_I(16777215, 255 / (var6 + 1));
  509.                 float var11 = 0.0F;
  510.                 var4.addVertexWithUV(-1.0D, -1.0D, 1.0D, (double)(0.0F + var11), (double)(0.0F + var11));
  511.                 var4.addVertexWithUV(1.0D, -1.0D, 1.0D, (double)(1.0F - var11), (double)(0.0F + var11));
  512.                 var4.addVertexWithUV(1.0D, 1.0D, 1.0D, (double)(1.0F - var11), (double)(1.0F - var11));
  513.                 var4.addVertexWithUV(-1.0D, 1.0D, 1.0D, (double)(0.0F + var11), (double)(1.0F - var11));
  514.                 var4.draw();
  515.                 GL11.glPopMatrix();
  516.             }
  517.  
  518.             GL11.glPopMatrix();
  519.             GL11.glColorMask(true, true, true, false);
  520.         }
  521.  
  522.         var4.setTranslation(0.0D, 0.0D, 0.0D);
  523.         GL11.glColorMask(true, true, true, true);
  524.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  525.         GL11.glPopMatrix();
  526.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  527.         GL11.glPopMatrix();
  528.         GL11.glDepthMask(true);
  529.         GL11.glEnable(GL11.GL_CULL_FACE);
  530.         GL11.glEnable(GL11.GL_DEPTH_TEST);
  531.     }
  532.  
  533.     /**
  534.      * Rotate and blurs the skybox view in the main menu
  535.      */
  536.     private void rotateAndBlurSkybox(float p_73968_1_)
  537.     {
  538.         this.mc.getTextureManager().bindTexture(this.field_110351_G);
  539.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
  540.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
  541.         GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256);
  542.         GL11.glEnable(GL11.GL_BLEND);
  543.         OpenGlHelper.glBlendFunc(770, 771, 1, 0);
  544.         GL11.glColorMask(true, true, true, false);
  545.         Tessellator var2 = Tessellator.instance;
  546.         var2.startDrawingQuads();
  547.         GL11.glDisable(GL11.GL_ALPHA_TEST);
  548.         byte var3 = 3;
  549.  
  550.         for (int var4 = 0; var4 < var3; ++var4)
  551.         {
  552.             var2.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F / (float)(var4 + 1));
  553.             int var5 = this.width;
  554.             int var6 = this.height;
  555.             float var7 = (float)(var4 - var3 / 2) / 256.0F;
  556.             var2.addVertexWithUV((double)var5, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 1.0D);
  557.             var2.addVertexWithUV((double)var5, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 1.0D);
  558.             var2.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 0.0D);
  559.             var2.addVertexWithUV(0.0D, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 0.0D);
  560.         }
  561.  
  562.         var2.draw();
  563.         GL11.glEnable(GL11.GL_ALPHA_TEST);
  564.         GL11.glColorMask(true, true, true, true);
  565.     }
  566.  
  567.     /**
  568.      * Renders the skybox in the main menu
  569.      */
  570.     private void renderSkybox(int p_73971_1_, int p_73971_2_, float p_73971_3_)
  571.     {
  572.         this.mc.getFramebuffer().unbindFramebuffer();
  573.         GL11.glViewport(0, 0, 256, 256);
  574.         this.drawPanorama(p_73971_1_, p_73971_2_, p_73971_3_);
  575.         this.rotateAndBlurSkybox(p_73971_3_);
  576.         this.rotateAndBlurSkybox(p_73971_3_);
  577.         this.rotateAndBlurSkybox(p_73971_3_);
  578.         this.rotateAndBlurSkybox(p_73971_3_);
  579.         this.rotateAndBlurSkybox(p_73971_3_);
  580.         this.rotateAndBlurSkybox(p_73971_3_);
  581.         this.rotateAndBlurSkybox(p_73971_3_);
  582.         this.mc.getFramebuffer().bindFramebuffer(true);
  583.         GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
  584.         Tessellator var4 = Tessellator.instance;
  585.         var4.startDrawingQuads();
  586.         float var5 = this.width > this.height ? 120.0F / (float)this.width : 120.0F / (float)this.height;
  587.         float var6 = (float)this.height * var5 / 256.0F;
  588.         float var7 = (float)this.width * var5 / 256.0F;
  589.         var4.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);
  590.         int var8 = this.width;
  591.         int var9 = this.height;
  592.         var4.addVertexWithUV(0.0D, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F + var7));
  593.         var4.addVertexWithUV((double)var8, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F - var7));
  594.         var4.addVertexWithUV((double)var8, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F - var7));
  595.         var4.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F + var7));
  596.         var4.draw();
  597.     }
  598.  
  599.     /**
  600.      * Draws the screen and all the components in it.
  601.      */
  602.     public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
  603.     {
  604.         GL11.glDisable(GL11.GL_ALPHA_TEST);
  605.         this.renderSkybox(p_73863_1_, p_73863_2_, p_73863_3_);
  606.         GL11.glEnable(GL11.GL_ALPHA_TEST);
  607.         Tessellator var4 = Tessellator.instance;
  608.         short var5 = 274;
  609.         int var6 = this.width / 2 - var5 / 2;
  610.         byte var7 = 30;
  611.         this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215);
  612.         this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
  613.         this.mc.getTextureManager().bindTexture(minecraftTitleTextures);
  614.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  615.  
  616.         if ((double)this.updateCounter < 1.0E-4D)
  617.         {
  618.             this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 99, 44);
  619.             this.drawTexturedModalRect(var6 + 99, var7 + 0, 129, 0, 27, 44);
  620.             this.drawTexturedModalRect(var6 + 99 + 26, var7 + 0, 126, 0, 3, 44);
  621.             this.drawTexturedModalRect(var6 + 99 + 26 + 3, var7 + 0, 99, 0, 26, 44);
  622.             this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44);
  623.         }
  624.         else
  625.         {
  626.             this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 155, 44);
  627.             this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44);
  628.         }
  629.  
  630.         var4.setColorOpaque_I(-1);
  631.         GL11.glPushMatrix();
  632.         GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F);
  633.         GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
  634.         float var8 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
  635.         var8 = var8 * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32);
  636.         GL11.glScalef(var8, var8, var8);
  637.         this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256);
  638.         GL11.glPopMatrix();
  639.         String var9 = bottomLeftText;
  640.  
  641.         this.drawString(this.fontRendererObj, var9, 2, this.height - 10, -1);
  642.         String var10 = bottomRightText;
  643.         this.drawString(this.fontRendererObj, var10, this.width - this.fontRendererObj.getStringWidth(var10) - 2, this.height - 10, -1);
  644.  
  645.         if (this.field_92025_p != null && this.field_92025_p.length() > 0)
  646.         {
  647.             drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512);
  648.             this.drawString(this.fontRendererObj, this.field_92025_p, this.field_92022_t, this.field_92021_u, -1);
  649.             this.drawString(this.fontRendererObj, this.field_146972_A, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).field_146129_i - 12, -1);
  650.         }
  651.  
  652.         super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
  653.     }
  654.  
  655.     /**
  656.      * Called when the mouse is clicked.
  657.      */
  658.     protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_)
  659.     {
  660.         super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
  661.         Object var4 = this.field_104025_t;
  662.  
  663.         synchronized (this.field_104025_t)
  664.         {
  665.             if (this.field_92025_p.length() > 0 && p_73864_1_ >= this.field_92022_t && p_73864_1_ <= this.field_92020_v && p_73864_2_ >= this.field_92021_u && p_73864_2_ <= this.field_92019_w)
  666.             {
  667.                 GuiConfirmOpenLink var5 = new GuiConfirmOpenLink(this, this.field_104024_v, 13, true);
  668.                 var5.func_146358_g();
  669.                 this.mc.displayGuiScreen(var5);
  670.             }
  671.         }
  672.     }
  673.     public static int readVarInt(DataInputStream in) throws IOException {
  674.         int i = 0;
  675.         int j = 0;
  676.         while (true) {
  677.             int k = in.readByte();
  678.             i |= (k & 0x7F) << j++ * 7;
  679.             if (j > 5) throw new RuntimeException("VarInt too big");
  680.             if ((k & 0x80) != 128) break;
  681.         }
  682.         return i;
  683.     }
  684.  
  685.     public static void writeVarInt(DataOutputStream out, int paramInt) throws IOException {
  686.         while (true) {
  687.             if ((paramInt & 0xFFFFFF80) == 0) {
  688.               out.writeByte(paramInt);
  689.               return;
  690.             }
  691.  
  692.             out.writeByte(paramInt & 0x7F | 0x80);
  693.             paramInt >>>= 7;
  694.         }
  695.     }
  696.     static String toButton;
  697.     static boolean enabled = true;
  698.     @SuppressWarnings("resource")
  699.     public static void getOnlineMaxOnline(GuiButton button) {
  700.         if (!loaded) {
  701.             if (updating!="none") {
  702.                 button.displayString = updating;
  703.                 try {
  704.                     Thread.sleep(1400);
  705.                 } catch (InterruptedException e1) {
  706.                     // TODO Auto-generated catch block
  707.                     e1.printStackTrace();
  708.                 }
  709.             } else {
  710.                 button.displayString = toButton;
  711.             }
  712.             try {
  713.                 Socket socket = new Socket(serverIp, Integer.valueOf(serverPort));
  714.                 OutputStream outputStream;
  715.                 DataOutputStream dataOutputStream;
  716.                 InputStream inputStream;
  717.                 InputStreamReader inputStreamReader;
  718.          
  719.                 socket.setSoTimeout(3000);
  720.          
  721.                 outputStream = socket.getOutputStream();
  722.                 dataOutputStream = new DataOutputStream(outputStream);
  723.          
  724.                 inputStream = socket.getInputStream();
  725.                 inputStreamReader = new InputStreamReader(inputStream);
  726.          
  727.                 ByteArrayOutputStream b = new ByteArrayOutputStream();
  728.                 DataOutputStream handshake = new DataOutputStream(b);
  729.                 handshake.writeByte(0x00); //packet id for handshake
  730.                 writeVarInt(handshake, 5); //protocol version
  731.                 writeVarInt(handshake, serverIp.length()); //host length
  732.                 handshake.writeBytes(serverIp); //host string
  733.                 handshake.writeShort(Short.valueOf(serverPort)); //port
  734.                 writeVarInt(handshake, 1); //state (1 for handshake)
  735.          
  736.                 writeVarInt(dataOutputStream, b.size()); //prepend size
  737.                 dataOutputStream.write(b.toByteArray()); //write handshake packet
  738.          
  739.          
  740.                 dataOutputStream.writeByte(0x01); //size is only 1
  741.                 dataOutputStream.writeByte(0x00); //packet id for ping
  742.                 DataInputStream dataInputStream = new DataInputStream(inputStream);
  743.                 int size = readVarInt(dataInputStream); //size of packet
  744.                 int id = readVarInt(dataInputStream); //packet id
  745.                 if (id == -1) {
  746.                     throw new IOException("Premature end of stream.");
  747.                 }
  748.                
  749.                 if (id != 0x00) { //we want a status response
  750.                     throw new IOException("Invalid packetID");
  751.                 }
  752.                 int length = readVarInt(dataInputStream); //length of json string
  753.                
  754.                 if (length == -1) {
  755.                     throw new IOException("Premature end of stream.");
  756.                 }
  757.          
  758.                 if (length == 0) {
  759.                     throw new IOException("Invalid string length.");
  760.                 }
  761.                 byte[] in = new byte[length];
  762.                 dataInputStream.readFully(in);  //read json string
  763.                 String json = new String(in);
  764.                
  765.                
  766.                 long now = System.currentTimeMillis();
  767.                 dataOutputStream.writeByte(0x09); //size of packet
  768.                 dataOutputStream.writeByte(0x01); //0x01 for ping
  769.                 dataOutputStream.writeLong(now); //time!?
  770.          
  771.                 readVarInt(dataInputStream);
  772.                 id = readVarInt(dataInputStream);
  773.                 if (id == -1) {
  774.                     throw new IOException("Premature end of stream.");
  775.                 }
  776.                
  777.                 if (id != 0x01) {
  778.                     throw new IOException("Invalid packetID");
  779.                 }
  780.                 long pingtime = dataInputStream.readLong(); //read response
  781.                
  782.                 Gson gson = new Gson();
  783.                 StatusResponse response = gson.fromJson(json, StatusResponse.class);
  784.                 response.setTime((int) (now - pingtime));
  785.                
  786.                 dataOutputStream.close();
  787.                 outputStream.close();
  788.                 inputStreamReader.close();
  789.                 inputStream.close();
  790.                 socket.close();
  791.                 int players = response.getPlayers().getOnline();
  792.                 int maxPlayers = response.getPlayers().getMax();
  793.                 toButton = GuiMainMenu.joinToServer + " " + GuiMainMenu.numberOfPlayersColor + Integer.toString(players) + GuiMainMenu.dividerColor + " / " + GuiMainMenu.numberOfPlayersColor + Integer.toString(maxPlayers);
  794.                 socket.close();
  795.                 enabled = true;
  796.             } catch (IOException e) {
  797.                 enabled = false;
  798.                 toButton = GuiMainMenu.serverIsNotResponding;
  799.             }
  800.             loaded = true;
  801.         }
  802.         button.enabled = enabled;
  803.         button.displayString = toButton;
  804.     }
  805. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement