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