Skip to content

Commit 6300dd6

Browse files
committed
Add utility for disabling Unihex font
Saves 10MB of RAM
1 parent ce8c6e0 commit 6300dd6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.embeddedt.modernfix.common.mixin.feature.disable_unihex_font;
2+
3+
import com.mojang.blaze3d.font.GlyphProvider;
4+
import com.mojang.datafixers.util.Either;
5+
import net.minecraft.client.gui.font.CodepointMap;
6+
import net.minecraft.client.gui.font.providers.GlyphProviderDefinition;
7+
import net.minecraft.client.gui.font.providers.UnihexProvider;
8+
import net.minecraft.server.packs.resources.ResourceManager;
9+
import org.embeddedt.modernfix.ModernFix;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
14+
15+
import java.io.IOException;
16+
import java.lang.reflect.Constructor;
17+
18+
@Mixin(UnihexProvider.Definition.class)
19+
public class UnihexProviderDefinitionMixin {
20+
@Inject(method = "unpack", at = @At("HEAD"), cancellable = true)
21+
private void disableProvider(CallbackInfoReturnable<Either<GlyphProviderDefinition.Loader, GlyphProviderDefinition.Reference>> cir) {
22+
cir.setReturnValue(Either.left(this::mfix$loadEmpty));
23+
}
24+
25+
private GlyphProvider mfix$loadEmpty(ResourceManager resourceManager) throws IOException {
26+
try {
27+
ModernFix.LOGGER.warn("Unihex provider is disabled, a number of Unicode characters will likely not render");
28+
Constructor<UnihexProvider> constructor = UnihexProvider.class.getDeclaredConstructor(CodepointMap.class);
29+
constructor.setAccessible(true);
30+
return constructor.newInstance(new CodepointMap<>(Object[]::new, Object[][]::new));
31+
} catch(ReflectiveOperationException e) {
32+
throw new IOException("Failed to create empty loader", e);
33+
}
34+
}
35+
}

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
@@ -161,6 +161,7 @@ public DefaultSettingMapBuilder put(String key, Boolean value) {
161161
.put("mixin.feature.integrated_server_watchdog", true)
162162
.put("mixin.perf.faster_item_rendering", false)
163163
.put("mixin.feature.spam_thread_dump", false)
164+
.put("mixin.feature.disable_unihex_font", false)
164165
.put("mixin.feature.snapshot_easter_egg", true)
165166
.put("mixin.feature.warn_missing_perf_mods", true)
166167
.put("mixin.feature.spark_profile_launch", false)

0 commit comments

Comments
 (0)