Fix Behavior With Unknown Items in Recipes (#8105)

This commit is contained in:
ChampionAsh5357 authored and GitHub committed 2021-10-20 11:56:23 -07:00
1 parent 11bdf592c8
commit 1e040c9f1f
2 files changed
+14 -4

No files matched your search

@@ -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