Skip to content

Commit 29c1a47

Browse files
Add mixin.feature.suppress_narrator_stacktrace to prevent some log spam on Linux (#590)
1 parent ee6489f commit 29c1a47

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.embeddedt.modernfix.common.mixin.feature.suppress_narrator_stacktrace;
2+
3+
import com.mojang.text2speech.Narrator;
4+
import com.mojang.text2speech.NarratorLinux;
5+
import com.mojang.text2speech.OperatingSystem;
6+
import net.minecraft.client.GameNarrator;
7+
import org.embeddedt.modernfix.ModernFix;
8+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Redirect;
12+
13+
@ClientOnlyMixin
14+
@Mixin(GameNarrator.class)
15+
public class GameNarratorMixin {
16+
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/text2speech/Narrator;getNarrator()Lcom/mojang/text2speech/Narrator;"))
17+
private Narrator suppressStacktracePrinting() {
18+
try {
19+
return switch (OperatingSystem.get()) {
20+
case LINUX -> new NarratorLinux();
21+
default -> Narrator.getNarrator();
22+
};
23+
} catch (Narrator.InitializeException e) {
24+
ModernFix.LOGGER.warn("Failed to initialize Linux Narrator. Make sure you have libflite installed!");
25+
return Narrator.EMPTY;
26+
}
27+
}
28+
}

common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public DefaultSettingMapBuilder put(String key, Boolean value) {
187187
.put("mixin.feature.log_stdout_in_log_files", true)
188188
.put("mixin.devenv", isDevEnv)
189189
.put("mixin.perf.remove_spawn_chunks", isDevEnv)
190+
.put("mixin.feature.suppress_narrator_stacktrace", !isDevEnv) // Not compatible with mixin.devenv
190191
.putConditionally(() -> !isFabric, "mixin.bugfix.fix_config_crashes", true)
191192
.putConditionally(() -> !isFabric, "mixin.bugfix.forge_at_inject_error", true)
192193
.putConditionally(() -> !isFabric, "mixin.feature.registry_event_progress", false)

common/src/main/resources/assets/modernfix/lang/de_de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,6 @@
120120
"modernfix.option.mixin.perf.compact_mojang_registries": "(Fabric) Experimentelle Option, die die Speichernutzung von Registern um etwa 50 % reduziert. In den meisten Modpacks nicht nützlich, es sei denn, sie enthalten Millionen von Blöcken und Gegenständen.",
121121
"modernfix.option.mixin.perf.dynamic_block_codecs": "Vermeidet das Speichern eines Codecs für jeden Block (Zustand) und generiert und speichert ihn stattdessen bei Bedarf im laufenden Betrieb. Im Allgemeinen lohnt es sich nicht, es zu aktivieren, es sei denn, Sie haben eine Million Blöcke/Elemente.",
122122
"modernfix.option.mixin.perf.faster_command_suggestions": "Verringern Sie Verzögerungen, wenn beim Eingeben eines Befehls Hunderttausende Vorschläge eingehen",
123-
"modernfix.option.mixin.perf.mojang_registry_size": "Behebt ein Problem, das dazu führt, dass sich die Registrierung von Blöcken/Elementen proportional zur bereits registrierten Anzahl verlangsamt. Dies verbessert die Startzeit."
123+
"modernfix.option.mixin.perf.mojang_registry_size": "Behebt ein Problem, das dazu führt, dass sich die Registrierung von Blöcken/Elementen proportional zur bereits registrierten Anzahl verlangsamt. Dies verbessert die Startzeit.",
124+
"modernfix.option.mixin.feature.suppress_narrator_stacktrace": "Hält das Spiel davon ab, einen sehr langen Stacktrace zu loggen, wenn der Erzähler auf Linux nicht erfolgreich lädt (oft verursacht dadurch, dass libflite nicht installiert ist)."
124125
}

common/src/main/resources/assets/modernfix/lang/en_us.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@
152152
"modernfix.option.mixin.perf.memoize_creative_tab_build": "Improves on vanilla's existing caching for creative tab contents in a way that is compatible with the timing requirements of mods like JEI/EMI. This can reduce the lag spike when opening the creative inventory for the first time in a modpack.",
153153
"modernfix.option.mixin.perf.potential_spawns_alloc": "Optimizes the Forge event for finding potential mobs that can spawn. This reduces allocations and the overhead of rebuilding a weighted list when no mods modify the potential spawns.",
154154
"modernfix.option.mixin.perf.ticking_chunk_alloc": "Optimizes chunk ticking in vanilla to reduce allocations.",
155-
"modernfix.option.mixin.perf.worldgen_allocation": "Optimizes some world generation logic in vanilla to reduce object allocations."
155+
"modernfix.option.mixin.perf.worldgen_allocation": "Optimizes some world generation logic in vanilla to reduce object allocations.",
156+
"modernfix.option.mixin.feature.suppress_narrator_stacktrace": "Prevents the game from logging a very long stacktrace when the narrator fails to load on Linux (usually caused by not having libflite installed)."
156157
}

0 commit comments

Comments
 (0)