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