diff --git a/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java b/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java index 5af379db..3b0ac05e 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java +++ b/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java @@ -75,7 +75,6 @@ public class ConfigValues { @Deprecated private final MutableFloat oldChromaSpeed = new MutableFloat(0.19354838F); // 2.0 private final MutableObject chromaMode = new MutableObject<>(EnumUtils.ChromaMode.FADE); - private final MutableFloat chromaFadeWidth = new MutableFloat(0.22580644F); // 10° Hue private final MutableObject discordDetails = new MutableObject<>(DiscordStatus.LOCATION); private final MutableObject discordStatus = new MutableObject<>(DiscordStatus.AUTO_STATUS); private final MutableObject discordAutoDefault = new MutableObject<>(DiscordStatus.NONE); @@ -211,7 +210,6 @@ public void loadValues() { deserializeNumber(healingCircleOpacity, "healingCircleOpacity", float.class); deserializeNumber(chromaSize, "chromaSize", float.class); deserializeEnumValueFromOrdinal(chromaMode, "chromaMode"); - deserializeNumber(chromaFadeWidth, "chromaFadeWidth", float.class); deserializeEnumValueFromOrdinal(discordStatus, "discordStatus"); deserializeEnumValueFromOrdinal(discordDetails, "discordDetails"); deserializeEnumValueFromOrdinal(discordAutoDefault, "discordAutoDefault"); @@ -974,14 +972,6 @@ public void setChromaMode(EnumUtils.ChromaMode chromaMode) { this.chromaMode.setValue(chromaMode); } - public void setChromaFadeWidth(float chromaFadeWidth) { - this.chromaFadeWidth.setValue(chromaFadeWidth); - } - - public float getChromaFadeWidth() { - return chromaFadeWidth.getValue(); - } - public void setDiscordDetails(DiscordStatus discordDetails) { this.discordDetails.setValue(discordDetails); } diff --git a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java index 63588ecf..2d36841b 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java +++ b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java @@ -258,7 +258,6 @@ public enum Feature { TEXT_STYLE(-1, "settings.textStyle", null, false), CHROMA_SPEED(-1, "settings.chromaSpeed", null, false), CHROMA_MODE(-1, "settings.chromaMode", null, false), - @Deprecated CHROMA_FADE_WIDTH(-1, "settings.chromaFadeWidth", null, false), CHROMA_SIZE(-1, "settings.chromaSize", null, false), CHROMA_SATURATION(-1, "settings.chromaSaturation", null, false), CHROMA_BRIGHTNESS(-1, "settings.chromaBrightness", null, false), diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/hooks/FontRendererHook.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/hooks/FontRendererHook.java index 2ba03309..0b37700f 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/mixins/hooks/FontRendererHook.java +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/hooks/FontRendererHook.java @@ -12,21 +12,18 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import java.util.LinkedHashMap; -import java.util.Map; - public class FontRendererHook { private static final SkyblockColor CHROMA_COLOR = new SkyblockColor(0xFFFFFFFF).setColorAnimation(SkyblockColor.ColorAnimation.CHROMA); private static final DrawStateFontRenderer DRAW_CHROMA = new DrawStateFontRenderer(CHROMA_COLOR); private static final SkyblockColor CHROMA_COLOR_SHADOW = new SkyblockColor(0xFF555555).setColorAnimation(SkyblockColor.ColorAnimation.CHROMA); private static final DrawStateFontRenderer DRAW_CHROMA_SHADOW = new DrawStateFontRenderer(CHROMA_COLOR_SHADOW); - private static final MaxSizeHashMap stringsWithChroma = new MaxSizeHashMap<>(1000); private static DrawStateFontRenderer currentDrawState = null; private static boolean modInitialized = false; private static final int CHROMA_FORMAT_INDEX = 22; private static final int WHITE_FORMAT_INDEX = 15; private static boolean turnAllText = false; + private static Feature fontFeature = null; public static void beforeRenderChar() { if (!shouldRenderChroma()) return; @@ -43,43 +40,12 @@ public static void setupFeatureFont(Feature feature) { ConfigValues config = SkyblockAddons.getInstance().getConfigValues(); if (config.getChromaMode() == EnumUtils.ChromaMode.FADE && config.getChromaFeatures().contains(feature)) { - DRAW_CHROMA.setupMulticolorFeature(config.getGuiScale(feature)); - DRAW_CHROMA_SHADOW.setupMulticolorFeature(config.getGuiScale(feature)); + fontFeature = feature; } } public static void endFeatureFont() { - DRAW_CHROMA.endMulticolorFeature(); - DRAW_CHROMA_SHADOW.endMulticolorFeature(); - } - - /** - * Called in patcher code to stop patcher optimization and do vanilla render - * @param s string to render - * @return true to override - */ - public static boolean shouldOverridePatcher(String s) { - if (shouldRenderChroma()) { - //return chromaStrings.get(s) == null || chromaStrings.get(s); - if (stringsWithChroma.get(s) != null) { - return stringsWithChroma.get(s); - } - // Check if there is a "§z" colorcode in the string and cache it - boolean hasChroma = false; - for (int i = 0; i < s.length(); i++) { - if (s.charAt(i) == '§') { - i++; - if (i < s.length() && (s.charAt(i) == 'z' || s.charAt(i) == 'Z')) { - hasChroma = true; - break; - } - } - } - stringsWithChroma.put(s, hasChroma); - return hasChroma; - } else { - return false; - } + fontFeature = null; } /** @@ -87,13 +53,28 @@ public static boolean shouldOverridePatcher(String s) { */ public static void beginRenderString(boolean shadow) { if (modInitialized && SkyblockAddons.getInstance().getUtils().isOnSkyblock()) { - currentDrawState = shadow ? DRAW_CHROMA_SHADOW : DRAW_CHROMA; - currentDrawState.loadFeatureColorEnv(); - boolean allChroma = Feature.TURN_ALL_TEXTS_CHROMA.isEnabled(); - if (allChroma || currentDrawState.isUsingShader()) { - float rgb = shadow ? 0.2f : 1f; - GlStateManager.color(rgb, rgb, rgb, ColorUtils.getAlpha()); + ConfigValues config = SkyblockAddons.getInstance().getConfigValues(); + + if (allChroma || fontFeature != null) { + if (fontFeature != null) { + DRAW_CHROMA.setupMulticolorFeature(config.getGuiScale(fontFeature)); + DRAW_CHROMA_SHADOW.setupMulticolorFeature(config.getGuiScale(fontFeature)); + } + + currentDrawState = shadow ? DRAW_CHROMA_SHADOW : DRAW_CHROMA; + currentDrawState.loadFeatureColorEnv(); + } else { + DRAW_CHROMA.endMulticolorFeature(); + DRAW_CHROMA_SHADOW.endMulticolorFeature(); + } + + if (allChroma || (currentDrawState != null && currentDrawState.isUsingShader())) { + // There is no need to force the white color if there is no fading + if (config.getChromaMode() == EnumUtils.ChromaMode.FADE) { + float rgb = shadow ? 0.2f : 1f; + GlStateManager.color(rgb, rgb, rgb, ColorUtils.getAlpha()); + } if (allChroma) { setupFeatureFont(Feature.TURN_ALL_TEXTS_CHROMA); turnAllText = true; @@ -114,11 +95,20 @@ public static void restoreChromaState() { /** * Called to turn chroma on */ - public static boolean toggleChromaOn(int formatIndex) { - if (shouldRenderChroma() && formatIndex == CHROMA_FORMAT_INDEX) { + public static boolean toggleChromaOn(int formatIndex, boolean shadow) { + if (!modInitialized || !SkyblockAddons.getInstance().getUtils().isOnSkyblock()) { + return false; + } + + if (formatIndex == CHROMA_FORMAT_INDEX) { + if (currentDrawState == null) { + currentDrawState = shadow ? DRAW_CHROMA_SHADOW : DRAW_CHROMA; + currentDrawState.loadFeatureColorEnv(); + } currentDrawState.newColorEnv().bindActualColor(); return true; } + return false; } @@ -128,6 +118,7 @@ public static boolean toggleChromaOn(int formatIndex) { public static void endRenderString() { if (shouldRenderChroma()) { currentDrawState.endColorEnv(); + currentDrawState = null; if (turnAllText && !Feature.TURN_ALL_TEXTS_CHROMA.isEnabled()) { endFeatureFont(); @@ -145,23 +136,6 @@ public static int forceWhiteColor(int formatIndex) { return formatIndex; } - /** - * HashMap with upper limit on storage size. Used to enforce the font renderer cache not getting too large over time - */ - public static class MaxSizeHashMap extends LinkedHashMap { - private final int maxSize; - - public MaxSizeHashMap(int maxSize) { - super(); - this.maxSize = maxSize; - } - - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > maxSize; - } - } - /** * Called by {@link SkyblockAddons#postInit(FMLPostInitializationEvent)} * Fixes NPE caused by Splash Screen, calling FontRendererHook before SBA is loaded. diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/FontRendererTransformer.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/FontRendererTransformer.java index a4800cf8..3df48a7d 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/FontRendererTransformer.java +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/FontRendererTransformer.java @@ -51,7 +51,7 @@ public void insertRestoreChromaState(CallbackInfo ci) { */ @Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Ljava/lang/String;indexOf(I)I", ordinal = 0, shift = At.Shift.BY, by = 2), locals = LocalCapture.CAPTURE_FAILHARD) public void toggleChromaCondition(String text, boolean shadow, CallbackInfo ci, int i, char c0, int i1) { - if (FontRendererHook.toggleChromaOn(i1)) { + if (FontRendererHook.toggleChromaOn(i1, shadow)) { this.resetStyles(); } } diff --git a/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/PatcherFontRendererTransformer.java b/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/PatcherFontRendererTransformer.java index 4e147b73..371cafee 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/PatcherFontRendererTransformer.java +++ b/src/main/java/codes/biscuit/skyblockaddons/mixins/transformers/PatcherFontRendererTransformer.java @@ -13,7 +13,7 @@ public class PatcherFontRendererTransformer { @Inject(method = "renderStringAtPos(Ljava/lang/String;Z)Z", at = @At("HEAD"), cancellable = true) public void overridePatcherFontRenderer(String string, boolean shadow, CallbackInfoReturnable cir) { - if (FontRendererHook.shouldRenderChroma()) { + if (FontRendererHook.shouldRenderChroma() || string.contains("§z") || string.contains("§Z")) { cir.cancel(); cir.setReturnValue(false); }