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