From fac83b1013454654f4fd1e287a35d624b2ffaaf4 Mon Sep 17 00:00:00 2001 From: nopo Date: Tue, 24 Dec 2024 14:19:27 +1100 Subject: [PATCH 1/3] fix shwords causing blank spaces in chat --- .../gui/MixinGuiUtilRenderComponents.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiUtilRenderComponents.java diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiUtilRenderComponents.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiUtilRenderComponents.java new file mode 100644 index 000000000000..df4530b5fbfc --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiUtilRenderComponents.java @@ -0,0 +1,17 @@ +package at.hannibal2.skyhanni.mixins.transformers.gui; + +import at.hannibal2.skyhanni.features.misc.visualwords.ModifyVisualWords; +import net.minecraft.client.gui.GuiUtilRenderComponents; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(GuiUtilRenderComponents.class) +public class MixinGuiUtilRenderComponents { + + @Redirect(method = "splitText", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/IChatComponent;getUnformattedTextForChat()Ljava/lang/String;")) + private static String onSplitText(IChatComponent instance) { + return ModifyVisualWords.INSTANCE.modifyText(instance.getUnformattedTextForChat()); + } +} From 27744f688381fe92d5251b30836732fa6a28ebca Mon Sep 17 00:00:00 2001 From: nopo Date: Tue, 24 Dec 2024 14:38:02 +1100 Subject: [PATCH 2/3] remove comment --- .../features/misc/visualwords/ModifyVisualWords.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt index ecf57e3f3314..c7a91264cb17 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -19,8 +19,6 @@ object ModifyVisualWords { var modifiedWords = mutableListOf() - val reverseRegex = "(§.|^|[\\s:()+-])([^§\\s:()+-]*)".toRegex() - fun modifyText(originalText: String?): String? { var modifiedText = originalText ?: return null if (!LorenzUtils.onHypixel) return originalText @@ -47,14 +45,6 @@ object ModifyVisualWords { } } - // Disabled, as it's only a novelty for 30 seconds and will annoy after that everyone. - /* - if (LorenzUtils.isAprilFoolsDay && !FontRendererHook.cameFromChat && Random.nextDouble() < 0.02) { - modifiedText = modifiedText.replace(reverseRegex) { - it.groupValues[1] + it.groupValues[2].reversed() - } - } - */ modifiedText } } From 93ce36dcaffc31473136173dfb8987eeaece543a Mon Sep 17 00:00:00 2001 From: nopo Date: Wed, 25 Dec 2024 12:08:45 +1100 Subject: [PATCH 3/3] pls --- .../misc/visualwords/ModifyVisualWords.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt index ca33b66907d3..83305d223dae 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -22,6 +22,32 @@ object ModifyVisualWords { // Replacements the user added manually via /shwords var userModifiedWords = mutableListOf() + // Replacements the mod added automatically for some features, april jokes, etc + var modModifiedWords = mutableListOf() + private var finalWordsList = listOf() + private var debug = false + + fun update() { + finalWordsList = modModifiedWords + userModifiedWords + textCache.clear() + } + + @HandleEvent + fun onCommandRegistration(event: CommandRegistrationEvent) { + event.register("shdebugvisualwords") { + description = "Prints in the console all replaced words by /shwords" + callback { toggleDebug() } + } + } + + private fun toggleDebug() { + debug = !debug + ChatUtils.chat("Visual Words debug ${if (debug) "enabled" else "disabled"}") + if (debug) { + update() + } + } + fun modifyText(originalText: String?): String? { var modifiedText = originalText ?: return null if (!LorenzUtils.onHypixel) return originalText