Создание крафтов

Примеры

Самый простой скрипт для добавления одного рецепта:

onEvent('recipes', event => {
  event.shaped('3x minecraft:stone', [
    'SAS',
    'S S',
    'SAS'
  ], {
    S: 'minecraft:sponge',
    A: 'minecraft:apple'
  })
})

Самый простой скрипт для удаления рецепта:

onEvent('recipes', event => {
  event.remove({output: 'minecraft:stick'})
})

Пример скрипта рецепта:

// kubejs/server_scripts/example.js
// Это всего лишь пример скрипта, демонстрирующий несколько типов рецептов и методов удаления.
// Поддерживает /reload

// Прослушивание события рецепта сервера
onEvent('recipes', event => {
  // Удалить неработающие рецепты из ванили и других модов
  // Это включено по умолчанию, поэтому вам не нужна эта строка
  //event.removeBrokenRecipes = true

  event.remove({}) //Удаляет все рецепты (опция ядерного оружия, обычно не рекомендуется)
  event.remove({output: 'minecraft:stone_pickaxe'}) // Удаляет все рецепты, в которых выходом является каменная кирка.
  event.remove({output: '#minecraft:wool'}) // Удаляет все рецепты, в которых на выходе указан тег «Шерсть».
  event.remove({input: '#forge:dusts/redstone'}) // Удаляет все рецепты, в которых введен тег Redstone Dust.
  event.remove({mod: 'quartzchests'}) // Удалить все рецепты из мода Quartz Chests.
  event.remove({type: 'minecraft:campfire_cooking'}) // Удалить все рецепты приготовления пищи на костре.
  event.remove({id: 'minecraft:glowstone'}) // Удаляет рецепт по идентификатору. в данном случае data/minecraft/recipes/glowstone.json
  event.remove({output: 'minecraft:cooked_chicken', type: 'minecraft:campfire_cooking'}) // Вы можете комбинировать фильтры для создания логики AND
  
  // Вы можете использовать синтаксис 'mod:id' для элементов размера 1. Для 2+ вам нужно использовать синтаксис «2x mod:id» или Item.of('mod:id', count). Если вам нужен NBT или шанс, требуется второе место.


  // Add shaped recipe for 3 Stone from 8 Sponge in chest shape
  // (Shortcut for event.recipes.minecraft.crafting_shaped)
  // If you want to use Extended Crafting, replace event.shapeless with event.recipes.extendedcrafting.shapeless_table
  
  // Добавляем фигурный рецепт для 3 камней из 8 губок в форме сундука
  // (ярлык для event.recipes.minecraft.crafting_shaped)
  // Если вы хотите использовать расширенное крафтинг, замените event.shapeless на event.recipes.extendedcrafting.shapeless_table
  event.shaped('3x minecraft:stone', [
    'SAS',
    'S S',
    'SAS'
  ], {
    S: 'minecraft:sponge',
    A: 'minecraft:apple'
  })

  // Добавляем бесформенный рецепт для 4 булыжников из 1 камня и 1 светящегося камня
  // (Ярлык для event.recipes.minecraft.crafting_shapeless)
  // Если вы хотите использовать расширенное крафтинг, замените event.shapeless на event.recipes.extendedcrafting.shapeless_table.
  event.shapeless('4x minecraft:cobblestone', ['minecraft:stone', '#forge:dusts/glowstone'])

  // Добавьте рецепт Камнетеса для получения 4 яблока из золотого яблока.
  event.stonecutting('4x minecraft:apple', 'minecraft:golden_apple')
  // Добавьте рецепт Камнетеса получить 2 морковки из золотого яблока
  event.stonecutting('2x minecraft:carrot', 'minecraft:golden_apple')

  // Рецепт для печи получение 2 морковки из золотого яблока
  // (Ярлык для event.recipes.minecraft.smelting)
  event.smelting('2x minecraft:carrot', 'minecraft:golden_apple')
  // Рецепт аналогичен приведенному выше, но на этот раз он имеет собственный статический идентификатор — обычно идентификаторы генерируются автоматически и изменяются. Полезно для Patchouli
  event.smelting('minecraft:golden_apple', 'minecraft:carrot').id('mymodpack:my_recipe_id')

  // Добавьте аналогичные рецепты для Доменной печи, Коптильни и Костра.
  event.blasting('3x minecraft:apple', 'minecraft:golden_apple')
  event.smoking('5x minecraft:apple', 'minecraft:golden_apple')
  event.campfireCooking('8x minecraft:apple', 'minecraft:golden_apple')
  // Вы так-же можете добавить .xp(1.0) =что-бы получить опыт за использование этого крафта
  
  // Добавьте рецепт кузнечного дела, который объединяет 2 предмета в один (в данном случае яблоко и золотой слиток в золотое яблоко).
  event.smithing('minecraft:golden_apple', 'minecraft:apple', 'minecraft:gold_ingot')

  // Создайте функцию и используйте ее, чтобы сократить работу. Вы можете объединить несколько действий
  let multiSmelt = (output, input, includeBlasting) => {
    event.smelting(output, input)
    
    if (includeBlasting) {
      event.blasting(output, input)
    }
  }
  
  multiSmelt('minecraft:blue_dye', '#forge:gems/lapis', true)
  multiSmelt('minecraft:black_dye', 'minecraft:ink_sac', true)
  multiSmelt('minecraft:white_dye', 'minecraft:bone_meal', false)

  // If you use custom({json}) it will be using vanilla Json/datapack syntax. Must include "type": "mod:recipe_id"!
  // You can add recipe to any recipe handler that uses vanilla recipe system or isn't supported by KubeJS
  // You can copy-paste the json directly, but you can also make more javascript-y by removing quotation marks from keys
  // You can replace {item: 'x', count: 4} in result fields with Item.of('x', 4).toResultJson()
  // You can replace {item: 'x'} / {tag: 'x'} with Ingredient.of('x').toJson() or Ingredient.of('#x').toJson()
  // In this case, add Create's crushing recipe, Oak Sapling to Apple + 50% Carrot
  
  // Important! Create has integration already, so you don't need to use this. This is just an example for datapack recipes!
  // Note that not all mods format their jsons the same, often the key names ('ingredients', 'results', ect) are different. 
  // You should check inside the mod jar (mod.jar/data/modid/recipes/) for examples
  event.custom({
    type: 'create:crushing',
    ingredients: [
      Ingredient.of('minecraft:oak_sapling').toJson()
    ],
    results: [
      Item.of('minecraft:apple').toResultJson(),
      Item.of('minecraft:carrot').withChance(0.5).toResultJson()
    ],
    processingTime: 100
  })
  
  // Example of using items with NBT in a recipe
  event.shaped('minecraft:book', [
    'CCC',
    'WGL',
    'CCC'
  ], {
    C: '#forge:cobblestone',
    // Item.of('id', '{key: value}'), it's recommended to use /kubejs hand
    // If you want to add a count its Item.of('id', count, '{key: value}'). This won't work here though as crafting table recipes to do accept stacked items
    L: Item.of('minecraft:enchanted_book', '{StoredEnchantments:[{lvl:1,id:"minecraft:sweeping"}]}'),
    // Same principle, but if its an enchantment, there's a helper method
    W: Item.of('minecraft:enchanted_book').enchant('minecraft:respiration', 2),
    G: '#forge:glass'
  })
  
  // 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')
  
  // By default KubeJS will mirror and shrink recipes, which makes things like UU-Matter crafting (from ic2) harder to do as you have less shapes.
  // You can use noMirror() and noShrink() to stop this behaviour.
  event.shaped('9x minecraft:emerald', [
    ' D ',
    'D  ',
    '   '
  ], {
    D: 'minecraft:diamond'
  }).noMirror().noShrink()
})

Last updated