From 115d78d83268a41dddfecef66ba206ba8bca8968 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Sat, 12 Oct 2024 08:17:23 -1000 Subject: [PATCH] Update JEI and Fix #905 (#912) --- build.gradle | 2 +- gradle.properties | 7 +- .../compat/viewer/impl/jei/DrawableIcon.java | 60 +++++++++++++ .../viewer/impl/jei/ViewerCategoryJei.java | 90 +++++-------------- 4 files changed, 89 insertions(+), 70 deletions(-) create mode 100644 src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/DrawableIcon.java diff --git a/build.gradle b/build.gradle index 7fc8cdadd..05e74446c 100644 --- a/build.gradle +++ b/build.gradle @@ -252,7 +252,7 @@ configurations { dependencies { api jarJar("dev.technici4n:GrandPower:${project.grandpower_version}") - compileOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge:${project.jei_version}" + compileOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge-api:${project.jei_version}" if (project.runtime_itemlist_mod == "jei") { localRuntimeOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge:${project.jei_version}" } diff --git a/gradle.properties b/gradle.properties index f61ec05f8..ce8cb1dd4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,9 +42,10 @@ emi_version=1.1.10 ftb_quests_version=2100.1.3 ftb_teams_version=2100.1.0 jade_file_id=5493270 -jei_minecraft_version=1.21 -jei_version=19.8.2.99 -jei_version_range=[19.8.2.99,] +# JEI Versions https://github.com/mezz/JustEnoughItems#1211 +jei_minecraft_version=1.21.1 +jei_version=19.20.0.241 +jei_version_range=[19.19.0,] kubejs_version=2100.7.0-build.102 patchouli_version=1.21-87-NEOFORGE-SNAPSHOT rei_version=16.0.729 diff --git a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/DrawableIcon.java b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/DrawableIcon.java new file mode 100644 index 000000000..98e771e46 --- /dev/null +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/DrawableIcon.java @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * 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 aztech.modern_industrialization.compat.viewer.impl.jei; + +import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.helpers.IGuiHelper; +import net.minecraft.client.gui.GuiGraphics; + +public class DrawableIcon implements IDrawable { + private final ViewerCategory.Icon.Texture texture; + + public static IDrawable create(IGuiHelper guiHelper, ViewerCategory.Icon icon) { + return switch (icon) { + case ViewerCategory.Icon.Stack stack -> guiHelper.createDrawableItemStack(stack.stack()); + case ViewerCategory.Icon.Texture texture -> new DrawableIcon(texture); + case null -> throw new NullPointerException("Icon cannot be null"); + }; + } + + public DrawableIcon(ViewerCategory.Icon.Texture texture) { + this.texture = texture; + } + + @Override + public int getWidth() { + return 18; + } + + @Override + public int getHeight() { + return 18; + } + + @Override + public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) { + guiGraphics.blit(texture.loc(), xOffset - 1, yOffset - 1, 0, texture.u(), texture.v(), 18, 18, 256, 256); + } +} diff --git a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/ViewerCategoryJei.java b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/ViewerCategoryJei.java index 7e577fdad..3681c354d 100644 --- a/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/ViewerCategoryJei.java +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/ViewerCategoryJei.java @@ -38,14 +38,12 @@ import mezz.jei.api.gui.builder.ITooltipBuilder; import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback; -import mezz.jei.api.gui.ingredient.IRecipeSlotView; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; @@ -56,58 +54,26 @@ import net.neoforged.neoforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; -class ViewerCategoryJei implements IRecipeCategory { +class ViewerCategoryJei extends AbstractRecipeCategory { private final IJeiHelpers helpers; public final ViewerCategory wrapped; public final RecipeType recipeType; - private final IDrawable background, icon, itemSlot, fluidSlot; + private final IDrawable fluidSlot; public ViewerCategoryJei(IJeiHelpers helpers, ViewerCategory wrapped) { + super( + RecipeType.create(wrapped.id.getNamespace(), wrapped.id.getPath(), wrapped.dataClass), + wrapped.title, + DrawableIcon.create(helpers.getGuiHelper(), wrapped.icon), + wrapped.width - 8, + wrapped.height - 8); + this.helpers = helpers; this.wrapped = wrapped; this.recipeType = RecipeType.create(wrapped.id.getNamespace(), wrapped.id.getPath(), wrapped.dataClass); - this.background = helpers.getGuiHelper().createBlankDrawable(wrapped.width - 8, wrapped.height - 8); - this.icon = wrapped.icon instanceof ViewerCategory.Icon.Stack stack ? helpers.getGuiHelper().createDrawableItemStack(stack.stack()) - : new IDrawable() { - @Override - public int getWidth() { - return 18; - } - - @Override - public int getHeight() { - return 18; - } - - @Override - public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) { - var texture = (ViewerCategory.Icon.Texture) wrapped.icon; - guiGraphics.blit(texture.loc(), xOffset - 1, yOffset - 1, 0, texture.u(), texture.v(), 18, 18, 256, 256); - } - }; - this.itemSlot = helpers.getGuiHelper().getSlotDrawable(); - this.fluidSlot = helpers.getGuiHelper().createDrawable(MachineScreen.SLOT_ATLAS, 18, 0, 18, 18); - } - - @Override - public RecipeType getRecipeType() { - return recipeType; - } - - @Override - public Component getTitle() { - return wrapped.title; - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public IDrawable getIcon() { - return icon; + var guiHelper = helpers.getGuiHelper(); + this.fluidSlot = guiHelper.createDrawable(MachineScreen.SLOT_ATLAS, 18, 0, 18, 18); } @Override @@ -130,8 +96,9 @@ public void invisibleOutput(ItemStack stack) { } private ViewerCategory.SlotBuilder slot(RecipeIngredientRole role, int x, int y) { - var slotBuilder = builder.addSlot(role, x - 4, y - 4); - slotBuilder.setBackground(itemSlot, -1, -1); + var slotBuilder = builder.addSlot(role, x - 4, y - 4) + .setStandardSlotBackground(); + return new ViewerCategory.SlotBuilder() { @Override public ViewerCategory.SlotBuilder variant(TransferVariant variant) { @@ -150,23 +117,11 @@ public ViewerCategory.SlotBuilder variant(TransferVariant variant) { } private static void addProbability(IRecipeSlotBuilder slot, float probability) { - slot.addTooltipCallback(new IRecipeSlotTooltipCallback() { - @Override - public void onTooltip(IRecipeSlotView recipeSlotView, List tooltip) { - var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT; - var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input); - if (probabilityLine != null) { - tooltip.add(probabilityLine); - } - } - - @Override - public void onRichTooltip(IRecipeSlotView recipeSlotView, ITooltipBuilder tooltip) { - var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT; - var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input); - if (probabilityLine != null) { - tooltip.add(probabilityLine); - } + slot.addRichTooltipCallback((recipeSlotView, tooltip) -> { + var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT; + var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input); + if (probabilityLine != null) { + tooltip.add(probabilityLine); } }); } @@ -218,6 +173,7 @@ public ViewerCategory.SlotBuilder markCatalyst() { @Override public void draw(D recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { + guiGraphics.pose().pushPose(); guiGraphics.pose().translate(-4, -4, 0); wrapped.buildWidgets(recipe, new ViewerCategory.WidgetList() { @@ -254,7 +210,7 @@ public void drawable(Consumer widget) { @Override public void item(double x, double y, double w, double h, ItemLike item) { guiGraphics.pose().pushPose(); - var drawable = helpers.getGuiHelper().createDrawableItemStack(item.asItem().getDefaultInstance()); + var drawable = helpers.getGuiHelper().createDrawableItemLike(item); guiGraphics.pose().translate(x, y, 0); guiGraphics.pose().scale((float) w / 16, (float) h / 16, 0); drawable.draw(guiGraphics); @@ -265,6 +221,8 @@ public void item(double x, double y, double w, double h, ItemLike item) { public void tooltip(int x, int y, int w, int h, List tooltip) { } }); + + guiGraphics.pose().popPose(); } @Override