├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── src └── main │ ├── resources │ └── mixins.emojiapi.json │ └── java │ └── dev │ └── tigr │ └── emojiapi │ ├── Emoji.java │ ├── Emojis.java │ └── mixin │ └── MixinFontRenderer.java ├── .gitignore ├── LICENSE ├── README.md ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2b2t-Utilities/emoji-api/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | # This is required to provide enough memory for the Minecraft decompilation process. 3 | org.gradle.jvmargs=-Xmx3G -------------------------------------------------------------------------------- /src/main/resources/mixins.emojiapi.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "dev.tigr.emojiapi.mixin", 5 | "refmap": "mixins.emojiapi.refmap.json", 6 | "mixins": [ 7 | "MixinFontRenderer" 8 | ] 9 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | -------------------------------------------------------------------------------- /src/main/java/dev/tigr/emojiapi/Emoji.java: -------------------------------------------------------------------------------- 1 | package dev.tigr.emojiapi; 2 | 3 | /** 4 | * @author Tigermouthbear 5 | * 5/5/20 6 | */ 7 | 8 | public class Emoji { 9 | private String name; 10 | 11 | public Emoji(String name) { 12 | this.name = name; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tigermouthbear 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # emoji-api 2 | An API used to add emojis to minecraft 3 | 4 | ![Showcase](https://cdn.discordapp.com/attachments/661446370359640074/707343317263843378/2020-05-05_16.45.20.png) 5 | 6 | ## Emojis 7 | Emojis in this mod are downloaded from https://github.com/2b2t-Utilities/emojis and can be updated without having to reinstall the mod 8 | 9 | ## Usage 10 | - Note: Gradle snippets ommit some basic setup 11 | --- 12 | First, add the tigr.dev maven repository to gradle: 13 | ``` 14 | repositories { 15 | maven { 16 | name = "tigr.dev" 17 | url = "https://maven.tigr.dev" 18 | } 19 | } 20 | ``` 21 | Next, add the emoji api to your dependencies: 22 | ``` 23 | dependencies { 24 | compile "dev.tigr:emojiapi:1.0" 25 | } 26 | ``` 27 | Then, add the emoji api to your shadow task: 28 | ``` 29 | shadowJar { 30 | dependencies { 31 | include(dependency("dev.tigr:emojiapi")) 32 | } 33 | } 34 | ``` 35 | Last, add the emoji-api to your mixin configs: 36 | ``` 37 | public class MixinLoader implements IFMLLoadingPlugin { 38 | public MixinLoader() { 39 | MixinBootstrap.init(); 40 | // mixins.ares.json is the config of the mod implementing the emoji api 41 | Mixins.addConfigurations("mixins.ares.json", "mixins.emojiapi.json"); 42 | MixinEnvironment.getDefaultEnvironment().setObfuscationContext("searge"); 43 | } 44 | 45 | @Override 46 | public String[] getASMTransformerClass() { 47 | return new String[0]; 48 | } 49 | 50 | @Override 51 | public String getModContainerClass() { 52 | return null; 53 | } 54 | 55 | @Override 56 | public String getSetupClass() { 57 | return null; 58 | } 59 | 60 | @Override 61 | public void injectData(Map data) { 62 | } 63 | 64 | @Override 65 | public String getAccessTransformerClass() { 66 | return null; 67 | } 68 | } 69 | ``` 70 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/java/dev/tigr/emojiapi/Emojis.java: -------------------------------------------------------------------------------- 1 | package dev.tigr.emojiapi; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonObject; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.renderer.texture.DynamicTexture; 7 | import net.minecraft.util.ResourceLocation; 8 | import org.apache.commons.compress.utils.Charsets; 9 | import org.apache.commons.io.IOUtils; 10 | 11 | import javax.imageio.ImageIO; 12 | import java.awt.image.BufferedImage; 13 | import java.io.*; 14 | import java.net.URL; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | import java.util.zip.ZipEntry; 20 | import java.util.zip.ZipInputStream; 21 | 22 | /** 23 | * @author Tigermouthbear 24 | * 5/5/20 25 | */ 26 | 27 | public class Emojis { 28 | private static final Minecraft MC = Minecraft.getMinecraft(); 29 | private static final String VERSION_URL = "https://raw.githubusercontent.com/2b2t-Utilities/emojis/master/version.json"; 30 | private static final String ZIP_URL = "https://github.com/2b2t-Utilities/emojis/archive/master.zip"; 31 | private static final String FOLDER = "emoji"; 32 | private static final File LOCAL_VERSION = new File(FOLDER + File.separator + "version.json"); 33 | private static final Map EMOJI_MAP = new HashMap<>(); 34 | 35 | static { 36 | load(); 37 | } 38 | 39 | private static void load() { 40 | File dir = new File("emoji"); 41 | if(!dir.exists()) dir.mkdir(); 42 | 43 | try { 44 | if(!LOCAL_VERSION.exists()) update_emojis(); 45 | else { 46 | // load version info 47 | JsonObject globalVer = read(new URL(VERSION_URL).openStream()); 48 | JsonObject localVer = read(new FileInputStream(LOCAL_VERSION)); 49 | 50 | // make sure current version is latest 51 | if(!globalVer.has("version")) update_emojis(); 52 | else { 53 | if(globalVer.get("version").getAsInt() != localVer.get("version").getAsInt()) update_emojis(); 54 | } 55 | } 56 | } catch(Exception ignored) { } 57 | 58 | try { 59 | Files.list(new File(FOLDER).toPath()).filter(path -> path.endsWith(".png")).forEach(path -> { 60 | try { 61 | addEmoji(path); 62 | } catch(Exception ignored) { } 63 | }); 64 | } catch(IOException e) { } 65 | } 66 | 67 | private static JsonObject read(InputStream stream) { 68 | Gson gson = new Gson(); 69 | JsonObject jsonObject = null; 70 | 71 | try { 72 | String json = IOUtils.toString(stream, Charsets.UTF_8); 73 | jsonObject = gson.fromJson(json, JsonObject.class); 74 | } catch(IOException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | return jsonObject; 79 | } 80 | 81 | private static void update_emojis() throws IOException { 82 | ZipInputStream zip = new ZipInputStream(new URL(ZIP_URL).openStream()); 83 | ZipEntry entry = zip.getNextEntry(); 84 | // iterates over entries in the zip file 85 | while(entry != null) { 86 | String filePath = FOLDER + File.separator + entry.getName().substring(entry.getName().indexOf("/")); 87 | if(!entry.isDirectory()) { 88 | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); 89 | byte[] bytesIn = new byte[4096]; 90 | int read; 91 | while((read = zip.read(bytesIn)) != -1) { 92 | bos.write(bytesIn, 0, read); 93 | } 94 | bos.close(); 95 | } 96 | zip.closeEntry(); 97 | entry = zip.getNextEntry(); 98 | } 99 | zip.close(); 100 | } 101 | 102 | private static void addEmoji(Path path) { 103 | File file = path.toFile(); 104 | DynamicTexture dynamicTexture; 105 | try { 106 | BufferedImage image = ImageIO.read(file); 107 | dynamicTexture = new DynamicTexture(image); 108 | dynamicTexture.loadTexture(MC.getResourceManager()); 109 | } catch(Exception ignored) { 110 | return; 111 | } 112 | 113 | EMOJI_MAP.put(file.getName().replaceAll(".png", ""), MC.getTextureManager().getDynamicTextureLocation(file.getName().replaceAll(".png", ""), dynamicTexture)); 114 | } 115 | 116 | public static ResourceLocation getEmoji(Emoji emoji) { 117 | return EMOJI_MAP.get(emoji.getName()); 118 | } 119 | 120 | public static boolean isEmoji(String name) { 121 | return EMOJI_MAP.containsKey(name); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /src/main/java/dev/tigr/emojiapi/mixin/MixinFontRenderer.java: -------------------------------------------------------------------------------- 1 | package dev.tigr.emojiapi.mixin; 2 | 3 | import dev.tigr.emojiapi.Emoji; 4 | import dev.tigr.emojiapi.Emojis; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.gui.FontRenderer; 7 | import net.minecraft.client.gui.Gui; 8 | import net.minecraft.client.renderer.GlStateManager; 9 | import org.spongepowered.asm.mixin.Final; 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Overwrite; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Locale; 17 | import java.util.Random; 18 | 19 | /** 20 | * @author Tigermouthbear 21 | * 5/5/20 22 | */ 23 | 24 | @Mixin(FontRenderer.class) 25 | public abstract class MixinFontRenderer { 26 | @Shadow 27 | private boolean randomStyle; 28 | @Shadow private boolean boldStyle; 29 | @Shadow private boolean strikethroughStyle; 30 | @Shadow private boolean underlineStyle; 31 | @Shadow private boolean italicStyle; 32 | @Shadow private boolean unicodeFlag; 33 | @Shadow private int textColor; 34 | @Shadow private float red; 35 | @Shadow private float green; 36 | @Shadow private float blue; 37 | @Shadow private float alpha; 38 | @Shadow protected float posX; 39 | @Shadow protected float posY; 40 | @Shadow public Random fontRandom; 41 | @Final 42 | @Shadow private int[] colorCode; 43 | @Shadow protected abstract void setColor(float r, float g, float b, float a); 44 | @Shadow public abstract int getCharWidth(char character); 45 | @Shadow protected abstract float renderChar(char ch, boolean italic); 46 | @Shadow protected abstract void doDraw(float f); 47 | 48 | /** 49 | * @author Tigermouthbear 50 | * @reason Emojis 51 | */ 52 | @Overwrite 53 | private void renderStringAtPos(String text, boolean shadow) { 54 | int size = getStringWidth(" "); 55 | List emojis = new ArrayList<>(); 56 | 57 | for(String possile : text.split(":")) { 58 | if(Emojis.isEmoji(possile)) emojis.add(new Emoji(possile)); 59 | } 60 | 61 | for(Emoji emoji : emojis) { 62 | if(!shadow) { 63 | int index = text.indexOf(":" + emoji.getName() + ":"); 64 | if(index == -1) continue; 65 | int x = getStringWidth(text.substring(0, index)); 66 | 67 | Minecraft.getMinecraft().getTextureManager().bindTexture(Emojis.getEmoji(emoji)); 68 | GlStateManager.color(1, 1, 1, alpha); 69 | Gui.drawScaledCustomSizeModalRect((int) (posX + x), (int) posY, 0, 0, size, size, size, size, size, size); 70 | } 71 | 72 | text = text.replaceFirst(":" + emoji.getName() + ":", " "); 73 | } 74 | 75 | for(int i = 0; i < text.length(); ++i) { 76 | char c0 = text.charAt(i); 77 | 78 | if(c0 == 167 && i + 1 < text.length()) { 79 | int i1 = "0123456789abcdefklmnor".indexOf(String.valueOf(text.charAt(i + 1)).toLowerCase(Locale.ROOT).charAt(0)); 80 | 81 | if(i1 < 16) { 82 | this.randomStyle = false; 83 | this.boldStyle = false; 84 | this.strikethroughStyle = false; 85 | this.underlineStyle = false; 86 | this.italicStyle = false; 87 | 88 | if(i1 < 0) { 89 | i1 = 15; 90 | } 91 | 92 | if(shadow) { 93 | i1 += 16; 94 | } 95 | 96 | int j1 = this.colorCode[i1]; 97 | this.textColor = j1; 98 | setColor((float) (j1 >> 16) / 255.0F, (float) (j1 >> 8 & 255) / 255.0F, (float) (j1 & 255) / 255.0F, this.alpha); 99 | } else if(i1 == 16) { 100 | this.randomStyle = true; 101 | } else if(i1 == 17) { 102 | this.boldStyle = true; 103 | } else if(i1 == 18) { 104 | this.strikethroughStyle = true; 105 | } else if(i1 == 19) { 106 | this.underlineStyle = true; 107 | } else if(i1 == 20) { 108 | this.italicStyle = true; 109 | } else { 110 | this.randomStyle = false; 111 | this.boldStyle = false; 112 | this.strikethroughStyle = false; 113 | this.underlineStyle = false; 114 | this.italicStyle = false; 115 | setColor(this.red, this.blue, this.green, this.alpha); 116 | } 117 | 118 | ++i; 119 | } else { 120 | int j = "\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".indexOf(c0); 121 | 122 | if(this.randomStyle && j != -1) { 123 | int k = this.getCharWidth(c0); 124 | char c1; 125 | 126 | do { 127 | j = this.fontRandom.nextInt("\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".length()); 128 | c1 = "\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".charAt(j); 129 | 130 | } while (k != this.getCharWidth(c1)); 131 | 132 | c0 = c1; 133 | } 134 | 135 | float f1 = j == -1 || this.unicodeFlag ? 0.5f: 1f; 136 | boolean flag = (c0 == 0 || j == -1 || this.unicodeFlag) && shadow; 137 | 138 | if(flag) { 139 | this.posX -= f1; 140 | this.posY -= f1; 141 | } 142 | 143 | float f = this.renderChar(c0, this.italicStyle); 144 | 145 | if(flag) { 146 | this.posX += f1; 147 | this.posY += f1; 148 | } 149 | 150 | if(this.boldStyle) { 151 | this.posX += f1; 152 | 153 | if(flag) { 154 | this.posX -= f1; 155 | this.posY -= f1; 156 | } 157 | 158 | this.renderChar(c0, this.italicStyle); 159 | this.posX -= f1; 160 | 161 | if(flag) { 162 | this.posX += f1; 163 | this.posY += f1; 164 | } 165 | 166 | ++f; 167 | } 168 | doDraw(f); 169 | } 170 | } 171 | } 172 | 173 | /** 174 | * @author cats 175 | * this fixes the issue with string width 176 | * @reason fix emoji string width 177 | */ 178 | @Overwrite 179 | public int getStringWidth(String text) { 180 | if (text == null) { 181 | return 0; 182 | } 183 | else { 184 | // As is done in the rendering, replace the emoji text with two spaces before getting width 185 | for (String possibleEmoji : text.split(":")) { 186 | if (Emojis.isEmoji(possibleEmoji)) { 187 | text = text.replaceFirst(":" + possibleEmoji+ ":", " "); 188 | } 189 | } 190 | 191 | int i = 0; 192 | boolean flag = false; 193 | 194 | for (int j = 0; j < text.length(); ++j) { 195 | char c0 = text.charAt(j); 196 | int k = this.getCharWidth(c0); 197 | 198 | if (k < 0 && j < text.length() - 1) { 199 | ++j; 200 | c0 = text.charAt(j); 201 | 202 | if (c0 != 'l' && c0 != 'L') { 203 | if (c0 == 'r' || c0 == 'R') { 204 | flag = false; 205 | } 206 | } 207 | else { 208 | flag = true; 209 | } 210 | 211 | k = 0; 212 | } 213 | 214 | i += k; 215 | 216 | if (flag && k > 0) { 217 | ++i; 218 | } 219 | } 220 | 221 | return i; 222 | } 223 | } 224 | } --------------------------------------------------------------------------------