diff --git a/patch/minecraft.patch b/patch/minecraft.patch index 939f3eb..8591ce4 100644 --- a/patch/minecraft.patch +++ b/patch/minecraft.patch @@ -1,6 +1,6 @@ -From 563ff46aae302fa4587684205966ea6cc63c1efe Mon Sep 17 00:00:00 2001 +From 23935209c22d93ce7788b68b795ce11bcb9f1ab2 Mon Sep 17 00:00:00 2001 From: Alexander01998 -Date: Sun, 16 Oct 2016 17:15:15 +0200 +Date: Wed, 19 Oct 2016 18:00:28 +0200 Subject: [PATCH] mod --- @@ -12,6 +12,7 @@ Subject: [PATCH] mod net/minecraft/block/BlockSoulSand.java | 6 + net/minecraft/client/Minecraft.java | 223 +++++++++++---------- net/minecraft/client/entity/EntityPlayerSP.java | 146 ++++++++++++-- + net/minecraft/client/gui/FontRenderer.java | 2 +- net/minecraft/client/gui/GuiButton.java | 14 +- net/minecraft/client/gui/GuiDisconnected.java | 87 ++++++++ net/minecraft/client/gui/GuiGameOver.java | 14 +- @@ -45,6 +46,7 @@ Subject: [PATCH] mod .../renderer/texture/TextureAtlasSprite.java | 2 +- .../client/renderer/texture/TextureManager.java | 2 +- .../client/renderer/texture/TextureMap.java | 6 +- + .../client/renderer/texture/TextureUtil.java | 2 +- net/minecraft/client/resources/SkinManager.java | 7 + net/minecraft/client/settings/KeyBinding.java | 2 +- net/minecraft/crash/CrashReport.java | 74 ++++++- @@ -71,7 +73,7 @@ Subject: [PATCH] mod net/minecraft/world/chunk/Chunk.java | 2 +- .../world/gen/structure/MapGenStructure.java | 6 +- net/minecraft/world/storage/WorldInfo.java | 18 +- - 67 files changed, 1263 insertions(+), 431 deletions(-) + 69 files changed, 1265 insertions(+), 433 deletions(-) diff --git a/net/minecraft/block/Block.java b/net/minecraft/block/Block.java index 25c6330..da46b84 100644 @@ -995,6 +997,19 @@ index 38f8c49..5864eae 100644 { if (this.field_189812_cs <= 0 && this.onGround && !this.isSneaking() && !this.isRiding()) { +diff --git a/net/minecraft/client/gui/FontRenderer.java b/net/minecraft/client/gui/FontRenderer.java +index 6439aa9..aae2a1c 100644 +--- a/net/minecraft/client/gui/FontRenderer.java ++++ b/net/minecraft/client/gui/FontRenderer.java +@@ -848,7 +848,7 @@ public class FontRenderer implements IResourceManagerReloadListener + /** + * Inserts newline and formatting into a string to wrap it within the specified width. + */ +- String wrapFormattedStringToWidth(String str, int wrapWidth) ++ protected String wrapFormattedStringToWidth(String str, int wrapWidth) + { + int i = this.sizeStringToWidth(str, wrapWidth); + diff --git a/net/minecraft/client/gui/GuiButton.java b/net/minecraft/client/gui/GuiButton.java index 93eccc5..9ee0d1c 100644 --- a/net/minecraft/client/gui/GuiButton.java @@ -3010,6 +3025,19 @@ index 9d91fa2..1a44f27 100644 { public String call() throws Exception { +diff --git a/net/minecraft/client/renderer/texture/TextureUtil.java b/net/minecraft/client/renderer/texture/TextureUtil.java +index b0a0490..c5c3031 100644 +--- a/net/minecraft/client/renderer/texture/TextureUtil.java ++++ b/net/minecraft/client/renderer/texture/TextureUtil.java +@@ -295,7 +295,7 @@ public class TextureUtil + DATA_BUFFER.position(0).limit(p_110994_2_); + } + +- static void bindTexture(int p_94277_0_) ++ public static void bindTexture(int p_94277_0_) + { + GlStateManager.bindTexture(p_94277_0_); + } diff --git a/net/minecraft/client/resources/SkinManager.java b/net/minecraft/client/resources/SkinManager.java index 6aee323..73e0c0d 100644 --- a/net/minecraft/client/resources/SkinManager.java diff --git a/src/org/darkstorm/minecraft/gui/theme/simple/SimpleTheme.java b/src/org/darkstorm/minecraft/gui/theme/simple/SimpleTheme.java index 9eb9cee..f070230 100644 --- a/src/org/darkstorm/minecraft/gui/theme/simple/SimpleTheme.java +++ b/src/org/darkstorm/minecraft/gui/theme/simple/SimpleTheme.java @@ -2,11 +2,10 @@ import java.awt.Font; -import net.minecraft.client.gui.FontRenderer; - import org.darkstorm.minecraft.gui.theme.AbstractTheme; -import tk.wurst_client.font.UnicodeFontRenderer; +import net.minecraft.client.gui.FontRenderer; +import tk.wurst_client.font.WurstFontRenderer; public class SimpleTheme extends AbstractTheme { @@ -14,8 +13,8 @@ public class SimpleTheme extends AbstractTheme public SimpleTheme() { - fontRenderer = - new UnicodeFontRenderer(new Font("Trebuchet MS", Font.PLAIN, 15)); + fontRenderer = new WurstFontRenderer( + new Font("Trebuchet MS", Font.PLAIN, 15), true, 8); installUI(new SimpleFrameUI(this)); installUI(new SimplePanelUI(this)); diff --git a/src/tk/wurst_client/font/Fonts.java b/src/tk/wurst_client/font/Fonts.java index f5f7d40..75195b3 100644 --- a/src/tk/wurst_client/font/Fonts.java +++ b/src/tk/wurst_client/font/Fonts.java @@ -11,14 +11,17 @@ public class Fonts { - public static UnicodeFontRenderer segoe22; - public static UnicodeFontRenderer segoe18; - public static UnicodeFontRenderer segoe15; + public static WurstFontRenderer segoe22; + public static WurstFontRenderer segoe18; + public static WurstFontRenderer segoe15; public static void loadFonts() { - segoe22 = new UnicodeFontRenderer(new Font("Segoe UI", Font.PLAIN, 44)); - segoe18 = new UnicodeFontRenderer(new Font("Segoe UI", Font.PLAIN, 36)); - segoe15 = new UnicodeFontRenderer(new Font("Segoe UI", Font.PLAIN, 30)); + segoe22 = new WurstFontRenderer(new Font("Segoe UI", Font.PLAIN, 44), + true, 8); + segoe18 = new WurstFontRenderer(new Font("Segoe UI", Font.PLAIN, 36), + true, 8); + segoe15 = new WurstFontRenderer(new Font("Segoe UI", Font.PLAIN, 30), + true, 8); } } diff --git a/src/tk/wurst_client/font/UnicodeFontRenderer.java b/src/tk/wurst_client/font/UnicodeFontRenderer.java deleted file mode 100644 index e1962e1..0000000 --- a/src/tk/wurst_client/font/UnicodeFontRenderer.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2014 - 2016 | Wurst-Imperium | All rights reserved. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package tk.wurst_client.font; - -import static org.lwjgl.opengl.GL11.*; - -import java.awt.Color; -import java.awt.Font; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.util.ResourceLocation; - -import org.newdawn.slick.SlickException; -import org.newdawn.slick.UnicodeFont; -import org.newdawn.slick.font.effects.ColorEffect; - -public class UnicodeFontRenderer extends FontRenderer -{ - private final UnicodeFont font; - - @SuppressWarnings("unchecked") - public UnicodeFontRenderer(Font awtFont) - { - super(Minecraft.getMinecraft().gameSettings, new ResourceLocation( - "textures/font/ascii.png"), Minecraft.getMinecraft() - .getTextureManager(), false); - - font = new UnicodeFont(awtFont); - font.addAsciiGlyphs(); - font.getEffects().add(new ColorEffect(Color.WHITE)); - try - { - font.loadGlyphs(); - }catch(SlickException exception) - { - throw new RuntimeException(exception); - } - String alphabet = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; - FONT_HEIGHT = font.getHeight(alphabet) / 4; - } - - @Override - public int drawString(String string, int x, int y, int color) - { - if(string == null) - return 0; - glPushMatrix(); - glScaled(0.25, 0.25, 0.25); - - boolean blend = glIsEnabled(GL_BLEND); - boolean lighting = glIsEnabled(GL_LIGHTING); - boolean texture = glIsEnabled(GL_TEXTURE_2D); - if(!blend) - glEnable(GL_BLEND); - if(lighting) - glDisable(GL_LIGHTING); - if(texture) - glDisable(GL_TEXTURE_2D); - x *= 4; - y *= 4; - - font.drawString(x, y, string, new org.newdawn.slick.Color(color)); - - if(texture) - glEnable(GL_TEXTURE_2D); - if(lighting) - glEnable(GL_LIGHTING); - if(!blend) - glDisable(GL_BLEND); - glPopMatrix(); - return x; - } - - @Override - public int drawStringWithShadow(String string, float x, float y, int color) - { - return drawString(string, (int)x, (int)y, color); - } - - @Override - public int getCharWidth(char c) - { - return getStringWidth(Character.toString(c)); - } - - @Override - public int getStringWidth(String string) - { - return font.getWidth(string) / 4; - } - - public int getStringHeight(String string) - { - return font.getHeight(string) / 4; - } -} diff --git a/src/tk/wurst_client/font/WurstFont.java b/src/tk/wurst_client/font/WurstFont.java new file mode 100644 index 0000000..902f940 --- /dev/null +++ b/src/tk/wurst_client/font/WurstFont.java @@ -0,0 +1,277 @@ +package tk.wurst_client.font; + +import static org.lwjgl.opengl.GL11.*; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; + +import net.minecraft.client.renderer.texture.TextureUtil; + +public class WurstFont +{ + + public int IMAGE_WIDTH = 1024; + public int IMAGE_HEIGHT = 1024; + private int texID; + private final IntObject[] chars = new IntObject[2048]; + private final Font font; + private boolean antiAlias; + private int fontHeight = -1; + private int charOffset = 8; + + public WurstFont(final Font font, final boolean antiAlias, + final int charOffset) + { + this.font = font; + this.antiAlias = antiAlias; + this.charOffset = charOffset; + setupTexture(antiAlias); + } + + public WurstFont(final Font font, final boolean antiAlias) + { + this.font = font; + this.antiAlias = antiAlias; + charOffset = 8; + setupTexture(antiAlias); + } + + private void setupTexture(final boolean antiAlias) + { + if(font.getSize() <= 15) + { + IMAGE_WIDTH = 256; + IMAGE_HEIGHT = 256; + } + if(font.getSize() <= 43) + { + IMAGE_WIDTH = 512; + IMAGE_HEIGHT = 512; + }else if(font.getSize() <= 91) + { + IMAGE_WIDTH = 1024; + IMAGE_HEIGHT = 1024; + }else + { + IMAGE_WIDTH = 2048; + IMAGE_HEIGHT = 2048; + } + + final BufferedImage img = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, + BufferedImage.TYPE_INT_ARGB); + final Graphics2D g = (Graphics2D)img.getGraphics(); + g.setFont(font); + + g.setColor(new Color(255, 255, 255, 0)); + g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); + g.setColor(Color.white); + + int rowHeight = 0; + int positionX = 0; + int positionY = 0; + for(int i = 0; i < 2048; i++) + { + final char ch = (char)i; + final BufferedImage fontImage = getFontImage(ch, antiAlias); + + final IntObject newIntObject = new IntObject(); + + newIntObject.width = fontImage.getWidth(); + newIntObject.height = fontImage.getHeight(); + + if(positionX + newIntObject.width >= IMAGE_WIDTH) + { + positionX = 0; + positionY += rowHeight; + rowHeight = 0; + } + + newIntObject.storedX = positionX; + newIntObject.storedY = positionY; + + if(newIntObject.height > fontHeight) + fontHeight = newIntObject.height; + + if(newIntObject.height > rowHeight) + rowHeight = newIntObject.height; + chars[i] = newIntObject; + g.drawImage(fontImage, positionX, positionY, null); + + positionX += newIntObject.width; + } + + try + { + texID = TextureUtil.uploadTextureImageAllocate( + TextureUtil.glGenTextures(), img, true, true); + }catch(final NullPointerException e) + { + e.printStackTrace(); + } + } + + private BufferedImage getFontImage(final char ch, final boolean antiAlias) + { + final BufferedImage tempfontImage = + new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + final Graphics2D g = (Graphics2D)tempfontImage.getGraphics(); + if(antiAlias) + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + else + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + g.setFont(font); + final FontMetrics fontMetrics = g.getFontMetrics(); + int charwidth = fontMetrics.charWidth(ch) + 8; + + if(charwidth <= 0) + charwidth = 7; + int charheight = fontMetrics.getHeight() + 3; + if(charheight <= 0) + charheight = font.getSize(); + final BufferedImage fontImage = new BufferedImage(charwidth, charheight, + BufferedImage.TYPE_INT_ARGB); + final Graphics2D gt = (Graphics2D)fontImage.getGraphics(); + if(antiAlias) + gt.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + else + gt.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + gt.setFont(font); + gt.setColor(Color.WHITE); + final int charx = 3; + final int chary = 1; + gt.drawString(String.valueOf(ch), charx, + chary + fontMetrics.getAscent()); + + return fontImage; + + } + + public void drawChar(final char c, final float x, final 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(final Exception e) + { + e.printStackTrace(); + } + } + + private void drawQuad(final float x, final float y, final float width, + final float height, final float srcX, final float srcY, + final float srcWidth, final float srcHeight) + { + final float renderSRCX = srcX / IMAGE_WIDTH, + renderSRCY = srcY / IMAGE_HEIGHT, + renderSRCWidth = srcWidth / IMAGE_WIDTH, + renderSRCHeight = srcHeight / IMAGE_HEIGHT; + glBegin(GL_TRIANGLES); + glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); + glVertex2d(x + width, y); + glTexCoord2f(renderSRCX, renderSRCY); + glVertex2d(x, y); + glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); + glVertex2d(x, y + height); + glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); + glVertex2d(x, y + height); + glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY + renderSRCHeight); + glVertex2d(x + width, y + height); + glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); + glVertex2d(x + width, y); + glEnd(); + } + + public void drawString(final String text, double x, double y, + final Color color, final boolean shadow) + { + x *= 2; + y = y * 2 - 2; + glPushMatrix(); + // glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST); + glScaled(0.25D, 0.25D, 0.25D); + // glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + TextureUtil.bindTexture(texID); + glColor(shadow ? new Color(0.05F, 0.05F, 0.05F, color.getAlpha() / 255F) + : color); + final int size = text.length(); + for(int indexInString = 0; indexInString < size; indexInString++) + { + final char character = text.charAt(indexInString); + if(character < chars.length && character >= 0) + { + drawChar(character, (float)x, (float)y); + x += chars[character].width - charOffset; + } + } + glPopMatrix(); + } + + public void glColor(final Color color) + { + final float red = color.getRed() / 255F, + green = color.getGreen() / 255F, blue = color.getBlue() / 255F, + alpha = color.getAlpha() / 255F; + glColor4f(red, green, blue, alpha); + } + + public int getStringHeight(final String text) + { + int lines = 1; + for(char c : text.toCharArray()) + if(c == '\n') + lines++; + return (fontHeight - charOffset) / 2 * lines; + } + + public int getHeight() + { + return (fontHeight - charOffset) / 2; + } + + public int getStringWidth(final String text) + { + int width = 0; + for(final char c : text.toCharArray()) + if(c < chars.length && c >= 0) + width += chars[c].width - charOffset; + return width / 2; + } + + public boolean isAntiAlias() + { + return antiAlias; + } + + public void setAntiAlias(final boolean antiAlias) + { + if(this.antiAlias != antiAlias) + { + this.antiAlias = antiAlias; + setupTexture(antiAlias); + } + } + + public Font getFont() + { + return font; + } + + private class IntObject + { + + public int width; + public int height; + public int storedX; + public int storedY; + } +} diff --git a/src/tk/wurst_client/font/WurstFontRenderer.java b/src/tk/wurst_client/font/WurstFontRenderer.java new file mode 100644 index 0000000..8390501 --- /dev/null +++ b/src/tk/wurst_client/font/WurstFontRenderer.java @@ -0,0 +1,703 @@ +package tk.wurst_client.font; + +import static org.lwjgl.opengl.GL11.*; + +import java.awt.Color; +import java.awt.Font; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraft.util.ResourceLocation; + +public class WurstFontRenderer extends FontRenderer +{ + + public final Random fontRandom = new Random(); + private final Color[] customColorCodes = new Color[256]; + private final int[] colorCode = new int[32]; + private WurstFont font, boldFont, italicFont, boldItalicFont; + private String colorcodeIdentifiers = "0123456789abcdefklmnor"; + private boolean bidi; + + /** + * Constructs a new font renderer. + * + * @param fontName + * @param fontSize + * @param antiAlias + */ + public WurstFontRenderer(final Font font, final boolean antiAlias, + final int charOffset) + { + super(Minecraft.getMinecraft().gameSettings, + new ResourceLocation("textures/font/ascii.png"), + Minecraft.getMinecraft().getTextureManager(), false); + setFont(font, antiAlias, charOffset); + customColorCodes['q'] = new Color(0, 90, 163); + colorcodeIdentifiers = setupColorcodeIdentifier(); + setupMinecraftColorcodes(); + FONT_HEIGHT = getHeight(); + } + + public int drawString(final String s, final float x, final float y, + final int color) + { + return drawString(s, x, y, color, false); + } + + @Override + public int drawStringWithShadow(final String s, final float x, + final float y, final int color) + { + return drawString(s, x, y, color, false); + } + + public void drawCenteredString(final String s, final int x, final int y, + final int color, final boolean shadow) + { + if(shadow) + drawStringWithShadow(s, x - getStringWidth(s) / 2, y, color); + else + drawString(s, x - getStringWidth(s) / 2, y, color); + } + + public void drawCenteredStringXY(final String s, final int x, final int y, + final int color, final boolean shadow) + { + drawCenteredString(s, x, y - getHeight() / 2, color, shadow); + } + + public void drawCenteredString(final String s, final int x, final int y, + final int color) + { + drawStringWithShadow(s, x - getStringWidth(s) / 2, y, color); + } + + @Override + public int drawString(final String text, final float x, final float y, + int color, final boolean shadow) + { + int result = 0; + + String[] lines = text.split("\n"); + for(int i = 0; i < lines.length; i++) + result = drawLine(lines[i], x, y + i * getHeight(), color, shadow); + + return result; + } + + private int drawLine(final String text, final float x, final float y, + int color, final boolean shadow) + { + if(text == null) + return 0; + glPushMatrix(); + glTranslated(x - 1.5, y + 0.5, 0); + final boolean wasBlend = glGetBoolean(GL_BLEND); + GlStateManager.enableAlpha(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_TEXTURE_2D); + if((color & -67108864) == 0) + color |= -16777216; + + if(shadow) + color = (color & 16579836) >> 2 | color & -16777216; + + final float red = (color >> 16 & 0xff) / 255F; + final float green = (color >> 8 & 0xff) / 255F; + final float blue = (color & 0xff) / 255F; + final float alpha = (color >> 24 & 0xff) / 255F; + final Color c = new Color(red, green, blue, alpha); + if(text.contains("\247")) + { + final String[] parts = text.split("\247"); + + Color currentColor = c; + WurstFont currentFont = font; + int width = 0; + boolean randomCase = false, bold = false, italic = false, + strikethrough = false, underline = false; + + for(int index = 0; index < parts.length; index++) + { + if(parts[index].length() <= 0) + continue; + if(index == 0) + { + + currentFont.drawString(parts[index], width, 0, currentColor, + shadow); + width += currentFont.getStringWidth(parts[index]); + + }else + { + final String words = parts[index].substring(1); + final char type = parts[index].charAt(0); + final int colorIndex = colorcodeIdentifiers.indexOf(type); + if(colorIndex != -1) + if(colorIndex < 16) + { // coloring + final int colorcode = colorCode[colorIndex]; + currentColor = getColor(colorcode, alpha); + bold = false; + italic = false; + randomCase = false; + underline = false; + strikethrough = false; + }else if(colorIndex == 16) + randomCase = true; + else if(colorIndex == 17) + bold = true; + else if(colorIndex == 18) + strikethrough = true; + else if(colorIndex == 19) + underline = true; + else if(colorIndex == 20) + italic = true; + else if(colorIndex == 21) + { // reset + bold = false; + italic = false; + randomCase = false; + underline = false; + strikethrough = false; + currentColor = c; + }else if(colorIndex > 21) + { // custom mang + final Color customColor = customColorCodes[type]; + currentColor = + new Color(customColor.getRed() / 255F, + customColor.getGreen() / 255F, + customColor.getBlue() / 255F, alpha); + } + + if(bold && italic) + { + boldItalicFont.drawString( + randomCase ? toRandom(currentFont, words) : words, + width, 0, currentColor, shadow); + currentFont = boldItalicFont; + }else if(bold) + { + boldFont.drawString( + randomCase ? toRandom(currentFont, words) : words, + width, 0, currentColor, shadow); + currentFont = boldFont; + }else if(italic) + { + italicFont.drawString( + randomCase ? toRandom(currentFont, words) : words, + width, 0, currentColor, shadow); + currentFont = italicFont; + }else + { + font.drawString( + randomCase ? toRandom(currentFont, words) : words, + width, 0, currentColor, shadow); + currentFont = font; + } + float u = font.getHeight() / 16f; + int h = currentFont.getStringHeight(words); + if(strikethrough) + drawLine(width / 2d + 1, h / 3, + (width + currentFont.getStringWidth(words)) / 2d + + 1, + h / 3, u); + if(underline) + drawLine(width / 2d + 1, h / 2, + (width + currentFont.getStringWidth(words)) / 2d + + 1, + h / 2, u); + width += currentFont.getStringWidth(words); + } + } + }else + font.drawString(text, 0, 0, c, shadow); + if(!wasBlend) + glDisable(GL_BLEND); + glPopMatrix(); + GL11.glColor4f(1, 1, 1, 1); + + return (int)(x + getStringWidth(text)); + } + + /** + * Make dis + */ + private String toRandom(final WurstFont font, final String text) + { + String newText = ""; + final String allowedCharacters = + "\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"; + for(final char c : text.toCharArray()) + if(ChatAllowedCharacters.isAllowedCharacter(c)) + { + final int index = + fontRandom.nextInt(allowedCharacters.length()); + newText += allowedCharacters.toCharArray()[index]; + } + return newText; + } + + public int getStringHeight(final String text) + { + if(text == null) + return 0; + return font.getStringHeight(text) / 2; + } + + public int getHeight() + { + return font.getHeight() / 2; + } + + public static String getFormatFromString(final String p_78282_0_) + { + String var1 = ""; + int var2 = -1; + final int var3 = p_78282_0_.length(); + + while((var2 = p_78282_0_.indexOf(167, var2 + 1)) != -1) + if(var2 < var3 - 1) + { + final char var4 = p_78282_0_.charAt(var2 + 1); + if(isFormatColor(var4)) + var1 = "\u00a7" + var4; + else if(isFormatSpecial(var4)) + var1 = var1 + "\u00a7" + var4; + } + + return var1; + } + + private static boolean isFormatSpecial(final char formatChar) + { + return formatChar >= 107 && formatChar <= 111 + || formatChar >= 75 && formatChar <= 79 || formatChar == 114 + || formatChar == 82; + } + + @Override + public int getColorCode(final char p_175064_1_) + { + return colorCode["0123456789abcdef".indexOf(p_175064_1_)]; + } + + @Override + public void setBidiFlag(final boolean state) + { + bidi = state; + } + + @Override + public boolean getBidiFlag() + { + return bidi; + } + + private int sizeStringToWidth(final String str, final int wrapWidth) + { + final int var3 = str.length(); + int var4 = 0; + int var5 = 0; + int var6 = -1; + + for(boolean var7 = false; var5 < var3; ++var5) + { + final char var8 = str.charAt(var5); + switch(var8) + { + case 10: + --var5; + break; + case 167: + if(var5 < var3 - 1) + { + ++var5; + final char var9 = str.charAt(var5); + if(var9 != 108 && var9 != 76) + { + if(var9 == 114 || var9 == 82 || isFormatColor(var9)) + var7 = false; + }else + var7 = true; + } + break; + case 32: + var6 = var5; + default: + var4 += getStringWidth(Character.toString(var8)); + if(var7) + ++var4; + } + + if(var8 == 10) + { + ++var5; + var6 = var5; + break; + } + + if(var4 > wrapWidth) + break; + } + + return var5 != var3 && var6 != -1 && var6 < var5 ? var6 : var5; + } + + private static boolean isFormatColor(final char colorChar) + { + return colorChar >= 48 && colorChar <= 57 + || colorChar >= 97 && colorChar <= 102 + || colorChar >= 65 && colorChar <= 70; + } + + @Override + public int getCharWidth(final char c) + { + return getStringWidth(Character.toString(c)); + } + + @Override + public int getStringWidth(final String text) + { + if(text == null) + return 0; + if(text.contains("\247")) + { + final String[] parts = text.split("\247"); + WurstFont currentFont = font; + int width = 0; + boolean bold = false, italic = false; + + for(int index = 0; index < parts.length; index++) + { + if(parts[index].length() <= 0) + continue; + if(index == 0) + width += currentFont.getStringWidth(parts[index]); + else + { + final String words = parts[index].substring(1); + final char type = parts[index].charAt(0); + final int colorIndex = colorcodeIdentifiers.indexOf(type); + if(colorIndex != -1) + if(colorIndex < 16) + { // coloring + bold = false; + italic = false; + }else if(colorIndex == 16) + {}else if(colorIndex == 17) + bold = true; + else if(colorIndex == 18) + {}else if(colorIndex == 19) + {}else if(colorIndex == 20) + italic = true; + else if(colorIndex == 21) + { // reset + bold = false; + italic = false; + } + if(bold && italic) + currentFont = boldItalicFont; + else if(bold) + currentFont = boldFont; + else if(italic) + currentFont = italicFont; + else + currentFont = font; + + width += currentFont.getStringWidth(words); + } + } + return width / 2; + }else + return font.getStringWidth(text) / 2; + } + + /** + * Instantiates the CFont objects that will be used to render the shit. + */ + public void setFont(final Font font, final boolean antiAlias, + final int charOffset) + { + synchronized(this) + { + this.font = new WurstFont(font, antiAlias, charOffset); + boldFont = new WurstFont(font.deriveFont(Font.BOLD), antiAlias, + charOffset); + italicFont = new WurstFont(font.deriveFont(Font.ITALIC), + antiAlias, charOffset); + boldItalicFont = + new WurstFont(font.deriveFont(Font.BOLD | Font.ITALIC), + antiAlias, charOffset); + FONT_HEIGHT = getHeight(); + } + } + + /** + * @return CFont instance. + */ + public WurstFont getFont() + { + return font; + } + + /** + * @return Font name. + */ + public String getFontName() + { + return font.getFont().getFontName(); + } + + /** + * @return Font size. + */ + public int getSize() + { + return font.getFont().getSize(); + } + + public List wrapWords(final String text, final double width) + { + final List finalWords = new ArrayList(); + if(getStringWidth(text) > width) + { + final String[] words = text.split(" "); + String currentWord = ""; + char lastColorCode = (char)-1; + + for(final String word : words) + { + for(int i = 0; i < word.toCharArray().length; i++) + { + final char c = word.toCharArray()[i]; + + if(c == '\247' && i < word.toCharArray().length - 1) + lastColorCode = word.toCharArray()[i + 1]; + } + if(getStringWidth(currentWord + word + " ") < width) + currentWord += word + " "; + else + { + finalWords.add(currentWord); + currentWord = lastColorCode == -1 ? word + " " + : "\247" + lastColorCode + word + " "; + } + } + if(!currentWord.equals("")) + if(getStringWidth(currentWord) < width) + { + finalWords.add(lastColorCode == -1 ? currentWord + " " + : "\247" + lastColorCode + currentWord + " "); + currentWord = ""; + }else + for(final String s : formatString(currentWord, width)) + finalWords.add(s); + }else + finalWords.add(text); + return finalWords; + } + + public List formatString(final String s, final double width) + { + final List finalWords = new ArrayList(); + String currentWord = ""; + char lastColorCode = (char)-1; + for(int i = 0; i < s.toCharArray().length; i++) + { + final char c = s.toCharArray()[i]; + + if(c == '\247' && i < s.toCharArray().length - 1) + lastColorCode = s.toCharArray()[i + 1]; + + if(getStringWidth(currentWord + c) < width) + currentWord += c; + else + { + finalWords.add(currentWord); + currentWord = lastColorCode == -1 ? String.valueOf(c) + : "\247" + lastColorCode + String.valueOf(c); + } + } + + if(!currentWord.equals("")) + finalWords.add(currentWord); + + return finalWords; + } + + /** + * Renders a line. + */ + private void drawLine(final double x, final double y, final double x1, + final double y1, final float width) + { + glDisable(GL_TEXTURE_2D); + glLineWidth(width); + glBegin(GL_LINES); + glVertex2d(x, y); + glVertex2d(x1, y1); + glEnd(); + glEnable(GL_TEXTURE_2D); + } + + /** + * @return True if the font is anti aliased. + */ + public boolean isAntiAliasing() + { + return font.isAntiAlias() && boldFont.isAntiAlias() + && italicFont.isAntiAlias() && boldItalicFont.isAntiAlias(); + } + + /** + * Resets the font with or without antialiasing enabled. + */ + public void setAntiAliasing(final boolean antiAlias) + { + font.setAntiAlias(antiAlias); + boldFont.setAntiAlias(antiAlias); + italicFont.setAntiAlias(antiAlias); + boldItalicFont.setAntiAlias(antiAlias); + } + + /** + * Sets up the color codes. + */ + private void setupMinecraftColorcodes() + { + for(int index = 0; index < 32; ++index) + { + final int var6 = (index >> 3 & 1) * 85; + int var7 = (index >> 2 & 1) * 170 + var6; + int var8 = (index >> 1 & 1) * 170 + var6; + int var9 = (index >> 0 & 1) * 170 + var6; + + if(index == 6) + var7 += 85; + + if(index >= 16) + { + var7 /= 4; + var8 /= 4; + var9 /= 4; + } + + colorCode[index] = + (var7 & 255) << 16 | (var8 & 255) << 8 | var9 & 255; + } + } + + @Override + public String trimStringToWidth(final String p_78269_1_, + final int p_78269_2_) + { + return this.trimStringToWidth(p_78269_1_, p_78269_2_, false); + } + + @Override + public String trimStringToWidth(final String p_78262_1_, + final int p_78262_2_, final boolean p_78262_3_) + { + final StringBuilder var4 = new StringBuilder(); + int var5 = 0; + final int var6 = p_78262_3_ ? p_78262_1_.length() - 1 : 0; + final int var7 = p_78262_3_ ? -1 : 1; + boolean var8 = false; + boolean var9 = false; + + for(int var10 = var6; var10 >= 0 && var10 < p_78262_1_.length() + && var5 < p_78262_2_; var10 += var7) + { + final char var11 = p_78262_1_.charAt(var10); + final int var12 = getStringWidth(Character.toString(var11)); + if(var8) + { + var8 = false; + if(var11 != 108 && var11 != 76) + { + if(var11 == 114 || var11 == 82) + var9 = false; + }else + var9 = true; + }else if(var12 < 0) + var8 = true; + else + { + var5 += var12; + if(var9) + ++var5; + } + + if(var5 > p_78262_2_) + break; + + if(p_78262_3_) + var4.insert(0, var11); + else + var4.append(var11); + } + + return var4.toString(); + } + + @Override + public List listFormattedStringToWidth(final String str, + final int wrapWidth) + { + return Arrays + .asList(wrapFormattedStringToWidth(str, wrapWidth).split("\n")); + } + + @Override + protected String wrapFormattedStringToWidth(final String str, + final int wrapWidth) + { + final int var3 = sizeStringToWidth(str, wrapWidth); + if(str.length() <= var3) + return str; + else + { + final String var4 = str.substring(0, var3); + final char var5 = str.charAt(var3); + final boolean var6 = var5 == 32 || var5 == 10; + final String var7 = getFormatFromString(var4) + + str.substring(var3 + (var6 ? 1 : 0)); + return var4 + "\n" + wrapFormattedStringToWidth(var7, wrapWidth); + } + } + + public Color getColor(final int colorCode, final float alpha) + { + return new Color((colorCode >> 16) / 255F, + (colorCode >> 8 & 0xff) / 255F, (colorCode & 0xff) / 255F, alpha); + } + + /** + * Sets up the color code identifier. + */ + private String setupColorcodeIdentifier() + { + String minecraftColorCodes = "0123456789abcdefklmnor"; + for(int i = 0; i < customColorCodes.length; i++) + if(customColorCodes[i] != null) + minecraftColorCodes += (char)i; + return minecraftColorCodes; + } + + @Override + public void onResourceManagerReload(final IResourceManager p_110549_1_) + {} +} diff --git a/src/tk/wurst_client/navigator/gui/NavigatorFeatureScreen.java b/src/tk/wurst_client/navigator/gui/NavigatorFeatureScreen.java index 19b5a74..a53a6db 100644 --- a/src/tk/wurst_client/navigator/gui/NavigatorFeatureScreen.java +++ b/src/tk/wurst_client/navigator/gui/NavigatorFeatureScreen.java @@ -132,7 +132,7 @@ protected void onResize() // add keybind button ButtonData addKeybindButton = new ButtonData(area.x + area.width - 16, area.y - + Fonts.segoe15.getStringHeight(text) - 8, 12, 8, "+", + + Fonts.segoe15.getStringHeight(text) - 7, 12, 8, "+", 0x00ff00) { @Override @@ -195,15 +195,15 @@ public void press() NavigatorItem[] seeAlso = item.getSeeAlso(); if(seeAlso.length != 0) { - text += "\n\nSee also:\n"; + text += "\n\nSee also:"; for(int i = 0; i < seeAlso.length; i++) { int y = 60 + getTextHeight() + 2; NavigatorItem seeAlsoItem = seeAlso[i]; String name = seeAlsoItem.getName(); - text += "- " + name + (i == seeAlso.length - 1 ? "" : "\n"); + text += "\n- " + name; buttonDatas.add(new ButtonData(middleX - 148, y, Fonts.segoe15 - .getStringWidth(name) + 3, 8, "", 0x404040) + .getStringWidth(name) + 1, 8, "", 0x404040) { @Override public void press() @@ -410,8 +410,8 @@ else if(mouseX >= x1 && mouseX <= x2 && mouseY >= y1 drawBox(x1, y1, x2, y2); // text - drawCenteredString(Fonts.segoe18, buttonData.buttonText, - (x1 + x2) / 2 - 1, y1 + (buttonData.height - 12) / 2 - 1, + drawCenteredString(Fonts.segoe15, buttonData.buttonText, + (x1 + x2) / 2, y1 + (buttonData.height - 10) / 2 - 1, buttonData.isLocked() ? 0xaaaaaa : buttonData.textColor); glDisable(GL_TEXTURE_2D); } @@ -451,8 +451,8 @@ else if(mouseX >= x1 && mouseX <= x2 && mouseY >= y1 glVertex2i(x1 + 7, y1 + 2); glVertex2i(x1 + 8, y1 + 3); - glVertex2i(x1 + 4, y1 + 6); glVertex2i(x1 + 4, y1 + 8); + glVertex2i(x1 + 4, y1 + 6); } glEnd(); diff --git a/src/tk/wurst_client/navigator/settings/CheckboxSetting.java b/src/tk/wurst_client/navigator/settings/CheckboxSetting.java index 06ac925..6d7e167 100644 --- a/src/tk/wurst_client/navigator/settings/CheckboxSetting.java +++ b/src/tk/wurst_client/navigator/settings/CheckboxSetting.java @@ -38,8 +38,8 @@ public final String getName() @Override public final void addToFeatureScreen(NavigatorFeatureScreen featureScreen) { + y = 60 + featureScreen.getTextHeight() + 4; featureScreen.addText("\n\n"); - y = 60 + featureScreen.getTextHeight() - 8; update(); featureScreen.addCheckbox(this); diff --git a/src/tk/wurst_client/navigator/settings/ModeSetting.java b/src/tk/wurst_client/navigator/settings/ModeSetting.java index 4d77b7a..f77ec93 100644 --- a/src/tk/wurst_client/navigator/settings/ModeSetting.java +++ b/src/tk/wurst_client/navigator/settings/ModeSetting.java @@ -55,12 +55,12 @@ public final void addToFeatureScreen(NavigatorFeatureScreen featureScreen) switch(i % 3) { case 0: - x -= 148; + x -= 150; + y = 60 + featureScreen.getTextHeight() + 3; featureScreen.addText("\n\n"); - y = 60 + featureScreen.getTextHeight() - 6; break; case 1: - x -= 48; + x -= 49; break; case 2: x += 52; @@ -68,7 +68,7 @@ public final void addToFeatureScreen(NavigatorFeatureScreen featureScreen) } final int iFinal = i; ButtonData button = - featureScreen.new ButtonData(x, y, 96, 16, modes[i], + featureScreen.new ButtonData(x, y, 97, 14, modes[i], i == getSelected() ? 0x00ff00 : 0x404040) { @Override diff --git a/src/tk/wurst_client/navigator/settings/SliderSetting.java b/src/tk/wurst_client/navigator/settings/SliderSetting.java index 0ef3ae2..2fbbf21 100644 --- a/src/tk/wurst_client/navigator/settings/SliderSetting.java +++ b/src/tk/wurst_client/navigator/settings/SliderSetting.java @@ -54,8 +54,9 @@ public final String getName() @Override public final void addToFeatureScreen(NavigatorFeatureScreen featureScreen) { - featureScreen.addText("\n" + name + ":\n"); + featureScreen.addText("\n" + name + ":"); y = 60 + featureScreen.getTextHeight(); + featureScreen.addText("\n"); double newValue = getValue(); valueString = valueDisplay.getValueString(newValue);