public static void startMainThread(String s, String s1, String s2) { boolean flag = false; String s3 = s; Frame frame = new Frame("Minecraft"); Canvas canvas = new Canvas(); frame.setLayout(new BorderLayout()); frame.add(canvas, "Center"); canvas.setPreferredSize(new Dimension(854, 480)); frame.pack(); frame.setLocationRelativeTo(null); MinecraftImpl minecraftimpl = new MinecraftImpl(frame, canvas, null, 854, 480, flag, frame); Thread thread = new Thread(minecraftimpl, "Minecraft main thread"); thread.setPriority(10); minecraftimpl.minecraftUri = "www.minecraft.net"; if (s3 != null && s1 != null) { minecraftimpl.session = new Session(s3, s1); } else { minecraftimpl.session = new Session( (new StringBuilder()) .append("Player") .append(System.currentTimeMillis() % 1000L) .toString(), ""); } if (s2 != null) { String as[] = s2.split(":"); minecraftimpl.setServer(as[0], Integer.parseInt(as[1])); } frame.setVisible(true); frame.addWindowListener(new GameWindowListener(minecraftimpl, thread)); thread.start(); }
private void init() throws LWJGLException { // create Window of size 800x600 Display.setDisplayMode(new DisplayMode(1024, 768)); Display.setLocation( (Display.getDisplayMode().getWidth() - 300) / 2, (Display.getDisplayMode().getHeight() - 300) / 2); Display.setTitle("Gears"); try { Display.create(); } catch (LWJGLException e) { // This COULD be because of a bug! A delay followed by a new attempt is supposed to fix it. e.printStackTrace(); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } Display.create(); } // setup ogl FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] {5.0f, 5.0f, 10.0f, 0.0f}); FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] {0.8f, 0.1f, 0.0f, 1.0f}); FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] {0.0f, 0.8f, 0.2f, 1.0f}); FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] {0.2f, 0.2f, 1.0f, 1.0f}); pos.flip(); red.flip(); green.flip(); blue.flip(); glLight(GL_LIGHT0, GL_POSITION, pos); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); /* make the gears */ gear1 = glGenLists(1); glNewList(gear1, GL_COMPILE); glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0f, 4.0f, 1.0f, 20, 0.7f); glEndList(); gear2 = glGenLists(1); glNewList(gear2, GL_COMPILE); glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); gear(0.5f, 2.0f, 2.0f, 10, 0.7f); glEndList(); gear3 = glGenLists(1); glNewList(gear3, GL_COMPILE); glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); gear(1.3f, 2.0f, 0.5f, 10, 0.7f); glEndList(); glEnable(GL_NORMALIZE); glMatrixMode(GL_PROJECTION); System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName()); System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR)); System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER)); System.err.println("GL_VERSION: " + glGetString(GL_VERSION)); System.err.println(); System.err.println( "glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix); if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) { // --- not using extensions glLoadIdentity(); } else { // --- using extensions final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16) .put(new float[] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}); identityTranspose.flip(); glLoadTransposeMatrixARB(identityTranspose); } float h = (float) 300 / (float) 300; glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -40.0f); }
public void startGame() throws LWJGLException { if (mcCanvas != null) { Graphics g = mcCanvas.getGraphics(); if (g != null) { g.setColor(Color.BLACK); g.fillRect(0, 0, displayWidth, displayHeight); g.dispose(); } Display.setParent(mcCanvas); } else if (fullscreen) { Display.setFullscreen(true); displayWidth = Display.getDisplayMode().getWidth(); displayHeight = Display.getDisplayMode().getHeight(); if (displayWidth <= 0) { displayWidth = 1; } if (displayHeight <= 0) { displayHeight = 1; } } else { Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight)); } Display.setTitle("Minecraft Minecraft Beta 1.7.3"); try { Display.create(); } catch (LWJGLException lwjglexception) { lwjglexception.printStackTrace(); try { Thread.sleep(1000L); } catch (InterruptedException interruptedexception) { } Display.create(); } mcDataDir = getMinecraftDir(); saveLoader = new SaveConverterMcRegion(new File(mcDataDir, "saves")); gameSettings = new GameSettings(this, mcDataDir); texturePackList = new TexturePackList(this, mcDataDir); renderEngine = new RenderEngine(texturePackList, gameSettings); fontRenderer = new FontRenderer(gameSettings, "/font/default.png", renderEngine); ColorizerWater.func_28182_a(renderEngine.func_28149_a("/misc/watercolor.png")); ColorizerGrass.func_28181_a(renderEngine.func_28149_a("/misc/grasscolor.png")); ColorizerFoliage.func_28152_a(renderEngine.func_28149_a("/misc/foliagecolor.png")); entityRenderer = new EntityRenderer(this); RenderManager.instance.itemRenderer = new ItemRenderer(this); statFileWriter = new StatFileWriter(session, mcDataDir); AchievementList.openInventory.setStatStringFormatter(new StatStringFormatKeyInv(this)); loadScreen(); Keyboard.create(); Mouse.create(); mouseHelper = new MouseHelper(mcCanvas); try { Controllers.create(); } catch (Exception exception) { exception.printStackTrace(); } checkGLError("Pre startup"); GL11.glEnable(3553 /*GL_TEXTURE_2D*/); GL11.glShadeModel(7425 /*GL_SMOOTH*/); GL11.glClearDepth(1.0D); GL11.glEnable(2929 /*GL_DEPTH_TEST*/); GL11.glDepthFunc(515); GL11.glEnable(3008 /*GL_ALPHA_TEST*/); GL11.glAlphaFunc(516, 0.1F); GL11.glCullFace(1029 /*GL_BACK*/); GL11.glMatrixMode(5889 /*GL_PROJECTION*/); GL11.glLoadIdentity(); GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/); checkGLError("Startup"); glCapabilities = new OpenGlCapsChecker(); sndManager.loadSoundSettings(gameSettings); renderEngine.registerTextureFX(textureLavaFX); renderEngine.registerTextureFX(textureWaterFX); renderEngine.registerTextureFX(new TexturePortalFX()); renderEngine.registerTextureFX(new TextureCompassFX(this)); renderEngine.registerTextureFX(new TextureWatchFX(this)); renderEngine.registerTextureFX(new TextureWaterFlowFX()); renderEngine.registerTextureFX(new TextureLavaFlowFX()); renderEngine.registerTextureFX(new TextureFlamesFX(0)); renderEngine.registerTextureFX(new TextureFlamesFX(1)); renderGlobal = new RenderGlobal(this, renderEngine); GL11.glViewport(0, 0, displayWidth, displayHeight); effectRenderer = new EffectRenderer(theWorld, renderEngine); try { downloadResourcesThread = new ThreadDownloadResources(mcDataDir, this); downloadResourcesThread.start(); } catch (Exception exception1) { } checkGLError("Post startup"); ingameGUI = new GuiIngame(this); if (serverName != null) { displayGuiScreen(new GuiConnecting(this, serverName, serverPort)); } else { displayGuiScreen(new GuiMainMenu()); } }
public void run() { running = true; try { startGame(); } catch (Exception exception) { exception.printStackTrace(); onMinecraftCrash(new UnexpectedThrowable("Failed to start game", exception)); return; } try { long l = System.currentTimeMillis(); int i = 0; do { if (!running) { break; } try { if (mcApplet != null && !mcApplet.isActive()) { break; } AxisAlignedBB.clearBoundingBoxPool(); Vec3D.initialize(); if (mcCanvas == null && Display.isCloseRequested()) { shutdown(); } if (isGamePaused && theWorld != null) { float f = timer.renderPartialTicks; timer.updateTimer(); timer.renderPartialTicks = f; } else { timer.updateTimer(); } long l1 = System.nanoTime(); for (int j = 0; j < timer.elapsedTicks; j++) { ticksRan++; try { runTick(); continue; } catch (MinecraftException minecraftexception1) { theWorld = null; } changeWorld1(null); displayGuiScreen(new GuiConflictWarning()); } long l2 = System.nanoTime() - l1; checkGLError("Pre render"); RenderBlocks.fancyGrass = gameSettings.fancyGraphics; sndManager.func_338_a(thePlayer, timer.renderPartialTicks); GL11.glEnable(3553 /*GL_TEXTURE_2D*/); if (theWorld != null) { theWorld.updatingLighting(); } if (!Keyboard.isKeyDown(65)) { Display.update(); } if (thePlayer != null && thePlayer.isEntityInsideOpaqueBlock()) { gameSettings.thirdPersonView = false; } if (!skipRenderWorld) { if (playerController != null) { playerController.setPartialTime(timer.renderPartialTicks); } entityRenderer.updateCameraAndRender(timer.renderPartialTicks); } if (!Display.isActive()) { if (fullscreen) { toggleFullscreen(); } Thread.sleep(10L); } if (gameSettings.showDebugInfo) { displayDebugInfo(l2); } else { prevFrameTime = System.nanoTime(); } guiAchievement.updateAchievementWindow(); Thread.yield(); if (Keyboard.isKeyDown(65)) { Display.update(); } screenshotListener(); if (mcCanvas != null && !fullscreen && (mcCanvas.getWidth() != displayWidth || mcCanvas.getHeight() != displayHeight)) { displayWidth = mcCanvas.getWidth(); displayHeight = mcCanvas.getHeight(); if (displayWidth <= 0) { displayWidth = 1; } if (displayHeight <= 0) { displayHeight = 1; } resize(displayWidth, displayHeight); } checkGLError("Post render"); i++; isGamePaused = !isMultiplayerWorld() && currentScreen != null && currentScreen.doesGuiPauseGame(); while (System.currentTimeMillis() >= l + 1000L) { debug = (new StringBuilder()) .append(i) .append(" fps, ") .append(WorldRenderer.chunksUpdated) .append(" chunk updates") .toString(); WorldRenderer.chunksUpdated = 0; l += 1000L; i = 0; } } catch (MinecraftException minecraftexception) { theWorld = null; changeWorld1(null); displayGuiScreen(new GuiConflictWarning()); } catch (OutOfMemoryError outofmemoryerror) { func_28002_e(); displayGuiScreen(new GuiErrorScreen()); System.gc(); } } while (true); } catch (MinecraftError minecrafterror) { } catch (Throwable throwable) { func_28002_e(); throwable.printStackTrace(); onMinecraftCrash(new UnexpectedThrowable("Unexpected error", throwable)); } finally { shutdownMinecraftApplet(); } }