Change the code so that the bot digs several blocks, and exactly how much I tell him. #3458
Labels
new feature
Stage1
just created by someone new to the project, we don't know yet if it deserves an implementation / a f
I took the code, but it breaks only one block, for example: collect dirt.
He will only break 1 block, but I want me to write: collect dirt 64, and he dug 64 dirt. Please help me!
Code:
let mcData
bot.once('spawn', () => {
mcData = require('minecraft-data')(bot.version);
})
bot.on('chat', async (username, message) => {
const args = message.split(' ')
if (args[0] !== 'collect') return
let count = 1
if (args.length === 3) count = parseInt(args[1])
let type = args[1]
if (args.length === 3) type = args[2]
const blockType = mcData.blocksByName[type]
if (!blockType) {
return
}
const blocks = bot.findBlocks({
matching: blockType.id,
maxDistance: 64,
count: count
})
if (blocks.length === 0) {
bot.chat("I don't see that block nearby.")
return
}
const targets = []
for (let i = 0; i < Math.min(blocks.length, count); i++) {
targets.push(bot.blockAt(blocks[i]))
}
bot.chat(
Found ${targets.length} ${type}(s)
)try {
await bot.collectBlock.collect(targets)
// All blocks have been collected.
bot.chat('Done')
} catch (err) {
// An error occurred, report it.
bot.chat(err.message)
console.log(err)
}
})
The text was updated successfully, but these errors were encountered: