diff --git a/gradle.properties b/gradle.properties index 6e8e5c2d2..5937ecbf4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ mcversion=1.12.2 -forgeversion=14.23.4.2749 +forgeversion=14.23.5.2775 mcp_mappings=stable_nodoc_39 curse_project_id=238222 diff --git a/src/main/java/mezz/jei/gui/recipes/RecipeCatalysts.java b/src/main/java/mezz/jei/gui/recipes/RecipeCatalysts.java index be4571990..02dcfd5d6 100644 --- a/src/main/java/mezz/jei/gui/recipes/RecipeCatalysts.java +++ b/src/main/java/mezz/jei/gui/recipes/RecipeCatalysts.java @@ -141,7 +141,7 @@ public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { if (hovered != null) { Object ingredientUnderMouse = hovered.getDisplayedIngredient(); if (ingredientUnderMouse != null) { - return new ClickedIngredient<>(ingredientUnderMouse, hovered.getRect()); + return ClickedIngredient.create(ingredientUnderMouse, hovered.getRect()); } } return null; diff --git a/src/main/java/mezz/jei/gui/recipes/RecipesGui.java b/src/main/java/mezz/jei/gui/recipes/RecipesGui.java index 0ff9e9be9..0c06495c1 100644 --- a/src/main/java/mezz/jei/gui/recipes/RecipesGui.java +++ b/src/main/java/mezz/jei/gui/recipes/RecipesGui.java @@ -263,7 +263,7 @@ public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { if (clicked != null) { Object displayedIngredient = clicked.getDisplayedIngredient(); if (displayedIngredient != null) { - return new ClickedIngredient<>(displayedIngredient, clicked.getRect()); + return ClickedIngredient.create(displayedIngredient, clicked.getRect()); } } } diff --git a/src/main/java/mezz/jei/input/ClickedIngredient.java b/src/main/java/mezz/jei/input/ClickedIngredient.java index 192c0fd78..be40a634b 100644 --- a/src/main/java/mezz/jei/input/ClickedIngredient.java +++ b/src/main/java/mezz/jei/input/ClickedIngredient.java @@ -3,7 +3,9 @@ import mezz.jei.Internal; import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRegistry; +import mezz.jei.ingredients.IngredientRegistry; import mezz.jei.util.ErrorUtil; +import mezz.jei.util.Log; import net.minecraft.item.ItemStack; import javax.annotation.Nullable; @@ -17,8 +19,25 @@ public class ClickedIngredient implements IClickedIngredient { private IOnClickHandler onClickHandler; private boolean allowsCheating; - public ClickedIngredient(V value, @Nullable Rectangle area) { - ErrorUtil.checkIsValidIngredient(value, "value"); + @Nullable + public static ClickedIngredient create(V value, @Nullable Rectangle area) { + ErrorUtil.checkNotNull(value, "value"); + IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(value); + try { + if (ingredientHelper.isValidIngredient(value)) { + return new ClickedIngredient<>(value, area); + } + String ingredientInfo = ingredientHelper.getErrorInfo(value); + Log.get().error("Clicked invalid ingredient. Ingredient Info: {}", ingredientInfo); + } catch (RuntimeException e) { + String ingredientInfo = ingredientHelper.getErrorInfo(value); + Log.get().error("Clicked invalid ingredient. Ingredient Info: {}", ingredientInfo, e); + } + return null; + } + + private ClickedIngredient(V value, @Nullable Rectangle area) { this.value = value; this.area = area; } diff --git a/src/main/java/mezz/jei/input/GuiContainerWrapper.java b/src/main/java/mezz/jei/input/GuiContainerWrapper.java index f94fc7cf5..8d054d8ca 100644 --- a/src/main/java/mezz/jei/input/GuiContainerWrapper.java +++ b/src/main/java/mezz/jei/input/GuiContainerWrapper.java @@ -27,7 +27,7 @@ public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { ItemStack stack = slotUnderMouse.getStack(); if (!stack.isEmpty()) { Rectangle slotArea = new Rectangle(slotUnderMouse.xPos, slotUnderMouse.yPos, 16, 16); - return new ClickedIngredient<>(stack, slotArea); + return ClickedIngredient.create(stack, slotArea); } } return getAdvancedGuiHandlerIngredientUnderMouse(guiContainer, mouseX, mouseY); @@ -46,7 +46,7 @@ private IClickedIngredient getAdvancedGuiHandlerIngr if (clicked instanceof ItemStack && slotUnderMouse != null && ItemStack.areItemStacksEqual(slotUnderMouse.getStack(), (ItemStack) clicked)) { area = new Rectangle(slotUnderMouse.xPos, slotUnderMouse.yPos, 16, 16); } - return new ClickedIngredient<>(clicked, area); + return ClickedIngredient.create(clicked, area); } } } diff --git a/src/main/java/mezz/jei/render/IngredientListBatchRenderer.java b/src/main/java/mezz/jei/render/IngredientListBatchRenderer.java index 4eb07c9ca..99d403072 100644 --- a/src/main/java/mezz/jei/render/IngredientListBatchRenderer.java +++ b/src/main/java/mezz/jei/render/IngredientListBatchRenderer.java @@ -116,7 +116,7 @@ public ClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { IngredientRenderer hovered = getHovered(mouseX, mouseY); if (hovered != null) { IIngredientListElement element = hovered.getElement(); - return new ClickedIngredient<>(element.getIngredient(), hovered.getArea()); + return ClickedIngredient.create(element.getIngredient(), hovered.getArea()); } return null; } diff --git a/src/main/java/mezz/jei/util/ErrorUtil.java b/src/main/java/mezz/jei/util/ErrorUtil.java index 5ebba5c32..d2eac4d9b 100644 --- a/src/main/java/mezz/jei/util/ErrorUtil.java +++ b/src/main/java/mezz/jei/util/ErrorUtil.java @@ -13,6 +13,7 @@ import mezz.jei.api.ingredients.VanillaTypes; import mezz.jei.api.recipe.IIngredientType; import mezz.jei.api.recipe.IRecipeWrapper; +import mezz.jei.ingredients.IngredientRegistry; import mezz.jei.ingredients.Ingredients; import mezz.jei.startup.ForgeModIdHelper; import net.minecraft.block.Block; @@ -220,10 +221,13 @@ public static T checkNotNull(@Nullable T object, String name) { return object; } - public static void checkIsValidIngredient(@Nullable Object ingredient, String name) { + public static void checkIsValidIngredient(@Nullable T ingredient, String name) { checkNotNull(ingredient, name); - if (!Internal.getIngredientRegistry().isValidIngredient(ingredient)) { - throw new IllegalArgumentException("Invalid ingredient found. Parameter Name: " + name + " Class: " + ingredient.getClass() + " Object: " + ingredient); + IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + if (!ingredientHelper.isValidIngredient(ingredient)) { + String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); + throw new IllegalArgumentException("Invalid ingredient found. Parameter Name: " + name + " Ingredient Info: " + ingredientInfo); } }