Add utility for disabling Unihex font

Saves 10MB of RAM
This commit is contained in:
embeddedt 2023-07-06 11:38:36 -04:00
parent ce8c6e0283
commit 6300dd6737
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package org.embeddedt.modernfix.common.mixin.feature.disable_unihex_font;
import com.mojang.blaze3d.font.GlyphProvider;
import com.mojang.datafixers.util.Either;
import net.minecraft.client.gui.font.CodepointMap;
import net.minecraft.client.gui.font.providers.GlyphProviderDefinition;
import net.minecraft.client.gui.font.providers.UnihexProvider;
import net.minecraft.server.packs.resources.ResourceManager;
import org.embeddedt.modernfix.ModernFix;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException;
import java.lang.reflect.Constructor;
@Mixin(UnihexProvider.Definition.class)
public class UnihexProviderDefinitionMixin {
@Inject(method = "unpack", at = @At("HEAD"), cancellable = true)
private void disableProvider(CallbackInfoReturnable<Either<GlyphProviderDefinition.Loader, GlyphProviderDefinition.Reference>> cir) {
cir.setReturnValue(Either.left(this::mfix$loadEmpty));
}
private GlyphProvider mfix$loadEmpty(ResourceManager resourceManager) throws IOException {
try {
ModernFix.LOGGER.warn("Unihex provider is disabled, a number of Unicode characters will likely not render");
Constructor<UnihexProvider> constructor = UnihexProvider.class.getDeclaredConstructor(CodepointMap.class);
constructor.setAccessible(true);
return constructor.newInstance(new CodepointMap<>(Object[]::new, Object[][]::new));
} catch(ReflectiveOperationException e) {
throw new IOException("Failed to create empty loader", e);
}
}
}

View File

@ -161,6 +161,7 @@ public class ModernFixEarlyConfig {
.put("mixin.feature.integrated_server_watchdog", true)
.put("mixin.perf.faster_item_rendering", false)
.put("mixin.feature.spam_thread_dump", false)
.put("mixin.feature.disable_unihex_font", false)
.put("mixin.feature.snapshot_easter_egg", true)
.put("mixin.feature.warn_missing_perf_mods", true)
.put("mixin.feature.spark_profile_launch", false)