diff options
Diffstat (limited to 'forge/src')
6 files changed, 190 insertions, 18 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/forge/CreativeModeTabCollectorImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java new file mode 100644 index 000000000..5cd817c82 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java @@ -0,0 +1,67 @@ +/* + * 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.forge; + +import me.shedaniel.rei.impl.common.InternalLogger; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.flag.FeatureFlagSet; +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.client.ForgeHooksClient; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +public class CreativeModeTabCollectorImpl { + public static Map<CreativeModeTab, Collection<ItemStack>> collectTabs() { + Map<CreativeModeTab, Collection<ItemStack>> map = new LinkedHashMap<>(); + FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); + + for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { + if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) { + try { + CreativeModeTab.ItemDisplayBuilder builder = new CreativeModeTab.ItemDisplayBuilder(tab, featureFlags); + ResourceKey<CreativeModeTab> resourceKey = BuiltInRegistries.CREATIVE_MODE_TAB + .getResourceKey(tab) + .orElseThrow(() -> new IllegalStateException("Unregistered creative tab: " + tab)); + ForgeHooksClient.onCreativeModeTabBuildContents(tab, resourceKey, tab.displayItemsGenerator, parameters, (stack, visibility) -> { + if (visibility == CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY) return; + builder.accept(stack, visibility); + }); + map.put(tab, builder.tabContents); + } catch (Throwable throwable) { + InternalLogger.getInstance().error("Failed to collect creative tab: " + tab, throwable); + } + } + } + + return map; + } +} 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); } diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index cd8fd6891..082c7dea2 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -29,18 +29,22 @@ public-f net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97 protected net.minecraft.client.gui.screens.Screen m_6575_(Lnet/minecraft/client/Minecraft;II)V public net.minecraft.client.gui.screens.Screen m_142416_(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener; public net.minecraft.client.gui.screens.Screen m_169394_(Lnet/minecraft/client/gui/components/Renderable;)Lnet/minecraft/client/gui/components/Renderable; -public net.minecraft.client.gui.screens.Screen m_262809_(Lcom/mojang/blaze3d/vertex/PoseStack;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V # renderTooltipInternal -public net.minecraft.client.gui.screens.Screen tooltipStack +public net.minecraft.client.gui.GuiGraphics m_280497_(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V # renderTooltipInternal +public net.minecraft.client.gui.GuiGraphics tooltipStack +public net.minecraft.client.gui.GuiGraphics m_280444_(Lnet/minecraft/resources/ResourceLocation;IIIIIFFFF)V # innerBlit public net.minecraft.client.renderer.RenderType m_173209_(Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; public net.minecraft.client.renderer.RenderType$OutlineProperty public net.minecraft.client.renderer.RenderType$CompositeState public net.minecraft.tags.TagEntry f_215914_ # tag public net.minecraft.tags.TagEntry f_215913_ # id -public net.minecraft.world.item.crafting.LegacyUpgradeRecipe f_265911_ # base -public net.minecraft.world.item.crafting.LegacyUpgradeRecipe f_265910_ # addition public net.minecraft.world.item.crafting.SmithingTransformRecipe f_265949_ # template public net.minecraft.world.item.crafting.SmithingTransformRecipe f_265888_ # base public net.minecraft.world.item.crafting.SmithingTransformRecipe f_265907_ # addition public net.minecraft.world.item.crafting.SmithingTrimRecipe f_265958_ # template public net.minecraft.world.item.crafting.SmithingTrimRecipe f_266040_ # base -public net.minecraft.world.item.crafting.SmithingTrimRecipe f_266053_ # addition
\ No newline at end of file +public net.minecraft.world.item.crafting.SmithingTrimRecipe f_266053_ # addition +public-f net.minecraft.client.gui.font.CodepointMap f_283911_ # empty +public-f net.minecraft.client.gui.font.CodepointMap f_283938_ # blockMap +public-f net.minecraft.client.gui.font.CodepointMap f_283773_ # blockConstructor +public net.minecraft.world.item.CreativeModeTab f_256824_ # displayItemsGenerator +public net.minecraft.world.item.CreativeModeTab$ItemDisplayBuilder |
