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