diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java b/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java index d4701ba26..c06516665 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java @@ -613,30 +613,43 @@ public Optional handleUserInput(Screen screen, UserInput inpu double mouseY = input.getMouseY(); if (recipesGui.isMouseOver(mouseX, mouseY)) { if (recipesGui.recipeCategoryTitle.isMouseOver(mouseX, mouseY)) { - if (input.is(keyBindings.getLeftClick()) && recipesGui.logic.showAllRecipes()) { - return Optional.of(this); - } + if (input.is(keyBindings.getLeftClick())) + if (input.isSimulate() || recipesGui.logic.showAllRecipes()) { + return Optional.of(this); + } } } Minecraft minecraft = Minecraft.getInstance(); if (input.is(keyBindings.getCloseRecipeGui()) || input.is(minecraft.options.keyInventory)) { - recipesGui.onClose(); + if (!input.isSimulate()) { + recipesGui.onClose(); + } return Optional.of(this); } else if (input.is(keyBindings.getRecipeBack())) { - recipesGui.back(); + if (!input.isSimulate()) { + recipesGui.back(); + } return Optional.of(this); } else if (input.is(keyBindings.getNextCategory())) { - recipesGui.logic.nextRecipeCategory(); + if (!input.isSimulate()) { + recipesGui.logic.nextRecipeCategory(); + } return Optional.of(this); } else if (input.is(keyBindings.getPreviousCategory())) { - recipesGui.logic.previousRecipeCategory(); + if (!input.isSimulate()) { + recipesGui.logic.previousRecipeCategory(); + } return Optional.of(this); } else if (input.is(keyBindings.getNextRecipePage())) { - recipesGui.logic.nextPage(); + if (!input.isSimulate()) { + recipesGui.logic.nextPage(); + } return Optional.of(this); } else if (input.is(keyBindings.getPreviousRecipePage())) { - recipesGui.logic.previousPage(); + if (!input.isSimulate()) { + recipesGui.logic.previousPage(); + } return Optional.of(this); } diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java index 6ee8106ed..ee7ed5b97 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java @@ -216,7 +216,6 @@ public RecipeLayout buildRecipeLayout( ); for (Map.Entry, List>> e : widgetSlots.entrySet()) { - // TODO: breaking change: add a type parameter to IRecipeLayoutBuilder to avoid this cast @SuppressWarnings("unchecked") mezz.jei.api.gui.widgets.ISlottedWidgetFactory factory = (mezz.jei.api.gui.widgets.ISlottedWidgetFactory) e.getKey(); List slots = sortSlots(e.getValue()); diff --git a/Library/src/main/java/mezz/jei/library/ingredients/DisplayIngredientAcceptor.java b/Library/src/main/java/mezz/jei/library/ingredients/DisplayIngredientAcceptor.java index 6f01b8104..a29515be7 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/DisplayIngredientAcceptor.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/DisplayIngredientAcceptor.java @@ -18,6 +18,8 @@ import mezz.jei.common.util.ErrorUtil; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.UnmodifiableView; @@ -26,7 +28,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.function.Function; public class DisplayIngredientAcceptor implements IIngredientAcceptor { private final IIngredientManager ingredientManager; @@ -57,13 +58,22 @@ public DisplayIngredientAcceptor addIngredients(IIngredientType ingredien ErrorUtil.checkNotNull(ingredientType, "ingredientType"); Preconditions.checkNotNull(ingredients, "ingredients"); - List>> typedIngredients = TypedIngredient.createAndFilterInvalidList(this.ingredientManager, ingredientType, ingredients, false); + List>> typedIngredients = TypedIngredient.createUnvalidatedList(ingredientType, ingredients); + @SuppressWarnings("unchecked") + List>> castTypedIngredients = (List>>) (Object) typedIngredients; + this.ingredients.addAll(castTypedIngredients); - if (!typedIngredients.isEmpty()) { - for (Optional> typedIngredientOptional : typedIngredients) { - this.ingredients.add(typedIngredientOptional.map(Function.identity())); - } - } + return this; + } + + @Override + public DisplayIngredientAcceptor addIngredients(Ingredient ingredient) { + Preconditions.checkNotNull(ingredient, "ingredient"); + + List>> typedIngredients = TypedIngredient.createUnvalidatedList(ingredient); + @SuppressWarnings("unchecked") + List>> castTypedIngredients = (List>>) (Object) typedIngredients; + this.ingredients.addAll(castTypedIngredients); return this; } @@ -81,8 +91,7 @@ public DisplayIngredientAcceptor addIngredient(IIngredientType ingredient public DisplayIngredientAcceptor addTypedIngredient(ITypedIngredient typedIngredient) { ErrorUtil.checkNotNull(typedIngredient, "typedIngredient"); - Optional> copy = TypedIngredient.deepCopy(ingredientManager, typedIngredient); - this.ingredients.add(copy.map(Function.identity())); + this.ingredients.add(Optional.of(typedIngredient)); return this; } @@ -141,8 +150,12 @@ public DisplayIngredientAcceptor addOptionalTypedIngredients(List void addIngredientInternal(IIngredientType ingredientType, @Nullable T ingredient) { - Optional> typedIngredient = TypedIngredient.createAndFilterInvalid(this.ingredientManager, ingredientType, ingredient, false); - this.ingredients.add(typedIngredient.map(Function.identity())); + if (ingredient == null) { + this.ingredients.add(Optional.empty()); + } else { + ITypedIngredient typedIngredient = TypedIngredient.createUnvalidated(ingredientType, ingredient); + this.ingredients.add(Optional.of(typedIngredient)); + } } @UnmodifiableView diff --git a/Library/src/main/java/mezz/jei/library/ingredients/TypedIngredient.java b/Library/src/main/java/mezz/jei/library/ingredients/TypedIngredient.java index b4410dc33..5636de1e0 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/TypedIngredient.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/TypedIngredient.java @@ -9,8 +9,7 @@ import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.library.ingredients.itemStacks.TypedItemStack; import net.minecraft.world.item.ItemStack; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import net.minecraft.world.item.crafting.Ingredient; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -18,8 +17,6 @@ import java.util.Optional; public final class TypedIngredient implements ITypedIngredient { - private static final Logger LOGGER = LogManager.getLogger(); - private static void checkParameters(IIngredientType ingredientType, T ingredient) { Preconditions.checkNotNull(ingredientType, "ingredientType"); Preconditions.checkNotNull(ingredient, "ingredient"); @@ -104,6 +101,33 @@ public static List>> createAndFilterInvalidList return results; } + public static List>> createUnvalidatedList( + IIngredientType ingredientType, + List<@Nullable T> ingredients + ) { + List>> results = new ArrayList<>(ingredients.size()); + for (T ingredient : ingredients) { + if (ingredient == null) { + results.add(Optional.empty()); + } else { + ITypedIngredient result = createUnvalidated(ingredientType, ingredient); + results.add(Optional.of(result)); + } + } + return results; + } + + public static List>> createUnvalidatedList(Ingredient ingredient) { + ItemStack[] itemStacks = ingredient.getItems(); + + List>> results = new ArrayList<>(itemStacks.length); + for (ItemStack itemStack : itemStacks) { + ITypedIngredient result = TypedItemStack.create(itemStack); + results.add(Optional.of(result)); + } + return results; + } + public static Optional> createAndFilterInvalid( IIngredientHelper ingredientHelper, IIngredientType ingredientType, @@ -117,11 +141,6 @@ public static Optional> createAndFilterInvalid( if (!ingredientHelper.isValidIngredient(ingredient)) { return Optional.empty(); } - if (!ingredientHelper.isIngredientOnServer(ingredient)) { - String errorInfo = ingredientHelper.getErrorInfo(ingredient); - LOGGER.warn("Ignoring ingredient that isn't on the server: {}", errorInfo); - return Optional.empty(); - } } catch (RuntimeException e) { String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); throw new IllegalArgumentException("Crashed when checking if ingredient is valid. Ingredient Info: " + ingredientInfo, e); diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java index 95625bc23..65b1e6fb4 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/VanillaPlugin.java @@ -172,11 +172,11 @@ public void registerItemSubtypes(ISubtypeRegistration registration) { @Override public void registerIngredients(IModIngredientRegistration registration) { ISubtypeManager subtypeManager = registration.getSubtypeManager(); - StackHelper stackHelper = new StackHelper(subtypeManager); - - List itemStacks = ItemStackListFactory.create(stackHelper); IColorHelper colorHelper = registration.getColorHelper(); + + StackHelper stackHelper = new StackHelper(subtypeManager); ItemStackHelper itemStackHelper = new ItemStackHelper(stackHelper, colorHelper); + List itemStacks = ItemStackListFactory.create(stackHelper, itemStackHelper); ItemStackRenderer itemStackRenderer = new ItemStackRenderer(); registration.register( VanillaTypes.ITEM_STACK, diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/ingredients/ItemStackListFactory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/ingredients/ItemStackListFactory.java index 184ccb28c..a9836b2cb 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/ingredients/ItemStackListFactory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/ingredients/ItemStackListFactory.java @@ -37,7 +37,7 @@ public final class ItemStackListFactory { private static final Logger LOGGER = LogManager.getLogger(); - public static List create(StackHelper stackHelper) { + public static List create(StackHelper stackHelper, ItemStackHelper itemStackHelper) { IJeiClientConfigs jeiClientConfigs = Internal.getJeiClientConfigs(); IClientConfig clientConfig = jeiClientConfigs.getClientConfig(); final boolean showHidden = clientConfig.isShowHiddenItemsEnabled(); @@ -117,6 +117,7 @@ public static List create(StackHelper stackHelper) { "displayItems", tab, stackHelper, + itemStackHelper, itemList, itemUidSet ); @@ -126,6 +127,7 @@ public static List create(StackHelper stackHelper) { "searchTabDisplayItems", tab, stackHelper, + itemStackHelper, itemList, itemUidSet ); @@ -144,6 +146,7 @@ private static void addFromTab( String displayType, CreativeModeTab tab, StackHelper stackHelper, + ItemStackHelper itemStackHelper, List itemList, Set itemUidSet ) { @@ -153,20 +156,33 @@ private static void addFromTab( int duplicateInTabCount = 0; for (ItemStack itemStack : tabDisplayItems) { if (itemStack.isEmpty()) { - LOGGER.error("Found an empty itemStack in '{}' creative tab's {}", tab, displayType); - } else { - Object itemKey = safeGetUid(stackHelper, itemStack); - if (itemKey != null) { - if (tabUidSet.contains(itemKey)) { - duplicateInTab.add(itemKey); - duplicateInTabCount++; - } - if (itemUidSet.add(itemKey)) { - tabUidSet.add(itemKey); - itemList.add(itemStack); - added++; - } - } + String errorInfo = itemStackHelper.getErrorInfo(itemStack); + LOGGER.error("Found an empty itemStack in '{}' creative tab's {}: {}", tab, displayType, errorInfo); + continue; + } + if (!itemStackHelper.isValidIngredient(itemStack)) { + String errorInfo = itemStackHelper.getErrorInfo(itemStack); + LOGGER.error("Ignoring ingredient in '{}' creative tab's {} that is considered invalid: {}", tab, displayType, errorInfo); + continue; + } + if (!itemStackHelper.isIngredientOnServer(itemStack)) { + String errorInfo = itemStackHelper.getErrorInfo(itemStack); + LOGGER.warn("Ignoring ingredient in '{}' creative tab's {} that isn't on the server: {}", tab, displayType, errorInfo); + continue; + } + Object itemKey = safeGetUid(stackHelper, itemStack); + if (itemKey == null) { + continue; + } + + if (tabUidSet.contains(itemKey)) { + duplicateInTab.add(itemKey); + duplicateInTabCount++; + } + if (itemUidSet.add(itemKey)) { + tabUidSet.add(itemKey); + itemList.add(itemStack); + added++; } } if (LOGGER.isDebugEnabled()) {