From 2ac4538172cf27cc6873b43c442f3ec203b5057e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 9 Nov 2022 02:05:13 +0800 Subject: Fix #1199 --- .../me/shedaniel/rei/mixin/forge/MixinFontSet.java | 60 ++++++++++++++++++++++ forge/src/main/resources/rei.mixins.json | 1 + 2 files changed, 61 insertions(+) create mode 100644 forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java new file mode 100644 index 000000000..0cba3c2ad --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java @@ -0,0 +1,60 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.mixin.forge; + +import com.mojang.blaze3d.font.GlyphInfo; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; +import it.unimi.dsi.fastutil.ints.IntList; +import net.minecraft.client.gui.font.FontSet; +import net.minecraft.client.gui.font.FontTexture; +import net.minecraft.client.gui.font.glyphs.BakedGlyph; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Collections; +import java.util.List; + +@Mixin(FontSet.class) +public class MixinFontSet { + @Shadow @Mutable @Final private Int2ObjectMap glyphs; + @Shadow @Mutable @Final private Int2ObjectMap glyphInfos; + @Shadow @Mutable @Final private Int2ObjectMap glyphsByWidth; + @Shadow @Mutable @Final private List textures; + + @Inject(method = "", at = @At("RETURN")) + private void init(TextureManager textureManager, ResourceLocation id, CallbackInfo ci) { + this.glyphs = Int2ObjectMaps.synchronize(this.glyphs); + this.glyphInfos = Int2ObjectMaps.synchronize(this.glyphInfos); + this.glyphsByWidth = Int2ObjectMaps.synchronize(this.glyphsByWidth); + this.textures = Collections.synchronizedList(this.textures); + } +} diff --git a/forge/src/main/resources/rei.mixins.json b/forge/src/main/resources/rei.mixins.json index d729d79f9..838df45f2 100644 --- a/forge/src/main/resources/rei.mixins.json +++ b/forge/src/main/resources/rei.mixins.json @@ -5,6 +5,7 @@ "client": [ "MixinClientPacketListener", "MixinEffectRenderingInventoryScreen", + "MixinFontSet", "MixinInputConstants", "MixinRecipeToast" ], -- cgit