diff --git a/patches/minecraft/net/minecraft/world/item/crafting/ShapedRecipe.java.patch b/patches/minecraft/net/minecraft/world/item/crafting/ShapedRecipe.java.patch index 94b9694e11..7777fdb60c 100644 --- a/patches/minecraft/net/minecraft/world/item/crafting/ShapedRecipe.java.patch +++ b/patches/minecraft/net/minecraft/world/item/crafting/ShapedRecipe.java.patch @@ -78,7 +78,7 @@ - return new ItemStack(item, i); - } - } -+ return net.minecraftforge.common.crafting.CraftingHelper.getItemStack(p_151275_, true); ++ return net.minecraftforge.common.crafting.CraftingHelper.getItemStack(p_151275_, true, false); // TODO: Swap false to true in 1.18 to mimic vanilla behavior } public static Item m_151278_(JsonObject p_151279_) { diff --git a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java index 28b2b3c30c..5fbfc4f0ed 100644 --- a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java +++ b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java @@ -38,6 +38,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraftforge.common.crafting.conditions.ICondition; import net.minecraftforge.common.crafting.conditions.IConditionSerializer; @@ -156,14 +157,23 @@ public class CraftingHelper } public static ItemStack getItemStack(JsonObject json, boolean readNBT) + { + return getItemStack(json, readNBT, false); + } + + public static ItemStack getItemStack(JsonObject json, boolean readNBT, boolean disallowsAirInRecipe) { String itemName = GsonHelper.getAsString(json, "item"); + ResourceLocation itemKey = new ResourceLocation(itemName); - Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)); - - if (item == null) + if (!ForgeRegistries.ITEMS.containsKey(itemKey)) throw new JsonSyntaxException("Unknown item '" + itemName + "'"); + Item item = ForgeRegistries.ITEMS.getValue(itemKey); + + if (disallowsAirInRecipe && item == Items.AIR) + throw new JsonSyntaxException("Invalid item: " + itemName); + if (readNBT && json.has("nbt")) { // Lets hope this works? Needs test