Add RecipeCatalyst system (#195)

* Add RecipeCatalyst system
This commit is contained in:
miozune authored and GitHub committed 2022-01-21 20:16:28 -08:00
1 parent 3ce702343d
commit 1e36822fa4
19 files changed
+490 -9

No files matched your search

@@ -550,6 +550,35 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
return handler;
}
/**
* First look up {@link RecipeCatalysts} whether target ingredient is registered for it.
* If so, load all recipes for this handler.
* Fallback to {@link TemplateRecipeHandler#getUsageHandler}.
*/
public IUsageHandler getUsageAndCatalystHandler(String inputId, Object... ingredients) {
TemplateRecipeHandler handler = newInstance();
if (inputId.equals("item")) {
ItemStack candidate = (ItemStack) ingredients[0];
if (RecipeCatalysts.containsCatalyst(handler.getClass(), candidate)) {
for (RecipeTransferRect rect : transferRects) {
if (specifyTransferRect() == null || Objects.equals(rect.outputId, specifyTransferRect())) {
handler.loadCraftingRecipes(rect.outputId, rect.results);
return handler;
}
}
}
}
return this.getUsageHandler(inputId, ingredients);
}
/**
* Override this if you have multiple {@link RecipeTransferRect}s.
* Used for {@link TemplateRecipeHandler#getUsageAndCatalystHandler}.
*/
public String specifyTransferRect() {
return null;
}
public int numRecipes() {
return arecipes.size();
}