diff --git a/OrangeX/build.gradle b/OrangeX/build.gradle index 958db7f..590734f 100644 --- a/OrangeX/build.gradle +++ b/OrangeX/build.gradle @@ -21,6 +21,10 @@ dependencies { implementation("org.ow2.asm:asm-tree:9.8") // https://mvnrepository.com/artifact/org.ow2.asm/asm-tree implementation("org.ow2.asm:asm:9.8") + // Source: https://mvnrepository.com/artifact/org.greenrobot/eventbus + implementation 'org.greenrobot:eventbus:3.1.1' + // Source: https://mvnrepository.com/artifact/com.google.code.gson/gson + implementation 'com.google.code.gson:gson:2.13.2' } shadowJar { diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java index bdc62c6..d96d6cf 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java @@ -1,10 +1,22 @@ package cn.xiaozhou233.orangex; +import cn.xiaozhou233.orangex.font.FontManager; import cn.xiaozhou233.orangex.mixin.MixinManager; +import lombok.Getter; +import org.greenrobot.eventbus.EventBus; +@Getter public class OrangeX { public static final OrangeX INSTANCE = new OrangeX(); public MixinManager mixinManager = new MixinManager(); + FontManager fontManager = new FontManager(); + private final EventBus eventBus = EventBus.builder() + .logNoSubscriberMessages(false) + .logSubscriberExceptions(false) + .sendNoSubscriberEvent(false) + .sendSubscriberExceptionEvent(false) + .build(); + public void start() { System.out.println("OrangeX starting..."); diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/CFont.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/CFont.java new file mode 100644 index 0000000..ec8c729 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/CFont.java @@ -0,0 +1,247 @@ +package cn.xiaozhou233.orangex.font; + + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.AbstractTexture; +import net.minecraft.client.renderer.texture.DynamicTexture; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + + + +public class CFont +{ + private float imgSize = 1024; + protected CharData[] charData = new CharData[256]; + protected Font font; + protected boolean antiAlias; + protected boolean fractionalMetrics; + protected int fontHeight = -1; + protected int charOffset = 0; + private BufferedImage fontImage; + protected AbstractTexture tex; + + public CFont(Font font, boolean antiAlias, boolean fractionalMetrics) + { + this.font = font; + this.antiAlias = antiAlias; + this.fractionalMetrics = fractionalMetrics; + this.fontImage = generateFontImage(font, antiAlias, fractionalMetrics, this.charData); + } + + protected AbstractTexture getTexture() + { + if (tex == null) + { + tex = setupTexture(fontImage); + fontImage = null; + } + return tex; + } + + public AbstractTexture setupTexture(BufferedImage img) + { + try + { + AbstractTexture texture = new DynamicTexture(img); + GlStateManager.bindTexture(texture.getGlTextureId()); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + return texture; + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + protected BufferedImage generateFontImage(Font font, boolean antiAlias, boolean fractionalMetrics, CharData[] chars) + { + int imgSize = (int) this.imgSize; + this.fontHeight = -1; + BufferedImage bufferedImage = null; + + while (true) + { + bufferedImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = (Graphics2D) bufferedImage.getGraphics(); + g.setFont(font.deriveFont(font.getSize2D() * 2.0F)); + g.setColor(new Color(255, 255, 255, 0)); + g.fillRect(0, 0, imgSize, imgSize); + g.setColor(Color.WHITE); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAlias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); + FontMetrics fontMetrics = g.getFontMetrics(); + int charHeight = 0; + int positionX = 0; + int positionY = 1; + boolean overflow = false; + + for (int i = 0; i < chars.length; i++) + { + char ch = (char) i; + CharData charData = new CharData(); + Rectangle2D dimensions = fontMetrics.getStringBounds(String.valueOf(ch), g); + charData.width = (dimensions.getBounds().width + 8); + charData.height = dimensions.getBounds().height; + + if (positionX + charData.width >= imgSize) + { + positionX = 0; + positionY += charHeight; + charHeight = 0; + } + + if (positionY + charData.height >= imgSize) + { + overflow = true; + break; + } + + if (charData.height > charHeight) + { + charHeight = charData.height; + } + + charData.storedX = positionX; + charData.storedY = positionY; + + if (charData.height > this.fontHeight) + { + this.fontHeight = charData.height; + } + + chars[i] = charData; + g.drawString(String.valueOf(ch), positionX + 2, positionY + fontMetrics.getAscent()); + positionX += charData.width; + } + + g.dispose(); + + if (!overflow) + { + this.imgSize = imgSize; + return bufferedImage; + } + + imgSize *= 2; + } + } + + public void drawChar(CharData[] chars, char c, float x, float y) throws ArrayIndexOutOfBoundsException + { + try + { + drawQuad(x, y, chars[c].width, chars[c].height, chars[c].storedX, chars[c].storedY, chars[c].width, chars[c].height); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + protected void drawQuad(float x, float y, float width, float height, float srcX, float srcY, float srcWidth, float srcHeight) + { + float renderSRCX = srcX / imgSize; + float renderSRCY = srcY / imgSize; + float renderSRCWidth = srcWidth / imgSize; + float renderSRCHeight = srcHeight / imgSize; + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); + GL11.glVertex2d(x + width, y); + GL11.glTexCoord2f(renderSRCX, renderSRCY); + GL11.glVertex2d(x, y); + GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); + GL11.glVertex2d(x, y + height); + GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); + GL11.glVertex2d(x, y + height); + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY + renderSRCHeight); + GL11.glVertex2d(x + width, y + height); + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); + GL11.glVertex2d(x + width, y); + } + + public int getStringHeight(String text) + { + return getHeight(); + } + + public int getHeight() + { + return (this.fontHeight - 8) / 2; + } + + public int getStringWidth(String text) + { + int width = 0; + + for (char c : text.toCharArray()) + { + if ((c < this.charData.length) && (c >= 0)) + { + width += this.charData[c].width - 8 + this.charOffset; + } + } + + return width / 2; + } + + public boolean isAntiAlias() + { + return this.antiAlias; + } + + public void setAntiAlias(boolean antiAlias) + { + if (this.antiAlias != antiAlias) + { + this.antiAlias = antiAlias; + this.fontImage = generateFontImage(this.font, antiAlias, this.fractionalMetrics, this.charData); + this.tex = null; + } + } + + public boolean isFractionalMetrics() + { + return this.fractionalMetrics; + } + + public void setFractionalMetrics(boolean fractionalMetrics) + { + if (this.fractionalMetrics != fractionalMetrics) + { + this.fractionalMetrics = fractionalMetrics; + this.fontImage = generateFontImage(this.font, this.antiAlias, fractionalMetrics, this.charData); + this.tex = null; + } + } + + public Font getFont() + { + return this.font; + } + + public void setFont(Font font) + { + this.font = font; + this.fontImage = generateFontImage(font, this.antiAlias, this.fractionalMetrics, this.charData); + this.tex = null; + } + + protected class CharData + { + public int width; + public int height; + public int storedX; + public int storedY; + + protected CharData() + { + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontManager.java new file mode 100644 index 0000000..d468119 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontManager.java @@ -0,0 +1,19 @@ +package cn.xiaozhou233.orangex.font; + +import java.awt.*; + +public class FontManager { + public FontRenderer MontserratLight18 = new FontRenderer("Montserrat-Light.ttf", 18, Font.PLAIN, true, true); + + public FontRenderer MontserratRegular18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true); + public FontRenderer MontserratRegular32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true); + + public FontRenderer MontserratMedium18 = new FontRenderer("Montserrat-Medium.ttf", 18, Font.PLAIN, true, true); + public FontRenderer MontserratMedium32 = new FontRenderer("Montserrat-Medium.ttf", 32, Font.PLAIN, true, true); + + public FontRenderer MontserratBold18 = new FontRenderer("Montserrat-Bold.ttf", 18, Font.PLAIN, true, true); + public FontRenderer MontserratBold32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true); + + public FontRenderer JelloMedium32 = new FontRenderer("JelloMedium.ttf", 32, Font.PLAIN, true, true); + public FontRenderer JelloRegular16 = new FontRenderer("JelloRegular.ttf", 16, Font.PLAIN, true, true); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontRenderer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontRenderer.java new file mode 100644 index 0000000..dc3a132 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontRenderer.java @@ -0,0 +1,506 @@ +package cn.xiaozhou233.orangex.font; + + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.AbstractTexture; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + + +public class FontRenderer extends CFont { + protected CFont.CharData[] boldChars = new CFont.CharData[256]; + protected CFont.CharData[] italicChars = new CFont.CharData[256]; + protected CFont.CharData[] boldItalicChars = new CFont.CharData[256]; + + private final int[] colorCode = new int[32]; + + /* + CREDIT G0dwhitelight. + */ + public FontRenderer(Font font, boolean antiAlias, boolean fractionalMetrics) { + super(font, antiAlias, fractionalMetrics); + setupMinecraftColorcodes(); + setupBoldItalicIDs(); + } + + public FontRenderer(String filePath, int size, int fontType, boolean antiAlias, boolean fractionalMetrics) { + super(FontUtil.getFontFromTTF( + FontRenderer.class.getClassLoader().getResourceAsStream("fonts/" + filePath), size, fontType), + antiAlias, fractionalMetrics); + setupMinecraftColorcodes(); + setupBoldItalicIDs(); + } + + public float drawString(String text, float x, float y, int color) { + return drawString(text, x, y, color, false); + } + + public float drawString(String text, double x, double y, int color) { + return drawString(text, x, y, color, false); + } + + public float drawStringWithShadow(String text, float x, float y, int color) { + float shadowWidth = drawString(text, x + 1D, y + .5D, color, true); + return Math.max(shadowWidth, drawString(text, x, y, color, false)); + } + + public float drawStringWithShadow(String text, double x, double y, int color) { + float shadowWidth = drawString(text, x + 1, y + .5, color, true); + return Math.max(shadowWidth, drawString(text, x, y, color, false)); + } + + public float drawCenteredString(String text, float x, float y, int color) { + return drawString(text, x - getStringWidth(text) / 2, y, color); + } + + public float drawCenteredString(String text, double x, double y, int color) { + return drawString(text, x - getStringWidth(text) / 2, y, color); + } + + public float drawCenteredStringWithShadow(String text, float x, float y, int color) { + float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true); + return drawString(text, x - getStringWidth(text) / 2, y, color); + } + + public void drawStringWithOutline(String text, double x, double y, int color) { + drawString(text, x - .5, y, 0x000000); + + drawString(text, x + .5, y, 0x000000); + + drawString(text, x, y - .5, 0x000000); + + drawString(text, x, y + .5, 0x000000); + + drawString(text, x, y, color); + } + + public void drawCenteredStringWithOutline(String text, double x, double y, int color) { + drawCenteredString(text, x - .5, y, 0x000000); + + drawCenteredString(text, x + .5, y, 0x000000); + + drawCenteredString(text, x, y - .5, 0x000000); + + drawCenteredString(text, x, y + .5, 0x000000); + + drawCenteredString(text, x, y, color); + } + + public float drawCenteredStringWithShadow(String text, double x, double y, int color) { + float shadowWidth = drawString(text, x - getStringWidth(text) / 2 + 0.45D, y + 0.5D, color, true); + return drawString(text, x - getStringWidth(text) / 2, y, color); + } + + public float drawString(String text, double x, double y, int color, boolean shadow) { + x -= 1; + + if (text == null) { + return 0.0F; + } + + if (color == 553648127) { + color = 16777215; + } + + if ((color & 0xFC000000) == 0) { + color |= -16777216; + } + + if (shadow) { + color = (color & 0xFCFCFC) >> 2 | color & new Color(20, 20, 20, 200).getRGB(); + } + + CFont.CharData[] currentData = this.charData; + float alpha = (color >> 24 & 0xFF) / 255.0F; + boolean randomCase = false; + boolean bold = false; + boolean italic = false; + boolean strikethrough = false; + boolean underline = false; + boolean render = true; + double scaleFactor = 2.0D / getFontScale(); + x *= scaleFactor; + y = (y - 3.0D) * scaleFactor; + + if (render) { + GL11.glPushMatrix(); + GlStateManager.scale(1.0D / scaleFactor, 1.0D / scaleFactor, 1.0D / scaleFactor); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha); + int size = text.length(); + GlStateManager.enableTexture2D(); + GlStateManager.bindTexture(getTexture().getGlTextureId()); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTexture().getGlTextureId()); + + for (int i = 0; i < size; i++) { + char character = text.charAt(i); + if ((String.valueOf(character).equals("\247")) && (i < size)) { + int colorIndex = 21; + + try { + colorIndex = "0123456789abcdefklmnor".indexOf(text.charAt(i + 1)); + } catch (Exception e) { + e.printStackTrace(); + } + + if (colorIndex < 16) { + bold = false; + italic = false; + randomCase = false; + underline = false; + strikethrough = false; + GlStateManager.bindTexture(getTexture().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // tex.getGlTextureId()); + currentData = this.charData; + + if ((colorIndex < 0) || (colorIndex > 15)) { + colorIndex = 15; + } + + if (shadow) { + colorIndex += 16; + } + + int colorcode = this.colorCode[colorIndex]; + GlStateManager.color((colorcode >> 16 & 0xFF) / 255.0F, (colorcode >> 8 & 0xFF) / 255.0F, (colorcode & 0xFF) / 255.0F, alpha); + } else if (colorIndex == 16) { + randomCase = true; + } else if (colorIndex == 17) { + bold = true; + + if (italic) { + GlStateManager.bindTexture(getTexItalicBold().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // texItalicBold.getGlTextureId()); + currentData = this.boldItalicChars; + } else { + GlStateManager.bindTexture(getTexBold().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // texBold.getGlTextureId()); + currentData = this.boldChars; + } + } else if (colorIndex == 18) { + strikethrough = true; + } else if (colorIndex == 19) { + underline = true; + } else if (colorIndex == 20) { + italic = true; + + if (bold) { + GlStateManager.bindTexture(getTexItalicBold().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // texItalicBold.getGlTextureId()); + currentData = this.boldItalicChars; + } else { + GlStateManager.bindTexture(getTexItalic().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // texItalic.getGlTextureId()); + currentData = this.italicChars; + } + } else if (colorIndex == 21) { + bold = false; + italic = false; + randomCase = false; + underline = false; + strikethrough = false; + GlStateManager.color((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, alpha); + GlStateManager.bindTexture(getTexture().getGlTextureId()); + // GL11.glfunc_179144_i(GL11.GL_TEXTURE_2D, + // tex.getGlTextureId()); + currentData = this.charData; + } + + i++; + } else if ((character < currentData.length) && (character >= 0)) { + GL11.glBegin(GL11.GL_TRIANGLES); + drawChar(currentData, character, (float) x, (float) y); + GL11.glEnd(); + + if (strikethrough) { + drawLine(x, y + currentData[character].height / 2, x + currentData[character].width - 8.0D, y + currentData[character].height / 2, 1.0F); + } + + if (underline) { + drawLine(x, y + currentData[character].height - 2.0D, x + currentData[character].width - 8.0D, y + currentData[character].height - 2.0D, 1.0F); + } + + x += currentData[character].width - 8 + this.charOffset; + } + } + + GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_DONT_CARE); + GL11.glPopMatrix(); + } + + return (float) (x / scaleFactor); + } + + public int getStringWidth(String text) { + if (text == null) { + return 0; + } + int width = 0; + CFont.CharData[] currentData = this.charData; + boolean bold = false; + boolean italic = false; + int size = text.length(); + + for (int i = 0; i < size; i++) { + char character = text.charAt(i); + + if ((String.valueOf(character).equals("\247")) && (i < size)) { + int colorIndex = "0123456789abcdefklmnor".indexOf(character); + + if (colorIndex < 16) { + bold = false; + italic = false; + } else if (colorIndex == 17) { + bold = true; + + if (italic) { + currentData = this.boldItalicChars; + } else { + currentData = this.boldChars; + } + } else if (colorIndex == 20) { + italic = true; + + if (bold) { + currentData = this.boldItalicChars; + } else { + currentData = this.italicChars; + } + } else if (colorIndex == 21) { + bold = false; + italic = false; + currentData = this.charData; + } + + i++; + } else if ((character < currentData.length) && (character >= 0)) { + width += currentData[character].width - 8 + this.charOffset; + } + } + + return (int) ((width / 2) * getFontScale()); + } + + public int getStringWidthCust(String text) { + if (text == null) { + return 0; + } + + int width = 0; + CFont.CharData[] currentData = this.charData; + boolean bold = false; + boolean italic = false; + int size = text.length(); + + for (int i = 0; i < size; i++) { + char character = text.charAt(i); + + if ((String.valueOf(character).equals("§")) && (i < size)) { + int colorIndex = "0123456789abcdefklmnor".indexOf(character); + + if (colorIndex < 16) { + bold = false; + italic = false; + } else if (colorIndex == 17) { + bold = true; + + if (italic) { + currentData = this.boldItalicChars; + } else { + currentData = this.boldChars; + } + } else if (colorIndex == 20) { + italic = true; + + if (bold) { + currentData = this.boldItalicChars; + } else { + currentData = this.italicChars; + } + } else if (colorIndex == 21) { + bold = false; + italic = false; + currentData = this.charData; + } + + i++; + } else if ((character < currentData.length) && (character >= 0)) { + width += currentData[character].width - 8 + this.charOffset; + } + } + + return (int) (((width - this.charOffset) / 2) * getFontScale()); + } + + public void setFont(Font font) { + super.setFont(font); + setupBoldItalicIDs(); + } + + public void setAntiAlias(boolean antiAlias) { + super.setAntiAlias(antiAlias); + setupBoldItalicIDs(); + } + + public void setFractionalMetrics(boolean fractionalMetrics) { + super.setFractionalMetrics(fractionalMetrics); + setupBoldItalicIDs(); + } + + protected AbstractTexture texBold; + protected AbstractTexture texItalic; + protected AbstractTexture texItalicBold; + private BufferedImage boldImage; + private BufferedImage italicImage; + private BufferedImage boldItalicImage; + + private void setupBoldItalicIDs() { + boldImage = generateFontImage(this.font.deriveFont(1), this.antiAlias, this.fractionalMetrics, this.boldChars); + italicImage = generateFontImage(this.font.deriveFont(2), this.antiAlias, this.fractionalMetrics, this.italicChars); + boldItalicImage = generateFontImage(this.font.deriveFont(3), this.antiAlias, this.fractionalMetrics, this.boldItalicChars); + texBold = null; + texItalic = null; + texItalicBold = null; + } + + private AbstractTexture getTexBold() { + if (texBold == null) { + texBold = setupTexture(boldImage); + boldImage = null; + } + return texBold; + } + + private AbstractTexture getTexItalic() { + if (texItalic == null) { + texItalic = setupTexture(italicImage); + italicImage = null; + } + return texItalic; + } + + private AbstractTexture getTexItalicBold() { + if (texItalicBold == null) { + texItalicBold = setupTexture(boldItalicImage); + boldItalicImage = null; + } + return texItalicBold; + } + + private void drawLine(double x, double y, double x1, double y1, float width) { + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glLineWidth(width); + GL11.glBegin(GL11.GL_LINES); + GL11.glVertex2d(x, y); + GL11.glVertex2d(x1, y1); + GL11.glEnd(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + public List wrapWords(String text, double width) { + List finalWords = new ArrayList(); + + if (getStringWidth(text) > width) { + String[] words = text.split(" "); + String currentWord = ""; + char lastColorCode = 65535; + + for (String word : words) { + for (int i = 0; i < word.toCharArray().length; i++) { + char c = word.toCharArray()[i]; + + if ((String.valueOf(c).equals("§")) && (i < word.toCharArray().length - 1)) { + lastColorCode = word.toCharArray()[(i + 1)]; + } + } + + if (getStringWidth(currentWord + word + " ") < width) { + currentWord = currentWord + word + " "; + } else { + finalWords.add(currentWord); + currentWord = "" + lastColorCode + word + " "; + } + } + + if (currentWord.length() > 0) if (getStringWidth(currentWord) < width) { + finalWords.add("" + lastColorCode + currentWord + " "); + currentWord = ""; + } else { + for (String s : formatString(currentWord, width)) { + finalWords.add(s); + } + } + } else { + finalWords.add(text); + } + + return finalWords; + } + + public List formatString(String string, double width) { + List finalWords = new ArrayList(); + String currentWord = ""; + char lastColorCode = 65535; + char[] chars = string.toCharArray(); + + for (int i = 0; i < chars.length; i++) { + char c = chars[i]; + + if ((String.valueOf(c).equals("§")) && (i < chars.length - 1))//Why does intelij replace "§" with § + { + lastColorCode = chars[(i + 1)]; + } + + if (getStringWidth(currentWord + c) < width) { + currentWord = currentWord + c; + } else { + finalWords.add(currentWord); + currentWord = "" + lastColorCode + String.valueOf(c); + } + } + + if (currentWord.length() > 0) { + finalWords.add(currentWord); + } + + return finalWords; + } + + private double getFontScale() { + return (Minecraft.getMinecraft().displayWidth / 1920.0D) * 0.5D; + } + + private void setupMinecraftColorcodes() { + for (int index = 0; index < 32; index++) { + int noClue = (index >> 3 & 0x1) * 85; + int red = (index >> 2 & 0x1) * 170 + noClue; + int green = (index >> 1 & 0x1) * 170 + noClue; + int blue = (index >> 0 & 0x1) * 170 + noClue; + + if (index == 6) { + red += 85; + } + + if (index >= 16) { + red /= 4; + green /= 4; + blue /= 4; + } + + this.colorCode[index] = ((red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF); + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontUtil.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontUtil.java new file mode 100644 index 0000000..18301cc --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/font/FontUtil.java @@ -0,0 +1,19 @@ +package cn.xiaozhou233.orangex.font; + +import java.awt.*; +import java.io.InputStream; + + +public class FontUtil { + + public static Font getFontFromTTF(InputStream inputStream, float fontSize, int fontType) { + Font output = null; + try { + output = Font.createFont(fontType, inputStream); + output = output.deriveFont(fontSize); + } catch (Exception e) { + e.printStackTrace(); + } + return output; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/MixinManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/MixinManager.java index 4756221..fef3946 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/MixinManager.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/MixinManager.java @@ -1,7 +1,7 @@ package cn.xiaozhou233.orangex.mixin; import cn.xiaozhou233.juiceremapper.utils.IOUtils; -import cn.xiaozhou233.orangex.mixin.impl.MixinMinecraft; +import cn.xiaozhou233.orangex.mixin.impl.*; import cn.xiaozhou233.orangex.utils.JuiceAgentFacade; import cn.yapeteam.ymixin.Transformer; import cn.yapeteam.ymixin.YMixin; @@ -63,6 +63,7 @@ public final class MixinManager { Transformer transformer = new Transformer(); try { transformer.addMixin(MixinMinecraft.class); + transformer.addMixin(MixinGuiIngame.class); } catch (Throwable e) { throw new RuntimeException("Failed to add mixin", e); } diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinGuiIngame.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinGuiIngame.java new file mode 100644 index 0000000..143673d --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinGuiIngame.java @@ -0,0 +1,41 @@ +package cn.xiaozhou233.orangex.mixin.impl; + +import cn.xiaozhou233.orangex.OrangeX; +import cn.yapeteam.ymixin.annotations.Inject; +import cn.yapeteam.ymixin.annotations.Local; +import cn.yapeteam.ymixin.annotations.Mixin; +import cn.yapeteam.ymixin.annotations.Target; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiIngame; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; + +@Mixin(GuiIngame.class) +public class MixinGuiIngame { + + @Inject(method = "renderGameOverlay", desc = "(F)V", target = @Target("HEAD")) + public void onRenderGameOverlay(@Local(source = "partialTicks", index = 1) float partialTicks) { + Minecraft mc = Minecraft.getMinecraft(); + ScaledResolution sr = new ScaledResolution(mc); + + GlStateManager.pushMatrix(); + GlStateManager.disableDepth(); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate( + GL11.GL_SRC_ALPHA, + GL11.GL_ONE_MINUS_SRC_ALPHA, + GL11.GL_ONE, + GL11.GL_ZERO + ); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + mc.entityRenderer.setupOverlayRendering(); + + OrangeX.getInstance().getFontManager().JelloMedium32.drawString("OrangeX", 5, 5, 0xFFA500); + + GlStateManager.enableDepth(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } +} \ No newline at end of file diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinMinecraft.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinMinecraft.java index 3ad6b56..8f7f51e 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinMinecraft.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/mixin/impl/MixinMinecraft.java @@ -14,7 +14,7 @@ public class MixinMinecraft { @Inject(method = "runGameLoop", desc = "()V", target = @Target("HEAD")) private void onLoop() { - System.out.println("LOOP!"); + } @Inject(method = "runTick", desc = "()V", target = @Target("HEAD")) diff --git a/OrangeX/src/main/resources/fonts/JelloLight.ttf b/OrangeX/src/main/resources/fonts/JelloLight.ttf new file mode 100644 index 0000000..c57bc96 Binary files /dev/null and b/OrangeX/src/main/resources/fonts/JelloLight.ttf differ diff --git a/OrangeX/src/main/resources/fonts/JelloMedium.ttf b/OrangeX/src/main/resources/fonts/JelloMedium.ttf new file mode 100644 index 0000000..be07dfd Binary files /dev/null and b/OrangeX/src/main/resources/fonts/JelloMedium.ttf differ diff --git a/OrangeX/src/main/resources/fonts/JelloRegular.ttf b/OrangeX/src/main/resources/fonts/JelloRegular.ttf new file mode 100644 index 0000000..7864fce Binary files /dev/null and b/OrangeX/src/main/resources/fonts/JelloRegular.ttf differ diff --git a/OrangeX/src/main/resources/fonts/Montserrat-Bold.ttf b/OrangeX/src/main/resources/fonts/Montserrat-Bold.ttf new file mode 100644 index 0000000..4033587 Binary files /dev/null and b/OrangeX/src/main/resources/fonts/Montserrat-Bold.ttf differ diff --git a/OrangeX/src/main/resources/fonts/Montserrat-Light.ttf b/OrangeX/src/main/resources/fonts/Montserrat-Light.ttf new file mode 100644 index 0000000..881f12d Binary files /dev/null and b/OrangeX/src/main/resources/fonts/Montserrat-Light.ttf differ diff --git a/OrangeX/src/main/resources/fonts/Montserrat-Medium.ttf b/OrangeX/src/main/resources/fonts/Montserrat-Medium.ttf new file mode 100644 index 0000000..c9a39ea Binary files /dev/null and b/OrangeX/src/main/resources/fonts/Montserrat-Medium.ttf differ diff --git a/OrangeX/src/main/resources/fonts/Montserrat-Regular.ttf b/OrangeX/src/main/resources/fonts/Montserrat-Regular.ttf new file mode 100644 index 0000000..895e220 Binary files /dev/null and b/OrangeX/src/main/resources/fonts/Montserrat-Regular.ttf differ diff --git a/OrangeX/src/main/resources/licenses/Montserrat.txt b/OrangeX/src/main/resources/licenses/Montserrat.txt new file mode 100644 index 0000000..4515774 --- /dev/null +++ b/OrangeX/src/main/resources/licenses/Montserrat.txt @@ -0,0 +1,93 @@ +Copyright 2024 The Montserrat.Git Project Authors (https://github.com/JulietaUla/Montserrat.git) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE.