How to use the minecraft-data.findItemOrBlockByName function in minecraft-data

To help you get started, we’ve selected a few minecraft-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrismarineJS / mineflayer / examples / inventory.js View on Github external
function craftItem (name, amount) {
  amount = parseInt(amount, 10)
  const item = require('minecraft-data')(bot.version).findItemOrBlockByName(name)
  const craftingTable = bot.findBlock({
    matching: 58
  })

  if (item) {
    const recipe = bot.recipesFor(item.id, null, 1, craftingTable)[0]
    if (recipe) {
      bot.chat(`I can make ${name}`)
      bot.craft(recipe, amount, craftingTable, (err) => {
        if (err) {
          bot.chat(`error making ${name}`)
        } else {
          bot.chat(`did the recipe for ${name} ${amount} times`)
        }
      })
    } else {