Add validation to recipe registry (#4957)

This commit is contained in:
Ben Staddon authored and mezz committed 2018-06-26 22:00:53 -07:00
1 parent d09a8d98d7
commit 43895d773e
6 files changed
+71 -6

No files matched your search

@@ -402,10 +402,22 @@ public class GameData
}
}
private static class RecipeCallbacks implements IForgeRegistry.MissingFactory<IRecipe>
private static class RecipeCallbacks implements IForgeRegistry.ValidateCallback<IRecipe>, IForgeRegistry.MissingFactory<IRecipe>
{
static final RecipeCallbacks INSTANCE = new RecipeCallbacks();
@Override
public void onValidate(IForgeRegistryInternal<IRecipe> owner, RegistryManager stage, int id, ResourceLocation key, IRecipe obj)
{
if (stage != RegistryManager.ACTIVE) return;
// verify the recipe output yields a registered item
Item item = obj.getRecipeOutput().getItem();
if (!stage.getRegistry(Item.class).containsValue(item))
{
throw new IllegalStateException(String.format("Recipe %s (%s) produces unregistered item %s (%s)", key, obj, item.getRegistryName(), item));
}
}
@Override
public IRecipe createMissing(ResourceLocation key, boolean isNetwork)
{