diff options
Diffstat (limited to 'forge/src/main/java')
4 files changed, 114 insertions, 13 deletions
diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/CodepointMapWrapper.java b/forge/src/main/java/me/shedaniel/rei/impl/client/CodepointMapWrapper.java new file mode 100644 index 000000000..fcc396b9c --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/CodepointMapWrapper.java @@ -0,0 +1,92 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client; + +import it.unimi.dsi.fastutil.ints.IntSet; +import net.minecraft.client.gui.font.CodepointMap; +import org.jetbrains.annotations.Nullable; + +import java.util.function.IntFunction; + +public class CodepointMapWrapper<T> extends CodepointMap<T> { + private final CodepointMap<T> delegate; + protected transient IntSet keys; + + public CodepointMapWrapper(CodepointMap<T> delegate) { + super(delegate.blockConstructor, i -> delegate.blockMap); + this.empty = delegate.empty; + this.blockMap = delegate.blockMap; + this.delegate = delegate; + } + + @Override + public void clear() { + synchronized (this) { + delegate.clear(); + } + } + + @Nullable + @Override + public T put(int i, T object) { + synchronized (this) { + return delegate.put(i, object); + } + } + + @Nullable + @Override + public T get(int i) { + synchronized (this) { + return delegate.get(i); + } + } + + @Override + public T computeIfAbsent(int i, IntFunction<T> intFunction) { + synchronized (this) { + return delegate.computeIfAbsent(i, intFunction); + } + } + + @Nullable + @Override + public T remove(int i) { + synchronized (this) { + return delegate.remove(i); + } + } + + @Override + public void forEach(Output<T> arg) { + synchronized (this) { + delegate.forEach(arg); + } + } + + @Override + public IntSet keySet() { + return delegate.keySet(); + } +} diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplForge.java b/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplForge.java index 832bd0b1d..e8937ca26 100644 --- a/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplForge.java +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplForge.java @@ -23,12 +23,14 @@ package me.shedaniel.rei.impl.client.gui.forge; -import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; @@ -39,15 +41,16 @@ import net.minecraftforge.client.ForgeHooksClient; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class ScreenOverlayImplForge extends ScreenOverlayImpl { @Override - public void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) { - matrices.pushPose(); + public void renderTooltipInner(Screen screen, GuiGraphics graphics, Tooltip tooltip, int mouseX, int mouseY) { + graphics.pose().pushPose(); EntryStack<?> stack = tooltip.getContextStack(); ItemStack itemStack = stack.getType() == VanillaEntryTypes.ITEM ? stack.castValue() : ItemStack.EMPTY; List<Component> texts = CollectionUtils.filterAndMap(tooltip.entries(), Tooltip.Entry::isText, Tooltip.Entry::getAsText); - List<ClientTooltipComponent> components = ForgeHooksClient.gatherTooltipComponents(itemStack, texts, mouseX, screen.width, screen.height, null, screen.getMinecraft().font); + List<ClientTooltipComponent> components = ForgeHooksClient.gatherTooltipComponents(itemStack, texts, Optional.empty(), mouseX, screen.width, screen.height, screen.getMinecraft().font); components = new ArrayList<>(components); for (Tooltip.Entry entry : tooltip.entries()) { if (!entry.isText()) { @@ -61,9 +64,13 @@ public class ScreenOverlayImplForge extends ScreenOverlayImpl { components.add(1, ClientTooltipComponent.create(component)); } } - screen.tooltipStack = itemStack; - screen.renderTooltipInternal(matrices, components, mouseX, mouseY, DefaultTooltipPositioner.INSTANCE); - screen.tooltipStack = ItemStack.EMPTY; - matrices.popPose(); + Font font = Minecraft.getInstance().font; + if (!itemStack.isEmpty()) { + font = ForgeHooksClient.getTooltipFont(itemStack, font); + } + graphics.tooltipStack = itemStack; + graphics.renderTooltipInternal(font, components, mouseX, mouseY, DefaultTooltipPositioner.INSTANCE); + graphics.tooltipStack = ItemStack.EMPTY; + graphics.pose().popPose(); } } diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinEffectRenderingInventoryScreen.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinEffectRenderingInventoryScreen.java index b3f1b9d58..db426f893 100644 --- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinEffectRenderingInventoryScreen.java +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinEffectRenderingInventoryScreen.java @@ -56,7 +56,7 @@ public abstract class MixinEffectRenderingInventoryScreen extends AbstractContai @ModifyVariable(method = "renderEffects", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen;renderBackgrounds(Lcom/mojang/blaze3d/vertex/PoseStack;IILjava/lang/Iterable;Z)V", + target = "Lnet/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen;renderBackgrounds(Lnet/minecraft/client/gui/GuiGraphics;IILjava/lang/Iterable;Z)V", ordinal = 0), ordinal = 0) // 1st bool public boolean modifyBl(boolean bl) { 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 index 9dee7c9fb..4d0adc4fd 100644 --- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinFontSet.java @@ -27,6 +27,8 @@ 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 me.shedaniel.rei.impl.client.CodepointMapWrapper; +import net.minecraft.client.gui.font.CodepointMap; import net.minecraft.client.gui.font.FontSet; import net.minecraft.client.gui.font.FontTexture; import net.minecraft.client.gui.font.glyphs.BakedGlyph; @@ -45,15 +47,15 @@ import java.util.List; @Mixin(FontSet.class) public class MixinFontSet { - @Shadow @Mutable @Final private Int2ObjectMap<BakedGlyph> glyphs; - @Shadow @Mutable @Final private Int2ObjectMap<GlyphInfo> glyphInfos; + @Shadow @Mutable @Final private CodepointMap<BakedGlyph> glyphs; + @Shadow @Mutable @Final private CodepointMap<?> glyphInfos; @Shadow @Mutable @Final private Int2ObjectMap<IntList> glyphsByWidth; @Shadow @Mutable @Final private List<FontTexture> textures; @Inject(method = "<init>", 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.glyphs = new CodepointMapWrapper<>(this.glyphs); + this.glyphInfos = new CodepointMapWrapper<>(this.glyphInfos); this.glyphsByWidth = Int2ObjectMaps.synchronize(this.glyphsByWidth); this.textures = Collections.synchronizedList(this.textures); } |
