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