|
| 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 | +} |
0 commit comments