Skip to main content

RecipeEventJS

Examples

// kubejs/server_scripts/example.js
// This is just an example script to show off multiple types of recipes and removal methods
// Supports /reload

// Enable recipe logging, off by default
settings.logAddedRecipes = true
settings.logRemovedRecipes = true
// Enable skipped recipe logging, on by default
settings.logSkippedRecipes = false

// Listen to server recipe event
onEvent('recipes', event => {
  // Remove broken recipes from vanilla and other mods
  // This is on by default, so you don't need this line
  //event.removeBrokenRecipes = true

  event.remove({}) // Deletes all recipes
  event.remove({id: 'minecraft:glowstone'}) // Removes data/minecraft/recipes/glowstone.json
  event.remove({input: '#forge:dusts/redstone'}) // Removes all recipes where input is Redstone Dust tag
  event.remove({output: '#minecraft:wool'}) // Removes all recipes where output is Wool tag
  event.remove({mod: 'quartzchests'}) // Remove all recipes from Quartz Chests mod
  event.remove({type: 'minecraft:campfire_cooking'}) // Remove all campfire cooking recipes

  // Add shaped recipe for 3 Stone from 8 Sponge in chest shape
  // (Shortcut for event.recipes.minecraft.crafting_shaped)
  event.shaped(item.of('minecraft:stone', 3), [
    'SSS',
    'S S',
    'SSS'
  ], {
    S: 'minecraft:sponge'
  })

  // Add shapeless recipe for 4 Cobblestone from 1 Stone and 1 Glowstone
  // (Shortcut for event.recipes.minecraft.crafting_shapeless)
  event.shapeless(item.of('minecraft:cobblestone', 4), ['minecraft:stone', '#forge:dusts/glowstone'])

  // Add Stonecutter recipe for Golden Apple to 4 Apples
  event.recipes.minecraft.stonecutting(item.of('minecraft:apple', 4), 'minecraft:golden_apple')
  // Add Stonecutter recipe for Golden Apple to 2 Carrots
  event.recipes.minecraft.stonecutting(item.of('minecraft:carrot', 2), 'minecraft:golden_apple')

  // Add Furnace recipe for Golden Apple to 3 Carrots
  // (Shortcut for event.recipes.minecraft.smelting)
  event.smelting(item.of('minecraft:carrot', 2), 'minecraft:golden_apple')

  // Add similar recipes for Blast Furnace, Smoker and Campfire
  event.recipes.minecraft.blasting(item.of('minecraft:apple', 3), 'minecraft:golden_apple')
  event.recipes.minecraft.smoking(item.of('minecraft:apple', 5), 'minecraft:golden_apple')
  event.recipes.minecraft.campfire_cooking('minecraft:apple', 'minecraft:golden_apple')
  // You can also add .xp(1.0) at end of any smelting recipe to change given XP

  // Create a variable for function and use that to make things shorter
  var s = event.recipes.minecraft.smelting
  s('minecraft:blue_dye', '#forge:gems/lapis')
  s('minecraft:black_dye', 'minecraft:ink_sac')
  s('minecraft:white_dye', 'minecraft:bone_meal')

  // Add Create's crushing recipe, Apple to Apple + 50% Carrot
  event.recipes.create.crushing(['minecraft:apple', item.of('minecraft:carrot').chance(0.5)], 'minecraft:apple', 100)

  // If you use {} as only argument, it will be using vanilla Json syntax
  // You can add recipe to any recipe handler that uses vanilla recipe system or isn't supported by KubeJS
  event.recipes.create.crushing({
    ingredients: [
      ingredient.of('minecraft:carrot').toJson()
    ],
    results: [
      item.of('minecraft:apple').chance(0.5).toResultJson(),
      item.of('minecraft:carrot').toResultJson()
    ],
    processingTime: 100
  })
  
  // In all shapeless crafting recipes, replace any planks with Gold Nugget in input items
  event.replaceInput({type: 'minecraft:crafting_shapeless'}, '#minecraft:planks', 'minecraft:gold_nugget')
  
  // In all recipes, replace Stick with Oak Sapling in output items 
  event.replaceOutput({}, 'minecraft:stick', 'minecraft:oak_sapling')
})