Java tutorial
/* Copyright (c) 2015 Lance Selga <lyonecro55@gmail.com> * * This work is free. You can redistribute it and/or modify it under the * terms of the Do What The Fuck You Want To Public License, Version 2, * as published by Sam Hocevar. See the COPYING file for more details. */ package lyonlancer5.xatrocore.lib.internal; import java.io.IOException; import java.io.InputStream; import javax.imageio.ImageIO; import lyonlancer5.xatrocore.lib.SharedLibrary; import lyonlancer5.xatrocore.lib.internal.ProgressManagerImpl.ProgressBarImpl; import net.minecraft.client.LoadingScreenRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.shader.Framebuffer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; import org.apache.commons.io.IOUtils; import org.lwjgl.LWJGLUtil; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.GL11; import com.google.common.base.CharMatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; /**<b><i>Minecraft 1.8+ Downgraded Handler</i></b></br> * <p>The class handles the methods found in 1.8. These methods are known to process methods found in {@link ProgressManagerImpl ProgressManager} * {@link ProgressBarImpl ProgressBar} and the {@link SplashProgress} class. */ public class MCv18 { //private static final Logger logger = Logger.getLogger("XC - Minecraft 1.8's Renderer"); //MINECRAFT METHODS private static final ResourceLocation locationMojangPng = new ResourceLocation("textures/gui/title/mojang.png"); private static ResourceLocation mojangLogo; @SideOnly(Side.CLIENT) protected static void drawSplashScreen(Minecraft mcIn, TextureManager textureManager) { ScaledResolution scaledresolution = new ScaledResolution(mcIn, mcIn.displayWidth, mcIn.displayHeight); int i = scaledresolution.getScaleFactor(); Framebuffer framebuffer = new Framebuffer(scaledresolution.getScaledWidth() * i, scaledresolution.getScaledHeight() * i, true); framebuffer.bindFramebuffer(false); //GlStateManager.matrixMode(5889); GL11.glMatrixMode(5889); //GlStateManager.loadIdentity(); GL11.glLoadIdentity(); //GlStateManager.ortho(0.0D, (double)scaledresolution.getScaledWidth(), (double)scaledresolution.getScaledHeight(), 0.0D, 1000.0D, 3000.0D); GL11.glOrtho(0.0D, (double) scaledresolution.getScaledWidth(), (double) scaledresolution.getScaledHeight(), 0.0D, 1000.0D, 3000.0D); //GlStateManager.matrixMode(5888); GL11.glMatrixMode(5888); //GlStateManager.loadIdentity(); GL11.glLoadIdentity(); //GlStateManager.translate(0.0F, 0.0F, -2000.0F); GL11.glTranslatef(0.0F, 0.0F, -2000.0F); //GlStateManager.disableLighting(); GL11.glDisable(GL11.GL_LIGHTING); //GlStateManager.disableFog(); GL11.glDisable(GL11.GL_FOG); //GlStateManager.disableDepth(); GL11.glDisable(GL11.GL_DEPTH); //GlStateManager.enableTexture2D(); GL11.glEnable(GL11.GL_TEXTURE_2D); InputStream inputstream = null; try { //inputstream = this.mcDefaultResourcePack.getInputStream(locationMojangPng); inputstream = mcIn.getResourcePackRepository().rprDefaultResourcePack.getInputStream(locationMojangPng); mojangLogo = textureManager.getDynamicTextureLocation("logo", new DynamicTexture(ImageIO.read(inputstream))); textureManager.bindTexture(mojangLogo); } catch (IOException ioexception) { //logger.error("Unable to load logo: " + locationMojangPng, ioexception); } finally { IOUtils.closeQuietly(inputstream); } Tessellator tessellator = Tessellator.instance; //WorldRenderer worldrenderer = tessellator.getWorldRenderer(); //worldrenderer.startDrawingQuads(); tessellator.startDrawingQuads(); //worldrenderer.setColorOpaque_I(16777215); tessellator.setColorOpaque_I(16777215); //worldrenderer.addVertexWithUV(0.0D, (double)mcIn.displayHeight, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV(0.0D, (double) mcIn.displayHeight, 0.0D, 0.0D, 0.0D); //worldrenderer.addVertexWithUV((double)mcIn.displayWidth, (double)mcIn.displayHeight, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV((double) mcIn.displayWidth, (double) mcIn.displayHeight, 0.0D, 0.0D, 0.0D); //worldrenderer.addVertexWithUV((double)this.displayWidth, 0.0D, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV((double) mcIn.displayWidth, 0.0D, 0.0D, 0.0D, 0.0D); //worldrenderer.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D); tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D); tessellator.draw(); //GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); //worldrenderer.setColorOpaque_I(16777215); tessellator.setColorOpaque_I(16777215); short short1 = 256; short short2 = 256; mcIn.scaledTessellator((scaledresolution.getScaledWidth() - short1) / 2, (scaledresolution.getScaledHeight() - short2) / 2, 0, 0, short1, short2); //GlStateManager.disableLighting(); GL11.glDisable(GL11.GL_LIGHTING); //GlStateManager.disableFog(); GL11.glDisable(GL11.GL_FOG); framebuffer.unbindFramebuffer(); framebuffer.framebufferRender(scaledresolution.getScaledWidth() * i, scaledresolution.getScaledHeight() * i); //GlStateManager.enableAlpha(); GL11.glEnable(GL11.GL_ALPHA); //GlStateManager.alphaFunc(516, 0.1F); GL11.glAlphaFunc(516, 0.1F); updateDisplay(mcIn); } @SideOnly(Side.CLIENT) protected static void updateDisplay(Minecraft mcIn) { mcIn.mcProfiler.startSection("display_update"); Display.update(); mcIn.mcProfiler.endSection(); checkWindowResize(mcIn); } @SideOnly(Side.CLIENT) protected static void checkWindowResize(Minecraft mcIn) { if (!mcIn.isFullScreen() && Display.wasResized()) { int i = mcIn.displayWidth; int j = mcIn.displayHeight; mcIn.displayWidth = Display.getWidth(); mcIn.displayHeight = Display.getHeight(); if (mcIn.displayWidth != i || mcIn.displayHeight != j) { if (mcIn.displayWidth <= 0) { mcIn.displayWidth = 1; } if (mcIn.displayHeight <= 0) { mcIn.displayHeight = 1; } resize(mcIn, mcIn.displayWidth, mcIn.displayHeight); } } } @SideOnly(Side.CLIENT) protected static void resize(Minecraft mcIn, int width, int height) { mcIn.displayWidth = width <= 0 ? 1 : width; mcIn.displayHeight = height <= 0 ? 1 : height; if (mcIn.currentScreen != null) { ScaledResolution scaledresolution = new ScaledResolution(mcIn, width, height); int k = scaledresolution.getScaledWidth(); int l = scaledresolution.getScaledHeight(); mcIn.currentScreen.setWorldAndResolution(mcIn, k, l); } mcIn.loadingScreen = new LoadingScreenRenderer(mcIn); updateFramebufferSize(mcIn); } @SideOnly(Side.CLIENT) protected static void updateFramebufferSize(Minecraft mcIn) { //mcIn.framebufferMc.createBindFramebuffer(mcIn.displayWidth, mcIn.displayHeight); mcIn.getFramebuffer().createBindFramebuffer(mcIn.displayWidth, mcIn.displayHeight); if (mcIn.entityRenderer != null) { mcIn.entityRenderer.updateShaderGroupSize(mcIn.displayWidth, mcIn.displayHeight); } } //FML METHODS /*public static void processWindowMessages() { IFMLSidedHandler handler = FMLCommonHandler.instance().getSidedDelegate(); if (handler == null) return; handler.processWindowMessages(); }*/ @SuppressWarnings("deprecation") protected static void processWindowMessages() { if (SharedLibrary.isClient()) { // workaround for windows requiring messages being processed on the main thread if (LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS) return; // If we can't grab the mutex, the update call is blocked, probably in native code, just skip it and carry on // We'll get another go next time if (!SplashProgress.mutex.tryAcquire()) return; Display.processMessages(); SplashProgress.mutex.release(); } } // From FontRenderer.renderCharAtPos private static final String ALLOWED_CHARS = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000"; protected static String stripSpecialChars(String message) { // We can't handle many unicode points in the splash renderer return CharMatcher.anyOf(ALLOWED_CHARS).retainFrom(StringUtils.stripControlCodes(message)); } }