feature request: getRecipeJSONs()
pm065 opened this issue ยท 2 comments
This is primarily for the purpose of transferring Crafting Table recipes to Artisan Worktables' (mod that adds themed crafting tables for modpacks) Basic Workbench, though I can imagine there would be quite a lot of use cases for this. Essentially, you'd call:
onEvent("recipes", event => {
event.getRecipeJSONs(filter)
})
getRecipeJSONs
would return an array of recipe JSON objects based off the input. Example:
console.log(event.getRecipeJSONs({id: "minecraft:iron_ingot"})); // outputs the recipe JSON of the iron_ingot recipe
console.log(event.getRecipeJSONs({output: "autumnity:snail_slime"})); // outputs the JSONs of every recipe with an output of autumnity:snail_slime
console.log(event.getRecipeJSONs({})); // outputs all recipe JSONs
// what I intend to do
var allShapeless = event.getRecipeJSONs({type: "minecraft:shapeless_crafting"});
var allShaped = event.getRecipeJSONs({type: "minecraft:shaped_crafting"});
// (and then functions that convert them into basic workbench recipes and remove the crafting table ones)
if I understand you correctly this is already possible when using event.forEachRecipe(filter, consumer)
function getRecipeJSONs(event, filter) {
const result = [];
event.forEachRecipe(filter, r => {
result.push(JSON.parse(r.json)); // Edit here. I wrapped it with JSON.parse to actually get a JS json object
})
return result;
}
onEvent("recipes", e => {
const recipeJsons = getRecipeJSONs(e, {id: "minecraft:iron_ingot"});
recipeJsons.forEach((r) => {
console.log(r);
})
const allShapeless = getRecipeJSONs(e, {type: "minecraft:crafting_shapeless"});
allShapeless.forEach((r) => {
console.log(r);
});
})