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