001    package net.minecraft.client;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.awt.BorderLayout;
006    import java.awt.Canvas;
007    import java.awt.Color;
008    import java.awt.Component;
009    import java.awt.Dimension;
010    import java.awt.Frame;
011    import java.awt.Graphics;
012    import java.io.File;
013    import java.io.IOException;
014    import java.nio.ByteBuffer;
015    import java.text.DecimalFormat;
016    import java.util.HashMap;
017    import java.util.List;
018    
019    import javax.swing.JPanel;
020    
021    import net.minecraft.src.AchievementList;
022    import net.minecraft.src.AnvilSaveConverter;
023    import net.minecraft.src.AxisAlignedBB;
024    import net.minecraft.src.Block;
025    import net.minecraft.src.CallableClientProfiler;
026    import net.minecraft.src.CallableGLInfo;
027    import net.minecraft.src.CallableLWJGLVersion;
028    import net.minecraft.src.CallableModded;
029    import net.minecraft.src.CallableTexturePack;
030    import net.minecraft.src.CallableType2;
031    import net.minecraft.src.ColorizerFoliage;
032    import net.minecraft.src.ColorizerGrass;
033    import net.minecraft.src.ColorizerWater;
034    import net.minecraft.src.CrashReport;
035    import net.minecraft.src.EffectRenderer;
036    import net.minecraft.src.EntityBoat;
037    import net.minecraft.src.EntityClientPlayerMP;
038    import net.minecraft.src.EntityList;
039    import net.minecraft.src.EntityLiving;
040    import net.minecraft.src.EntityMinecart;
041    import net.minecraft.src.EntityPainting;
042    import net.minecraft.src.EntityRenderer;
043    import net.minecraft.src.EnumMovingObjectType;
044    import net.minecraft.src.EnumOS;
045    import net.minecraft.src.EnumOSHelper;
046    import net.minecraft.src.EnumOptions;
047    import net.minecraft.src.FontRenderer;
048    import net.minecraft.src.GLAllocation;
049    import net.minecraft.src.GameSettings;
050    import net.minecraft.src.GameWindowListener;
051    import net.minecraft.src.GuiAchievement;
052    import net.minecraft.src.GuiChat;
053    import net.minecraft.src.GuiConnecting;
054    import net.minecraft.src.GuiErrorScreen;
055    import net.minecraft.src.GuiGameOver;
056    import net.minecraft.src.GuiIngame;
057    import net.minecraft.src.GuiIngameMenu;
058    import net.minecraft.src.GuiInventory;
059    import net.minecraft.src.GuiMainMenu;
060    import net.minecraft.src.GuiMemoryErrorScreen;
061    import net.minecraft.src.GuiScreen;
062    import net.minecraft.src.GuiSleepMP;
063    import net.minecraft.src.IPlayerUsage;
064    import net.minecraft.src.ISaveFormat;
065    import net.minecraft.src.ISaveHandler;
066    import net.minecraft.src.IntegratedServer;
067    import net.minecraft.src.Item;
068    import net.minecraft.src.ItemRenderer;
069    import net.minecraft.src.ItemStack;
070    import net.minecraft.src.KeyBinding;
071    import net.minecraft.src.LoadingScreenRenderer;
072    import net.minecraft.src.MathHelper;
073    import net.minecraft.src.MemoryConnection;
074    import net.minecraft.src.MinecraftError;
075    import net.minecraft.src.MinecraftFakeLauncher;
076    import net.minecraft.src.MouseHelper;
077    import net.minecraft.src.MovementInputFromOptions;
078    import net.minecraft.src.MovingObjectPosition;
079    import net.minecraft.src.NetClientHandler;
080    import net.minecraft.src.NetworkManager;
081    import net.minecraft.src.OpenGlHelper;
082    import net.minecraft.src.Packet3Chat;
083    import net.minecraft.src.PlayerControllerMP;
084    import net.minecraft.src.PlayerUsageSnooper;
085    import net.minecraft.src.Profiler;
086    import net.minecraft.src.ProfilerResult;
087    import net.minecraft.src.RenderBlocks;
088    import net.minecraft.src.RenderEngine;
089    import net.minecraft.src.RenderGlobal;
090    import net.minecraft.src.RenderManager;
091    import net.minecraft.src.ReportedException;
092    import net.minecraft.src.ScaledResolution;
093    import net.minecraft.src.ScreenShotHelper;
094    import net.minecraft.src.ServerData;
095    import net.minecraft.src.Session;
096    import net.minecraft.src.SoundManager;
097    import net.minecraft.src.StatCollector;
098    import net.minecraft.src.StatFileWriter;
099    import net.minecraft.src.StatList;
100    import net.minecraft.src.StatStringFormatKeyInv;
101    import net.minecraft.src.StringTranslate;
102    import net.minecraft.src.Tessellator;
103    import net.minecraft.src.TextureCompassFX;
104    import net.minecraft.src.TextureFlamesFX;
105    import net.minecraft.src.TextureLavaFX;
106    import net.minecraft.src.TextureLavaFlowFX;
107    import net.minecraft.src.TexturePackList;
108    import net.minecraft.src.TexturePortalFX;
109    import net.minecraft.src.TextureWatchFX;
110    import net.minecraft.src.TextureWaterFX;
111    import net.minecraft.src.TextureWaterFlowFX;
112    import net.minecraft.src.ThreadClientSleep;
113    import net.minecraft.src.ThreadDownloadResources;
114    import net.minecraft.src.ThreadShutdown;
115    import net.minecraft.src.Timer;
116    import net.minecraft.src.Vec3;
117    import net.minecraft.src.WorldClient;
118    import net.minecraft.src.WorldInfo;
119    import net.minecraft.src.WorldRenderer;
120    import net.minecraft.src.WorldSettings;
121    import net.minecraftforge.common.ForgeHooks;
122    
123    import org.lwjgl.LWJGLException;
124    import org.lwjgl.Sys;
125    import org.lwjgl.input.Keyboard;
126    import org.lwjgl.input.Mouse;
127    import org.lwjgl.opengl.ContextCapabilities;
128    import org.lwjgl.opengl.Display;
129    import org.lwjgl.opengl.DisplayMode;
130    import org.lwjgl.opengl.GL11;
131    import org.lwjgl.opengl.GLContext;
132    import org.lwjgl.opengl.PixelFormat;
133    import org.lwjgl.util.glu.GLU;
134    
135    import cpw.mods.fml.client.FMLClientHandler;
136    import cpw.mods.fml.common.FMLCommonHandler;
137    import cpw.mods.fml.common.Side;
138    import cpw.mods.fml.relauncher.ArgsWrapper;
139    import cpw.mods.fml.relauncher.FMLRelauncher;
140    
141    @SideOnly(Side.CLIENT)
142    public abstract class Minecraft implements Runnable, IPlayerUsage
143    {
144        /** The experienceTotal value the client thinks the player has. */
145        public static byte[] clientExperience = new byte[10485760];
146        private ServerData currentServerData;
147    
148        /**
149         * Set to 'this' in Minecraft constructor; used by some settings get methods
150         */
151        private static Minecraft theMinecraft;
152        public PlayerControllerMP playerController;
153        private boolean fullscreen = false;
154        private boolean hasCrashed = false;
155    
156        /** Instance of CrashReport. */
157        private CrashReport crashReporter;
158        public int displayWidth;
159        public int displayHeight;
160        private Timer timer = new Timer(20.0F);
161    
162        /** Instance of PlayerUsageSnooper. */
163        private PlayerUsageSnooper usageSnooper = new PlayerUsageSnooper("client", this);
164        public WorldClient theWorld;
165        public RenderGlobal renderGlobal;
166        public EntityClientPlayerMP thePlayer;
167    
168        /**
169         * The Entity from which the renderer determines the render viewpoint. Currently is always the parent Minecraft
170         * class's 'thePlayer' instance. Modification of its location, rotation, or other settings at render time will
171         * modify the camera likewise, with the caveat of triggering chunk rebuilds as it moves, making it unsuitable for
172         * changing the viewpoint mid-render.
173         */
174        public EntityLiving renderViewEntity;
175        public EffectRenderer effectRenderer;
176        public Session session = null;
177        public String minecraftUri;
178        public Canvas mcCanvas;
179    
180        /** a boolean to hide a Quit button from the main menu */
181        public boolean hideQuitButton = false;
182        public volatile boolean isGamePaused = false;
183    
184        /** The RenderEngine instance used by Minecraft */
185        public RenderEngine renderEngine;
186    
187        /** The font renderer used for displaying and measuring text. */
188        public FontRenderer fontRenderer;
189        public FontRenderer standardGalacticFontRenderer;
190    
191        /** The GuiScreen that's being displayed at the moment. */
192        public GuiScreen currentScreen = null;
193        public LoadingScreenRenderer loadingScreen;
194        public EntityRenderer entityRenderer;
195    
196        /** Reference to the download resources thread. */
197        private ThreadDownloadResources downloadResourcesThread;
198    
199        /** Mouse left click counter */
200        private int leftClickCounter = 0;
201    
202        /** Display width */
203        private int tempDisplayWidth;
204    
205        /** Display height */
206        private int tempDisplayHeight;
207    
208        /** Instance of IntegratedServer. */
209        private IntegratedServer theIntegratedServer;
210    
211        /** Gui achievement */
212        public GuiAchievement guiAchievement = new GuiAchievement(this);
213        public GuiIngame ingameGUI;
214    
215        /** Skip render world */
216        public boolean skipRenderWorld = false;
217    
218        /** The ray trace hit that the mouse is over. */
219        public MovingObjectPosition objectMouseOver = null;
220    
221        /** The game settings that currently hold effect. */
222        public GameSettings gameSettings;
223        protected MinecraftApplet mcApplet;
224        public SoundManager sndManager = new SoundManager();
225    
226        /** Mouse helper instance. */
227        public MouseHelper mouseHelper;
228    
229        /** The TexturePackLister used by this instance of Minecraft... */
230        public TexturePackList texturePackList;
231        public File mcDataDir;
232        private ISaveFormat saveLoader;
233        private static int field_71470_ab;
234    
235        /**
236         * When you place a block, it's set to 6, decremented once per tick, when it's 0, you can place another block.
237         */
238        private int rightClickDelayTimer = 0;
239        private boolean field_71468_ad;
240    
241        /** Stat file writer */
242        public StatFileWriter statFileWriter;
243        private String serverName;
244        private int serverPort;
245        private TextureWaterFX textureWaterFX = new TextureWaterFX();
246        private TextureLavaFX textureLavaFX = new TextureLavaFX();
247    
248        /**
249         * Makes sure it doesn't keep taking screenshots when both buttons are down.
250         */
251        boolean isTakingScreenshot = false;
252    
253        /**
254         * Does the actual gameplay have focus. If so then mouse and keys will effect the player instead of menus.
255         */
256        public boolean inGameHasFocus = false;
257        long systemTime = getSystemTime();
258    
259        /** Join player counter */
260        private int joinPlayerCounter = 0;
261        private boolean isDemo;
262        private NetworkManager myNetworkManager;
263        private boolean integratedServerIsRunning;
264    
265        /** The profiler instance */
266        public final Profiler mcProfiler = new Profiler();
267    
268        /** The working dir (OS specific) for minecraft */
269        private static File minecraftDir = null;
270    
271        /**
272         * Set to true to keep the game loop running. Set to false by shutdown() to allow the game loop to exit cleanly.
273         */
274        public volatile boolean running = true;
275    
276        /** String that shows the debug information */
277        public String debug = "";
278    
279        /** Approximate time (in ms) of last update to debug string */
280        long debugUpdateTime = getSystemTime();
281    
282        /** holds the current fps */
283        int fpsCounter = 0;
284        long prevFrameTime = -1L;
285    
286        /** Profiler currently displayed in the debug screen pie chart */
287        private String debugProfilerName = "root";
288    
289        public Minecraft(Canvas par1Canvas, MinecraftApplet par2MinecraftApplet, int par3, int par4, boolean par5)
290        {
291            StatList.func_75919_a();
292            this.tempDisplayHeight = par4;
293            this.fullscreen = par5;
294            this.mcApplet = par2MinecraftApplet;
295            Packet3Chat.maxChatLength = 32767;
296            this.startTimerHackThread();
297            this.mcCanvas = par1Canvas;
298            this.displayWidth = par3;
299            this.displayHeight = par4;
300            this.fullscreen = par5;
301            theMinecraft = this;
302        }
303    
304        private void startTimerHackThread()
305        {
306            ThreadClientSleep var1 = new ThreadClientSleep(this, "Timer hack thread");
307            var1.setDaemon(true);
308            var1.start();
309        }
310    
311        public void crashed(CrashReport par1CrashReport)
312        {
313            this.hasCrashed = true;
314            this.crashReporter = par1CrashReport;
315        }
316    
317        /**
318         * Wrapper around displayCrashReportInternal
319         */
320        public void displayCrashReport(CrashReport par1CrashReport)
321        {
322            this.hasCrashed = true;
323            this.displayCrashReportInternal(par1CrashReport);
324        }
325    
326        public abstract void displayCrashReportInternal(CrashReport var1);
327    
328        public void setServer(String par1Str, int par2)
329        {
330            this.serverName = par1Str;
331            this.serverPort = par2;
332        }
333    
334        /**
335         * Starts the game: initializes the canvas, the title, the settings, etcetera.
336         */
337        public void startGame() throws LWJGLException
338        {
339            if (this.mcCanvas != null)
340            {
341                Graphics var1 = this.mcCanvas.getGraphics();
342    
343                if (var1 != null)
344                {
345                    var1.setColor(Color.BLACK);
346                    var1.fillRect(0, 0, this.displayWidth, this.displayHeight);
347                    var1.dispose();
348                }
349    
350                Display.setParent(this.mcCanvas);
351            }
352            else if (this.fullscreen)
353            {
354                Display.setFullscreen(true);
355                this.displayWidth = Display.getDisplayMode().getWidth();
356                this.displayHeight = Display.getDisplayMode().getHeight();
357    
358                if (this.displayWidth <= 0)
359                {
360                    this.displayWidth = 1;
361                }
362    
363                if (this.displayHeight <= 0)
364                {
365                    this.displayHeight = 1;
366                }
367            }
368            else
369            {
370                Display.setDisplayMode(new DisplayMode(this.displayWidth, this.displayHeight));
371            }
372    
373            Display.setTitle("Minecraft Minecraft 1.3.2");
374            System.out.println("LWJGL Version: " + Sys.getVersion());
375    
376            try
377            {
378                Display.create((new PixelFormat()).withDepthBits(24));
379            }
380            catch (LWJGLException var5)
381            {
382                var5.printStackTrace();
383    
384                try
385                {
386                    Thread.sleep(1000L);
387                }
388                catch (InterruptedException var4)
389                {
390                    ;
391                }
392    
393                Display.create();
394            }
395    
396            OpenGlHelper.initializeTextures();
397            this.mcDataDir = getMinecraftDir();
398            this.saveLoader = new AnvilSaveConverter(new File(this.mcDataDir, "saves"));
399            this.gameSettings = new GameSettings(this, this.mcDataDir);
400            this.texturePackList = new TexturePackList(this.mcDataDir, this);
401            this.renderEngine = new RenderEngine(this.texturePackList, this.gameSettings);
402            this.loadScreen();
403            this.fontRenderer = new FontRenderer(this.gameSettings, "/font/default.png", this.renderEngine, false);
404            this.standardGalacticFontRenderer = new FontRenderer(this.gameSettings, "/font/alternate.png", this.renderEngine, false);
405            FMLClientHandler.instance().beginMinecraftLoading(this);
406            if (this.gameSettings.language != null)
407            {
408                StringTranslate.getInstance().setLanguage(this.gameSettings.language);
409                this.fontRenderer.setUnicodeFlag(StringTranslate.getInstance().isUnicode());
410                this.fontRenderer.setBidiFlag(StringTranslate.isBidirectional(this.gameSettings.language));
411            }
412    
413            ColorizerWater.setWaterBiomeColorizer(this.renderEngine.getTextureContents("/misc/watercolor.png"));
414            ColorizerGrass.setGrassBiomeColorizer(this.renderEngine.getTextureContents("/misc/grasscolor.png"));
415            ColorizerFoliage.getFoilageBiomeColorizer(this.renderEngine.getTextureContents("/misc/foliagecolor.png"));
416            this.entityRenderer = new EntityRenderer(this);
417            RenderManager.instance.itemRenderer = new ItemRenderer(this);
418            this.statFileWriter = new StatFileWriter(this.session, this.mcDataDir);
419            AchievementList.openInventory.setStatStringFormatter(new StatStringFormatKeyInv(this));
420            this.loadScreen();
421            Mouse.create();
422            this.mouseHelper = new MouseHelper(this.mcCanvas);
423            this.checkGLError("Pre startup");
424            GL11.glEnable(GL11.GL_TEXTURE_2D);
425            GL11.glShadeModel(GL11.GL_SMOOTH);
426            GL11.glClearDepth(1.0D);
427            GL11.glEnable(GL11.GL_DEPTH_TEST);
428            GL11.glDepthFunc(GL11.GL_LEQUAL);
429            GL11.glEnable(GL11.GL_ALPHA_TEST);
430            GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
431            GL11.glCullFace(GL11.GL_BACK);
432            GL11.glMatrixMode(GL11.GL_PROJECTION);
433            GL11.glLoadIdentity();
434            GL11.glMatrixMode(GL11.GL_MODELVIEW);
435            this.checkGLError("Startup");
436            this.sndManager.loadSoundSettings(this.gameSettings);
437            this.renderEngine.registerTextureFX(this.textureLavaFX);
438            this.renderEngine.registerTextureFX(this.textureWaterFX);
439            this.renderEngine.registerTextureFX(new TexturePortalFX());
440            this.renderEngine.registerTextureFX(new TextureCompassFX(this));
441            this.renderEngine.registerTextureFX(new TextureWatchFX(this));
442            this.renderEngine.registerTextureFX(new TextureWaterFlowFX());
443            this.renderEngine.registerTextureFX(new TextureLavaFlowFX());
444            this.renderEngine.registerTextureFX(new TextureFlamesFX(0));
445            this.renderEngine.registerTextureFX(new TextureFlamesFX(1));
446            this.renderGlobal = new RenderGlobal(this, this.renderEngine);
447            GL11.glViewport(0, 0, this.displayWidth, this.displayHeight);
448            this.effectRenderer = new EffectRenderer(this.theWorld, this.renderEngine);
449    
450            FMLClientHandler.instance().finishMinecraftLoading();
451    
452            try
453            {
454                this.downloadResourcesThread = new ThreadDownloadResources(this.mcDataDir, this);
455                this.downloadResourcesThread.start();
456            }
457            catch (Exception var3)
458            {
459                ;
460            }
461    
462            this.checkGLError("Post startup");
463            this.ingameGUI = new GuiIngame(this);
464    
465            if (this.serverName != null)
466            {
467                this.displayGuiScreen(new GuiConnecting(this, this.serverName, this.serverPort));
468            }
469            else
470            {
471                this.displayGuiScreen(new GuiMainMenu());
472            }
473    
474            this.loadingScreen = new LoadingScreenRenderer(this);
475    
476            if (this.gameSettings.fullScreen && !this.fullscreen)
477            {
478                this.toggleFullscreen();
479            }
480            FMLClientHandler.instance().onInitializationComplete();
481        }
482    
483        /**
484         * Displays a new screen.
485         */
486        private void loadScreen() throws LWJGLException
487        {
488            ScaledResolution var1 = new ScaledResolution(this.gameSettings, this.displayWidth, this.displayHeight);
489            GL11.glClear(16640);
490            GL11.glMatrixMode(GL11.GL_PROJECTION);
491            GL11.glLoadIdentity();
492            GL11.glOrtho(0.0D, var1.getScaledWidth_double(), var1.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D);
493            GL11.glMatrixMode(GL11.GL_MODELVIEW);
494            GL11.glLoadIdentity();
495            GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
496            GL11.glViewport(0, 0, this.displayWidth, this.displayHeight);
497            GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
498            GL11.glDisable(GL11.GL_LIGHTING);
499            GL11.glEnable(GL11.GL_TEXTURE_2D);
500            GL11.glDisable(GL11.GL_FOG);
501            Tessellator var2 = Tessellator.instance;
502            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.renderEngine.getTexture("/title/mojang.png"));
503            var2.startDrawingQuads();
504            var2.setColorOpaque_I(16777215);
505            var2.addVertexWithUV(0.0D, (double)this.displayHeight, 0.0D, 0.0D, 0.0D);
506            var2.addVertexWithUV((double)this.displayWidth, (double)this.displayHeight, 0.0D, 0.0D, 0.0D);
507            var2.addVertexWithUV((double)this.displayWidth, 0.0D, 0.0D, 0.0D, 0.0D);
508            var2.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
509            var2.draw();
510            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
511            var2.setColorOpaque_I(16777215);
512            short var3 = 256;
513            short var4 = 256;
514            this.scaledTessellator((var1.getScaledWidth() - var3) / 2, (var1.getScaledHeight() - var4) / 2, 0, 0, var3, var4);
515            GL11.glDisable(GL11.GL_LIGHTING);
516            GL11.glDisable(GL11.GL_FOG);
517            GL11.glEnable(GL11.GL_ALPHA_TEST);
518            GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
519            Display.swapBuffers();
520        }
521    
522        /**
523         * Loads Tessellator with a scaled resolution
524         */
525        public void scaledTessellator(int par1, int par2, int par3, int par4, int par5, int par6)
526        {
527            float var7 = 0.00390625F;
528            float var8 = 0.00390625F;
529            Tessellator var9 = Tessellator.instance;
530            var9.startDrawingQuads();
531            var9.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), 0.0D, (double)((float)(par3 + 0) * var7), (double)((float)(par4 + par6) * var8));
532            var9.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), 0.0D, (double)((float)(par3 + par5) * var7), (double)((float)(par4 + par6) * var8));
533            var9.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), 0.0D, (double)((float)(par3 + par5) * var7), (double)((float)(par4 + 0) * var8));
534            var9.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), 0.0D, (double)((float)(par3 + 0) * var7), (double)((float)(par4 + 0) * var8));
535            var9.draw();
536        }
537    
538        /**
539         * gets the working dir (OS specific) for minecraft
540         */
541        public static File getMinecraftDir()
542        {
543            if (minecraftDir == null)
544            {
545                minecraftDir = getAppDir("minecraft");
546            }
547    
548            return minecraftDir;
549        }
550    
551        /**
552         * gets the working dir (OS specific) for the specific application (which is always minecraft)
553         */
554        public static File getAppDir(String par0Str)
555        {
556            String var1 = System.getProperty("user.home", ".");
557            File var2;
558    
559            switch (EnumOSHelper.field_74533_a[getOs().ordinal()])
560            {
561                case 1:
562                case 2:
563                    var2 = new File(var1, '.' + par0Str + '/');
564                    break;
565                case 3:
566                    String var3 = System.getenv("APPDATA");
567    
568                    if (var3 != null)
569                    {
570                        var2 = new File(var3, "." + par0Str + '/');
571                    }
572                    else
573                    {
574                        var2 = new File(var1, '.' + par0Str + '/');
575                    }
576    
577                    break;
578                case 4:
579                    var2 = new File(var1, "Library/Application Support/" + par0Str);
580                    break;
581                default:
582                    var2 = new File(var1, par0Str + '/');
583            }
584    
585            if (!var2.exists() && !var2.mkdirs())
586            {
587                throw new RuntimeException("The working directory could not be created: " + var2);
588            }
589            else
590            {
591                return var2;
592            }
593        }
594    
595        public static EnumOS getOs()
596        {
597            String var0 = System.getProperty("os.name").toLowerCase();
598            return var0.contains("win") ? EnumOS.WINDOWS : (var0.contains("mac") ? EnumOS.MACOS : (var0.contains("solaris") ? EnumOS.SOLARIS : (var0.contains("sunos") ? EnumOS.SOLARIS : (var0.contains("linux") ? EnumOS.LINUX : (var0.contains("unix") ? EnumOS.LINUX : EnumOS.UNKNOWN)))));
599        }
600    
601        /**
602         * Returns the save loader that is currently being used
603         */
604        public ISaveFormat getSaveLoader()
605        {
606            return this.saveLoader;
607        }
608    
609        /**
610         * Sets the argument GuiScreen as the main (topmost visible) screen.
611         */
612        public void displayGuiScreen(GuiScreen par1GuiScreen)
613        {
614            if (!(this.currentScreen instanceof GuiErrorScreen))
615            {
616                if (this.currentScreen != null)
617                {
618                    this.currentScreen.onGuiClosed();
619                }
620    
621                this.statFileWriter.syncStats();
622    
623                if (par1GuiScreen == null && this.theWorld == null)
624                {
625                    par1GuiScreen = new GuiMainMenu();
626                }
627                else if (par1GuiScreen == null && this.thePlayer.getHealth() <= 0)
628                {
629                    par1GuiScreen = new GuiGameOver();
630                }
631    
632                if (par1GuiScreen instanceof GuiMainMenu)
633                {
634                    this.gameSettings.showDebugInfo = false;
635                    this.ingameGUI.getChatGUI().func_73761_a();
636                }
637    
638                this.currentScreen = (GuiScreen)par1GuiScreen;
639    
640                if (par1GuiScreen != null)
641                {
642                    this.setIngameNotInFocus();
643                    ScaledResolution var2 = new ScaledResolution(this.gameSettings, this.displayWidth, this.displayHeight);
644                    int var3 = var2.getScaledWidth();
645                    int var4 = var2.getScaledHeight();
646                    ((GuiScreen)par1GuiScreen).setWorldAndResolution(this, var3, var4);
647                    this.skipRenderWorld = false;
648                }
649                else
650                {
651                    this.setIngameFocus();
652                }
653            }
654        }
655    
656        /**
657         * Checks for an OpenGL error. If there is one, prints the error ID and error string.
658         */
659        private void checkGLError(String par1Str)
660        {
661            int var2 = GL11.glGetError();
662    
663            if (var2 != 0)
664            {
665                String var3 = GLU.gluErrorString(var2);
666                System.out.println("########## GL ERROR ##########");
667                System.out.println("@ " + par1Str);
668                System.out.println(var2 + ": " + var3);
669            }
670        }
671    
672        /**
673         * Shuts down the minecraft applet by stopping the resource downloads, and clearing up GL stuff; called when the
674         * application (or web page) is exited.
675         */
676        public void shutdownMinecraftApplet()
677        {
678            try
679            {
680                this.statFileWriter.syncStats();
681    
682                try
683                {
684                    if (this.downloadResourcesThread != null)
685                    {
686                        this.downloadResourcesThread.closeMinecraft();
687                    }
688                }
689                catch (Exception var9)
690                {
691                    ;
692                }
693    
694                System.out.println("Stopping!");
695    
696                try
697                {
698                    this.loadWorld((WorldClient)null);
699                }
700                catch (Throwable var8)
701                {
702                    ;
703                }
704    
705                try
706                {
707                    GLAllocation.deleteTexturesAndDisplayLists();
708                }
709                catch (Throwable var7)
710                {
711                    ;
712                }
713    
714                this.sndManager.closeMinecraft();
715                Mouse.destroy();
716                Keyboard.destroy();
717            }
718            finally
719            {
720                Display.destroy();
721    
722                if (!this.hasCrashed)
723                {
724                    System.exit(0);
725                }
726            }
727    
728            System.gc();
729        }
730    
731        public void run()
732        {
733            this.running = true;
734    
735            try
736            {
737                this.startGame();
738            }
739            catch (Exception var11)
740            {
741                var11.printStackTrace();
742                this.displayCrashReport(this.func_71396_d(new CrashReport("Failed to start game", var11)));
743                return;
744            }
745    
746            try
747            {
748                while (this.running)
749                {
750                    if (this.hasCrashed && this.crashReporter != null)
751                    {
752                        this.displayCrashReport(this.crashReporter);
753                        return;
754                    }
755    
756                    if (this.field_71468_ad)
757                    {
758                        this.field_71468_ad = false;
759                        this.renderEngine.refreshTextures();
760                    }
761    
762                    try
763                    {
764                        this.runGameLoop();
765                    }
766                    catch (OutOfMemoryError var10)
767                    {
768                        this.freeMemory();
769                        this.displayGuiScreen(new GuiMemoryErrorScreen());
770                        System.gc();
771                    }
772                }
773            }
774            catch (MinecraftError var12)
775            {
776                ;
777            }
778            catch (ReportedException var13)
779            {
780                this.func_71396_d(var13.func_71575_a());
781                this.freeMemory();
782                var13.printStackTrace();
783                this.displayCrashReport(var13.func_71575_a());
784            }
785            catch (Throwable var14)
786            {
787                CrashReport var2 = this.func_71396_d(new CrashReport("Unexpected error", var14));
788                this.freeMemory();
789                var14.printStackTrace();
790                this.displayCrashReport(var2);
791            }
792            finally
793            {
794                this.shutdownMinecraftApplet();
795            }
796        }
797    
798        /**
799         * Called repeatedly from run()
800         */
801        private void runGameLoop()
802        {
803            if (this.mcApplet != null && !this.mcApplet.isActive())
804            {
805                this.running = false;
806            }
807            else
808            {
809                AxisAlignedBB.getAABBPool().cleanPool();
810                Vec3.getVec3Pool().clear();
811                this.mcProfiler.startSection("root");
812    
813                if (this.mcCanvas == null && Display.isCloseRequested())
814                {
815                    this.shutdown();
816                }
817    
818                if (this.isGamePaused && this.theWorld != null)
819                {
820                    float var1 = this.timer.renderPartialTicks;
821                    this.timer.updateTimer();
822                    this.timer.renderPartialTicks = var1;
823                }
824                else
825                {
826                    this.timer.updateTimer();
827                }
828    
829                long var6 = System.nanoTime();
830                this.mcProfiler.startSection("tick");
831    
832                for (int var3 = 0; var3 < this.timer.elapsedTicks; ++var3)
833                {
834                    this.runTick();
835                }
836    
837                this.mcProfiler.endStartSection("preRenderErrors");
838                long var7 = System.nanoTime() - var6;
839                this.checkGLError("Pre render");
840                RenderBlocks.fancyGrass = this.gameSettings.fancyGraphics;
841                this.mcProfiler.endStartSection("sound");
842                this.sndManager.setListener(this.thePlayer, this.timer.renderPartialTicks);
843                this.mcProfiler.endStartSection("updatelights");
844    
845                if (this.theWorld != null)
846                {
847                    this.theWorld.updatingLighting();
848                }
849    
850                this.mcProfiler.endSection();
851                this.mcProfiler.startSection("render");
852                this.mcProfiler.startSection("display");
853                GL11.glEnable(GL11.GL_TEXTURE_2D);
854    
855                if (!Keyboard.isKeyDown(65))
856                {
857                    Display.update();
858                }
859    
860                if (this.thePlayer != null && this.thePlayer.isEntityInsideOpaqueBlock())
861                {
862                    this.gameSettings.thirdPersonView = 0;
863                }
864    
865                this.mcProfiler.endSection();
866    
867                if (!this.skipRenderWorld)
868                {
869                    FMLCommonHandler.instance().onRenderTickStart(this.timer.renderPartialTicks);
870                    this.mcProfiler.endStartSection("gameRenderer");
871                    this.entityRenderer.updateCameraAndRender(this.timer.renderPartialTicks);
872                    this.mcProfiler.endSection();
873                    FMLCommonHandler.instance().onRenderTickEnd(this.timer.renderPartialTicks);
874                }
875    
876                GL11.glFlush();
877                this.mcProfiler.endSection();
878    
879                if (!Display.isActive() && this.fullscreen)
880                {
881                    this.toggleFullscreen();
882                }
883    
884                if (this.gameSettings.showDebugInfo && this.gameSettings.field_74329_Q)
885                {
886                    if (!this.mcProfiler.profilingEnabled)
887                    {
888                        this.mcProfiler.clearProfiling();
889                    }
890    
891                    this.mcProfiler.profilingEnabled = true;
892                    this.displayDebugInfo(var7);
893                }
894                else
895                {
896                    this.mcProfiler.profilingEnabled = false;
897                    this.prevFrameTime = System.nanoTime();
898                }
899    
900                this.guiAchievement.updateAchievementWindow();
901                this.mcProfiler.startSection("root");
902                Thread.yield();
903    
904                if (Keyboard.isKeyDown(65))
905                {
906                    Display.update();
907                }
908    
909                this.screenshotListener();
910    
911                if (this.mcCanvas != null && !this.fullscreen && (this.mcCanvas.getWidth() != this.displayWidth || this.mcCanvas.getHeight() != this.displayHeight))
912                {
913                    this.displayWidth = this.mcCanvas.getWidth();
914                    this.displayHeight = this.mcCanvas.getHeight();
915    
916                    if (this.displayWidth <= 0)
917                    {
918                        this.displayWidth = 1;
919                    }
920    
921                    if (this.displayHeight <= 0)
922                    {
923                        this.displayHeight = 1;
924                    }
925    
926                    this.resize(this.displayWidth, this.displayHeight);
927                }
928    
929                this.checkGLError("Post render");
930                ++this.fpsCounter;
931                boolean var5 = this.isGamePaused;
932                this.isGamePaused = this.isSingleplayer() && this.currentScreen != null && this.currentScreen.doesGuiPauseGame() && !this.theIntegratedServer.func_71344_c();
933    
934                if (this.isIntegratedServerRunning() && this.thePlayer != null && this.thePlayer.sendQueue != null && this.isGamePaused != var5)
935                {
936                    ((MemoryConnection)this.thePlayer.sendQueue.getNetManager()).setGamePaused(this.isGamePaused);
937                }
938    
939                while (getSystemTime() >= this.debugUpdateTime + 1000L)
940                {
941                    field_71470_ab = this.fpsCounter;
942                    this.debug = field_71470_ab + " fps, " + WorldRenderer.chunksUpdated + " chunk updates";
943                    WorldRenderer.chunksUpdated = 0;
944                    this.debugUpdateTime += 1000L;
945                    this.fpsCounter = 0;
946                    this.usageSnooper.addMemoryStatsToSnooper();
947    
948                    if (!this.usageSnooper.isSnooperRunning())
949                    {
950                        this.usageSnooper.startSnooper();
951                    }
952                }
953    
954                this.mcProfiler.endSection();
955    
956                if (this.gameSettings.limitFramerate > 0)
957                {
958                    EntityRenderer var10000 = this.entityRenderer;
959                    Display.sync(EntityRenderer.func_78465_a(this.gameSettings.limitFramerate));
960                }
961            }
962        }
963    
964        public void freeMemory()
965        {
966            try
967            {
968                clientExperience = new byte[0];
969                this.renderGlobal.func_72728_f();
970            }
971            catch (Throwable var4)
972            {
973                ;
974            }
975    
976            try
977            {
978                System.gc();
979                AxisAlignedBB.getAABBPool().clearPool();
980                Vec3.getVec3Pool().clearAndFreeCache();
981            }
982            catch (Throwable var3)
983            {
984                ;
985            }
986    
987            try
988            {
989                System.gc();
990                this.loadWorld((WorldClient)null);
991            }
992            catch (Throwable var2)
993            {
994                ;
995            }
996    
997            System.gc();
998        }
999    
1000        /**
1001         * checks if keys are down
1002         */
1003        private void screenshotListener()
1004        {
1005            if (Keyboard.isKeyDown(60))
1006            {
1007                if (!this.isTakingScreenshot)
1008                {
1009                    this.isTakingScreenshot = true;
1010                    this.ingameGUI.getChatGUI().printChatMessage(ScreenShotHelper.saveScreenshot(minecraftDir, this.displayWidth, this.displayHeight));
1011                }
1012            }
1013            else
1014            {
1015                this.isTakingScreenshot = false;
1016            }
1017        }
1018    
1019        /**
1020         * Update debugProfilerName in response to number keys in debug screen
1021         */
1022        private void updateDebugProfilerName(int par1)
1023        {
1024            List var2 = this.mcProfiler.getProfilingData(this.debugProfilerName);
1025    
1026            if (var2 != null && !var2.isEmpty())
1027            {
1028                ProfilerResult var3 = (ProfilerResult)var2.remove(0);
1029    
1030                if (par1 == 0)
1031                {
1032                    if (var3.field_76331_c.length() > 0)
1033                    {
1034                        int var4 = this.debugProfilerName.lastIndexOf(".");
1035    
1036                        if (var4 >= 0)
1037                        {
1038                            this.debugProfilerName = this.debugProfilerName.substring(0, var4);
1039                        }
1040                    }
1041                }
1042                else
1043                {
1044                    --par1;
1045    
1046                    if (par1 < var2.size() && !((ProfilerResult)var2.get(par1)).field_76331_c.equals("unspecified"))
1047                    {
1048                        if (this.debugProfilerName.length() > 0)
1049                        {
1050                            this.debugProfilerName = this.debugProfilerName + ".";
1051                        }
1052    
1053                        this.debugProfilerName = this.debugProfilerName + ((ProfilerResult)var2.get(par1)).field_76331_c;
1054                    }
1055                }
1056            }
1057        }
1058    
1059        private void displayDebugInfo(long par1)
1060        {
1061            if (this.mcProfiler.profilingEnabled)
1062            {
1063                List var3 = this.mcProfiler.getProfilingData(this.debugProfilerName);
1064                ProfilerResult var4 = (ProfilerResult)var3.remove(0);
1065                GL11.glClear(256);
1066                GL11.glMatrixMode(GL11.GL_PROJECTION);
1067                GL11.glEnable(GL11.GL_COLOR_MATERIAL);
1068                GL11.glLoadIdentity();
1069                GL11.glOrtho(0.0D, (double)this.displayWidth, (double)this.displayHeight, 0.0D, 1000.0D, 3000.0D);
1070                GL11.glMatrixMode(GL11.GL_MODELVIEW);
1071                GL11.glLoadIdentity();
1072                GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
1073                GL11.glLineWidth(1.0F);
1074                GL11.glDisable(GL11.GL_TEXTURE_2D);
1075                Tessellator var5 = Tessellator.instance;
1076                short var6 = 160;
1077                int var7 = this.displayWidth - var6 - 10;
1078                int var8 = this.displayHeight - var6 * 2;
1079                GL11.glEnable(GL11.GL_BLEND);
1080                var5.startDrawingQuads();
1081                var5.setColorRGBA_I(0, 200);
1082                var5.addVertex((double)((float)var7 - (float)var6 * 1.1F), (double)((float)var8 - (float)var6 * 0.6F - 16.0F), 0.0D);
1083                var5.addVertex((double)((float)var7 - (float)var6 * 1.1F), (double)(var8 + var6 * 2), 0.0D);
1084                var5.addVertex((double)((float)var7 + (float)var6 * 1.1F), (double)(var8 + var6 * 2), 0.0D);
1085                var5.addVertex((double)((float)var7 + (float)var6 * 1.1F), (double)((float)var8 - (float)var6 * 0.6F - 16.0F), 0.0D);
1086                var5.draw();
1087                GL11.glDisable(GL11.GL_BLEND);
1088                double var9 = 0.0D;
1089                int var13;
1090    
1091                for (int var11 = 0; var11 < var3.size(); ++var11)
1092                {
1093                    ProfilerResult var12 = (ProfilerResult)var3.get(var11);
1094                    var13 = MathHelper.floor_double(var12.field_76332_a / 4.0D) + 1;
1095                    var5.startDrawing(6);
1096                    var5.setColorOpaque_I(var12.func_76329_a());
1097                    var5.addVertex((double)var7, (double)var8, 0.0D);
1098                    int var14;
1099                    float var15;
1100                    float var17;
1101                    float var16;
1102    
1103                    for (var14 = var13; var14 >= 0; --var14)
1104                    {
1105                        var15 = (float)((var9 + var12.field_76332_a * (double)var14 / (double)var13) * Math.PI * 2.0D / 100.0D);
1106                        var16 = MathHelper.sin(var15) * (float)var6;
1107                        var17 = MathHelper.cos(var15) * (float)var6 * 0.5F;
1108                        var5.addVertex((double)((float)var7 + var16), (double)((float)var8 - var17), 0.0D);
1109                    }
1110    
1111                    var5.draw();
1112                    var5.startDrawing(5);
1113                    var5.setColorOpaque_I((var12.func_76329_a() & 16711422) >> 1);
1114    
1115                    for (var14 = var13; var14 >= 0; --var14)
1116                    {
1117                        var15 = (float)((var9 + var12.field_76332_a * (double)var14 / (double)var13) * Math.PI * 2.0D / 100.0D);
1118                        var16 = MathHelper.sin(var15) * (float)var6;
1119                        var17 = MathHelper.cos(var15) * (float)var6 * 0.5F;
1120                        var5.addVertex((double)((float)var7 + var16), (double)((float)var8 - var17), 0.0D);
1121                        var5.addVertex((double)((float)var7 + var16), (double)((float)var8 - var17 + 10.0F), 0.0D);
1122                    }
1123    
1124                    var5.draw();
1125                    var9 += var12.field_76332_a;
1126                }
1127    
1128                DecimalFormat var19 = new DecimalFormat("##0.00");
1129                GL11.glEnable(GL11.GL_TEXTURE_2D);
1130                String var18 = "";
1131    
1132                if (!var4.field_76331_c.equals("unspecified"))
1133                {
1134                    var18 = var18 + "[0] ";
1135                }
1136    
1137                if (var4.field_76331_c.length() == 0)
1138                {
1139                    var18 = var18 + "ROOT ";
1140                }
1141                else
1142                {
1143                    var18 = var18 + var4.field_76331_c + " ";
1144                }
1145    
1146                var13 = 16777215;
1147                this.fontRenderer.drawStringWithShadow(var18, var7 - var6, var8 - var6 / 2 - 16, var13);
1148                this.fontRenderer.drawStringWithShadow(var18 = var19.format(var4.field_76330_b) + "%", var7 + var6 - this.fontRenderer.getStringWidth(var18), var8 - var6 / 2 - 16, var13);
1149    
1150                for (int var21 = 0; var21 < var3.size(); ++var21)
1151                {
1152                    ProfilerResult var20 = (ProfilerResult)var3.get(var21);
1153                    String var22 = "";
1154    
1155                    if (var20.field_76331_c.equals("unspecified"))
1156                    {
1157                        var22 = var22 + "[?] ";
1158                    }
1159                    else
1160                    {
1161                        var22 = var22 + "[" + (var21 + 1) + "] ";
1162                    }
1163    
1164                    var22 = var22 + var20.field_76331_c;
1165                    this.fontRenderer.drawStringWithShadow(var22, var7 - var6, var8 + var6 / 2 + var21 * 8 + 20, var20.func_76329_a());
1166                    this.fontRenderer.drawStringWithShadow(var22 = var19.format(var20.field_76332_a) + "%", var7 + var6 - 50 - this.fontRenderer.getStringWidth(var22), var8 + var6 / 2 + var21 * 8 + 20, var20.func_76329_a());
1167                    this.fontRenderer.drawStringWithShadow(var22 = var19.format(var20.field_76330_b) + "%", var7 + var6 - this.fontRenderer.getStringWidth(var22), var8 + var6 / 2 + var21 * 8 + 20, var20.func_76329_a());
1168                }
1169            }
1170        }
1171    
1172        /**
1173         * Called when the window is closing. Sets 'running' to false which allows the game loop to exit cleanly.
1174         */
1175        public void shutdown()
1176        {
1177            this.running = false;
1178        }
1179    
1180        /**
1181         * Will set the focus to ingame if the Minecraft window is the active with focus. Also clears any GUI screen
1182         * currently displayed
1183         */
1184        public void setIngameFocus()
1185        {
1186            if (Display.isActive())
1187            {
1188                if (!this.inGameHasFocus)
1189                {
1190                    this.inGameHasFocus = true;
1191                    this.mouseHelper.grabMouseCursor();
1192                    this.displayGuiScreen((GuiScreen)null);
1193                    this.leftClickCounter = 10000;
1194                }
1195            }
1196        }
1197    
1198        /**
1199         * Resets the player keystate, disables the ingame focus, and ungrabs the mouse cursor.
1200         */
1201        public void setIngameNotInFocus()
1202        {
1203            if (this.inGameHasFocus)
1204            {
1205                KeyBinding.unPressAllKeys();
1206                this.inGameHasFocus = false;
1207                this.mouseHelper.ungrabMouseCursor();
1208            }
1209        }
1210    
1211        /**
1212         * Displays the ingame menu
1213         */
1214        public void displayInGameMenu()
1215        {
1216            if (this.currentScreen == null)
1217            {
1218                this.displayGuiScreen(new GuiIngameMenu());
1219            }
1220        }
1221    
1222        private void sendClickBlockToController(int par1, boolean par2)
1223        {
1224            if (!par2)
1225            {
1226                this.leftClickCounter = 0;
1227            }
1228    
1229            if (par1 != 0 || this.leftClickCounter <= 0)
1230            {
1231                if (par2 && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == EnumMovingObjectType.TILE && par1 == 0)
1232                {
1233                    int var3 = this.objectMouseOver.blockX;
1234                    int var4 = this.objectMouseOver.blockY;
1235                    int var5 = this.objectMouseOver.blockZ;
1236                    this.playerController.onPlayerDamageBlock(var3, var4, var5, this.objectMouseOver.sideHit);
1237    
1238                    if (this.thePlayer.canPlayerEdit(var3, var4, var5))
1239                    {
1240                        this.effectRenderer.addBlockHitEffects(var3, var4, var5, this.objectMouseOver.sideHit);
1241                        this.thePlayer.swingItem();
1242                    }
1243                }
1244                else
1245                {
1246                    this.playerController.resetBlockRemoving();
1247                }
1248            }
1249        }
1250    
1251        /**
1252         * Called whenever the mouse is clicked. Button clicked is 0 for left clicking and 1 for right clicking. Args:
1253         * buttonClicked
1254         */
1255        private void clickMouse(int par1)
1256        {
1257            if (par1 != 0 || this.leftClickCounter <= 0)
1258            {
1259                if (par1 == 0)
1260                {
1261                    this.thePlayer.swingItem();
1262                }
1263    
1264                if (par1 == 1)
1265                {
1266                    this.rightClickDelayTimer = 4;
1267                }
1268    
1269                boolean var2 = true;
1270                ItemStack var3 = this.thePlayer.inventory.getCurrentItem();
1271    
1272                if (this.objectMouseOver == null)
1273                {
1274                    if (par1 == 0 && this.playerController.isNotCreative())
1275                    {
1276                        this.leftClickCounter = 10;
1277                    }
1278                }
1279                else if (this.objectMouseOver.typeOfHit == EnumMovingObjectType.ENTITY)
1280                {
1281                    if (par1 == 0)
1282                    {
1283                        this.playerController.attackEntity(this.thePlayer, this.objectMouseOver.entityHit);
1284                    }
1285    
1286                    if (par1 == 1 && this.playerController.func_78768_b(this.thePlayer, this.objectMouseOver.entityHit))
1287                    {
1288                        var2 = false;
1289                    }
1290                }
1291                else if (this.objectMouseOver.typeOfHit == EnumMovingObjectType.TILE)
1292                {
1293                    int var4 = this.objectMouseOver.blockX;
1294                    int var5 = this.objectMouseOver.blockY;
1295                    int var6 = this.objectMouseOver.blockZ;
1296                    int var7 = this.objectMouseOver.sideHit;
1297    
1298                    if (par1 == 0)
1299                    {
1300                        this.playerController.clickBlock(var4, var5, var6, this.objectMouseOver.sideHit);
1301                    }
1302                    else
1303                    {
1304                        int var8 = var3 != null ? var3.stackSize : 0;
1305    
1306                        if (this.playerController.onPlayerRightClick(this.thePlayer, this.theWorld, var3, var4, var5, var6, var7, this.objectMouseOver.hitVec))
1307                        {
1308                            var2 = false;
1309                            this.thePlayer.swingItem();
1310                        }
1311    
1312                        if (var3 == null)
1313                        {
1314                            return;
1315                        }
1316    
1317                        if (var3.stackSize == 0)
1318                        {
1319                            this.thePlayer.inventory.mainInventory[this.thePlayer.inventory.currentItem] = null;
1320                        }
1321                        else if (var3.stackSize != var8 || this.playerController.isInCreativeMode())
1322                        {
1323                            this.entityRenderer.itemRenderer.func_78444_b();
1324                        }
1325                    }
1326                }
1327    
1328                if (var2 && par1 == 1)
1329                {
1330                    ItemStack var9 = this.thePlayer.inventory.getCurrentItem();
1331    
1332                    if (var9 != null && this.playerController.sendUseItem(this.thePlayer, this.theWorld, var9))
1333                    {
1334                        this.entityRenderer.itemRenderer.func_78445_c();
1335                    }
1336                }
1337            }
1338        }
1339    
1340        /**
1341         * Toggles fullscreen mode.
1342         */
1343        public void toggleFullscreen()
1344        {
1345            try
1346            {
1347                this.fullscreen = !this.fullscreen;
1348    
1349                if (this.fullscreen)
1350                {
1351                    Display.setDisplayMode(Display.getDesktopDisplayMode());
1352                    this.displayWidth = Display.getDisplayMode().getWidth();
1353                    this.displayHeight = Display.getDisplayMode().getHeight();
1354    
1355                    if (this.displayWidth <= 0)
1356                    {
1357                        this.displayWidth = 1;
1358                    }
1359    
1360                    if (this.displayHeight <= 0)
1361                    {
1362                        this.displayHeight = 1;
1363                    }
1364                }
1365                else
1366                {
1367                    if (this.mcCanvas != null)
1368                    {
1369                        this.displayWidth = this.mcCanvas.getWidth();
1370                        this.displayHeight = this.mcCanvas.getHeight();
1371                    }
1372                    else
1373                    {
1374                        this.displayWidth = this.tempDisplayWidth;
1375                        this.displayHeight = this.tempDisplayHeight;
1376                    }
1377    
1378                    if (this.displayWidth <= 0)
1379                    {
1380                        this.displayWidth = 1;
1381                    }
1382    
1383                    if (this.displayHeight <= 0)
1384                    {
1385                        this.displayHeight = 1;
1386                    }
1387                }
1388    
1389                if (this.currentScreen != null)
1390                {
1391                    this.resize(this.displayWidth, this.displayHeight);
1392                }
1393    
1394                Display.setFullscreen(this.fullscreen);
1395                Display.setVSyncEnabled(this.gameSettings.enableVsync);
1396                Display.update();
1397            }
1398            catch (Exception var2)
1399            {
1400                var2.printStackTrace();
1401            }
1402        }
1403    
1404        /**
1405         * Called to resize the current screen.
1406         */
1407        private void resize(int par1, int par2)
1408        {
1409            this.displayWidth = par1 <= 0 ? 1 : par1;
1410            this.displayHeight = par2 <= 0 ? 1 : par2;
1411    
1412            if (this.currentScreen != null)
1413            {
1414                ScaledResolution var3 = new ScaledResolution(this.gameSettings, par1, par2);
1415                int var4 = var3.getScaledWidth();
1416                int var5 = var3.getScaledHeight();
1417                this.currentScreen.setWorldAndResolution(this, var4, var5);
1418            }
1419        }
1420    
1421        /**
1422         * Runs the current tick.
1423         */
1424        public void runTick()
1425        {
1426            FMLCommonHandler.instance().rescheduleTicks(Side.CLIENT);
1427            if (this.rightClickDelayTimer > 0)
1428            {
1429                --this.rightClickDelayTimer;
1430            }
1431    
1432            FMLCommonHandler.instance().onPreClientTick();
1433            this.mcProfiler.startSection("stats");
1434            this.statFileWriter.func_77449_e();
1435            this.mcProfiler.endStartSection("gui");
1436    
1437            if (!this.isGamePaused)
1438            {
1439                this.ingameGUI.updateTick();
1440            }
1441    
1442            this.mcProfiler.endStartSection("pick");
1443            this.entityRenderer.getMouseOver(1.0F);
1444            this.mcProfiler.endStartSection("gameMode");
1445    
1446            if (!this.isGamePaused && this.theWorld != null)
1447            {
1448                this.playerController.updateController();
1449            }
1450    
1451            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.renderEngine.getTexture("/terrain.png"));
1452            this.mcProfiler.endStartSection("textures");
1453    
1454            if (!this.isGamePaused)
1455            {
1456                this.renderEngine.updateDynamicTextures();
1457            }
1458    
1459            if (this.currentScreen == null && this.thePlayer != null)
1460            {
1461                if (this.thePlayer.getHealth() <= 0)
1462                {
1463                    this.displayGuiScreen((GuiScreen)null);
1464                }
1465                else if (this.thePlayer.isPlayerSleeping() && this.theWorld != null)
1466                {
1467                    this.displayGuiScreen(new GuiSleepMP());
1468                }
1469            }
1470            else if (this.currentScreen != null && this.currentScreen instanceof GuiSleepMP && !this.thePlayer.isPlayerSleeping())
1471            {
1472                this.displayGuiScreen((GuiScreen)null);
1473            }
1474    
1475            if (this.currentScreen != null)
1476            {
1477                this.leftClickCounter = 10000;
1478            }
1479    
1480            if (this.currentScreen != null)
1481            {
1482                this.currentScreen.handleInput();
1483    
1484                if (this.currentScreen != null)
1485                {
1486                    this.currentScreen.guiParticles.update();
1487                    this.currentScreen.updateScreen();
1488                }
1489            }
1490    
1491            if (this.currentScreen == null || this.currentScreen.allowUserInput)
1492            {
1493                this.mcProfiler.endStartSection("mouse");
1494    
1495                while (Mouse.next())
1496                {
1497                    KeyBinding.setKeyBindState(Mouse.getEventButton() - 100, Mouse.getEventButtonState());
1498    
1499                    if (Mouse.getEventButtonState())
1500                    {
1501                        KeyBinding.onTick(Mouse.getEventButton() - 100);
1502                    }
1503    
1504                    long var1 = getSystemTime() - this.systemTime;
1505    
1506                    if (var1 <= 200L)
1507                    {
1508                        int var3 = Mouse.getEventDWheel();
1509    
1510                        if (var3 != 0)
1511                        {
1512                            this.thePlayer.inventory.changeCurrentItem(var3);
1513    
1514                            if (this.gameSettings.noclip)
1515                            {
1516                                if (var3 > 0)
1517                                {
1518                                    var3 = 1;
1519                                }
1520    
1521                                if (var3 < 0)
1522                                {
1523                                    var3 = -1;
1524                                }
1525    
1526                                this.gameSettings.noclipRate += (float)var3 * 0.25F;
1527                            }
1528                        }
1529    
1530                        if (this.currentScreen == null)
1531                        {
1532                            if (!this.inGameHasFocus && Mouse.getEventButtonState())
1533                            {
1534                                this.setIngameFocus();
1535                            }
1536                        }
1537                        else if (this.currentScreen != null)
1538                        {
1539                            this.currentScreen.handleMouseInput();
1540                        }
1541                    }
1542                }
1543    
1544                if (this.leftClickCounter > 0)
1545                {
1546                    --this.leftClickCounter;
1547                }
1548    
1549                this.mcProfiler.endStartSection("keyboard");
1550                boolean var4;
1551    
1552                while (Keyboard.next())
1553                {
1554                    KeyBinding.setKeyBindState(Keyboard.getEventKey(), Keyboard.getEventKeyState());
1555    
1556                    if (Keyboard.getEventKeyState())
1557                    {
1558                        KeyBinding.onTick(Keyboard.getEventKey());
1559                    }
1560    
1561                    if (Keyboard.getEventKeyState())
1562                    {
1563                        if (Keyboard.getEventKey() == 87)
1564                        {
1565                            this.toggleFullscreen();
1566                        }
1567                        else
1568                        {
1569                            if (this.currentScreen != null)
1570                            {
1571                                this.currentScreen.handleKeyboardInput();
1572                            }
1573                            else
1574                            {
1575                                if (Keyboard.getEventKey() == 1)
1576                                {
1577                                    this.displayInGameMenu();
1578                                }
1579    
1580                                if (Keyboard.getEventKey() == 31 && Keyboard.isKeyDown(61))
1581                                {
1582                                    this.forceReload();
1583                                }
1584    
1585                                if (Keyboard.getEventKey() == 20 && Keyboard.isKeyDown(61))
1586                                {
1587                                    this.renderEngine.refreshTextures();
1588                                }
1589    
1590                                if (Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(61))
1591                                {
1592                                    var4 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
1593                                    this.gameSettings.setOptionValue(EnumOptions.RENDER_DISTANCE, var4 ? -1 : 1);
1594                                }
1595    
1596                                if (Keyboard.getEventKey() == 30 && Keyboard.isKeyDown(61))
1597                                {
1598                                    this.renderGlobal.loadRenderers();
1599                                }
1600    
1601                                if (Keyboard.getEventKey() == 59)
1602                                {
1603                                    this.gameSettings.hideGUI = !this.gameSettings.hideGUI;
1604                                }
1605    
1606                                if (Keyboard.getEventKey() == 61)
1607                                {
1608                                    this.gameSettings.showDebugInfo = !this.gameSettings.showDebugInfo;
1609                                    this.gameSettings.field_74329_Q = !GuiScreen.isShiftKeyDown();
1610                                }
1611    
1612                                if (Keyboard.getEventKey() == 63)
1613                                {
1614                                    ++this.gameSettings.thirdPersonView;
1615    
1616                                    if (this.gameSettings.thirdPersonView > 2)
1617                                    {
1618                                        this.gameSettings.thirdPersonView = 0;
1619                                    }
1620                                }
1621    
1622                                if (Keyboard.getEventKey() == 66)
1623                                {
1624                                    this.gameSettings.smoothCamera = !this.gameSettings.smoothCamera;
1625                                }
1626                            }
1627    
1628                            int var5;
1629    
1630                            for (var5 = 0; var5 < 9; ++var5)
1631                            {
1632                                if (Keyboard.getEventKey() == 2 + var5)
1633                                {
1634                                    this.thePlayer.inventory.currentItem = var5;
1635                                }
1636                            }
1637    
1638                            if (this.gameSettings.showDebugInfo && this.gameSettings.field_74329_Q)
1639                            {
1640                                if (Keyboard.getEventKey() == 11)
1641                                {
1642                                    this.updateDebugProfilerName(0);
1643                                }
1644    
1645                                for (var5 = 0; var5 < 9; ++var5)
1646                                {
1647                                    if (Keyboard.getEventKey() == 2 + var5)
1648                                    {
1649                                        this.updateDebugProfilerName(var5 + 1);
1650                                    }
1651                                }
1652                            }
1653                        }
1654                    }
1655                }
1656    
1657                var4 = this.gameSettings.chatVisibility != 2;
1658    
1659                while (this.gameSettings.keyBindInventory.isPressed())
1660                {
1661                    this.displayGuiScreen(new GuiInventory(this.thePlayer));
1662                }
1663    
1664                while (this.gameSettings.keyBindDrop.isPressed())
1665                {
1666                    this.thePlayer.dropOneItem();
1667                }
1668    
1669                while (this.gameSettings.keyBindChat.isPressed() && var4)
1670                {
1671                    this.displayGuiScreen(new GuiChat());
1672                }
1673    
1674                if (this.currentScreen == null && this.gameSettings.field_74323_J.isPressed() && var4)
1675                {
1676                    this.displayGuiScreen(new GuiChat("/"));
1677                }
1678    
1679                if (this.thePlayer.isUsingItem())
1680                {
1681                    if (!this.gameSettings.keyBindUseItem.pressed)
1682                    {
1683                        this.playerController.onStoppedUsingItem(this.thePlayer);
1684                    }
1685    
1686                    label309:
1687    
1688                    while (true)
1689                    {
1690                        if (!this.gameSettings.keyBindAttack.isPressed())
1691                        {
1692                            while (this.gameSettings.keyBindUseItem.isPressed())
1693                            {
1694                                ;
1695                            }
1696    
1697                            while (true)
1698                            {
1699                                if (this.gameSettings.keyBindPickBlock.isPressed())
1700                                {
1701                                    continue;
1702                                }
1703    
1704                                break label309;
1705                            }
1706                        }
1707                    }
1708                }
1709                else
1710                {
1711                    while (this.gameSettings.keyBindAttack.isPressed())
1712                    {
1713                        this.clickMouse(0);
1714                    }
1715    
1716                    while (this.gameSettings.keyBindUseItem.isPressed())
1717                    {
1718                        this.clickMouse(1);
1719                    }
1720    
1721                    while (this.gameSettings.keyBindPickBlock.isPressed())
1722                    {
1723                        this.clickMiddleMouseButton();
1724                    }
1725                }
1726    
1727                if (this.gameSettings.keyBindUseItem.pressed && this.rightClickDelayTimer == 0 && !this.thePlayer.isUsingItem())
1728                {
1729                    this.clickMouse(1);
1730                }
1731    
1732                this.sendClickBlockToController(0, this.currentScreen == null && this.gameSettings.keyBindAttack.pressed && this.inGameHasFocus);
1733            }
1734    
1735            if (this.theWorld != null)
1736            {
1737                if (this.thePlayer != null)
1738                {
1739                    ++this.joinPlayerCounter;
1740    
1741                    if (this.joinPlayerCounter == 30)
1742                    {
1743                        this.joinPlayerCounter = 0;
1744                        this.theWorld.joinEntityInSurroundings(this.thePlayer);
1745                    }
1746                }
1747    
1748                this.mcProfiler.endStartSection("gameRenderer");
1749    
1750                if (!this.isGamePaused)
1751                {
1752                    this.entityRenderer.updateRenderer();
1753                }
1754    
1755                this.mcProfiler.endStartSection("levelRenderer");
1756    
1757                if (!this.isGamePaused)
1758                {
1759                    this.renderGlobal.updateClouds();
1760                }
1761    
1762                this.mcProfiler.endStartSection("level");
1763    
1764                if (!this.isGamePaused)
1765                {
1766                    if (this.theWorld.lightningFlash > 0)
1767                    {
1768                        --this.theWorld.lightningFlash;
1769                    }
1770    
1771                    this.theWorld.updateEntities();
1772                }
1773    
1774                if (!this.isGamePaused)
1775                {
1776                    this.theWorld.setAllowedSpawnTypes(this.theWorld.difficultySetting > 0, true);
1777                    this.theWorld.tick();
1778                }
1779    
1780                this.mcProfiler.endStartSection("animateTick");
1781    
1782                if (!this.isGamePaused && this.theWorld != null)
1783                {
1784                    this.theWorld.func_73029_E(MathHelper.floor_double(this.thePlayer.posX), MathHelper.floor_double(this.thePlayer.posY), MathHelper.floor_double(this.thePlayer.posZ));
1785                }
1786    
1787                this.mcProfiler.endStartSection("particles");
1788    
1789                if (!this.isGamePaused)
1790                {
1791                    this.effectRenderer.updateEffects();
1792                }
1793            }
1794            else if (this.myNetworkManager != null)
1795            {
1796                this.mcProfiler.endStartSection("pendingConnection");
1797                this.myNetworkManager.processReadPackets();
1798            }
1799    
1800            FMLCommonHandler.instance().onPostClientTick();
1801            this.mcProfiler.endSection();
1802            this.systemTime = getSystemTime();
1803        }
1804    
1805        /**
1806         * Forces a reload of the sound manager and all the resources. Called in game by holding 'F3' and pressing 'S'.
1807         */
1808        private void forceReload()
1809        {
1810            System.out.println("FORCING RELOAD!");
1811            this.sndManager = new SoundManager();
1812            this.sndManager.loadSoundSettings(this.gameSettings);
1813            this.downloadResourcesThread.reloadResources();
1814        }
1815    
1816        /**
1817         * Arguments: World foldername,  World ingame name, WorldSettings
1818         */
1819        public void launchIntegratedServer(String par1Str, String par2Str, WorldSettings par3WorldSettings)
1820        {
1821            this.loadWorld((WorldClient)null);
1822            System.gc();
1823            ISaveHandler var4 = this.saveLoader.getSaveLoader(par1Str, false);
1824            WorldInfo var5 = var4.loadWorldInfo();
1825    
1826            if (var5 == null && par3WorldSettings != null)
1827            {
1828                this.statFileWriter.readStat(StatList.createWorldStat, 1);
1829                var5 = new WorldInfo(par3WorldSettings, par1Str);
1830                var4.saveWorldInfo(var5);
1831            }
1832    
1833            if (par3WorldSettings == null)
1834            {
1835                par3WorldSettings = new WorldSettings(var5);
1836            }
1837    
1838            this.statFileWriter.readStat(StatList.startGameStat, 1);
1839            this.theIntegratedServer = new IntegratedServer(this, par1Str, par2Str, par3WorldSettings);
1840            this.theIntegratedServer.startServerThread();
1841            this.integratedServerIsRunning = true;
1842            this.loadingScreen.displayProgressMessage(StatCollector.translateToLocal("menu.loadingLevel"));
1843    
1844            while (!this.theIntegratedServer.serverIsInRunLoop())
1845            {
1846                String var6 = this.theIntegratedServer.getUserMessage();
1847    
1848                if (var6 != null)
1849                {
1850                    this.loadingScreen.resetProgresAndWorkingMessage(StatCollector.translateToLocal(var6));
1851                }
1852                else
1853                {
1854                    this.loadingScreen.resetProgresAndWorkingMessage("");
1855                }
1856    
1857                try
1858                {
1859                    Thread.sleep(200L);
1860                }
1861                catch (InterruptedException var9)
1862                {
1863                    ;
1864                }
1865            }
1866    
1867            this.displayGuiScreen((GuiScreen)null);
1868    
1869            try
1870            {
1871                NetClientHandler var10 = new NetClientHandler(this, this.theIntegratedServer);
1872                this.myNetworkManager = var10.getNetManager();
1873            }
1874            catch (IOException var8)
1875            {
1876                this.displayCrashReport(this.func_71396_d(new CrashReport("Connecting to integrated server", var8)));
1877            }
1878        }
1879    
1880        /**
1881         * unloads the current world first
1882         */
1883        public void loadWorld(WorldClient par1WorldClient)
1884        {
1885            this.loadWorld(par1WorldClient, "");
1886        }
1887    
1888        /**
1889         * par2Str is displayed on the loading screen to the user unloads the current world first
1890         */
1891        public void loadWorld(WorldClient par1WorldClient, String par2Str)
1892        {
1893            this.statFileWriter.syncStats();
1894    
1895            if (par1WorldClient == null)
1896            {
1897                NetClientHandler var3 = this.getSendQueue();
1898    
1899                if (var3 != null)
1900                {
1901                    var3.cleanup();
1902                }
1903    
1904                if (this.myNetworkManager != null)
1905                {
1906                    this.myNetworkManager.closeConnections();
1907                }
1908    
1909                if (this.theIntegratedServer != null)
1910                {
1911                    this.theIntegratedServer.setServerStopping();
1912                }
1913    
1914                this.theIntegratedServer = null;
1915            }
1916    
1917            this.renderViewEntity = null;
1918            this.myNetworkManager = null;
1919    
1920            if (this.loadingScreen != null)
1921            {
1922                this.loadingScreen.resetProgressAndMessage(par2Str);
1923                this.loadingScreen.resetProgresAndWorkingMessage("");
1924            }
1925    
1926            if (par1WorldClient == null && this.theWorld != null)
1927            {
1928                if (this.texturePackList.func_77295_a())
1929                {
1930                    this.texturePackList.func_77304_b();
1931                }
1932    
1933                this.setServerData((ServerData)null);
1934                this.integratedServerIsRunning = false;
1935            }
1936    
1937            this.sndManager.playStreaming((String)null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
1938            this.theWorld = par1WorldClient;
1939    
1940            if (par1WorldClient != null)
1941            {
1942                if (this.renderGlobal != null)
1943                {
1944                    this.renderGlobal.setWorldAndLoadRenderers(par1WorldClient);
1945                }
1946    
1947                if (this.effectRenderer != null)
1948                {
1949                    this.effectRenderer.clearEffects(par1WorldClient);
1950                }
1951    
1952                if (this.thePlayer == null)
1953                {
1954                    this.thePlayer = this.playerController.func_78754_a(par1WorldClient);
1955                    this.playerController.flipPlayer(this.thePlayer);
1956                }
1957    
1958                this.thePlayer.preparePlayerToSpawn();
1959                par1WorldClient.spawnEntityInWorld(this.thePlayer);
1960                this.thePlayer.movementInput = new MovementInputFromOptions(this.gameSettings);
1961                this.playerController.func_78748_a(this.thePlayer);
1962                this.renderViewEntity = this.thePlayer;
1963            }
1964            else
1965            {
1966                this.saveLoader.flushCache();
1967                this.thePlayer = null;
1968            }
1969    
1970            System.gc();
1971            this.systemTime = 0L;
1972        }
1973    
1974        /**
1975         * Installs a resource. Currently only sounds are download so this method just adds them to the SoundManager.
1976         */
1977        public void installResource(String par1Str, File par2File)
1978        {
1979            int var3 = par1Str.indexOf("/");
1980            String var4 = par1Str.substring(0, var3);
1981            par1Str = par1Str.substring(var3 + 1);
1982    
1983            if (!var4.equalsIgnoreCase("sound") && !var4.equalsIgnoreCase("newsound"))
1984            {
1985                if (var4.equalsIgnoreCase("streaming"))
1986                {
1987                    this.sndManager.addStreaming(par1Str, par2File);
1988                }
1989                else if (var4.equalsIgnoreCase("music") || var4.equalsIgnoreCase("newmusic"))
1990                {
1991                    this.sndManager.addMusic(par1Str, par2File);
1992                }
1993            }
1994            else
1995            {
1996                this.sndManager.addSound(par1Str, par2File);
1997            }
1998        }
1999    
2000        /**
2001         * A String of renderGlobal.getDebugInfoRenders
2002         */
2003        public String debugInfoRenders()
2004        {
2005            return this.renderGlobal.getDebugInfoRenders();
2006        }
2007    
2008        /**
2009         * Gets the information in the F3 menu about how many entities are infront/around you
2010         */
2011        public String getEntityDebug()
2012        {
2013            return this.renderGlobal.getDebugInfoEntities();
2014        }
2015    
2016        /**
2017         * Gets the name of the world's current chunk provider
2018         */
2019        public String getWorldProviderName()
2020        {
2021            return this.theWorld.getProviderName();
2022        }
2023    
2024        /**
2025         * A String of how many entities are in the world
2026         */
2027        public String debugInfoEntities()
2028        {
2029            return "P: " + this.effectRenderer.getStatistics() + ". T: " + this.theWorld.getDebugLoadedEntities();
2030        }
2031    
2032        public void setDimensionAndSpawnPlayer(int par1)
2033        {
2034            this.theWorld.setSpawnLocation();
2035            this.theWorld.removeAllEntities();
2036            int var2 = 0;
2037    
2038            if (this.thePlayer != null)
2039            {
2040                var2 = this.thePlayer.entityId;
2041                this.theWorld.setEntityDead(this.thePlayer);
2042            }
2043    
2044            this.renderViewEntity = null;
2045            this.thePlayer = this.playerController.func_78754_a(this.theWorld);
2046            this.thePlayer.dimension = par1;
2047            this.renderViewEntity = this.thePlayer;
2048            this.thePlayer.preparePlayerToSpawn();
2049            this.theWorld.spawnEntityInWorld(this.thePlayer);
2050            this.playerController.flipPlayer(this.thePlayer);
2051            this.thePlayer.movementInput = new MovementInputFromOptions(this.gameSettings);
2052            this.thePlayer.entityId = var2;
2053            this.playerController.func_78748_a(this.thePlayer);
2054    
2055            if (this.currentScreen instanceof GuiGameOver)
2056            {
2057                this.displayGuiScreen((GuiScreen)null);
2058            }
2059        }
2060    
2061        /**
2062         * Sets whether this is a demo or not.
2063         */
2064        void setDemo(boolean par1)
2065        {
2066            this.isDemo = par1;
2067        }
2068    
2069        /**
2070         * Gets whether this is a demo or not.
2071         */
2072        public final boolean isDemo()
2073        {
2074            return this.isDemo;
2075        }
2076    
2077        /**
2078         * get the client packet send queue
2079         */
2080        public NetClientHandler getSendQueue()
2081        {
2082            return this.thePlayer != null ? this.thePlayer.sendQueue : null;
2083        }
2084    
2085        public static void main(String[] par0ArrayOfStr)
2086        {
2087            FMLRelauncher.handleClientRelaunch(new ArgsWrapper(par0ArrayOfStr));
2088        }
2089    
2090        public static void fmlReentry(ArgsWrapper wrapper)
2091        {
2092            String[] par0ArrayOfStr = wrapper.args;
2093            HashMap var1 = new HashMap();
2094            boolean var2 = false;
2095            boolean var3 = true;
2096            boolean var4 = false;
2097            String var5 = "Player" + getSystemTime() % 1000L;
2098    
2099            if (par0ArrayOfStr.length > 0)
2100            {
2101                var5 = par0ArrayOfStr[0];
2102            }
2103    
2104            String var6 = "-";
2105    
2106            if (par0ArrayOfStr.length > 1)
2107            {
2108                var6 = par0ArrayOfStr[1];
2109            }
2110    
2111            for (int var7 = 2; var7 < par0ArrayOfStr.length; ++var7)
2112            {
2113                String var8 = par0ArrayOfStr[var7];
2114                String var10000;
2115    
2116                if (var7 == par0ArrayOfStr.length - 1)
2117                {
2118                    var10000 = null;
2119                }
2120                else
2121                {
2122                    var10000 = par0ArrayOfStr[var7 + 1];
2123                }
2124    
2125                boolean var10 = false;
2126    
2127                if (!var8.equals("-demo") && !var8.equals("--demo"))
2128                {
2129                    if (var8.equals("--applet"))
2130                    {
2131                        var3 = false;
2132                    }
2133                }
2134                else
2135                {
2136                    var2 = true;
2137                }
2138    
2139                if (var10)
2140                {
2141                    ++var7;
2142                }
2143            }
2144    
2145            var1.put("demo", "" + var2);
2146            var1.put("stand-alone", "" + var3);
2147            var1.put("username", var5);
2148            var1.put("fullscreen", "" + var4);
2149            var1.put("sessionid", var6);
2150            Frame var12 = new Frame();
2151            var12.setTitle("Minecraft");
2152            var12.setBackground(Color.BLACK);
2153            JPanel var11 = new JPanel();
2154            var12.setLayout(new BorderLayout());
2155            var11.setPreferredSize(new Dimension(854, 480));
2156            var12.add(var11, "Center");
2157            var12.pack();
2158            var12.setLocationRelativeTo((Component)null);
2159            var12.setVisible(true);
2160            var12.addWindowListener(new GameWindowListener());
2161            MinecraftFakeLauncher var9 = new MinecraftFakeLauncher(var1);
2162            MinecraftApplet var13 = new MinecraftApplet();
2163            var13.setStub(var9);
2164            var9.setLayout(new BorderLayout());
2165            var9.add(var13, "Center");
2166            var9.validate();
2167            var12.removeAll();
2168            var12.setLayout(new BorderLayout());
2169            var12.add(var9, "Center");
2170            var12.validate();
2171            var13.init();
2172            var13.start();
2173            Runtime.getRuntime().addShutdownHook(new ThreadShutdown());
2174        }
2175    
2176        public static boolean isGuiEnabled()
2177        {
2178            return theMinecraft == null || !theMinecraft.gameSettings.hideGUI;
2179        }
2180    
2181        public static boolean isFancyGraphicsEnabled()
2182        {
2183            return theMinecraft != null && theMinecraft.gameSettings.fancyGraphics;
2184        }
2185    
2186        /**
2187         * Returns if ambient occlusion is enabled
2188         */
2189        public static boolean isAmbientOcclusionEnabled()
2190        {
2191            return theMinecraft != null && theMinecraft.gameSettings.ambientOcclusion;
2192        }
2193    
2194        public static boolean isDebugInfoEnabled()
2195        {
2196            return theMinecraft != null && theMinecraft.gameSettings.showDebugInfo;
2197        }
2198    
2199        /**
2200         * Returns true if the message is a client command and should not be sent to the server. However there are no such
2201         * commands at this point in time.
2202         */
2203        public boolean handleClientCommand(String par1Str)
2204        {
2205            return !par1Str.startsWith("/") ? false : false;
2206        }
2207    
2208        /**
2209         * Called when the middle mouse button gets clicked
2210         */
2211        private void clickMiddleMouseButton()
2212        {
2213            if (this.objectMouseOver != null)
2214            {
2215                boolean var1 = this.thePlayer.capabilities.isCreativeMode;
2216                int var5;
2217    
2218                if (!ForgeHooks.onPickBlock(this.objectMouseOver, this.thePlayer, this.theWorld))
2219                {
2220                    return;
2221                }
2222    
2223                if (var1)
2224                {
2225                    var5 = this.thePlayer.inventorySlots.inventorySlots.size() - 9 + this.thePlayer.inventory.currentItem;
2226                    this.playerController.sendSlotPacket(this.thePlayer.inventory.getStackInSlot(this.thePlayer.inventory.currentItem), var5);
2227                }
2228            }
2229        }
2230    
2231        public CrashReport func_71396_d(CrashReport par1CrashReport)
2232        {
2233            par1CrashReport.addCrashSectionCallable("LWJGL", new CallableLWJGLVersion(this));
2234            par1CrashReport.addCrashSectionCallable("OpenGL", new CallableGLInfo(this));
2235            par1CrashReport.addCrashSectionCallable("Is Modded", new CallableModded(this));
2236            par1CrashReport.addCrashSectionCallable("Type", new CallableType2(this));
2237            par1CrashReport.addCrashSectionCallable("Texture Pack", new CallableTexturePack(this));
2238            par1CrashReport.addCrashSectionCallable("Profiler Position", new CallableClientProfiler(this));
2239    
2240            if (this.theWorld != null)
2241            {
2242                this.theWorld.addWorldInfoToCrashReport(par1CrashReport);
2243            }
2244    
2245            return par1CrashReport;
2246        }
2247    
2248        /**
2249         * Return the singleton Minecraft instance for the game
2250         */
2251        public static Minecraft getMinecraft()
2252        {
2253            return theMinecraft;
2254        }
2255    
2256        public void func_71395_y()
2257        {
2258            this.field_71468_ad = true;
2259        }
2260    
2261        public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper)
2262        {
2263            par1PlayerUsageSnooper.addData("fps", Integer.valueOf(field_71470_ab));
2264            par1PlayerUsageSnooper.addData("texpack_name", this.texturePackList.getSelectedTexturePack().func_77538_c());
2265            par1PlayerUsageSnooper.addData("texpack_resolution", Integer.valueOf(this.texturePackList.getSelectedTexturePack().func_77534_f()));
2266            par1PlayerUsageSnooper.addData("vsync_enabled", Boolean.valueOf(this.gameSettings.enableVsync));
2267            par1PlayerUsageSnooper.addData("display_frequency", Integer.valueOf(Display.getDisplayMode().getFrequency()));
2268            par1PlayerUsageSnooper.addData("display_type", this.fullscreen ? "fullscreen" : "windowed");
2269    
2270            if (this.theIntegratedServer != null && this.theIntegratedServer.func_80003_ah() != null)
2271            {
2272                par1PlayerUsageSnooper.addData("snooper_partner", this.theIntegratedServer.func_80003_ah().func_80006_f());
2273            }
2274        }
2275    
2276        public void addServerTypeToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper)
2277        {
2278            par1PlayerUsageSnooper.addData("opengl_version", GL11.glGetString(GL11.GL_VERSION));
2279            par1PlayerUsageSnooper.addData("opengl_vendor", GL11.glGetString(GL11.GL_VENDOR));
2280            par1PlayerUsageSnooper.addData("client_brand", ClientBrandRetriever.getClientModName());
2281            par1PlayerUsageSnooper.addData("applet", Boolean.valueOf(this.hideQuitButton));
2282            ContextCapabilities var2 = GLContext.getCapabilities();
2283            par1PlayerUsageSnooper.addData("gl_caps[ARB_multitexture]", Boolean.valueOf(var2.GL_ARB_multitexture));
2284            par1PlayerUsageSnooper.addData("gl_caps[ARB_multisample]", Boolean.valueOf(var2.GL_ARB_multisample));
2285            par1PlayerUsageSnooper.addData("gl_caps[ARB_texture_cube_map]", Boolean.valueOf(var2.GL_ARB_texture_cube_map));
2286            par1PlayerUsageSnooper.addData("gl_caps[ARB_vertex_blend]", Boolean.valueOf(var2.GL_ARB_vertex_blend));
2287            par1PlayerUsageSnooper.addData("gl_caps[ARB_matrix_palette]", Boolean.valueOf(var2.GL_ARB_matrix_palette));
2288            par1PlayerUsageSnooper.addData("gl_caps[ARB_vertex_program]", Boolean.valueOf(var2.GL_ARB_vertex_program));
2289            par1PlayerUsageSnooper.addData("gl_caps[ARB_vertex_shader]", Boolean.valueOf(var2.GL_ARB_vertex_shader));
2290            par1PlayerUsageSnooper.addData("gl_caps[ARB_fragment_program]", Boolean.valueOf(var2.GL_ARB_fragment_program));
2291            par1PlayerUsageSnooper.addData("gl_caps[ARB_fragment_shader]", Boolean.valueOf(var2.GL_ARB_fragment_shader));
2292            par1PlayerUsageSnooper.addData("gl_caps[ARB_shader_objects]", Boolean.valueOf(var2.GL_ARB_shader_objects));
2293            par1PlayerUsageSnooper.addData("gl_caps[ARB_vertex_buffer_object]", Boolean.valueOf(var2.GL_ARB_vertex_buffer_object));
2294            par1PlayerUsageSnooper.addData("gl_caps[ARB_framebuffer_object]", Boolean.valueOf(var2.GL_ARB_framebuffer_object));
2295            par1PlayerUsageSnooper.addData("gl_caps[ARB_pixel_buffer_object]", Boolean.valueOf(var2.GL_ARB_pixel_buffer_object));
2296            par1PlayerUsageSnooper.addData("gl_caps[ARB_uniform_buffer_object]", Boolean.valueOf(var2.GL_ARB_uniform_buffer_object));
2297            par1PlayerUsageSnooper.addData("gl_caps[ARB_texture_non_power_of_two]", Boolean.valueOf(var2.GL_ARB_texture_non_power_of_two));
2298            par1PlayerUsageSnooper.addData("gl_max_texture_size", Integer.valueOf(func_71369_N()));
2299        }
2300    
2301        private static int func_71369_N()
2302        {
2303            for (int var0 = 16384; var0 > 0; var0 >>= 1)
2304            {
2305                GL11.glTexImage2D(GL11.GL_PROXY_TEXTURE_2D, 0, GL11.GL_RGBA, var0, var0, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);
2306                int var1 = GL11.glGetTexLevelParameteri(GL11.GL_PROXY_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
2307    
2308                if (var1 != 0)
2309                {
2310                    return var0;
2311                }
2312            }
2313    
2314            return -1;
2315        }
2316    
2317        /**
2318         * Returns whether snooping is enabled or not.
2319         */
2320        public boolean isSnooperEnabled()
2321        {
2322            return this.gameSettings.snooperEnabled;
2323        }
2324    
2325        /**
2326         * Set the current ServerData instance.
2327         */
2328        public void setServerData(ServerData par1ServerData)
2329        {
2330            this.currentServerData = par1ServerData;
2331        }
2332    
2333        /**
2334         * Get the current ServerData instance.
2335         */
2336        public ServerData getServerData()
2337        {
2338            return this.currentServerData;
2339        }
2340    
2341        public boolean isIntegratedServerRunning()
2342        {
2343            return this.integratedServerIsRunning;
2344        }
2345    
2346        /**
2347         * Returns true if there is only one player playing, and the current server is the integrated one.
2348         */
2349        public boolean isSingleplayer()
2350        {
2351            return this.integratedServerIsRunning && this.theIntegratedServer != null;
2352        }
2353    
2354        /**
2355         * Returns the currently running integrated server
2356         */
2357        public IntegratedServer getIntegratedServer()
2358        {
2359            return this.theIntegratedServer;
2360        }
2361    
2362        public static void stopIntegratedServer()
2363        {
2364            if (theMinecraft != null)
2365            {
2366                IntegratedServer var0 = theMinecraft.getIntegratedServer();
2367    
2368                if (var0 != null)
2369                {
2370                    var0.stopServer();
2371                }
2372            }
2373        }
2374    
2375        /**
2376         * Returns the PlayerUsageSnooper instance.
2377         */
2378        public PlayerUsageSnooper getPlayerUsageSnooper()
2379        {
2380            return this.usageSnooper;
2381        }
2382    
2383        /**
2384         * Gets the system time in milliseconds.
2385         */
2386        public static long getSystemTime()
2387        {
2388            return Sys.getTime() * 1000L / Sys.getTimerResolution();
2389        }
2390    
2391        /**
2392         * Returns whether we're in full screen or not.
2393         */
2394        public boolean isFullScreen()
2395        {
2396            return this.fullscreen;
2397        }
2398    }