Basic Syntax: Remove And Modify Recipes
This chapter introduces recipe filters, and how to use them to remove or modify recipes.
Recipe Filters
In KubeJS, you can use recipe filters when removing or modifying recipes to match recipes that meet certain conditions.
The most basic recipe filters are these five:
{output : 'item_id'}
{input : 'item_id'}
{mod : 'mod_id'}
{id : 'recipe_id'}
{type : 'recipe_type'}Explanation:
output: matches the output item. If A+B+C crafts into D, then D is the output. When removing recipes, any recipe whose output matches D will be removed.input: matches an input ingredient. If A+B+C crafts into D, then A/B/C are inputs. If you setinputto B, then any recipe that contains B as an ingredient can match.mod: matches a mod id. For example, if you setmod: "create", it can match recipes from Create.id: matches a specific recipe id. If you have JEI installed and enable advanced tooltips withF3+H, you can see recipe ids. Usingidlets you target the recipe precisely.type: matches the recipe type (crafting table, furnace, etc.). Usingtypecan remove an entire category of recipes.
In addition to these basics, KubeJS also supports combining filters. In real projects you often need stricter matching, so here are three more patterns:
{basicFilter1, basicFilter2, basicFilter3, ...}
[{basicFilter1, basicFilter2, basicFilter3, ...}, {basicFilter1, basicFilter2, basicFilter3, ...}, ...]
{not:{basicFilter1, basicFilter2, basicFilter3, ...}}Explanation and examples:
- The first form means "match all conditions". If any condition is not satisfied, the recipe does not match. For example, for the
inputfilter you might write:
{{input : 'stone'}},{input : 'redstone'},{input : 'grass'}}Then a recipe would need to satisfy all three conditions to match. If it only satisfies one or two, it would not match.
- The second form is similar, but it is an array of "match all" groups. If the recipe matches any one group in the array, it matches.
- The third form is the negation form. It matches recipes that do NOT match the inner filter.
Removing Recipes
Now that we've introduced recipe filters, let's use them. It's easier to understand by trying them directly.
There is only one method to remove recipes: event.remove(...). Everything depends on the recipe filters described above.
ServerEvents.recipes(event => {
// Remove all recipes whose output is stone bricks
event.remove({output : 'stone_bricks'});
// Remove all recipes that have stone bricks as an input
event.remove({input : 'stone_bricks'});
// Remove all recipes from the minecraft namespace
event.remove({mod : 'minecraft'});
// Remove the recipe with id minecraft:oak_wood (4 oak logs -> oak wood)
event.remove({id : "minecraft:oak_wood"});
// Remove all smelting recipes
event.remove({type : "smelting"});
});Aside from removing by exact recipe id, the other filters can match a very broad set of recipes. If an item has both crafting and smelting recipes and you only want to remove the smelting one, you should combine filters:
ServerEvents.recipes(event => {
event.remove({type:"crafting_shaped",output:"end_stone_bricks"});
});In 1.20, end stone bricks can be crafted via crafting table and stonecutter. The filter above only removes the crafting-table recipe; the stonecutter recipe still exists.
Replacing Ingredients/Outputs
The advanced filters become more useful when replacing inputs/outputs.
KubeJS provides two replacement helpers:
replaceInput (replace matching input ingredients) and replaceOutput (replace matching outputs).
Here are three examples:
ServerEvents.recipes(event =>{
// Only match recipes that include both stick and the planks tag, then replace stick with blaze rod
event.replaceInput({input:'minecraft:stick',input:'#minecraft:planks'},'minecraft:stick','minecraft:blaze_rod');
// Only match recipes whose output is dispenser/dropper/furnace, then replace cobblestone input with diamond
event.replaceInput([{output:'minecraft:dispenser'},{output:'minecraft:dropper'},{output:'minecraft:furnace'}],"minecraft:cobblestone",'minecraft:diamond');
// For recipes that do NOT match (stick + planks), replace outputs in the logs tag with stone bricks
event.replaceOutput({not:{input:'minecraft:stick',input:'#minecraft:planks'}},'#minecraft:logs','minecraft:stone_bricks');
})A Simple Helper Snippet For Removing Recipes
// Put the things you want to remove into the arrays below. Remember to separate entries with commas.
/*
* let output = [
* "minecraft:crafting_table",
* "create:brass_ingot"
* ]
* output.forEach((item) => {
* event.remove({ output: item })
* })
*/
ServerEvents.recipes((event) => {
// Outputs
let output = [
]
output.forEach((item) => {
event.remove({ output: item })
})
// Inputs
let input = [
]
input.forEach((item) => {
event.remove({ input: item })
})
// Recipe types
let recipeType = [
]
recipeType.forEach((type) => {
event.remove({ type: type })
})
// Mod recipes
let modRecipes = [
]
modRecipes.forEach((modid) => {
event.remove({ mod: modid })
})
})