|
@@ -0,0 +1,165 @@
|
|
|
|
+package me.ktcm.events;
|
|
|
|
+
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
+import net.minecraft.client.Minecraft;
|
|
|
|
+import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
|
|
|
+import net.minecraft.client.gui.FontRenderer;
|
|
|
|
+
|
|
|
|
+public class Hooks
|
|
|
|
+{
|
|
|
|
+ public static int onColorCodeChosen(char c, boolean shadow)
|
|
|
|
+ {
|
|
|
|
+ switch(c)
|
|
|
|
+ {
|
|
|
|
+ case '0': return 0;
|
|
|
|
+ case '1': return 1;
|
|
|
|
+ case '2': return 2;
|
|
|
|
+ case '3': return 3;
|
|
|
|
+ case '4': return 4;
|
|
|
|
+ case '5': return 5;
|
|
|
|
+ case '6': return 6;
|
|
|
|
+ case '7': return 7;
|
|
|
|
+ case '8': return 8;
|
|
|
|
+ case '9': return 9;
|
|
|
|
+ case 'a': return 10;
|
|
|
|
+ case 'b': return 11;
|
|
|
|
+ case 'c': return 12;
|
|
|
|
+ case 'd': return 13;
|
|
|
|
+ case 'e': return 14;
|
|
|
|
+ case 'f': return 15;
|
|
|
|
+ case 'k': return 16;
|
|
|
|
+ case 'l': return 17;
|
|
|
|
+ case 'm': return 18;
|
|
|
|
+ case 'n': return 19;
|
|
|
|
+ case 'o': return 20;
|
|
|
|
+ case 'r': return 21;
|
|
|
|
+ case 'A': return 10;
|
|
|
|
+ case 'B': return 11;
|
|
|
|
+ case 'C': return 12;
|
|
|
|
+ case 'D': return 13;
|
|
|
|
+ case 'E': return 14;
|
|
|
|
+ case 'F': return 15;
|
|
|
|
+ case 'K': return 16;
|
|
|
|
+ case 'L': return 17;
|
|
|
|
+ case 'M': return 18;
|
|
|
|
+ case 'N': return 19;
|
|
|
|
+ case 'O': return 20;
|
|
|
|
+ case 'R': return 21;
|
|
|
|
+
|
|
|
|
+ // brown
|
|
|
|
+ case 'g':
|
|
|
|
+ case 'G': setColor(shadow, 0.4f, 0.2f, 0.0f, 0.1f, 0.05f, 0.0f); return 22;
|
|
|
|
+ case 'h':
|
|
|
|
+ case 'H': setColor(shadow, 0.6f, 0.4f, 0.2f, 0.15f, 0.1f, 0.05f); return 22;
|
|
|
|
+
|
|
|
|
+ // blue
|
|
|
|
+ case 'i':
|
|
|
|
+ case 'I': setColor(shadow, 0.0f, 0.2f, 0.4f, 0.0f, 0.05f, 0.1f); return 22;
|
|
|
|
+ case 'j':
|
|
|
|
+ case 'J': setColor(shadow, 0.0f, 0.4f, 0.6f, 0.0f, 0.1f, 0.15f); return 22;
|
|
|
|
+
|
|
|
|
+ // green
|
|
|
|
+ case 'p':
|
|
|
|
+ case 'P': setColor(shadow, 0.4f, 0.6f, 0.0f, 0.1f, 0.15f, 0.0f); return 22;
|
|
|
|
+ case 'q':
|
|
|
|
+ case 'Q': setColor(shadow, 0.6f, 0.8f, 0.0f, 0.15f, 0.2f, 0.0f); return 22;
|
|
|
|
+
|
|
|
|
+ // cyan
|
|
|
|
+ case 's':
|
|
|
|
+ case 'S': setColor(shadow, 0.0f, 0.6f, 1.0f, 0.0f, 0.15f, 0.25f); return 22;
|
|
|
|
+ case 't':
|
|
|
|
+ case 'T': setColor(shadow, 0.4f, 0.8f, 1.0f, 0.1f, 0.2f, 0.25f); return 22;
|
|
|
|
+
|
|
|
|
+ // red
|
|
|
|
+ case 'u':
|
|
|
|
+ case 'U': setColor(shadow, 0.6f, 0.2f, 0.0f, 0.15f, 0.05f, 0.0f); return 22;
|
|
|
|
+ case 'v':
|
|
|
|
+ case 'V': setColor(shadow, 0.8f, 0.4f, 0.0f, 0.2f, 0.1f, 0.0f); return 22;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // violet
|
|
|
|
+ case 'w':
|
|
|
|
+ case 'W': setColor(shadow, 0.4f, 0.0f, 0.4f, 0.1f, 0.0f, 0.1f); return 22;
|
|
|
|
+ case 'x':
|
|
|
|
+ case 'X': setColor(shadow, 0.6f, 0.0f, 0.8f, 0.15f, 0.0f, 0.2f); return 22;
|
|
|
|
+
|
|
|
|
+ // yellow
|
|
|
|
+ case 'y':
|
|
|
|
+ case 'Y': setColor(shadow, 0.8f, 0.6f, 0.0f, 0.2f, 0.15f, 0.0f); return 22;
|
|
|
|
+ case 'z':
|
|
|
|
+ case 'Z': setColor(shadow, 1.0f, 0.8f, 0.0f, 0.25f, 0.2f, 0.0f); return 22;
|
|
|
|
+ }
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void setColor(boolean shadow, float r, float g, float b, float dr, float dg, float db)
|
|
|
|
+ {
|
|
|
|
+ if(shadow)
|
|
|
|
+ {
|
|
|
|
+ setColor(dr, dg, db);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ setColor(r, g, b);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static Method getMethod(Class c, String name, String oName, Class... classes)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ return ReflectionHelper.findMethod(c, name, oName, classes);
|
|
|
|
+ }
|
|
|
|
+ catch(SecurityException | ReflectionHelper.UnableToFindFieldException ex)
|
|
|
|
+ {
|
|
|
|
+ System.out.println(name + " - " + oName + " - " + ex);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static Field getField(Class c, String... field)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ return ReflectionHelper.findField(c, field);
|
|
|
|
+ }
|
|
|
|
+ catch(SecurityException | ReflectionHelper.UnableToFindFieldException ex)
|
|
|
|
+ {
|
|
|
|
+ System.out.println(String.join(" - ", field) + " - " + ex);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private final static FontRenderer FONT = Minecraft.getMinecraft().fontRenderer;
|
|
|
|
+ // /home/kajetan/.gradle/caches/minecraft/de/oceanlabs/mcp/mcp_snapshot/20171003/1.12.2/srgs/mcp-srg.srg
|
|
|
|
+ // FD: net/minecraft/client/gui/FontRenderer/alpha net/minecraft/client/gui/FontRenderer/field_78305_q
|
|
|
|
+ private final static Field ALPHA = getField(FontRenderer.class, "field_78305_q", "alpha");
|
|
|
|
+
|
|
|
|
+ public static float getAlpha()
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ return ALPHA.getFloat(FONT);
|
|
|
|
+ }
|
|
|
|
+ catch(SecurityException | IllegalAccessException | IllegalArgumentException ex)
|
|
|
|
+ {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private final static Method SET_COLOR = getMethod(FontRenderer.class, "setColor", null, float.class, float.class, float.class, float.class);
|
|
|
|
+
|
|
|
|
+ public static void setColor(float r, float g, float b)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ SET_COLOR.invoke(FONT, r, g, b, getAlpha());
|
|
|
|
+ }
|
|
|
|
+ catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
|
|
|
|
+ {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|