Advertisement
Guest User

minecraft.java

a guest
Apr 13th, 2012
2,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.30 KB | None | 0 0
  1. package net.minecraft.client;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Canvas;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.awt.Frame;
  9. import java.awt.Graphics;
  10. import java.io.File;
  11. import java.io.PrintStream;
  12. import java.text.DecimalFormat;
  13. import net.minecraft.src.Achievement;
  14. import net.minecraft.src.AchievementList;
  15. import net.minecraft.src.AnvilSaveConverter;
  16. import net.minecraft.src.AxisAlignedBB;
  17. import net.minecraft.src.Block;
  18. import net.minecraft.src.BlockGrass;
  19. import net.minecraft.src.ChunkCoordinates;
  20. import net.minecraft.src.ChunkProviderLoadOrGenerate;
  21. import net.minecraft.src.ColorizerFoliage;
  22. import net.minecraft.src.ColorizerGrass;
  23. import net.minecraft.src.ColorizerWater;
  24. import net.minecraft.src.Container;
  25. import net.minecraft.src.EffectRenderer;
  26. import net.minecraft.src.EntityClientPlayerMP;
  27. import net.minecraft.src.EntityLiving;
  28. import net.minecraft.src.EntityPlayer;
  29. import net.minecraft.src.EntityPlayerSP;
  30. import net.minecraft.src.EntityRenderer;
  31. import net.minecraft.src.EnumMovingObjectType;
  32. import net.minecraft.src.EnumOS2;
  33. import net.minecraft.src.EnumOSMappingHelper;
  34. import net.minecraft.src.EnumOptions;
  35. import net.minecraft.src.FontRenderer;
  36. import net.minecraft.src.GLAllocation;
  37. import net.minecraft.src.GameSettings;
  38. import net.minecraft.src.GameWindowListener;
  39. import net.minecraft.src.GuiAchievement;
  40. import net.minecraft.src.GuiChat;
  41. import net.minecraft.src.GuiConflictWarning;
  42. import net.minecraft.src.GuiConnecting;
  43. import net.minecraft.src.GuiErrorScreen;
  44. import net.minecraft.src.GuiGameOver;
  45. import net.minecraft.src.GuiIngame;
  46. import net.minecraft.src.GuiIngameMenu;
  47. import net.minecraft.src.GuiInventory;
  48. import net.minecraft.src.GuiMainMenu;
  49. import net.minecraft.src.GuiMemoryErrorScreen;
  50. import net.minecraft.src.GuiParticle;
  51. import net.minecraft.src.GuiScreen;
  52. import net.minecraft.src.GuiSleepMP;
  53. import net.minecraft.src.ISaveFormat;
  54. import net.minecraft.src.InventoryPlayer;
  55. import net.minecraft.src.Item;
  56. import net.minecraft.src.ItemBlock;
  57. import net.minecraft.src.ItemRenderer;
  58. import net.minecraft.src.ItemStack;
  59. import net.minecraft.src.KeyBinding;
  60. import net.minecraft.src.LoadingScreenRenderer;
  61. import net.minecraft.src.MathHelper;
  62. import net.minecraft.src.MinecraftError;
  63. import net.minecraft.src.MinecraftException;
  64. import net.minecraft.src.MinecraftImpl;
  65. import net.minecraft.src.ModelBiped;
  66. import net.minecraft.src.MouseHelper;
  67. import net.minecraft.src.MovementInputFromOptions;
  68. import net.minecraft.src.MovingObjectPosition;
  69. import net.minecraft.src.NetClientHandler;
  70. import net.minecraft.src.OpenGlCapsChecker;
  71. import net.minecraft.src.OpenGlHelper;
  72. import net.minecraft.src.Packet3Chat;
  73. import net.minecraft.src.PlayerCapabilities;
  74. import net.minecraft.src.PlayerController;
  75. import net.minecraft.src.PlayerUsageSnooper;
  76. import net.minecraft.src.Profiler;
  77. import net.minecraft.src.ProfilerResult;
  78. import net.minecraft.src.RenderBlocks;
  79. import net.minecraft.src.RenderEngine;
  80. import net.minecraft.src.RenderGlobal;
  81. import net.minecraft.src.RenderManager;
  82. import net.minecraft.src.ScaledResolution;
  83. import net.minecraft.src.ScreenShotHelper;
  84. import net.minecraft.src.Session;
  85. import net.minecraft.src.SoundManager;
  86. import net.minecraft.src.StatCollector;
  87. import net.minecraft.src.StatFileWriter;
  88. import net.minecraft.src.StatList;
  89. import net.minecraft.src.StatStringFormatKeyInv;
  90. import net.minecraft.src.StringTranslate;
  91. import net.minecraft.src.Teleporter;
  92. import net.minecraft.src.Tessellator;
  93. import net.minecraft.src.TextureCompassFX;
  94. import net.minecraft.src.TextureFlamesFX;
  95. import net.minecraft.src.TextureLavaFX;
  96. import net.minecraft.src.TextureLavaFlowFX;
  97. import net.minecraft.src.TexturePackList;
  98. import net.minecraft.src.TexturePortalFX;
  99. import net.minecraft.src.TextureWatchFX;
  100. import net.minecraft.src.TextureWaterFX;
  101. import net.minecraft.src.TextureWaterFlowFX;
  102. import net.minecraft.src.ThreadCheckHasPaid;
  103. import net.minecraft.src.ThreadClientSleep;
  104. import net.minecraft.src.ThreadDownloadResources;
  105. import net.minecraft.src.Timer;
  106. import net.minecraft.src.UnexpectedThrowable;
  107. import net.minecraft.src.Vec3D;
  108. import net.minecraft.src.World;
  109. import net.minecraft.src.WorldInfo;
  110. import net.minecraft.src.WorldProvider;
  111. import net.minecraft.src.WorldRenderer;
  112. import net.minecraft.src.WorldSettings;
  113. import net.minecraft.src.WorldType;
  114. import org.lwjgl.LWJGLException;
  115. import org.lwjgl.Sys;
  116. import org.lwjgl.input.Controllers;
  117. import org.lwjgl.input.Keyboard;
  118. import org.lwjgl.input.Mouse;
  119. import org.lwjgl.opengl.Display;
  120. import org.lwjgl.opengl.DisplayMode;
  121. import org.lwjgl.opengl.GL11;
  122. import org.lwjgl.opengl.PixelFormat;
  123. import org.lwjgl.util.glu.GLU;
  124.  
  125. public abstract class Minecraft implements Runnable
  126. {
  127. public static byte field_28006_b[] = new byte[0xa00000];
  128.  
  129. /**
  130. * Set to 'this' in Minecraft constructor; used by some settings get methods
  131. */
  132. private static Minecraft theMinecraft;
  133. public PlayerController playerController;
  134. private boolean fullscreen;
  135. private boolean hasCrashed;
  136. public int displayWidth;
  137. public int displayHeight;
  138.  
  139. /** Checks OpenGL capabilities (as of 1.2.3_04 effectively unused). */
  140. private OpenGlCapsChecker glCapabilities;
  141. private Timer timer;
  142.  
  143. /** The World instance that Minecraft uses. */
  144. public World theWorld;
  145. public RenderGlobal renderGlobal;
  146.  
  147. /** The player who's actually in control of this game. */
  148. public EntityPlayerSP thePlayer;
  149.  
  150. /**
  151. * The Entity from which the renderer determines the render viewpoint. Currently is always the parent Minecraft
  152. * class's 'thePlayer' instance. Modification of its location, rotation, or other settings at render time will
  153. * modify the camera likewise, with the caveat of triggering chunk rebuilds as it moves, making it unsuitable for
  154. * changing the viewpoint mid-render.
  155. */
  156. public EntityLiving renderViewEntity;
  157. public EffectRenderer effectRenderer;
  158. public Session session;
  159. public String minecraftUri;
  160. public Canvas mcCanvas;
  161.  
  162. /** a boolean to hide a Quit button from the main menu */
  163. public boolean hideQuitButton;
  164. public volatile boolean isGamePaused;
  165.  
  166. /** The RenderEngine instance used by Minecraft */
  167. public RenderEngine renderEngine;
  168.  
  169. /** The font renderer used for displaying and measuring text. */
  170. public FontRenderer fontRenderer;
  171. public FontRenderer standardGalacticFontRenderer;
  172.  
  173. /** The GuiScreen that's being displayed at the moment. */
  174. public GuiScreen currentScreen;
  175. public LoadingScreenRenderer loadingScreen;
  176. public EntityRenderer entityRenderer;
  177.  
  178. /** Reference to the download resources thread. */
  179. private ThreadDownloadResources downloadResourcesThread;
  180.  
  181. /** Number of ticks ran since the program was started. */
  182. private int ticksRan;
  183.  
  184. /** Mouse left click counter */
  185. private int leftClickCounter;
  186.  
  187. /** Display width */
  188. private int tempDisplayWidth;
  189.  
  190. /** Display height */
  191. private int tempDisplayHeight;
  192.  
  193. /** Gui achievement */
  194. public GuiAchievement guiAchievement;
  195. public GuiIngame ingameGUI;
  196.  
  197. /** Skip render world */
  198. public boolean skipRenderWorld;
  199.  
  200. /** The ModelBiped of the player */
  201. public ModelBiped playerModelBiped;
  202.  
  203. /** The ray trace hit that the mouse is over. */
  204. public MovingObjectPosition objectMouseOver;
  205.  
  206. /** The game settings that currently hold effect. */
  207. public GameSettings gameSettings;
  208. protected MinecraftApplet mcApplet;
  209. public SoundManager sndManager;
  210.  
  211. /** Mouse helper instance. */
  212. public MouseHelper mouseHelper;
  213.  
  214. /** The TexturePackLister used by this instance of Minecraft... */
  215. public TexturePackList texturePackList;
  216. public File mcDataDir;
  217. private ISaveFormat saveLoader;
  218. public static long frameTimes[] = new long[512];
  219. public static long tickTimes[] = new long[512];
  220. public static int numRecordedFrameTimes = 0;
  221.  
  222. /**
  223. * time in milliseconds when TheadCheckHasPaid determined you have not paid. 0 if you have paid. Used in
  224. * GuiAchievement whether to display the nag text.
  225. */
  226. public static long hasPaidCheckTime = 0L;
  227.  
  228. /**
  229. * When you place a block, it's set to 6, decremented once per tick, when it's 0, you can place another block.
  230. */
  231. private int rightClickDelayTimer;
  232.  
  233. /** Stat file writer */
  234. public StatFileWriter statFileWriter;
  235. private String serverName;
  236. private int serverPort;
  237. private TextureWaterFX textureWaterFX;
  238. private TextureLavaFX textureLavaFX;
  239.  
  240. /** The working dir (OS specific) for minecraft */
  241. private static File minecraftDir = null;
  242.  
  243. /**
  244. * Set to true to keep the game loop running. Set to false by shutdown() to allow the game loop to exit cleanly.
  245. */
  246. public volatile boolean running;
  247.  
  248. /** String that shows the debug information */
  249. public String debug;
  250.  
  251. /** Approximate time (in ms) of last update to debug string */
  252. long debugUpdateTime;
  253.  
  254. /** holds the current fps */
  255. int fpsCounter;
  256.  
  257. /**
  258. * Makes sure it doesn't keep taking screenshots when both buttons are down.
  259. */
  260. boolean isTakingScreenshot;
  261. long prevFrameTime;
  262.  
  263. /** Profiler currently displayed in the debug screen pie chart */
  264. private String debugProfilerName;
  265.  
  266. /**
  267. * Does the actual gameplay have focus. If so then mouse and keys will effect the player instead of menus.
  268. */
  269. public boolean inGameHasFocus;
  270. public boolean isRaining;
  271. long systemTime;
  272.  
  273. /** Join player counter */
  274. private int joinPlayerCounter;
  275.  
  276. public Minecraft(Component par1Component, Canvas par2Canvas, MinecraftApplet par3MinecraftApplet, int par4, int par5, boolean par6)
  277. {
  278. fullscreen = false;
  279. hasCrashed = false;
  280. timer = new Timer(20F);
  281. session = null;
  282. hideQuitButton = false;
  283. isGamePaused = false;
  284. currentScreen = null;
  285. ticksRan = 0;
  286. leftClickCounter = 0;
  287. guiAchievement = new GuiAchievement(this);
  288. skipRenderWorld = false;
  289. playerModelBiped = new ModelBiped(0.0F);
  290. objectMouseOver = null;
  291. sndManager = new SoundManager();
  292. rightClickDelayTimer = 0;
  293. textureWaterFX = new TextureWaterFX();
  294. textureLavaFX = new TextureLavaFX();
  295. running = true;
  296. debug = "";
  297. debugUpdateTime = System.currentTimeMillis();
  298. fpsCounter = 0;
  299. isTakingScreenshot = false;
  300. prevFrameTime = -1L;
  301. debugProfilerName = "root";
  302. inGameHasFocus = false;
  303. isRaining = false;
  304. systemTime = System.currentTimeMillis();
  305. joinPlayerCounter = 0;
  306. StatList.func_27360_a();
  307. tempDisplayHeight = par5;
  308. fullscreen = par6;
  309. mcApplet = par3MinecraftApplet;
  310. Packet3Chat.field_52010_b = 32767;
  311. new ThreadClientSleep(this, "Timer hack thread");
  312. mcCanvas = par2Canvas;
  313. displayWidth = par4;
  314. displayHeight = par5;
  315. fullscreen = par6;
  316.  
  317. if (par3MinecraftApplet == null || "true".equals(par3MinecraftApplet.getParameter("stand-alone")))
  318. {
  319. hideQuitButton = false;
  320. }
  321.  
  322. theMinecraft = this;
  323. }
  324.  
  325. public void onMinecraftCrash(UnexpectedThrowable par1UnexpectedThrowable)
  326. {
  327. hasCrashed = true;
  328. displayUnexpectedThrowable(par1UnexpectedThrowable);
  329. }
  330.  
  331. /**
  332. * Displays an unexpected error that has come up during the game.
  333. */
  334. public abstract void displayUnexpectedThrowable(UnexpectedThrowable unexpectedthrowable);
  335.  
  336. public void setServer(String par1Str, int par2)
  337. {
  338. serverName = par1Str;
  339. serverPort = par2;
  340. }
  341.  
  342. /**
  343. * Starts the game: initializes the canvas, the title, the settings, etcetera.
  344. */
  345. public void startGame() throws LWJGLException
  346. {
  347. if (mcCanvas != null)
  348. {
  349. Graphics g = mcCanvas.getGraphics();
  350.  
  351. if (g != null)
  352. {
  353. g.setColor(Color.BLACK);
  354. g.fillRect(0, 0, displayWidth, displayHeight);
  355. g.dispose();
  356. }
  357.  
  358. Display.setParent(mcCanvas);
  359. }
  360. else if (fullscreen)
  361. {
  362. Display.setFullscreen(true);
  363. displayWidth = Display.getDisplayMode().getWidth();
  364. displayHeight = Display.getDisplayMode().getHeight();
  365.  
  366. if (displayWidth <= 0)
  367. {
  368. displayWidth = 1;
  369. }
  370.  
  371. if (displayHeight <= 0)
  372. {
  373. displayHeight = 1;
  374. }
  375. }
  376. else
  377. {
  378. Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
  379. }
  380.  
  381. Display.setTitle("Minecraft Minecraft 1.2.5");
  382. System.out.println((new StringBuilder()).append("LWJGL Version: ").append(Sys.getVersion()).toString());
  383.  
  384. try
  385. {
  386. PixelFormat pixelformat = new PixelFormat();
  387. pixelformat = pixelformat.withDepthBits(24);
  388. Display.create(pixelformat);
  389. }
  390. catch (LWJGLException lwjglexception)
  391. {
  392. lwjglexception.printStackTrace();
  393.  
  394. try
  395. {
  396. Thread.sleep(1000L);
  397. }
  398. catch (InterruptedException interruptedexception) { }
  399.  
  400. Display.create();
  401. }
  402.  
  403. OpenGlHelper.initializeTextures();
  404. mcDataDir = getMinecraftDir();
  405. saveLoader = new AnvilSaveConverter(new File(mcDataDir, "saves"));
  406. gameSettings = new GameSettings(this, mcDataDir);
  407. texturePackList = new TexturePackList(this, mcDataDir);
  408. renderEngine = new RenderEngine(texturePackList, gameSettings);
  409. loadScreen();
  410. fontRenderer = new FontRenderer(gameSettings, "/font/default.png", renderEngine, false);
  411. standardGalacticFontRenderer = new FontRenderer(gameSettings, "/font/alternate.png", renderEngine, false);
  412.  
  413. if (gameSettings.language != null)
  414. {
  415. StringTranslate.getInstance().setLanguage(gameSettings.language);
  416. fontRenderer.setUnicodeFlag(StringTranslate.getInstance().isUnicode());
  417. fontRenderer.setBidiFlag(StringTranslate.isBidrectional(gameSettings.language));
  418. }
  419.  
  420. ColorizerWater.setWaterBiomeColorizer(renderEngine.getTextureContents("/misc/watercolor.png"));
  421. ColorizerGrass.setGrassBiomeColorizer(renderEngine.getTextureContents("/misc/grasscolor.png"));
  422. ColorizerFoliage.getFoilageBiomeColorizer(renderEngine.getTextureContents("/misc/foliagecolor.png"));
  423. entityRenderer = new EntityRenderer(this);
  424. RenderManager.instance.itemRenderer = new ItemRenderer(this);
  425. statFileWriter = new StatFileWriter(session, mcDataDir);
  426. AchievementList.openInventory.setStatStringFormatter(new StatStringFormatKeyInv(this));
  427. loadScreen();
  428. Mouse.create();
  429. mouseHelper = new MouseHelper(mcCanvas);
  430.  
  431. try
  432. {
  433. Controllers.create();
  434. }
  435. catch (Exception exception)
  436. {
  437. exception.printStackTrace();
  438. }
  439.  
  440. func_52004_D();
  441. checkGLError("Pre startup");
  442. GL11.glEnable(GL11.GL_TEXTURE_2D);
  443. GL11.glShadeModel(GL11.GL_SMOOTH);
  444. GL11.glClearDepth(1.0D);
  445. GL11.glEnable(GL11.GL_DEPTH_TEST);
  446. GL11.glDepthFunc(GL11.GL_LEQUAL);
  447. GL11.glEnable(GL11.GL_ALPHA_TEST);
  448. GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
  449. GL11.glCullFace(GL11.GL_BACK);
  450. GL11.glMatrixMode(GL11.GL_PROJECTION);
  451. GL11.glLoadIdentity();
  452. GL11.glMatrixMode(GL11.GL_MODELVIEW);
  453. checkGLError("Startup");
  454. glCapabilities = new OpenGlCapsChecker();
  455. sndManager.loadSoundSettings(gameSettings);
  456. renderEngine.registerTextureFX(textureLavaFX);
  457. renderEngine.registerTextureFX(textureWaterFX);
  458. renderEngine.registerTextureFX(new TexturePortalFX());
  459. renderEngine.registerTextureFX(new TextureCompassFX(this));
  460. renderEngine.registerTextureFX(new TextureWatchFX(this));
  461. renderEngine.registerTextureFX(new TextureWaterFlowFX());
  462. renderEngine.registerTextureFX(new TextureLavaFlowFX());
  463. renderEngine.registerTextureFX(new TextureFlamesFX(0));
  464. renderEngine.registerTextureFX(new TextureFlamesFX(1));
  465. renderGlobal = new RenderGlobal(this, renderEngine);
  466. GL11.glViewport(0, 0, displayWidth, displayHeight);
  467. effectRenderer = new EffectRenderer(theWorld, renderEngine);
  468.  
  469. try
  470. {
  471. downloadResourcesThread = new ThreadDownloadResources(mcDataDir, this);
  472. downloadResourcesThread.start();
  473. }
  474. catch (Exception exception1) { }
  475.  
  476. checkGLError("Post startup");
  477. ingameGUI = new GuiIngame(this);
  478.  
  479. if (serverName != null)
  480. {
  481. displayGuiScreen(new GuiConnecting(this, serverName, serverPort));
  482. }
  483. else
  484. {
  485. displayGuiScreen(new GuiMainMenu());
  486. }
  487.  
  488. loadingScreen = new LoadingScreenRenderer(this);
  489. }
  490.  
  491. /**
  492. * Displays a new screen.
  493. */
  494. private void loadScreen() throws LWJGLException
  495. {
  496. ScaledResolution scaledresolution = new ScaledResolution(gameSettings, displayWidth, displayHeight);
  497. GL11.glClear(16640);
  498. GL11.glMatrixMode(GL11.GL_PROJECTION);
  499. GL11.glLoadIdentity();
  500. GL11.glOrtho(0.0D, scaledresolution.scaledWidthD, scaledresolution.scaledHeightD, 0.0D, 1000D, 3000D);
  501. GL11.glMatrixMode(GL11.GL_MODELVIEW);
  502. GL11.glLoadIdentity();
  503. GL11.glTranslatef(0.0F, 0.0F, -2000F);
  504. GL11.glViewport(0, 0, displayWidth, displayHeight);
  505. GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
  506. Tessellator tessellator = Tessellator.instance;
  507. GL11.glDisable(GL11.GL_LIGHTING);
  508. GL11.glEnable(GL11.GL_TEXTURE_2D);
  509. GL11.glDisable(GL11.GL_FOG);
  510. GL11.glBindTexture(GL11.GL_TEXTURE_2D, renderEngine.getTexture("/title/mojang.png"));
  511. tessellator.startDrawingQuads();
  512. tessellator.setColorOpaque_I(0xffffff);
  513. tessellator.addVertexWithUV(0.0D, displayHeight, 0.0D, 0.0D, 0.0D);
  514. tessellator.addVertexWithUV(displayWidth, displayHeight, 0.0D, 0.0D, 0.0D);
  515. tessellator.addVertexWithUV(displayWidth, 0.0D, 0.0D, 0.0D, 0.0D);
  516. tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
  517. tessellator.draw();
  518. char c = 256;
  519. char c1 = 256;
  520. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  521. tessellator.setColorOpaque_I(0xffffff);
  522. scaledTessellator((scaledresolution.getScaledWidth() - c) / 2, (scaledresolution.getScaledHeight() - c1) / 2, 0, 0, c, c1);
  523. GL11.glDisable(GL11.GL_LIGHTING);
  524. GL11.glDisable(GL11.GL_FOG);
  525. GL11.glEnable(GL11.GL_ALPHA_TEST);
  526. GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
  527. Display.swapBuffers();
  528. }
  529.  
  530. /**
  531. * Loads Tessellator with a scaled resolution
  532. */
  533. public void scaledTessellator(int par1, int par2, int par3, int par4, int par5, int par6)
  534. {
  535. float f = 0.00390625F;
  536. float f1 = 0.00390625F;
  537. Tessellator tessellator = Tessellator.instance;
  538. tessellator.startDrawingQuads();
  539. tessellator.addVertexWithUV(par1 + 0, par2 + par6, 0.0D, (float)(par3 + 0) * f, (float)(par4 + par6) * f1);
  540. tessellator.addVertexWithUV(par1 + par5, par2 + par6, 0.0D, (float)(par3 + par5) * f, (float)(par4 + par6) * f1);
  541. tessellator.addVertexWithUV(par1 + par5, par2 + 0, 0.0D, (float)(par3 + par5) * f, (float)(par4 + 0) * f1);
  542. tessellator.addVertexWithUV(par1 + 0, par2 + 0, 0.0D, (float)(par3 + 0) * f, (float)(par4 + 0) * f1);
  543. tessellator.draw();
  544. }
  545.  
  546. /**
  547. * gets the working dir (OS specific) for minecraft
  548. */
  549. public static File getMinecraftDir()
  550. {
  551. if (minecraftDir == null)
  552. {
  553. minecraftDir = getAppDir("minecraft");
  554. }
  555.  
  556. return minecraftDir;
  557. }
  558.  
  559. /**
  560. * gets the working dir (OS specific) for the specific application (which is always minecraft)
  561. */
  562. public static File getAppDir(String par0Str)
  563. {
  564. String s = System.getProperty("user.home", ".");
  565. File file;
  566.  
  567. switch (EnumOSMappingHelper.enumOSMappingArray[getOs().ordinal()])
  568. {
  569. case 1:
  570. case 2:
  571. file = new File(s, (new StringBuilder()).append('.').append(par0Str).append('/').toString());
  572. break;
  573.  
  574. case 3:
  575. String s1 = System.getenv("APPDATA");
  576.  
  577. if (s1 != null)
  578. {
  579. file = new File(s1, (new StringBuilder()).append(".").append(par0Str).append('/').toString());
  580. }
  581. else
  582. {
  583. file = new File(s, (new StringBuilder()).append('.').append(par0Str).append('/').toString());
  584. }
  585.  
  586. break;
  587.  
  588. case 4:
  589. file = new File(s, (new StringBuilder()).append("Library/Application Support/").append(par0Str).toString());
  590. break;
  591.  
  592. default:
  593. file = new File(s, (new StringBuilder()).append(par0Str).append('/').toString());
  594. break;
  595. }
  596.  
  597. if (!file.exists() && !file.mkdirs())
  598. {
  599. throw new RuntimeException((new StringBuilder()).append("The working directory could not be created: ").append(file).toString());
  600. }
  601. else
  602. {
  603. return file;
  604. }
  605. }
  606.  
  607. private static EnumOS2 getOs()
  608. {
  609. String s = System.getProperty("os.name").toLowerCase();
  610.  
  611. if (s.contains("win"))
  612. {
  613. return EnumOS2.windows;
  614. }
  615.  
  616. if (s.contains("mac"))
  617. {
  618. return EnumOS2.macos;
  619. }
  620.  
  621. if (s.contains("solaris"))
  622. {
  623. return EnumOS2.solaris;
  624. }
  625.  
  626. if (s.contains("sunos"))
  627. {
  628. return EnumOS2.solaris;
  629. }
  630.  
  631. if (s.contains("linux"))
  632. {
  633. return EnumOS2.linux;
  634. }
  635.  
  636. if (s.contains("unix"))
  637. {
  638. return EnumOS2.linux;
  639. }
  640. else
  641. {
  642. return EnumOS2.unknown;
  643. }
  644. }
  645.  
  646. /**
  647. * Returns the save loader that is currently being used
  648. */
  649. public ISaveFormat getSaveLoader()
  650. {
  651. return saveLoader;
  652. }
  653.  
  654. /**
  655. * Sets the argument GuiScreen as the main (topmost visible) screen.
  656. */
  657. public void displayGuiScreen(GuiScreen par1GuiScreen)
  658. {
  659. if (currentScreen instanceof GuiErrorScreen)
  660. {
  661. return;
  662. }
  663.  
  664. if (currentScreen != null)
  665. {
  666. currentScreen.onGuiClosed();
  667. }
  668.  
  669. if (par1GuiScreen instanceof GuiMainMenu)
  670. {
  671. statFileWriter.func_27175_b();
  672. }
  673.  
  674. statFileWriter.syncStats();
  675.  
  676. if (par1GuiScreen == null && theWorld == null)
  677. {
  678. par1GuiScreen = new GuiMainMenu();
  679. }
  680. else if (par1GuiScreen == null && thePlayer.getHealth() <= 0)
  681. {
  682. par1GuiScreen = new GuiGameOver();
  683. }
  684.  
  685. if (par1GuiScreen instanceof GuiMainMenu)
  686. {
  687. gameSettings.showDebugInfo = false;
  688. ingameGUI.clearChatMessages();
  689. }
  690.  
  691. currentScreen = par1GuiScreen;
  692.  
  693. if (par1GuiScreen != null)
  694. {
  695. setIngameNotInFocus();
  696. ScaledResolution scaledresolution = new ScaledResolution(gameSettings, displayWidth, displayHeight);
  697. int i = scaledresolution.getScaledWidth();
  698. int j = scaledresolution.getScaledHeight();
  699. par1GuiScreen.setWorldAndResolution(this, i, j);
  700. skipRenderWorld = false;
  701. }
  702. else
  703. {
  704. setIngameFocus();
  705. }
  706. }
  707.  
  708. /**
  709. * Checks for an OpenGL error. If there is one, prints the error ID and error string.
  710. */
  711. private void checkGLError(String par1Str)
  712. {
  713. int i = GL11.glGetError();
  714.  
  715. if (i != 0)
  716. {
  717. String s = GLU.gluErrorString(i);
  718. System.out.println("########## GL ERROR ##########");
  719. System.out.println((new StringBuilder()).append("@ ").append(par1Str).toString());
  720. System.out.println((new StringBuilder()).append(i).append(": ").append(s).toString());
  721. }
  722. }
  723.  
  724. /**
  725. * Shuts down the minecraft applet by stopping the resource downloads, and clearing up GL stuff; called when the
  726. * application (or web page) is exited.
  727. */
  728. public void shutdownMinecraftApplet()
  729. {
  730. try
  731. {
  732. statFileWriter.func_27175_b();
  733. statFileWriter.syncStats();
  734.  
  735. if (mcApplet != null)
  736. {
  737. mcApplet.clearApplet();
  738. }
  739.  
  740. try
  741. {
  742. if (downloadResourcesThread != null)
  743. {
  744. downloadResourcesThread.closeMinecraft();
  745. }
  746. }
  747. catch (Exception exception) { }
  748.  
  749. System.out.println("Stopping!");
  750.  
  751. try
  752. {
  753. changeWorld1(null);
  754. }
  755. catch (Throwable throwable) { }
  756.  
  757. try
  758. {
  759. GLAllocation.deleteTexturesAndDisplayLists();
  760. }
  761. catch (Throwable throwable1) { }
  762.  
  763. sndManager.closeMinecraft();
  764. Mouse.destroy();
  765. Keyboard.destroy();
  766. }
  767. finally
  768. {
  769. Display.destroy();
  770.  
  771. if (!hasCrashed)
  772. {
  773. System.exit(0);
  774. }
  775. }
  776.  
  777. System.gc();
  778. }
  779.  
  780. public void run()
  781. {
  782. running = true;
  783.  
  784. try
  785. {
  786. startGame();
  787. }
  788. catch (Exception exception)
  789. {
  790. exception.printStackTrace();
  791. onMinecraftCrash(new UnexpectedThrowable("Failed to start game", exception));
  792. return;
  793. }
  794.  
  795. try
  796. {
  797. while (running)
  798. {
  799. try
  800. {
  801. runGameLoop();
  802. }
  803. catch (MinecraftException minecraftexception)
  804. {
  805. theWorld = null;
  806. changeWorld1(null);
  807. displayGuiScreen(new GuiConflictWarning());
  808. }
  809. catch (OutOfMemoryError outofmemoryerror)
  810. {
  811. freeMemory();
  812. displayGuiScreen(new GuiMemoryErrorScreen());
  813. System.gc();
  814. }
  815. }
  816. }
  817. catch (MinecraftError minecrafterror) { }
  818. catch (Throwable throwable)
  819. {
  820. freeMemory();
  821. throwable.printStackTrace();
  822. onMinecraftCrash(new UnexpectedThrowable("Unexpected error", throwable));
  823. }
  824. finally
  825. {
  826. shutdownMinecraftApplet();
  827. }
  828. }
  829.  
  830. /**
  831. * Called repeatedly from run()
  832. */
  833. private void runGameLoop()
  834. {
  835. if (mcApplet != null && !mcApplet.isActive())
  836. {
  837. running = false;
  838. return;
  839. }
  840.  
  841. AxisAlignedBB.clearBoundingBoxPool();
  842. Vec3D.initialize();
  843. Profiler.startSection("root");
  844.  
  845. if (mcCanvas == null && Display.isCloseRequested())
  846. {
  847. shutdown();
  848. }
  849.  
  850. if (isGamePaused && theWorld != null)
  851. {
  852. float f = timer.renderPartialTicks;
  853. timer.updateTimer();
  854. timer.renderPartialTicks = f;
  855. }
  856. else
  857. {
  858. timer.updateTimer();
  859. }
  860.  
  861. long l = System.nanoTime();
  862. Profiler.startSection("tick");
  863.  
  864. for (int i = 0; i < timer.elapsedTicks; i++)
  865. {
  866. ticksRan++;
  867.  
  868. try
  869. {
  870. runTick();
  871. continue;
  872. }
  873. catch (MinecraftException minecraftexception)
  874. {
  875. theWorld = null;
  876. }
  877.  
  878. changeWorld1(null);
  879. displayGuiScreen(new GuiConflictWarning());
  880. }
  881.  
  882. Profiler.endSection();
  883. long l1 = System.nanoTime() - l;
  884. checkGLError("Pre render");
  885. RenderBlocks.fancyGrass = gameSettings.fancyGraphics;
  886. Profiler.startSection("sound");
  887. sndManager.setListener(thePlayer, timer.renderPartialTicks);
  888. Profiler.endStartSection("updatelights");
  889.  
  890. if (theWorld != null)
  891. {
  892. theWorld.updatingLighting();
  893. }
  894.  
  895. Profiler.endSection();
  896. Profiler.startSection("render");
  897. Profiler.startSection("display");
  898. GL11.glEnable(GL11.GL_TEXTURE_2D);
  899.  
  900. if (!Keyboard.isKeyDown(65))
  901. {
  902. Display.update();
  903. }
  904.  
  905. if (thePlayer != null && thePlayer.isEntityInsideOpaqueBlock())
  906. {
  907. gameSettings.thirdPersonView = 0;
  908. }
  909.  
  910. Profiler.endSection();
  911.  
  912. if (!skipRenderWorld)
  913. {
  914. Profiler.startSection("gameMode");
  915.  
  916. if (playerController != null)
  917. {
  918. playerController.setPartialTime(timer.renderPartialTicks);
  919. }
  920.  
  921. Profiler.endStartSection("gameRenderer");
  922. entityRenderer.updateCameraAndRender(timer.renderPartialTicks);
  923. Profiler.endSection();
  924. }
  925.  
  926. GL11.glFlush();
  927. Profiler.endSection();
  928.  
  929. if (!Display.isActive() && fullscreen)
  930. {
  931. toggleFullscreen();
  932. }
  933.  
  934. Profiler.endSection();
  935.  
  936. if (gameSettings.showDebugInfo && gameSettings.field_50119_G)
  937. {
  938. if (!Profiler.profilingEnabled)
  939. {
  940. Profiler.clearProfiling();
  941. }
  942.  
  943. Profiler.profilingEnabled = true;
  944. displayDebugInfo(l1);
  945. }
  946. else
  947. {
  948. Profiler.profilingEnabled = false;
  949. prevFrameTime = System.nanoTime();
  950. }
  951.  
  952. guiAchievement.updateAchievementWindow();
  953. Profiler.startSection("root");
  954. Thread.yield();
  955.  
  956. if (Keyboard.isKeyDown(65))
  957. {
  958. Display.update();
  959. }
  960.  
  961. screenshotListener();
  962.  
  963. if (mcCanvas != null && !fullscreen && (mcCanvas.getWidth() != displayWidth || mcCanvas.getHeight() != displayHeight))
  964. {
  965. displayWidth = mcCanvas.getWidth();
  966. displayHeight = mcCanvas.getHeight();
  967.  
  968. if (displayWidth <= 0)
  969. {
  970. displayWidth = 1;
  971. }
  972.  
  973. if (displayHeight <= 0)
  974. {
  975. displayHeight = 1;
  976. }
  977.  
  978. resize(displayWidth, displayHeight);
  979. }
  980.  
  981. checkGLError("Post render");
  982. fpsCounter++;
  983. isGamePaused = !isMultiplayerWorld() && currentScreen != null && currentScreen.doesGuiPauseGame();
  984.  
  985. while (System.currentTimeMillis() >= debugUpdateTime + 1000L)
  986. {
  987. debug = (new StringBuilder()).append(fpsCounter).append(" fps, ").append(WorldRenderer.chunksUpdated).append(" chunk updates").toString();
  988. WorldRenderer.chunksUpdated = 0;
  989. debugUpdateTime += 1000L;
  990. fpsCounter = 0;
  991. }
  992.  
  993. Profiler.endSection();
  994. }
  995.  
  996. public void freeMemory()
  997. {
  998. try
  999. {
  1000. field_28006_b = new byte[0];
  1001. renderGlobal.func_28137_f();
  1002. }
  1003. catch (Throwable throwable) { }
  1004.  
  1005. try
  1006. {
  1007. System.gc();
  1008. AxisAlignedBB.clearBoundingBoxes();
  1009. Vec3D.clearVectorList();
  1010. }
  1011. catch (Throwable throwable1) { }
  1012.  
  1013. try
  1014. {
  1015. System.gc();
  1016. changeWorld1(null);
  1017. }
  1018. catch (Throwable throwable2) { }
  1019.  
  1020. System.gc();
  1021. }
  1022.  
  1023. /**
  1024. * checks if keys are down
  1025. */
  1026. private void screenshotListener()
  1027. {
  1028. if (Keyboard.isKeyDown(60))
  1029. {
  1030. if (!isTakingScreenshot)
  1031. {
  1032. isTakingScreenshot = true;
  1033. ingameGUI.addChatMessage(ScreenShotHelper.saveScreenshot(minecraftDir, displayWidth, displayHeight));
  1034. }
  1035. }
  1036. else
  1037. {
  1038. isTakingScreenshot = false;
  1039. }
  1040. }
  1041.  
  1042. /**
  1043. * Update debugProfilerName in response to number keys in debug screen
  1044. */
  1045. private void updateDebugProfilerName(int par1)
  1046. {
  1047. java.util.List list;
  1048. ProfilerResult profilerresult;
  1049. list = Profiler.getProfilingData(debugProfilerName);
  1050.  
  1051. if (list == null || list.size() == 0)
  1052. {
  1053. return;
  1054. }
  1055.  
  1056. profilerresult = (ProfilerResult)list.remove(0);
  1057.  
  1058. if (!(par1 != 0))
  1059. {
  1060. if (profilerresult.name.length() > 0)
  1061. {
  1062. int i = debugProfilerName.lastIndexOf(".");
  1063.  
  1064. if (i >= 0)
  1065. {
  1066. debugProfilerName = debugProfilerName.substring(0, i);
  1067. }
  1068. }
  1069. }
  1070. else if (!(--par1 >= list.size() || ((ProfilerResult)list.get(par1)).name.equals("unspecified")))
  1071. {
  1072. if (!(debugProfilerName.length() <= 0))
  1073. {
  1074. debugProfilerName += ".";
  1075. }
  1076.  
  1077. debugProfilerName += ((ProfilerResult)list.get(par1)).name;
  1078. }
  1079. }
  1080.  
  1081. private void displayDebugInfo(long par1)
  1082. {
  1083. java.util.List list = Profiler.getProfilingData(debugProfilerName);
  1084. ProfilerResult profilerresult = (ProfilerResult)list.remove(0);
  1085. long l = 0xfe502aL;
  1086.  
  1087. if (prevFrameTime == -1L)
  1088. {
  1089. prevFrameTime = System.nanoTime();
  1090. }
  1091.  
  1092. long l1 = System.nanoTime();
  1093. tickTimes[numRecordedFrameTimes & frameTimes.length - 1] = par1;
  1094. frameTimes[numRecordedFrameTimes++ & frameTimes.length - 1] = l1 - prevFrameTime;
  1095. prevFrameTime = l1;
  1096. GL11.glClear(256);
  1097. GL11.glMatrixMode(GL11.GL_PROJECTION);
  1098. GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  1099. GL11.glLoadIdentity();
  1100. GL11.glOrtho(0.0D, displayWidth, displayHeight, 0.0D, 1000D, 3000D);
  1101. GL11.glMatrixMode(GL11.GL_MODELVIEW);
  1102. GL11.glLoadIdentity();
  1103. GL11.glTranslatef(0.0F, 0.0F, -2000F);
  1104. GL11.glLineWidth(1.0F);
  1105. GL11.glDisable(GL11.GL_TEXTURE_2D);
  1106. Tessellator tessellator = Tessellator.instance;
  1107. tessellator.startDrawing(7);
  1108. int i = (int)(l / 0x30d40L);
  1109. tessellator.setColorOpaque_I(0x20000000);
  1110. tessellator.addVertex(0.0D, displayHeight - i, 0.0D);
  1111. tessellator.addVertex(0.0D, displayHeight, 0.0D);
  1112. tessellator.addVertex(frameTimes.length, displayHeight, 0.0D);
  1113. tessellator.addVertex(frameTimes.length, displayHeight - i, 0.0D);
  1114. tessellator.setColorOpaque_I(0x20200000);
  1115. tessellator.addVertex(0.0D, displayHeight - i * 2, 0.0D);
  1116. tessellator.addVertex(0.0D, displayHeight - i, 0.0D);
  1117. tessellator.addVertex(frameTimes.length, displayHeight - i, 0.0D);
  1118. tessellator.addVertex(frameTimes.length, displayHeight - i * 2, 0.0D);
  1119. tessellator.draw();
  1120. long l2 = 0L;
  1121.  
  1122. for (int j = 0; j < frameTimes.length; j++)
  1123. {
  1124. l2 += frameTimes[j];
  1125. }
  1126.  
  1127. int k = (int)(l2 / 0x30d40L / (long)frameTimes.length);
  1128. tessellator.startDrawing(7);
  1129. tessellator.setColorOpaque_I(0x20400000);
  1130. tessellator.addVertex(0.0D, displayHeight - k, 0.0D);
  1131. tessellator.addVertex(0.0D, displayHeight, 0.0D);
  1132. tessellator.addVertex(frameTimes.length, displayHeight, 0.0D);
  1133. tessellator.addVertex(frameTimes.length, displayHeight - k, 0.0D);
  1134. tessellator.draw();
  1135. tessellator.startDrawing(1);
  1136.  
  1137. for (int i1 = 0; i1 < frameTimes.length; i1++)
  1138. {
  1139. int k1 = ((i1 - numRecordedFrameTimes & frameTimes.length - 1) * 255) / frameTimes.length;
  1140. int j2 = (k1 * k1) / 255;
  1141. j2 = (j2 * j2) / 255;
  1142. int i3 = (j2 * j2) / 255;
  1143. i3 = (i3 * i3) / 255;
  1144.  
  1145. if (frameTimes[i1] > l)
  1146. {
  1147. tessellator.setColorOpaque_I(0xff000000 + j2 * 0x10000);
  1148. }
  1149. else
  1150. {
  1151. tessellator.setColorOpaque_I(0xff000000 + j2 * 256);
  1152. }
  1153.  
  1154. long l3 = frameTimes[i1] / 0x30d40L;
  1155. long l4 = tickTimes[i1] / 0x30d40L;
  1156. tessellator.addVertex((float)i1 + 0.5F, (float)((long)displayHeight - l3) + 0.5F, 0.0D);
  1157. tessellator.addVertex((float)i1 + 0.5F, (float)displayHeight + 0.5F, 0.0D);
  1158. tessellator.setColorOpaque_I(0xff000000 + j2 * 0x10000 + j2 * 256 + j2 * 1);
  1159. tessellator.addVertex((float)i1 + 0.5F, (float)((long)displayHeight - l3) + 0.5F, 0.0D);
  1160. tessellator.addVertex((float)i1 + 0.5F, (float)((long)displayHeight - (l3 - l4)) + 0.5F, 0.0D);
  1161. }
  1162.  
  1163. tessellator.draw();
  1164. int j1 = 160;
  1165. int i2 = displayWidth - j1 - 10;
  1166. int k2 = displayHeight - j1 * 2;
  1167. GL11.glEnable(GL11.GL_BLEND);
  1168. tessellator.startDrawingQuads();
  1169. tessellator.setColorRGBA_I(0, 200);
  1170. tessellator.addVertex((float)i2 - (float)j1 * 1.1F, (float)k2 - (float)j1 * 0.6F - 16F, 0.0D);
  1171. tessellator.addVertex((float)i2 - (float)j1 * 1.1F, k2 + j1 * 2, 0.0D);
  1172. tessellator.addVertex((float)i2 + (float)j1 * 1.1F, k2 + j1 * 2, 0.0D);
  1173. tessellator.addVertex((float)i2 + (float)j1 * 1.1F, (float)k2 - (float)j1 * 0.6F - 16F, 0.0D);
  1174. tessellator.draw();
  1175. GL11.glDisable(GL11.GL_BLEND);
  1176. double d = 0.0D;
  1177.  
  1178. for (int j3 = 0; j3 < list.size(); j3++)
  1179. {
  1180. ProfilerResult profilerresult1 = (ProfilerResult)list.get(j3);
  1181. int i4 = MathHelper.floor_double(profilerresult1.sectionPercentage / 4D) + 1;
  1182. tessellator.startDrawing(6);
  1183. tessellator.setColorOpaque_I(profilerresult1.getDisplayColor());
  1184. tessellator.addVertex(i2, k2, 0.0D);
  1185.  
  1186. for (int k4 = i4; k4 >= 0; k4--)
  1187. {
  1188. float f = (float)(((d + (profilerresult1.sectionPercentage * (double)k4) / (double)i4) * Math.PI * 2D) / 100D);
  1189. float f2 = MathHelper.sin(f) * (float)j1;
  1190. float f4 = MathHelper.cos(f) * (float)j1 * 0.5F;
  1191. tessellator.addVertex((float)i2 + f2, (float)k2 - f4, 0.0D);
  1192. }
  1193.  
  1194. tessellator.draw();
  1195. tessellator.startDrawing(5);
  1196. tessellator.setColorOpaque_I((profilerresult1.getDisplayColor() & 0xfefefe) >> 1);
  1197.  
  1198. for (int i5 = i4; i5 >= 0; i5--)
  1199. {
  1200. float f1 = (float)(((d + (profilerresult1.sectionPercentage * (double)i5) / (double)i4) * Math.PI * 2D) / 100D);
  1201. float f3 = MathHelper.sin(f1) * (float)j1;
  1202. float f5 = MathHelper.cos(f1) * (float)j1 * 0.5F;
  1203. tessellator.addVertex((float)i2 + f3, (float)k2 - f5, 0.0D);
  1204. tessellator.addVertex((float)i2 + f3, ((float)k2 - f5) + 10F, 0.0D);
  1205. }
  1206.  
  1207. tessellator.draw();
  1208. d += profilerresult1.sectionPercentage;
  1209. }
  1210.  
  1211. DecimalFormat decimalformat = new DecimalFormat("##0.00");
  1212. GL11.glEnable(GL11.GL_TEXTURE_2D);
  1213. String s = "";
  1214.  
  1215. if (!profilerresult.name.equals("unspecified"))
  1216. {
  1217. s = (new StringBuilder()).append(s).append("[0] ").toString();
  1218. }
  1219.  
  1220. if (profilerresult.name.length() == 0)
  1221. {
  1222. s = (new StringBuilder()).append(s).append("ROOT ").toString();
  1223. }
  1224. else
  1225. {
  1226. s = (new StringBuilder()).append(s).append(profilerresult.name).append(" ").toString();
  1227. }
  1228.  
  1229. int j4 = 0xffffff;
  1230. fontRenderer.drawStringWithShadow(s, i2 - j1, k2 - j1 / 2 - 16, j4);
  1231. fontRenderer.drawStringWithShadow(s = (new StringBuilder()).append(decimalformat.format(profilerresult.globalPercentage)).append("%").toString(), (i2 + j1) - fontRenderer.getStringWidth(s), k2 - j1 / 2 - 16, j4);
  1232.  
  1233. for (int k3 = 0; k3 < list.size(); k3++)
  1234. {
  1235. ProfilerResult profilerresult2 = (ProfilerResult)list.get(k3);
  1236. String s1 = "";
  1237.  
  1238. if (!profilerresult2.name.equals("unspecified"))
  1239. {
  1240. s1 = (new StringBuilder()).append(s1).append("[").append(k3 + 1).append("] ").toString();
  1241. }
  1242. else
  1243. {
  1244. s1 = (new StringBuilder()).append(s1).append("[?] ").toString();
  1245. }
  1246.  
  1247. s1 = (new StringBuilder()).append(s1).append(profilerresult2.name).toString();
  1248. fontRenderer.drawStringWithShadow(s1, i2 - j1, k2 + j1 / 2 + k3 * 8 + 20, profilerresult2.getDisplayColor());
  1249. fontRenderer.drawStringWithShadow(s1 = (new StringBuilder()).append(decimalformat.format(profilerresult2.sectionPercentage)).append("%").toString(), (i2 + j1) - 50 - fontRenderer.getStringWidth(s1), k2 + j1 / 2 + k3 * 8 + 20, profilerresult2.getDisplayColor());
  1250. fontRenderer.drawStringWithShadow(s1 = (new StringBuilder()).append(decimalformat.format(profilerresult2.globalPercentage)).append("%").toString(), (i2 + j1) - fontRenderer.getStringWidth(s1), k2 + j1 / 2 + k3 * 8 + 20, profilerresult2.getDisplayColor());
  1251. }
  1252. }
  1253.  
  1254. /**
  1255. * Called when the window is closing. Sets 'running' to false which allows the game loop to exit cleanly.
  1256. */
  1257. public void shutdown()
  1258. {
  1259. running = false;
  1260. }
  1261.  
  1262. /**
  1263. * Will set the focus to ingame if the Minecraft window is the active with focus. Also clears any GUI screen
  1264. * currently displayed
  1265. */
  1266. public void setIngameFocus()
  1267. {
  1268. if (!Display.isActive())
  1269. {
  1270. return;
  1271. }
  1272.  
  1273. if (inGameHasFocus)
  1274. {
  1275. return;
  1276. }
  1277. else
  1278. {
  1279. inGameHasFocus = true;
  1280. mouseHelper.grabMouseCursor();
  1281. displayGuiScreen(null);
  1282. leftClickCounter = 10000;
  1283. return;
  1284. }
  1285. }
  1286.  
  1287. /**
  1288. * Resets the player keystate, disables the ingame focus, and ungrabs the mouse cursor.
  1289. */
  1290. public void setIngameNotInFocus()
  1291. {
  1292. if (!inGameHasFocus)
  1293. {
  1294. return;
  1295. }
  1296. else
  1297. {
  1298. KeyBinding.unPressAllKeys();
  1299. inGameHasFocus = false;
  1300. mouseHelper.ungrabMouseCursor();
  1301. return;
  1302. }
  1303. }
  1304.  
  1305. /**
  1306. * Displays the ingame menu
  1307. */
  1308. public void displayInGameMenu()
  1309. {
  1310. if (currentScreen != null)
  1311. {
  1312. return;
  1313. }
  1314. else
  1315. {
  1316. displayGuiScreen(new GuiIngameMenu());
  1317. return;
  1318. }
  1319. }
  1320.  
  1321. private void sendClickBlockToController(int par1, boolean par2)
  1322. {
  1323. if (!par2)
  1324. {
  1325. leftClickCounter = 0;
  1326. }
  1327.  
  1328. if (par1 == 0 && leftClickCounter > 0)
  1329. {
  1330. return;
  1331. }
  1332.  
  1333. if (par2 && objectMouseOver != null && objectMouseOver.typeOfHit == EnumMovingObjectType.TILE && par1 == 0)
  1334. {
  1335. int i = objectMouseOver.blockX;
  1336. int j = objectMouseOver.blockY;
  1337. int k = objectMouseOver.blockZ;
  1338. playerController.onPlayerDamageBlock(i, j, k, objectMouseOver.sideHit);
  1339.  
  1340. if (thePlayer.canPlayerEdit(i, j, k))
  1341. {
  1342. effectRenderer.addBlockHitEffects(i, j, k, objectMouseOver.sideHit);
  1343. thePlayer.swingItem();
  1344. }
  1345. }
  1346. else
  1347. {
  1348. playerController.resetBlockRemoving();
  1349. }
  1350. }
  1351.  
  1352. /**
  1353. * Called whenever the mouse is clicked. Button clicked is 0 for left clicking and 1 for right clicking. Args:
  1354. * buttonClicked
  1355. */
  1356. private void clickMouse(int par1)
  1357. {
  1358. if (par1 == 0 && leftClickCounter > 0)
  1359. {
  1360. return;
  1361. }
  1362.  
  1363. if (par1 == 0)
  1364. {
  1365. thePlayer.swingItem();
  1366. }
  1367.  
  1368. if (par1 == 1)
  1369. {
  1370. rightClickDelayTimer = 4;
  1371. }
  1372.  
  1373. boolean flag = true;
  1374. ItemStack itemstack = thePlayer.inventory.getCurrentItem();
  1375.  
  1376. if (objectMouseOver == null)
  1377. {
  1378. if (par1 == 0 && playerController.isNotCreative())
  1379. {
  1380. leftClickCounter = 10;
  1381. }
  1382. }
  1383. else if (objectMouseOver.typeOfHit == EnumMovingObjectType.ENTITY)
  1384. {
  1385. if (par1 == 0)
  1386. {
  1387. playerController.attackEntity(thePlayer, objectMouseOver.entityHit);
  1388. }
  1389.  
  1390. if (par1 == 1)
  1391. {
  1392. playerController.interactWithEntity(thePlayer, objectMouseOver.entityHit);
  1393. }
  1394. }
  1395. else if (objectMouseOver.typeOfHit == EnumMovingObjectType.TILE)
  1396. {
  1397. int i = objectMouseOver.blockX;
  1398. int j = objectMouseOver.blockY;
  1399. int k = objectMouseOver.blockZ;
  1400. int l = objectMouseOver.sideHit;
  1401.  
  1402. if (par1 == 0)
  1403. {
  1404. playerController.clickBlock(i, j, k, objectMouseOver.sideHit);
  1405. }
  1406. else
  1407. {
  1408. ItemStack itemstack2 = itemstack;
  1409. int i1 = itemstack2 == null ? 0 : itemstack2.stackSize;
  1410.  
  1411. if (playerController.onPlayerRightClick(thePlayer, theWorld, itemstack2, i, j, k, l))
  1412. {
  1413. flag = false;
  1414. thePlayer.swingItem();
  1415. }
  1416.  
  1417. if (itemstack2 == null)
  1418. {
  1419. return;
  1420. }
  1421.  
  1422. if (itemstack2.stackSize == 0)
  1423. {
  1424. thePlayer.inventory.mainInventory[thePlayer.inventory.currentItem] = null;
  1425. }
  1426. else if (itemstack2.stackSize != i1 || playerController.isInCreativeMode())
  1427. {
  1428. entityRenderer.itemRenderer.func_9449_b();
  1429. }
  1430. }
  1431. }
  1432.  
  1433. if (flag && par1 == 1)
  1434. {
  1435. ItemStack itemstack1 = thePlayer.inventory.getCurrentItem();
  1436.  
  1437. if (itemstack1 != null && playerController.sendUseItem(thePlayer, theWorld, itemstack1))
  1438. {
  1439. entityRenderer.itemRenderer.func_9450_c();
  1440. }
  1441. }
  1442. }
  1443.  
  1444. /**
  1445. * Toggles fullscreen mode.
  1446. */
  1447. public void toggleFullscreen()
  1448. {
  1449. try
  1450. {
  1451. fullscreen = !fullscreen;
  1452.  
  1453. if (fullscreen)
  1454. {
  1455. Display.setDisplayMode(Display.getDesktopDisplayMode());
  1456. displayWidth = Display.getDisplayMode().getWidth();
  1457. displayHeight = Display.getDisplayMode().getHeight();
  1458.  
  1459. if (displayWidth <= 0)
  1460. {
  1461. displayWidth = 1;
  1462. }
  1463.  
  1464. if (displayHeight <= 0)
  1465. {
  1466. displayHeight = 1;
  1467. }
  1468. }
  1469. else
  1470. {
  1471. if (mcCanvas != null)
  1472. {
  1473. displayWidth = mcCanvas.getWidth();
  1474. displayHeight = mcCanvas.getHeight();
  1475. }
  1476. else
  1477. {
  1478. displayWidth = tempDisplayWidth;
  1479. displayHeight = tempDisplayHeight;
  1480. }
  1481.  
  1482. if (displayWidth <= 0)
  1483. {
  1484. displayWidth = 1;
  1485. }
  1486.  
  1487. if (displayHeight <= 0)
  1488. {
  1489. displayHeight = 1;
  1490. }
  1491. }
  1492.  
  1493. if (currentScreen != null)
  1494. {
  1495. resize(displayWidth, displayHeight);
  1496. }
  1497.  
  1498. Display.setFullscreen(fullscreen);
  1499. Display.update();
  1500. }
  1501. catch (Exception exception)
  1502. {
  1503. exception.printStackTrace();
  1504. }
  1505. }
  1506.  
  1507. /**
  1508. * Called to resize the current screen.
  1509. */
  1510. private void resize(int par1, int par2)
  1511. {
  1512. if (par1 <= 0)
  1513. {
  1514. par1 = 1;
  1515. }
  1516.  
  1517. if (par2 <= 0)
  1518. {
  1519. par2 = 1;
  1520. }
  1521.  
  1522. displayWidth = par1;
  1523. displayHeight = par2;
  1524.  
  1525. if (currentScreen != null)
  1526. {
  1527. ScaledResolution scaledresolution = new ScaledResolution(gameSettings, par1, par2);
  1528. int i = scaledresolution.getScaledWidth();
  1529. int j = scaledresolution.getScaledHeight();
  1530. currentScreen.setWorldAndResolution(this, i, j);
  1531. }
  1532. }
  1533.  
  1534. private void startThreadCheckHasPaid()
  1535. {
  1536. (new ThreadCheckHasPaid(this)).start();
  1537. }
  1538.  
  1539. /**
  1540. * Runs the current tick.
  1541. */
  1542. public void runTick()
  1543. {
  1544. if (rightClickDelayTimer > 0)
  1545. {
  1546. rightClickDelayTimer--;
  1547. }
  1548.  
  1549. if (ticksRan == 6000)
  1550. {
  1551. startThreadCheckHasPaid();
  1552. }
  1553.  
  1554. Profiler.startSection("stats");
  1555. statFileWriter.func_27178_d();
  1556. Profiler.endStartSection("gui");
  1557.  
  1558. if (!isGamePaused)
  1559. {
  1560. ingameGUI.updateTick();
  1561. }
  1562.  
  1563. Profiler.endStartSection("pick");
  1564. entityRenderer.getMouseOver(1.0F);
  1565. Profiler.endStartSection("centerChunkSource");
  1566.  
  1567. if (thePlayer != null)
  1568. {
  1569. net.minecraft.src.IChunkProvider ichunkprovider = theWorld.getChunkProvider();
  1570.  
  1571. if (ichunkprovider instanceof ChunkProviderLoadOrGenerate)
  1572. {
  1573. ChunkProviderLoadOrGenerate chunkproviderloadorgenerate = (ChunkProviderLoadOrGenerate)ichunkprovider;
  1574. int k = MathHelper.floor_float((int)thePlayer.posX) >> 4;
  1575. int j1 = MathHelper.floor_float((int)thePlayer.posZ) >> 4;
  1576. chunkproviderloadorgenerate.setCurrentChunkOver(k, j1);
  1577. }
  1578. }
  1579.  
  1580. Profiler.endStartSection("gameMode");
  1581.  
  1582. if (!isGamePaused && theWorld != null)
  1583. {
  1584. playerController.updateController();
  1585. }
  1586.  
  1587. GL11.glBindTexture(GL11.GL_TEXTURE_2D, renderEngine.getTexture("/terrain.png"));
  1588. Profiler.endStartSection("textures");
  1589.  
  1590. if (!isGamePaused)
  1591. {
  1592. renderEngine.updateDynamicTextures();
  1593. }
  1594.  
  1595. if (currentScreen == null && thePlayer != null)
  1596. {
  1597. if (thePlayer.getHealth() <= 0)
  1598. {
  1599. displayGuiScreen(null);
  1600. }
  1601. else if (thePlayer.isPlayerSleeping() && theWorld != null && theWorld.isRemote)
  1602. {
  1603. displayGuiScreen(new GuiSleepMP());
  1604. }
  1605. }
  1606. else if (currentScreen != null && (currentScreen instanceof GuiSleepMP) && !thePlayer.isPlayerSleeping())
  1607. {
  1608. displayGuiScreen(null);
  1609. }
  1610.  
  1611. if (currentScreen != null)
  1612. {
  1613. leftClickCounter = 10000;
  1614. }
  1615.  
  1616. if (currentScreen != null)
  1617. {
  1618. currentScreen.handleInput();
  1619.  
  1620. if (currentScreen != null)
  1621. {
  1622. currentScreen.guiParticles.update();
  1623. currentScreen.updateScreen();
  1624. }
  1625. }
  1626.  
  1627. if (currentScreen == null || currentScreen.allowUserInput)
  1628. {
  1629. Profiler.endStartSection("mouse");
  1630.  
  1631. do
  1632. {
  1633. if (!Mouse.next())
  1634. {
  1635. break;
  1636. }
  1637.  
  1638. KeyBinding.setKeyBindState(Mouse.getEventButton() - 100, Mouse.getEventButtonState());
  1639.  
  1640. if (Mouse.getEventButtonState())
  1641. {
  1642. KeyBinding.onTick(Mouse.getEventButton() - 100);
  1643. }
  1644.  
  1645. long l = System.currentTimeMillis() - systemTime;
  1646.  
  1647. if (l <= 200L)
  1648. {
  1649. int i1 = Mouse.getEventDWheel();
  1650.  
  1651. if (i1 != 0)
  1652. {
  1653. thePlayer.inventory.changeCurrentItem(i1);
  1654.  
  1655. if (gameSettings.noclip)
  1656. {
  1657. if (i1 > 0)
  1658. {
  1659. i1 = 1;
  1660. }
  1661.  
  1662. if (i1 < 0)
  1663. {
  1664. i1 = -1;
  1665. }
  1666.  
  1667. gameSettings.noclipRate += (float)i1 * 0.25F;
  1668. }
  1669. }
  1670.  
  1671. if (currentScreen == null)
  1672. {
  1673. if (!inGameHasFocus && Mouse.getEventButtonState())
  1674. {
  1675. setIngameFocus();
  1676. }
  1677. }
  1678. else if (currentScreen != null)
  1679. {
  1680. currentScreen.handleMouseInput();
  1681. }
  1682. }
  1683. }
  1684. while (true);
  1685.  
  1686. if (leftClickCounter > 0)
  1687. {
  1688. leftClickCounter--;
  1689. }
  1690.  
  1691. Profiler.endStartSection("keyboard");
  1692.  
  1693. do
  1694. {
  1695. if (!Keyboard.next())
  1696. {
  1697. break;
  1698. }
  1699.  
  1700. KeyBinding.setKeyBindState(Keyboard.getEventKey(), Keyboard.getEventKeyState());
  1701.  
  1702. if (Keyboard.getEventKeyState())
  1703. {
  1704. KeyBinding.onTick(Keyboard.getEventKey());
  1705. }
  1706.  
  1707. if (Keyboard.getEventKeyState())
  1708. {
  1709. if (Keyboard.getEventKey() == 87)
  1710. {
  1711. toggleFullscreen();
  1712. }
  1713. else
  1714. {
  1715. if (currentScreen != null)
  1716. {
  1717. currentScreen.handleKeyboardInput();
  1718. }
  1719. else
  1720. {
  1721. if (Keyboard.getEventKey() == 1)
  1722. {
  1723. displayInGameMenu();
  1724. }
  1725.  
  1726. if (Keyboard.getEventKey() == 31 && Keyboard.isKeyDown(61))
  1727. {
  1728. forceReload();
  1729. }
  1730.  
  1731. if (Keyboard.getEventKey() == 20 && Keyboard.isKeyDown(61))
  1732. {
  1733. renderEngine.refreshTextures();
  1734. }
  1735.  
  1736. if (Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(61))
  1737. {
  1738. boolean flag = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
  1739. gameSettings.setOptionValue(EnumOptions.RENDER_DISTANCE, flag ? -1 : 1);
  1740. }
  1741.  
  1742. if (Keyboard.getEventKey() == 30 && Keyboard.isKeyDown(61))
  1743. {
  1744. renderGlobal.loadRenderers();
  1745. }
  1746.  
  1747. if (Keyboard.getEventKey() == 59)
  1748. {
  1749. gameSettings.hideGUI = !gameSettings.hideGUI;
  1750. }
  1751.  
  1752. if (Keyboard.getEventKey() == 61)
  1753. {
  1754. gameSettings.showDebugInfo = !gameSettings.showDebugInfo;
  1755. gameSettings.field_50119_G = !GuiScreen.func_50049_m();
  1756. }
  1757.  
  1758. if (Keyboard.getEventKey() == 63)
  1759. {
  1760. gameSettings.thirdPersonView++;
  1761.  
  1762. if (gameSettings.thirdPersonView > 2)
  1763. {
  1764. gameSettings.thirdPersonView = 0;
  1765. }
  1766. }
  1767.  
  1768. if (Keyboard.getEventKey() == 66)
  1769. {
  1770. gameSettings.smoothCamera = !gameSettings.smoothCamera;
  1771. }
  1772. }
  1773.  
  1774. for (int i = 0; i < 9; i++)
  1775. {
  1776. if (Keyboard.getEventKey() == 2 + i)
  1777. {
  1778. thePlayer.inventory.currentItem = i;
  1779. }
  1780. }
  1781.  
  1782. if (gameSettings.showDebugInfo && gameSettings.field_50119_G)
  1783. {
  1784. if (Keyboard.getEventKey() == 11)
  1785. {
  1786. updateDebugProfilerName(0);
  1787. }
  1788.  
  1789. int j = 0;
  1790.  
  1791. while (j < 9)
  1792. {
  1793. if (Keyboard.getEventKey() == 2 + j)
  1794. {
  1795. updateDebugProfilerName(j + 1);
  1796. }
  1797.  
  1798. j++;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. while (true);
  1805.  
  1806. for (; gameSettings.keyBindInventory.isPressed(); displayGuiScreen(new GuiInventory(thePlayer))) { }
  1807.  
  1808. for (; gameSettings.keyBindDrop.isPressed(); thePlayer.dropOneItem()) { }
  1809.  
  1810. for (; isMultiplayerWorld() && gameSettings.keyBindChat.isPressed(); displayGuiScreen(new GuiChat())) { }
  1811.  
  1812. if (isMultiplayerWorld() && currentScreen == null && (Keyboard.isKeyDown(53) || Keyboard.isKeyDown(181)))
  1813. {
  1814. displayGuiScreen(new GuiChat("/"));
  1815. }
  1816.  
  1817. if (thePlayer.isUsingItem())
  1818. {
  1819. if (!gameSettings.keyBindUseItem.pressed)
  1820. {
  1821. playerController.onStoppedUsingItem(thePlayer);
  1822. }
  1823.  
  1824. while (gameSettings.keyBindAttack.isPressed()) ;
  1825.  
  1826. while (gameSettings.keyBindUseItem.isPressed()) ;
  1827.  
  1828. while (gameSettings.keyBindPickBlock.isPressed()) ;
  1829. }
  1830. else
  1831. {
  1832. for (; gameSettings.keyBindAttack.isPressed(); clickMouse(0)) { }
  1833.  
  1834. for (; gameSettings.keyBindUseItem.isPressed(); clickMouse(1)) { }
  1835.  
  1836. for (; gameSettings.keyBindPickBlock.isPressed(); clickMiddleMouseButton()) { }
  1837. }
  1838.  
  1839. if (gameSettings.keyBindUseItem.pressed && rightClickDelayTimer == 0 && !thePlayer.isUsingItem())
  1840. {
  1841. clickMouse(1);
  1842. }
  1843.  
  1844. sendClickBlockToController(0, currentScreen == null && gameSettings.keyBindAttack.pressed && inGameHasFocus);
  1845. }
  1846.  
  1847. if (theWorld != null)
  1848. {
  1849. if (thePlayer != null)
  1850. {
  1851. joinPlayerCounter++;
  1852.  
  1853. if (joinPlayerCounter == 30)
  1854. {
  1855. joinPlayerCounter = 0;
  1856. theWorld.joinEntityInSurroundings(thePlayer);
  1857. }
  1858. }
  1859.  
  1860. if (theWorld.getWorldInfo().isHardcoreModeEnabled())
  1861. {
  1862. theWorld.difficultySetting = 3;
  1863. }
  1864. else
  1865. {
  1866. theWorld.difficultySetting = gameSettings.difficulty;
  1867. }
  1868.  
  1869. if (theWorld.isRemote)
  1870. {
  1871. theWorld.difficultySetting = 1;
  1872. }
  1873.  
  1874. Profiler.endStartSection("gameRenderer");
  1875.  
  1876. if (!isGamePaused)
  1877. {
  1878. entityRenderer.updateRenderer();
  1879. }
  1880.  
  1881. Profiler.endStartSection("levelRenderer");
  1882.  
  1883. if (!isGamePaused)
  1884. {
  1885. renderGlobal.updateClouds();
  1886. }
  1887.  
  1888. Profiler.endStartSection("level");
  1889.  
  1890. if (!isGamePaused)
  1891. {
  1892. if (theWorld.lightningFlash > 0)
  1893. {
  1894. theWorld.lightningFlash--;
  1895. }
  1896.  
  1897. theWorld.updateEntities();
  1898. }
  1899.  
  1900. if (!isGamePaused || isMultiplayerWorld())
  1901. {
  1902. theWorld.setAllowedSpawnTypes(theWorld.difficultySetting > 0, true);
  1903. theWorld.tick();
  1904. }
  1905.  
  1906. Profiler.endStartSection("animateTick");
  1907.  
  1908. if (!isGamePaused && theWorld != null)
  1909. {
  1910. theWorld.randomDisplayUpdates(MathHelper.floor_double(thePlayer.posX), MathHelper.floor_double(thePlayer.posY), MathHelper.floor_double(thePlayer.posZ));
  1911. }
  1912.  
  1913. Profiler.endStartSection("particles");
  1914.  
  1915. if (!isGamePaused)
  1916. {
  1917. effectRenderer.updateEffects();
  1918. }
  1919. }
  1920.  
  1921. Profiler.endSection();
  1922. systemTime = System.currentTimeMillis();
  1923. }
  1924.  
  1925. /**
  1926. * Forces a reload of the sound manager and all the resources. Called in game by holding 'F3' and pressing 'S'.
  1927. */
  1928. private void forceReload()
  1929. {
  1930. System.out.println("FORCING RELOAD!");
  1931. sndManager = new SoundManager();
  1932. sndManager.loadSoundSettings(gameSettings);
  1933. downloadResourcesThread.reloadResources();
  1934. }
  1935.  
  1936. /**
  1937. * Checks if the current world is a multiplayer world, returns true if it is, false otherwise.
  1938. */
  1939. public boolean isMultiplayerWorld()
  1940. {
  1941. return theWorld != null && theWorld.isRemote;
  1942. }
  1943.  
  1944. /**
  1945. * creates a new world or loads an existing one
  1946. */
  1947. public void startWorld(String par1Str, String par2Str, WorldSettings par3WorldSettings)
  1948. {
  1949. changeWorld1(null);
  1950. System.gc();
  1951.  
  1952. if (saveLoader.isOldMapFormat(par1Str))
  1953. {
  1954. convertMapFormat(par1Str, par2Str);
  1955. }
  1956. else
  1957. {
  1958. if (loadingScreen != null)
  1959. {
  1960. loadingScreen.printText(StatCollector.translateToLocal("menu.switchingLevel"));
  1961. loadingScreen.displayLoadingString("");
  1962. }
  1963.  
  1964. net.minecraft.src.ISaveHandler isavehandler = saveLoader.getSaveLoader(par1Str, false);
  1965. World world = null;
  1966. world = new World(isavehandler, par2Str, par3WorldSettings);
  1967.  
  1968. if (world.isNewWorld)
  1969. {
  1970. statFileWriter.readStat(StatList.createWorldStat, 1);
  1971. statFileWriter.readStat(StatList.startGameStat, 1);
  1972. changeWorld2(world, StatCollector.translateToLocal("menu.generatingLevel"));
  1973. }
  1974. else
  1975. {
  1976. statFileWriter.readStat(StatList.loadWorldStat, 1);
  1977. statFileWriter.readStat(StatList.startGameStat, 1);
  1978. changeWorld2(world, StatCollector.translateToLocal("menu.loadingLevel"));
  1979. }
  1980. }
  1981. }
  1982.  
  1983. /**
  1984. * Will use a portal teleport switching the dimension the player is in.
  1985. */
  1986. public void usePortal(int par1)
  1987. {
  1988. int i = thePlayer.dimension;
  1989. thePlayer.dimension = par1;
  1990. theWorld.setEntityDead(thePlayer);
  1991. thePlayer.isDead = false;
  1992. double d = thePlayer.posX;
  1993. double d1 = thePlayer.posZ;
  1994. double d2 = 1.0D;
  1995.  
  1996. if (i > -1 && thePlayer.dimension == -1)
  1997. {
  1998. d2 = 0.125D;
  1999. }
  2000. else if (i == -1 && thePlayer.dimension > -1)
  2001. {
  2002. d2 = 8D;
  2003. }
  2004.  
  2005. d *= d2;
  2006. d1 *= d2;
  2007.  
  2008. if (thePlayer.dimension == -1)
  2009. {
  2010. thePlayer.setLocationAndAngles(d, thePlayer.posY, d1, thePlayer.rotationYaw, thePlayer.rotationPitch);
  2011.  
  2012. if (thePlayer.isEntityAlive())
  2013. {
  2014. theWorld.updateEntityWithOptionalForce(thePlayer, false);
  2015. }
  2016.  
  2017. World world = null;
  2018. world = new World(theWorld, WorldProvider.getProviderForDimension(thePlayer.dimension));
  2019. changeWorld(world, "Entering the Nether", thePlayer);
  2020. }
  2021. else if (thePlayer.dimension == 0)
  2022. {
  2023. if (thePlayer.isEntityAlive())
  2024. {
  2025. thePlayer.setLocationAndAngles(d, thePlayer.posY, d1, thePlayer.rotationYaw, thePlayer.rotationPitch);
  2026. theWorld.updateEntityWithOptionalForce(thePlayer, false);
  2027. }
  2028.  
  2029. World world1 = null;
  2030. world1 = new World(theWorld, WorldProvider.getProviderForDimension(thePlayer.dimension));
  2031.  
  2032. if (i == -1)
  2033. {
  2034. changeWorld(world1, "Leaving the Nether", thePlayer);
  2035. }
  2036. else
  2037. {
  2038. changeWorld(world1, "Leaving the End", thePlayer);
  2039. }
  2040. }
  2041. else
  2042. {
  2043. World world2 = null;
  2044. world2 = new World(theWorld, WorldProvider.getProviderForDimension(thePlayer.dimension));
  2045. ChunkCoordinates chunkcoordinates = world2.getEntrancePortalLocation();
  2046. d = chunkcoordinates.posX;
  2047. thePlayer.posY = chunkcoordinates.posY;
  2048. d1 = chunkcoordinates.posZ;
  2049. thePlayer.setLocationAndAngles(d, thePlayer.posY, d1, 90F, 0.0F);
  2050.  
  2051. if (thePlayer.isEntityAlive())
  2052. {
  2053. world2.updateEntityWithOptionalForce(thePlayer, false);
  2054. }
  2055.  
  2056. changeWorld(world2, "Entering the End", thePlayer);
  2057. }
  2058.  
  2059. thePlayer.worldObj = theWorld;
  2060. System.out.println((new StringBuilder()).append("Teleported to ").append(theWorld.worldProvider.worldType).toString());
  2061.  
  2062. if (thePlayer.isEntityAlive() && i < 1)
  2063. {
  2064. thePlayer.setLocationAndAngles(d, thePlayer.posY, d1, thePlayer.rotationYaw, thePlayer.rotationPitch);
  2065. theWorld.updateEntityWithOptionalForce(thePlayer, false);
  2066. (new Teleporter()).placeInPortal(theWorld, thePlayer);
  2067. }
  2068. }
  2069.  
  2070. /**
  2071. * Unloads the current world, and displays a String while waiting
  2072. */
  2073. public void exitToMainMenu(String par1Str)
  2074. {
  2075. theWorld = null;
  2076. changeWorld2(null, par1Str);
  2077. }
  2078.  
  2079. /**
  2080. * Changes the world, no message, no player.
  2081. */
  2082. public void changeWorld1(World par1World)
  2083. {
  2084. changeWorld2(par1World, "");
  2085. }
  2086.  
  2087. /**
  2088. * Changes the world with given message, no player.
  2089. */
  2090. public void changeWorld2(World par1World, String par2Str)
  2091. {
  2092. changeWorld(par1World, par2Str, null);
  2093. }
  2094.  
  2095. /**
  2096. * first argument is the world to change to, second one is a loading message and the third the player itself
  2097. */
  2098. public void changeWorld(World par1World, String par2Str, EntityPlayer par3EntityPlayer)
  2099. {
  2100. statFileWriter.func_27175_b();
  2101. statFileWriter.syncStats();
  2102. renderViewEntity = null;
  2103.  
  2104. if (loadingScreen != null)
  2105. {
  2106. loadingScreen.printText(par2Str);
  2107. loadingScreen.displayLoadingString("");
  2108. }
  2109.  
  2110. sndManager.playStreaming(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
  2111.  
  2112. if (theWorld != null)
  2113. {
  2114. theWorld.saveWorldIndirectly(loadingScreen);
  2115. }
  2116.  
  2117. theWorld = par1World;
  2118.  
  2119. if (par1World != null)
  2120. {
  2121. if (playerController != null)
  2122. {
  2123. playerController.onWorldChange(par1World);
  2124. }
  2125.  
  2126. if (!isMultiplayerWorld())
  2127. {
  2128. if (par3EntityPlayer == null)
  2129. {
  2130. thePlayer = (EntityPlayerSP)par1World.func_4085_a(net.minecraft.src.EntityPlayerSP.class);
  2131. }
  2132. }
  2133. else if (thePlayer != null)
  2134. {
  2135. thePlayer.preparePlayerToSpawn();
  2136.  
  2137. if (par1World != null)
  2138. {
  2139. par1World.spawnEntityInWorld(thePlayer);
  2140. }
  2141. }
  2142.  
  2143. if (!par1World.isRemote)
  2144. {
  2145. preloadWorld(par2Str);
  2146. }
  2147.  
  2148. if (thePlayer == null)
  2149. {
  2150. thePlayer = (EntityPlayerSP)playerController.createPlayer(par1World);
  2151. thePlayer.preparePlayerToSpawn();
  2152. playerController.flipPlayer(thePlayer);
  2153. }
  2154.  
  2155. thePlayer.movementInput = new MovementInputFromOptions(gameSettings);
  2156.  
  2157. if (renderGlobal != null)
  2158. {
  2159. renderGlobal.changeWorld(par1World);
  2160. }
  2161.  
  2162. if (effectRenderer != null)
  2163. {
  2164. effectRenderer.clearEffects(par1World);
  2165. }
  2166.  
  2167. if (par3EntityPlayer != null)
  2168. {
  2169. par1World.func_6464_c();
  2170. }
  2171.  
  2172. net.minecraft.src.IChunkProvider ichunkprovider = par1World.getChunkProvider();
  2173.  
  2174. if (ichunkprovider instanceof ChunkProviderLoadOrGenerate)
  2175. {
  2176. ChunkProviderLoadOrGenerate chunkproviderloadorgenerate = (ChunkProviderLoadOrGenerate)ichunkprovider;
  2177. int i = MathHelper.floor_float((int)thePlayer.posX) >> 4;
  2178. int j = MathHelper.floor_float((int)thePlayer.posZ) >> 4;
  2179. chunkproviderloadorgenerate.setCurrentChunkOver(i, j);
  2180. }
  2181.  
  2182. par1World.spawnPlayerWithLoadedChunks(thePlayer);
  2183. playerController.func_6473_b(thePlayer);
  2184.  
  2185. if (par1World.isNewWorld)
  2186. {
  2187. par1World.saveWorldIndirectly(loadingScreen);
  2188. }
  2189.  
  2190. renderViewEntity = thePlayer;
  2191. }
  2192. else
  2193. {
  2194. saveLoader.flushCache();
  2195. thePlayer = null;
  2196. }
  2197.  
  2198. System.gc();
  2199. systemTime = 0L;
  2200. }
  2201.  
  2202. /**
  2203. * Converts from old map format to new map format
  2204. */
  2205. private void convertMapFormat(String par1Str, String par2Str)
  2206. {
  2207. loadingScreen.printText((new StringBuilder()).append("Converting World to ").append(saveLoader.getFormatName()).toString());
  2208. loadingScreen.displayLoadingString("This may take a while :)");
  2209. saveLoader.convertMapFormat(par1Str, loadingScreen);
  2210. startWorld(par1Str, par2Str, new WorldSettings(0L, 0, true, false, WorldType.DEFAULT));
  2211. }
  2212.  
  2213. /**
  2214. * Display the preload world loading screen then load SP World.
  2215. */
  2216. private void preloadWorld(String par1Str)
  2217. {
  2218. if (loadingScreen != null)
  2219. {
  2220. loadingScreen.printText(par1Str);
  2221. loadingScreen.displayLoadingString(StatCollector.translateToLocal("menu.generatingTerrain"));
  2222. }
  2223.  
  2224. char c = '\200';
  2225.  
  2226. if (playerController.func_35643_e())
  2227. {
  2228. c = '@';
  2229. }
  2230.  
  2231. int i = 0;
  2232. int j = (c * 2) / 16 + 1;
  2233. j *= j;
  2234. net.minecraft.src.IChunkProvider ichunkprovider = theWorld.getChunkProvider();
  2235. ChunkCoordinates chunkcoordinates = theWorld.getSpawnPoint();
  2236.  
  2237. if (thePlayer != null)
  2238. {
  2239. chunkcoordinates.posX = (int)thePlayer.posX;
  2240. chunkcoordinates.posZ = (int)thePlayer.posZ;
  2241. }
  2242.  
  2243. if (ichunkprovider instanceof ChunkProviderLoadOrGenerate)
  2244. {
  2245. ChunkProviderLoadOrGenerate chunkproviderloadorgenerate = (ChunkProviderLoadOrGenerate)ichunkprovider;
  2246. chunkproviderloadorgenerate.setCurrentChunkOver(chunkcoordinates.posX >> 4, chunkcoordinates.posZ >> 4);
  2247. }
  2248.  
  2249. for (int k = -c; k <= c; k += 16)
  2250. {
  2251. for (int l = -c; l <= c; l += 16)
  2252. {
  2253. if (loadingScreen != null)
  2254. {
  2255. loadingScreen.setLoadingProgress((i++ * 100) / j);
  2256. }
  2257.  
  2258. theWorld.getBlockId(chunkcoordinates.posX + k, 64, chunkcoordinates.posZ + l);
  2259.  
  2260. if (playerController.func_35643_e())
  2261. {
  2262. continue;
  2263. }
  2264.  
  2265. while (theWorld.updatingLighting()) ;
  2266. }
  2267. }
  2268.  
  2269. if (!playerController.func_35643_e())
  2270. {
  2271. if (loadingScreen != null)
  2272. {
  2273. loadingScreen.displayLoadingString(StatCollector.translateToLocal("menu.simulating"));
  2274. }
  2275.  
  2276. char c1 = 2000;
  2277. theWorld.dropOldChunks();
  2278. }
  2279. }
  2280.  
  2281. /**
  2282. * Installs a resource. Currently only sounds are download so this method just adds them to the SoundManager.
  2283. */
  2284. public void installResource(String par1Str, File par2File)
  2285. {
  2286. int i = par1Str.indexOf("/");
  2287. String s = par1Str.substring(0, i);
  2288. par1Str = par1Str.substring(i + 1);
  2289.  
  2290. if (s.equalsIgnoreCase("sound"))
  2291. {
  2292. sndManager.addSound(par1Str, par2File);
  2293. }
  2294. else if (s.equalsIgnoreCase("newsound"))
  2295. {
  2296. sndManager.addSound(par1Str, par2File);
  2297. }
  2298. else if (s.equalsIgnoreCase("streaming"))
  2299. {
  2300. sndManager.addStreaming(par1Str, par2File);
  2301. }
  2302. else if (s.equalsIgnoreCase("music"))
  2303. {
  2304. sndManager.addMusic(par1Str, par2File);
  2305. }
  2306. else if (s.equalsIgnoreCase("newmusic"))
  2307. {
  2308. sndManager.addMusic(par1Str, par2File);
  2309. }
  2310. }
  2311.  
  2312. /**
  2313. * A String of renderGlobal.getDebugInfoRenders
  2314. */
  2315. public String debugInfoRenders()
  2316. {
  2317. return renderGlobal.getDebugInfoRenders();
  2318. }
  2319.  
  2320. /**
  2321. * Gets the information in the F3 menu about how many entities are infront/around you
  2322. */
  2323. public String getEntityDebug()
  2324. {
  2325. return renderGlobal.getDebugInfoEntities();
  2326. }
  2327.  
  2328. /**
  2329. * Gets the name of the world's current chunk provider
  2330. */
  2331. public String getWorldProviderName()
  2332. {
  2333. return theWorld.getProviderName();
  2334. }
  2335.  
  2336. /**
  2337. * A String of how many entities are in the world
  2338. */
  2339. public String debugInfoEntities()
  2340. {
  2341. return (new StringBuilder()).append("P: ").append(effectRenderer.getStatistics()).append(". T: ").append(theWorld.getDebugLoadedEntities()).toString();
  2342. }
  2343.  
  2344. /**
  2345. * Called when the respawn button is pressed after the player dies.
  2346. */
  2347. public void respawn(boolean par1, int par2, boolean par3)
  2348. {
  2349. if (!theWorld.isRemote && !theWorld.worldProvider.canRespawnHere())
  2350. {
  2351. usePortal(0);
  2352. }
  2353.  
  2354. ChunkCoordinates chunkcoordinates = null;
  2355. ChunkCoordinates chunkcoordinates1 = null;
  2356. boolean flag = true;
  2357.  
  2358. if (thePlayer != null && !par1)
  2359. {
  2360. chunkcoordinates = thePlayer.getSpawnChunk();
  2361.  
  2362. if (chunkcoordinates != null)
  2363. {
  2364. chunkcoordinates1 = EntityPlayer.verifyRespawnCoordinates(theWorld, chunkcoordinates);
  2365.  
  2366. if (chunkcoordinates1 == null)
  2367. {
  2368. thePlayer.addChatMessage("tile.bed.notValid");
  2369. }
  2370. }
  2371. }
  2372.  
  2373. if (chunkcoordinates1 == null)
  2374. {
  2375. chunkcoordinates1 = theWorld.getSpawnPoint();
  2376. flag = false;
  2377. }
  2378.  
  2379. net.minecraft.src.IChunkProvider ichunkprovider = theWorld.getChunkProvider();
  2380.  
  2381. if (ichunkprovider instanceof ChunkProviderLoadOrGenerate)
  2382. {
  2383. ChunkProviderLoadOrGenerate chunkproviderloadorgenerate = (ChunkProviderLoadOrGenerate)ichunkprovider;
  2384. chunkproviderloadorgenerate.setCurrentChunkOver(chunkcoordinates1.posX >> 4, chunkcoordinates1.posZ >> 4);
  2385. }
  2386.  
  2387. theWorld.setSpawnLocation();
  2388. theWorld.updateEntityList();
  2389. int i = 0;
  2390.  
  2391. if (thePlayer != null)
  2392. {
  2393. i = thePlayer.entityId;
  2394. theWorld.setEntityDead(thePlayer);
  2395. }
  2396.  
  2397. EntityPlayerSP entityplayersp = thePlayer;
  2398. renderViewEntity = null;
  2399. thePlayer = (EntityPlayerSP)playerController.createPlayer(theWorld);
  2400.  
  2401. if (par3)
  2402. {
  2403. thePlayer.copyPlayer(entityplayersp);
  2404. }
  2405.  
  2406. thePlayer.dimension = par2;
  2407. renderViewEntity = thePlayer;
  2408. thePlayer.preparePlayerToSpawn();
  2409.  
  2410. if (flag)
  2411. {
  2412. thePlayer.setSpawnChunk(chunkcoordinates);
  2413. thePlayer.setLocationAndAngles((float)chunkcoordinates1.posX + 0.5F, (float)chunkcoordinates1.posY + 0.1F, (float)chunkcoordinates1.posZ + 0.5F, 0.0F, 0.0F);
  2414. }
  2415.  
  2416. playerController.flipPlayer(thePlayer);
  2417. theWorld.spawnPlayerWithLoadedChunks(thePlayer);
  2418. thePlayer.movementInput = new MovementInputFromOptions(gameSettings);
  2419. thePlayer.entityId = i;
  2420. thePlayer.func_6420_o();
  2421. playerController.func_6473_b(thePlayer);
  2422. preloadWorld(StatCollector.translateToLocal("menu.respawning"));
  2423.  
  2424. if (currentScreen instanceof GuiGameOver)
  2425. {
  2426. displayGuiScreen(null);
  2427. }
  2428. }
  2429.  
  2430. public static void startMainThread1(String par0Str, String par1Str)
  2431. {
  2432. startMainThread(par0Str, par1Str, null);
  2433. }
  2434.  
  2435. public static void startMainThread(String par0Str, String par1Str, String par2Str)
  2436. {
  2437. boolean flag = false;
  2438. String s = par0Str;
  2439. Frame frame = new Frame("Minecraft");
  2440. Canvas canvas = new Canvas();
  2441. frame.setLayout(new BorderLayout());
  2442. frame.add(canvas, "Center");
  2443. canvas.setPreferredSize(new Dimension(854, 480));
  2444. frame.pack();
  2445. frame.setLocationRelativeTo(null);
  2446. MinecraftImpl minecraftimpl = new MinecraftImpl(frame, canvas, null, 854, 480, flag, frame);
  2447. Thread thread = new Thread(minecraftimpl, "Minecraft main thread");
  2448. thread.setPriority(10);
  2449. minecraftimpl.minecraftUri = "www.minecraft.net";
  2450.  
  2451. if (s != null && par1Str != null)
  2452. {
  2453. minecraftimpl.session = new Session(s, par1Str);
  2454. }
  2455. else
  2456. {
  2457. minecraftimpl.session = new Session((new StringBuilder()).append("Player").append(System.currentTimeMillis() % 1000L).toString(), "");
  2458. }
  2459.  
  2460. if (par2Str != null)
  2461. {
  2462. String as[] = par2Str.split(":");
  2463. minecraftimpl.setServer(as[0], Integer.parseInt(as[1]));
  2464. }
  2465.  
  2466. frame.setVisible(true);
  2467. frame.addWindowListener(new GameWindowListener(minecraftimpl, thread));
  2468. thread.start();
  2469. }
  2470.  
  2471. /**
  2472. * get the client packet send queue
  2473. */
  2474. public NetClientHandler getSendQueue()
  2475. {
  2476. if (thePlayer instanceof EntityClientPlayerMP)
  2477. {
  2478. return ((EntityClientPlayerMP)thePlayer).sendQueue;
  2479. }
  2480. else
  2481. {
  2482. return null;
  2483. }
  2484. }
  2485.  
  2486. public static void main(String par0ArrayOfStr[])
  2487. {
  2488. String s = null;
  2489. String s1 = null;
  2490. s = (new StringBuilder()).append("Player").append(System.currentTimeMillis() % 1000L).toString();
  2491.  
  2492. if (par0ArrayOfStr.length > 0)
  2493. {
  2494. s = par0ArrayOfStr[0];
  2495. }
  2496.  
  2497. s1 = "-";
  2498.  
  2499. if (par0ArrayOfStr.length > 1)
  2500. {
  2501. s1 = par0ArrayOfStr[1];
  2502. }
  2503.  
  2504. startMainThread1(s, s1);
  2505. }
  2506.  
  2507. public static boolean isGuiEnabled()
  2508. {
  2509. return theMinecraft == null || !theMinecraft.gameSettings.hideGUI;
  2510. }
  2511.  
  2512. public static boolean isFancyGraphicsEnabled()
  2513. {
  2514. return theMinecraft != null && theMinecraft.gameSettings.fancyGraphics;
  2515. }
  2516.  
  2517. /**
  2518. * Returns if ambient occlusion is enabled
  2519. */
  2520. public static boolean isAmbientOcclusionEnabled()
  2521. {
  2522. return theMinecraft != null && theMinecraft.gameSettings.ambientOcclusion;
  2523. }
  2524.  
  2525. public static boolean isDebugInfoEnabled()
  2526. {
  2527. return theMinecraft != null && theMinecraft.gameSettings.showDebugInfo;
  2528. }
  2529.  
  2530. /**
  2531. * Returns true if string begins with '/'
  2532. */
  2533. public boolean lineIsCommand(String par1Str)
  2534. {
  2535. if (!par1Str.startsWith("/"));
  2536.  
  2537. return false;
  2538. }
  2539.  
  2540. /**
  2541. * Called when the middle mouse button gets clicked
  2542. */
  2543. private void clickMiddleMouseButton()
  2544. {
  2545. if (objectMouseOver != null)
  2546. {
  2547. boolean flag = thePlayer.capabilities.isCreativeMode;
  2548. int i = theWorld.getBlockId(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
  2549.  
  2550. if (!flag)
  2551. {
  2552. if (i == Block.grass.blockID)
  2553. {
  2554. i = Block.dirt.blockID;
  2555. }
  2556.  
  2557. if (i == Block.stairDouble.blockID)
  2558. {
  2559. i = Block.stairSingle.blockID;
  2560. }
  2561.  
  2562. if (i == Block.bedrock.blockID)
  2563. {
  2564. i = Block.stone.blockID;
  2565. }
  2566. }
  2567.  
  2568. int j = 0;
  2569. boolean flag1 = false;
  2570.  
  2571. if (Item.itemsList[i] != null && Item.itemsList[i].getHasSubtypes())
  2572. {
  2573. j = theWorld.getBlockMetadata(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
  2574. flag1 = true;
  2575. }
  2576.  
  2577. if (Item.itemsList[i] != null && (Item.itemsList[i] instanceof ItemBlock))
  2578. {
  2579. Block block = Block.blocksList[i];
  2580. int l = block.idDropped(j, thePlayer.worldObj.rand, 0);
  2581.  
  2582. if (l > 0)
  2583. {
  2584. i = l;
  2585. }
  2586. }
  2587.  
  2588. thePlayer.inventory.setCurrentItem(i, j, flag1, flag);
  2589.  
  2590. if (flag)
  2591. {
  2592. int k = (thePlayer.inventorySlots.inventorySlots.size() - 9) + thePlayer.inventory.currentItem;
  2593. playerController.sendSlotPacket(thePlayer.inventory.getStackInSlot(thePlayer.inventory.currentItem), k);
  2594. }
  2595. }
  2596. }
  2597.  
  2598. public static String func_52003_C()
  2599. {
  2600. return "1.2.5";
  2601. }
  2602.  
  2603. public static void func_52004_D()
  2604. {
  2605. PlayerUsageSnooper playerusagesnooper = new PlayerUsageSnooper("client");
  2606. playerusagesnooper.func_52022_a("version", func_52003_C());
  2607. playerusagesnooper.func_52022_a("os_name", System.getProperty("os.name"));
  2608. playerusagesnooper.func_52022_a("os_version", System.getProperty("os.version"));
  2609. playerusagesnooper.func_52022_a("os_architecture", System.getProperty("os.arch"));
  2610. playerusagesnooper.func_52022_a("memory_total", Long.valueOf(Runtime.getRuntime().totalMemory()));
  2611. playerusagesnooper.func_52022_a("memory_max", Long.valueOf(Runtime.getRuntime().maxMemory()));
  2612. playerusagesnooper.func_52022_a("java_version", System.getProperty("java.version"));
  2613. playerusagesnooper.func_52022_a("opengl_version", GL11.glGetString(GL11.GL_VERSION));
  2614. playerusagesnooper.func_52022_a("opengl_vendor", GL11.glGetString(GL11.GL_VENDOR));
  2615. playerusagesnooper.func_52021_a();
  2616. }
  2617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement