From d698ee2add0caacf484fbe8677aa7c6606623688 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 13 Dec 2024 19:21:00 +0800 Subject: [PATCH] Update to 1.21.4 --- .github/workflows/curseforge.yml | 1 + .../shedaniel/rei/impl/ClientInternals.java | 2 +- .../displays/DefaultSmithingDisplay.java | 5 +- fabric/build.gradle | 2 +- gradle.properties | 14 ++-- neoforge/build.gradle | 4 +- .../rei/RoughlyEnoughItemsCoreClient.java | 2 +- .../impl/client/gui/ScreenOverlayImpl.java | 14 +++- .../client/gui/config/REIConfigScreen.java | 24 +++++-- .../components/ConfigCategoryEntryWidget.java | 2 +- .../config/components/ConfigSearchWidget.java | 42 +++++------ .../client/gui/modules/AbstractMenuEntry.java | 8 ++- .../screen/AbstractDisplayViewingScreen.java | 13 +++- .../screen/CompositeDisplayViewingScreen.java | 13 ++++ .../screen/DefaultDisplayViewingScreen.java | 15 +++- .../gui/widget/CachedEntryListRender.java | 3 +- .../widget/DelegateWidgetWithTranslate.java | 11 +-- .../impl/client/gui/widget/ListWidget.java | 5 ++ .../impl/client/gui/widget/MergedWidget.java | 23 ++++++ .../gui/widget/MergedWidgetWithBounds.java | 19 +++++ .../client/entry/FluidEntryDefinition.java | 3 +- .../client/entry/ItemEntryDefinition.java | 71 ++++++++++--------- 22 files changed, 208 insertions(+), 88 deletions(-) diff --git a/.github/workflows/curseforge.yml b/.github/workflows/curseforge.yml index 652724937..b8b60ea80 100644 --- a/.github/workflows/curseforge.yml +++ b/.github/workflows/curseforge.yml @@ -21,6 +21,7 @@ on: - 15.x-1.20.5 - 16.x-1.21 - 17.x-1.21.2 + - 18.x-1.21.4 jobs: build: diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java index 98263245d..6b00b4d7d 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -45,9 +45,9 @@ import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.data.models.blockstates.PropertyDispatch; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; -import net.minecraft.data.models.blockstates.PropertyDispatch; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java index 9fe55fede..a682850ab 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java @@ -56,6 +56,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; public class DefaultSmithingDisplay extends BasicDisplay implements SmithingDisplay { public static final DisplaySerializer SERIALIZER = DisplaySerializer.of( @@ -96,12 +97,12 @@ public static DefaultSmithingDisplay ofTransforming(RecipeHolder fromTrimming(RecipeHolder recipe) { RegistryAccess registryAccess = BasicDisplay.registryAccess(); List displays = new ArrayList<>(); - for (Holder templateItem : recipe.value().templateIngredient().map(Ingredient::items).orElse(List.of())) { + for (Holder templateItem : (Iterable>) recipe.value().templateIngredient().map(Ingredient::items).orElse(Stream.of())::iterator) { Holder.Reference trimPattern = getPatternFromTemplate(registryAccess, templateItem) .orElse(null); if (trimPattern == null) continue; - for (Holder additionStack : recipe.value().additionIngredient().map(Ingredient::items).orElse(List.of())) { + for (Holder additionStack : (Iterable>) recipe.value().additionIngredient().map(Ingredient::items).orElse(Stream.of())::iterator) { Holder.Reference trimMaterial = getMaterialFromIngredient(registryAccess, additionStack) .orElse(null); if (trimMaterial == null) continue; diff --git a/fabric/build.gradle b/fabric/build.gradle index ccd6ce158..33fc3bffe 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -121,7 +121,7 @@ unifiedPublishing { project { displayName = "[Fabric $rootProject.supported_version] v$project.version" releaseType = rootProject.unstable == "false" ? "release" : "alpha" - gameVersions = ["1.21.2", "1.21.3"] + gameVersions = ["1.21.4"] gameLoaders = ["fabric"] changelog = rootProject.releaseChangelog diff --git a/gradle.properties b/gradle.properties index 4c76c39f9..fbce35e45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,16 @@ org.gradle.jvmargs=-Xmx6G -base_version=17.0 +base_version=18.0 unstable=false -supported_version=1.21.2/3 -minecraft_version=1.21.2 +supported_version=1.21.4 +minecraft_version=1.21.4 platforms=fabric,neoforge forge_version=49.1.10 -neoforge_version=21.2.0-beta +neoforge_version=21.4.20-beta neoforge_pr= fabricloader_version=0.16.7 -cloth_config_version=16.0.141 +cloth_config_version=17.0.144 modmenu_version=11.0.0-rc.2 -fabric_api=0.106.1+1.21.2 -architectury_version=14.0.3 +fabric_api=0.112.0+1.21.4 +architectury_version=15.0.1 api_exculde= #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric diff --git a/neoforge/build.gradle b/neoforge/build.gradle index e90d7d6f0..e7cbcec72 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -168,7 +168,7 @@ unifiedPublishing { project { displayName = "[NeoForge $rootProject.supported_version] v$project.version" releaseType = "beta" - gameVersions = ["1.21.2", "1.21.3"] + gameVersions = ["1.21.4"] gameLoaders = ["neoforge"] changelog = rootProject.releaseChangelog @@ -208,7 +208,7 @@ unifiedPublishing { project { displayName = "[NeoForge $rootProject.supported_version] v$project.version" releaseType = "release" - gameVersions = ["1.21.2", "1.21.3"] + gameVersions = ["1.21.4"] gameLoaders = ["neoforge"] changelog = rootProject.releaseChangelog diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index c8905db02..86ccdcb37 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -99,6 +99,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; +import net.minecraft.client.data.models.blockstates.PropertyDispatch; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -108,7 +109,6 @@ import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.models.blockstates.PropertyDispatch; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundRecipeBookAddPacket; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index 0c081340e..fe905b5cc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -519,8 +519,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!visible) { return false; } + if (draggingStack != null) { + draggingStack.mouseClicked(mouseX, mouseY, button); + } for (GuiEventListener element : widgets) { - if (element != configButton && element != menuHolder.widget() && element != hintsWidget && element.mouseClicked(mouseX, mouseY, button)) { + if (element != configButton && element != menuHolder.widget() && element != hintsWidget && element != draggingStack && element.mouseClicked(mouseX, mouseY, button)) { this.setFocused(element); if (button == 0) this.setDragging(true); @@ -550,6 +553,15 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del return (this.getFocused() != null && this.isDragging() && button == 0) && this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (draggingStack != null) { + draggingStack.mouseReleased(mouseX, mouseY, button); + } + + return super.mouseReleased(mouseX, mouseY, button); + } + @Override public GuiEventListener getFocused() { if (choosePageWidget != null) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java index af8ae2132..e9a766c5d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java @@ -62,10 +62,7 @@ import org.apache.commons.lang3.mutable.MutableObject; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiConsumer; import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal; @@ -306,6 +303,25 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return super.mouseClicked(mouseX, mouseY, button); } + @Override + public Optional getChildAt(double mouseX, double mouseY) { + if (menu != null) { + if (menu.containsMouse(mouseX, mouseY)) { + return Optional.of(menu); + } + } + + // Reverse iteration + for (int i = widgets.size() - 1; i >= 0; i--) { + Widget widget = widgets.get(i); + if (widget.containsMouse(mouseX, mouseY)) { + return Optional.of(widget); + } + } + + return Optional.empty(); + } + @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { if (menu != null && menu.mouseReleased(mouseX, mouseY, button)) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoryEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoryEntryWidget.java index e701eac07..1716578a5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoryEntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigCategoryEntryWidget.java @@ -50,7 +50,7 @@ public static WidgetWithBounds create(OptionCategory category, int width) { Widget descriptionLabel = Widgets.createDrawableWidget((graphics, mouseX, mouseY, delta) -> { renderTextScrolling(graphics, description, 0, 0, (int) ((width - 21 - 6) / 0.75), 0xFFB0B0B0); }); - Rectangle bounds = new Rectangle(0, 0, label.getBounds().getMaxX(), hasDescription ? 24 : 7 * 3); + Rectangle bounds = new Rectangle(0, 0, width, hasDescription ? 24 : 7 * 3); return Widgets.concatWithBounds( bounds, label, diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigSearchWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigSearchWidget.java index 40986fc47..9d811892f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigSearchWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigSearchWidget.java @@ -51,13 +51,12 @@ public static WidgetWithBounds create(IntSupplier width) { Label label = Widgets.createLabel(new Point(21, 6), translatable("config.rei.texts.search_options")) .leftAligned(); Font font = Minecraft.getInstance().font; - Rectangle bounds = new Rectangle(0, 0, label.getBounds().getMaxX(), 7 * 3); return Widgets.concatWithBounds( - bounds, - new Widget() { + () -> new Rectangle(0, 0, width.getAsInt(), 7 * 3), + new WidgetWithBounds() { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - boolean hovering = new Rectangle(-1, -1, width.getAsInt() + 2, 21).contains(mouseX, mouseY); + boolean hovering = containsMouse(mouseX, mouseY); for (Widget widget : List.of(Widgets.createFilledRectangle(new Rectangle(1, 1, width.getAsInt() - 2, 18), hovering ? 0x50FFFFFF : 0x25FFFFFF), Widgets.createFilledRectangle(new Rectangle(-1, -1, width.getAsInt() + 2, 1), hovering ? 0x90FFFFFF : 0x45FFFFFF), Widgets.createFilledRectangle(new Rectangle(-1, 20, width.getAsInt() + 2, 1), hovering ? 0x90FFFFFF : 0x45FFFFFF), @@ -75,18 +74,18 @@ public List children() { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (new Rectangle(-1, -1, width.getAsInt() + 2, 21).contains(mouseX, mouseY)) { - Widgets.produceClickSound(); - ((REIConfigScreen) Minecraft.getInstance().screen).setSearching(true); - return true; - } - - return false; + Widgets.produceClickSound(); + ((REIConfigScreen) Minecraft.getInstance().screen).setSearching(true); + return true; + } + + @Override + public Rectangle getBounds() { + return new Rectangle(-1, -1, width.getAsInt() + 2, 21); } }, Widgets.withTranslate(label, 0, 0.5, 0), Widgets.createTexturedWidget(ResourceLocation.parse("roughlyenoughitems:textures/gui/config/search_options.png"), new Rectangle(3, 3, 16, 16), 0, 0, 1, 1, 1, 1) - ); } @@ -94,10 +93,10 @@ public static WidgetWithBounds createTiny() { Rectangle bounds = new Rectangle(0, 0, 16, 16); return Widgets.withTooltip(Widgets.concatWithBounds( bounds, - new Widget() { + new WidgetWithBounds() { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - boolean hovering = new Rectangle(-1, -1, 18, 18).contains(mouseX, mouseY); + boolean hovering = containsMouse(mouseX, mouseY); graphics.pose().pushPose(); graphics.pose().translate(-0.5, -0.5, 0); for (Widget widget : List.of(Widgets.createFilledRectangle(new Rectangle(-1, -1, 18, 18), hovering ? 0x50FFFFFF : 0x25FFFFFF), @@ -117,13 +116,14 @@ public List children() { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (new Rectangle(-1, -1, 18, 18).contains(mouseX, mouseY)) { - Widgets.produceClickSound(); - ((REIConfigScreen) Minecraft.getInstance().screen).setSearching(true); - return true; - } - - return false; + Widgets.produceClickSound(); + ((REIConfigScreen) Minecraft.getInstance().screen).setSearching(true); + return true; + } + + @Override + public Rectangle getBounds() { + return new Rectangle(-1, -1, 18, 18); } }, Widgets.createTexturedWidget(ResourceLocation.parse("roughlyenoughitems:textures/gui/config/search_options.png"), bounds, 0, 0, 1, 1, 1, 1) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java index 7cd5c574d..849950ec8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.modules; +import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; public abstract class AbstractMenuEntry extends FavoriteMenuEntry { @@ -41,7 +42,7 @@ public void updateInformation(int xPos, int yPos, boolean selected, boolean cont @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (isRendering() && mouseX >= getX() && mouseX <= getX() + getWidth() && mouseY >= getY() && mouseY < getY() + getEntryHeight()) { + if (containsMouse(mouseX, mouseY)) { if (onClick(mouseX, mouseY, button)) { return true; } @@ -76,4 +77,9 @@ public boolean containsMouse() { public boolean isRendering() { return rendering; } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return isRendering() && new Rectangle(getX(), getY(), getWidth(), getEntryHeight()).contains(mouseX, mouseY); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index eb094d8d2..5005aa93e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -465,7 +465,18 @@ private boolean handleFocuses() { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - return super.mouseClicked(mouseX, mouseY, button) || (getOverlay().mouseClicked(mouseX, mouseY, button) && handleFocuses(button)); + Optional hovered = this.getChildAt(mouseX, mouseY); + if (hovered.isPresent() && hovered.get().mouseClicked(mouseX, mouseY, button)) { + this.setFocused(hovered.get()); + if (button == 0) { + this.setDragging(true); + } + + if (getOverlay().mouseClicked(mouseX, mouseY, button)) handleFocuses(button); + return true; + } + + return getOverlay().mouseClicked(mouseX, mouseY, button) && handleFocuses(button); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index 3788f162e..18767d4b6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -223,6 +223,19 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return super.mouseClicked(mouseX, mouseY, button); } + @Override + public Optional getChildAt(double mouseX, double mouseY) { + // Reverse iteration + for (int i = widgets.size() - 1; i >= 0; i--) { + Widget widget = widgets.get(i); + if (widget.containsMouse(mouseX, mouseY)) { + return Optional.of(widget); + } + } + + return Optional.empty(); + } + @Override public boolean charTyped(char char_1, int int_1) { for (GuiEventListener listener : children()) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index ca6fe77a0..f5d1a8c0e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -27,7 +27,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.Tesselator; import it.unimi.dsi.fastutil.Pair; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.clothconfig2.api.animator.ValueAnimator; @@ -66,7 +65,6 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.ConfirmScreen; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; @@ -501,6 +499,19 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return super.mouseClicked(mouseX, mouseY, button); } + @Override + public Optional getChildAt(double mouseX, double mouseY) { + // Reverse iteration + for (int i = widgets.size() - 1; i >= 0; i--) { + Widget widget = widgets.get(i); + if (widget.containsMouse(mouseX, mouseY)) { + return Optional.of(widget); + } + } + + return Optional.empty(); + } + public static class WorkstationSlotWidget extends EntryWidget { public WorkstationSlotWidget(int x, int y, EntryIngredient widgets) { super(new Point(x, y)); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java index 236c791f6..12196723f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java @@ -176,7 +176,8 @@ private static void prepare() { nativeImage.flipY(); cachedTexture = new DynamicTexture(nativeImage); - cachedTextureLocation = minecraft.getTextureManager().register("rei_cached_entries", cachedTexture); + cachedTextureLocation = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "rei_cached_entries"); + minecraft.getTextureManager().register(cachedTextureLocation, cachedTexture); renderType.reset(); target.destroyBuffers(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java index 6213b47b6..87ad675bc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.impl.client.gui.widget; import com.mojang.math.Transformation; +import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.DelegateWidget; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; @@ -42,11 +43,6 @@ public DelegateWidgetWithTranslate(WidgetWithBounds widget, Supplier t this.translate = translate; } - public DelegateWidgetWithTranslate(Widget widget, Supplier translate) { - super(widget); - this.translate = translate; - } - protected Matrix4f translate() { return translate.get(); } @@ -135,4 +131,9 @@ public double getZRenderingPriority() { Transformation transformation = new Transformation(translate()); return transformation.getTranslation().z() + super.getZRenderingPriority(); } + + @Override + public Rectangle getBounds() { + return MatrixUtils.transform(translate(), super.getBounds()); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ListWidget.java index 313ad40a2..3121a5d95 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ListWidget.java @@ -223,6 +223,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return clicked; } + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return super.containsMouse(mouseX, mouseY); + } + @Override protected Matrix4f translate() { Rectangle bounds = delegate().getBounds(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java index 32a76895c..54a801061 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java @@ -32,6 +32,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.Optional; public class MergedWidget extends Widget { private final List widgets; @@ -115,4 +116,26 @@ public double getZRenderingPriority() { return CollectionUtils.max(widgets, Comparator.comparingDouble(Widget::getZRenderingPriority)) .map(Widget::getZRenderingPriority).orElse(0.0); } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + for (Widget widget : this.widgets) { + if (widget.containsMouse(mouseX, mouseY)) + return true; + } + return false; + } + + @Override + public Optional getChildAt(double mouseX, double mouseY) { + // Reverse iteration + for (int i = widgets.size() - 1; i >= 0; i--) { + Widget widget = widgets.get(i); + if (widget.containsMouse(mouseX, mouseY)) { + return Optional.of(widget); + } + } + + return Optional.empty(); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidgetWithBounds.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidgetWithBounds.java index 23eb26c90..89e05d1ee 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidgetWithBounds.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidgetWithBounds.java @@ -32,6 +32,7 @@ import java.util.Comparator; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; public class MergedWidgetWithBounds extends WidgetWithBounds { @@ -128,4 +129,22 @@ public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouse render(graphics, mouseX, mouseY, delta); getBounds().setBounds(clone); } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return getBounds().contains(mouseX, mouseY); + } + + @Override + public Optional getChildAt(double mouseX, double mouseY) { + // Reverse iteration + for (int i = widgets.size() - 1; i >= 0; i--) { + Widget widget = widgets.get(i); + if (widget.containsMouse(mouseX, mouseY)) { + return Optional.of(widget); + } + } + + return Optional.empty(); + } } \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java index 4480cda5b..d217e1000 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java @@ -69,7 +69,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; -import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.FlowingFluid; @@ -282,7 +281,7 @@ public void render(EntryStack entry, GuiGraphics graphics, Rectangle .alpha(0xff) .normal(graphics.pose().last().normal(), 0, 0, 0) .position(graphics.pose().last().pose(), bounds.x, bounds.getMaxY() - bounds.height * Mth.clamp(entry.get(EntryStack.Settings.FLUID_RENDER_RATIO), 0, 1), bounds.getMaxX(), bounds.getMaxY(), 0) - .next(InventoryMenu.BLOCK_ATLAS); + .next(TextureAtlas.LOCATION_BLOCKS); immediate.endBatch(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java index a2c046e9f..963f6833b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -53,10 +53,10 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.item.ItemStackRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.resources.language.I18n; -import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; @@ -245,86 +245,87 @@ public void fillCrashReport(CrashReport report, CrashReportCategory category, En } @Environment(EnvType.CLIENT) - public class ItemEntryRenderer implements BatchedEntryRenderer { + public class ItemEntryRenderer implements BatchedEntryRenderer { private static final float SCALE = 20.0F; public static final int ITEM_LIGHT = 0xf000f0; @Override - public BakedModel getExtraData(EntryStack entry) { + public ItemStackRenderState getExtraData(EntryStack entry) { Minecraft minecraft = Minecraft.getInstance(); - return minecraft.getItemRenderer().getModel(entry.getValue(), minecraft.level, minecraft.player, 0); + ItemStackRenderState renderState = new ItemStackRenderState(); + minecraft.getItemModelResolver().updateForTopItem(renderState, entry.getValue(), ItemDisplayContext.GUI, false, minecraft.level, minecraft.player, 0); + return renderState; } @Override public void render(EntryStack entry, GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { - BakedModel model = getExtraData(entry); - setupGL(entry, model); if (!entry.isEmpty()) { ItemStack value = entry.getValue(); + ItemStackRenderState renderState = getExtraData(entry); + setupGL(entry, renderState); graphics.pose().pushPose(); graphics.pose().translate(bounds.getCenterX(), bounds.getCenterY(), 0); graphics.pose().mulPose(new Matrix4f().scaling(1.0F, -1.0F, 1.0F)); graphics.pose().scale(bounds.getWidth(), bounds.getHeight(), (bounds.getWidth() + bounds.getHeight()) / 2.0F); MultiBufferSource.BufferSource immediate = graphics.bufferSource; - Minecraft.getInstance().getItemRenderer().render(value, ItemDisplayContext.GUI, false, graphics.pose(), immediate, - ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); + renderState.render(graphics.pose(), immediate, ITEM_LIGHT, OverlayTexture.NO_OVERLAY); immediate.endBatch(); graphics.pose().popPose(); + + Matrix4fStack modelViewStack = RenderSystem.getModelViewStack(); + modelViewStack.pushMatrix(); + modelViewStack.mul(graphics.pose().last().pose()); + modelViewStack.translate(bounds.x, bounds.y, 0); + modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); + graphics.drawSpecial(source -> { + if (source instanceof MultiBufferSource.BufferSource multiBufferSource) { + renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds); + } + }); + modelViewStack.popMatrix(); + endGL(entry, renderState); } - Matrix4fStack modelViewStack = RenderSystem.getModelViewStack(); - modelViewStack.pushMatrix(); - modelViewStack.mul(graphics.pose().last().pose()); - modelViewStack.translate(bounds.x, bounds.y, 0); - modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); - graphics.drawSpecial(source -> { - if (source instanceof MultiBufferSource.BufferSource multiBufferSource) { - renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds); - } - }); - modelViewStack.popMatrix(); - endGL(entry, model); } @Override - public int getBatchIdentifier(EntryStack entry, Rectangle bounds, BakedModel model) { - return 1738923 + (model.usesBlockLight() ? 1 : 0); + public int getBatchIdentifier(EntryStack entry, Rectangle bounds, ItemStackRenderState renderState) { + return 1738923 + (renderState.usesBlockLight() ? 1 : 0); } @Override - public void startBatch(EntryStack entry, BakedModel model, GuiGraphics graphics, float delta) { - setupGL(entry, model); + public void startBatch(EntryStack entry, ItemStackRenderState renderState, GuiGraphics graphics, float delta) { + setupGL(entry, renderState); } - public void setupGL(EntryStack entry, BakedModel model) { + public void setupGL(EntryStack entry, ItemStackRenderState renderState) { Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false); RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS); RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - boolean sideLit = model.usesBlockLight(); + boolean sideLit = renderState.usesBlockLight(); if (!sideLit) Lighting.setupForFlatItems(); } @Override - public void renderBase(EntryStack entry, BakedModel model, GuiGraphics graphics, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { + public void renderBase(EntryStack entry, ItemStackRenderState renderState, GuiGraphics graphics, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { if (!entry.isEmpty()) { ItemStack value = entry.getValue(); graphics.pose().pushPose(); graphics.pose().translate(bounds.getCenterX(), bounds.getCenterY(), 0); graphics.pose().scale(bounds.getWidth(), (bounds.getWidth() + bounds.getHeight()) / -2f, (bounds.getWidth() + bounds.getHeight()) / 2f); - Minecraft.getInstance().getItemRenderer().render(value, ItemDisplayContext.GUI, false, graphics.pose(), immediate, - ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); + renderState.render(graphics.pose(), immediate, ITEM_LIGHT, OverlayTexture.NO_OVERLAY); graphics.pose().popPose(); } } @Override - public void afterBase(EntryStack entry, BakedModel model, GuiGraphics graphics, float delta) { - endGL(entry, model); + public void afterBase(EntryStack entry, ItemStackRenderState renderState, GuiGraphics graphics, float delta) { + endGL(entry, renderState); } @Override - public void renderOverlay(EntryStack entry, BakedModel model, GuiGraphics graphics, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { + public void renderOverlay(EntryStack entry, ItemStackRenderState renderState, GuiGraphics graphics, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { Matrix4fStack modelViewStack = RenderSystem.getModelViewStack(); modelViewStack.pushMatrix(); modelViewStack.mul(graphics.pose().last().pose()); @@ -345,12 +346,12 @@ public void renderOverlay(GuiGraphics graphics, EntryStack entry, Rec } @Override - public void endBatch(EntryStack entry, BakedModel model, GuiGraphics graphics, float delta) { + public void endBatch(EntryStack entry, ItemStackRenderState renderState, GuiGraphics graphics, float delta) { } - public void endGL(EntryStack entry, BakedModel model) { + public void endGL(EntryStack entry, ItemStackRenderState renderState) { RenderSystem.enableDepthTest(); - boolean sideLit = model.usesBlockLight(); + boolean sideLit = renderState.usesBlockLight(); if (!sideLit) Lighting.setupFor3DItems(); }