From 12561092af8fb1fc7afa93d00aa558c2eb66e978 Mon Sep 17 00:00:00 2001 From: mezz Date: Tue, 8 Oct 2024 11:58:17 +0900 Subject: [PATCH 1/2] Update JEI and Fix #905 --- build.gradle | 2 +- gradle.properties | 7 +- .../compat/viewer/impl/jei/DrawableIcon.java | 37 +++++++ .../viewer/impl/jei/ViewerCategoryJei.java | 102 ++++++------------ 4 files changed, 73 insertions(+), 75 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..d54f0e5cd --- /dev/null +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/impl/jei/DrawableIcon.java @@ -0,0 +1,37 @@ +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..271d5687b 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 @@ -30,22 +30,17 @@ import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.storage.TransferVariant; -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Stream; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.builder.IRecipeSlotBuilder; 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 +51,31 @@ import net.neoforged.neoforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; -class ViewerCategoryJei implements IRecipeCategory { +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Stream; + +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 +98,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,25 +119,13 @@ 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); + } + }); } @Override @@ -218,6 +175,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 +212,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 +223,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 From 77f1f70d5ec98933cbae6d65abf4e1198ee7dbda Mon Sep 17 00:00:00 2001 From: mezz Date: Tue, 8 Oct 2024 12:08:17 +0900 Subject: [PATCH 2/2] spotless --- .../compat/viewer/impl/jei/DrawableIcon.java | 69 ++++++++++++------- .../viewer/impl/jei/ViewerCategoryJei.java | 32 ++++----- 2 files changed, 61 insertions(+), 40 deletions(-) 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 index d54f0e5cd..98e771e46 100644 --- 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 @@ -1,3 +1,26 @@ +/* + * 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; @@ -6,32 +29,32 @@ import net.minecraft.client.gui.GuiGraphics; public class DrawableIcon implements IDrawable { - private final ViewerCategory.Icon.Texture texture; + 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 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; - } + public DrawableIcon(ViewerCategory.Icon.Texture texture) { + this.texture = texture; + } - @Override - public int getWidth() { - return 18; - } + @Override + public int getWidth() { + return 18; + } - @Override - public int getHeight() { - 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); - } + @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 271d5687b..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 @@ -30,6 +30,9 @@ import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.storage.TransferVariant; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Stream; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.builder.IRecipeSlotBuilder; import mezz.jei.api.gui.builder.ITooltipBuilder; @@ -51,10 +54,6 @@ import net.neoforged.neoforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Stream; - class ViewerCategoryJei extends AbstractRecipeCategory { private final IJeiHelpers helpers; public final ViewerCategory wrapped; @@ -63,12 +62,11 @@ class ViewerCategoryJei extends AbstractRecipeCategory { 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 - ); + 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; @@ -99,7 +97,7 @@ public void invisibleOutput(ItemStack stack) { private ViewerCategory.SlotBuilder slot(RecipeIngredientRole role, int x, int y) { var slotBuilder = builder.addSlot(role, x - 4, y - 4) - .setStandardSlotBackground(); + .setStandardSlotBackground(); return new ViewerCategory.SlotBuilder() { @Override @@ -120,12 +118,12 @@ public ViewerCategory.SlotBuilder variant(TransferVariant variant) { private static void addProbability(IRecipeSlotBuilder slot, float probability) { slot.addRichTooltipCallback((recipeSlotView, tooltip) -> { - var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT; - var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input); - if (probabilityLine != null) { - tooltip.add(probabilityLine); - } - }); + var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT; + var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input); + if (probabilityLine != null) { + tooltip.add(probabilityLine); + } + }); } @Override