A high-level, general purpose and modular minecraft bot using hot re-loadable (without restarting the bot!) plugins. Batteries included, launch to run!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

53 lines
1.4 KiB

// const performance = require('performance-now')
const {Vec3} = require('vec3')
let mcData = require('minecraft-data')
let cfg = {}
let bot = {}
function findBlocks(name){
// const name = message.split(' ')[1]
if (mcData.blocksByName[name] === undefined) {
bot.chat(`${name} is not a block name`)
return
} else if (["ancient_debris", "diamond_ore", "emerald_ore"].includes(name)) {
return
}
const ids = [mcData.blocksByName[name].id]
// const startTime = performance.now()
const blocks = bot.findBlocks({ matching: ids, maxDistance: 128, count: 10 })
// const time = (performance.now() - startTime).toFixed(2)
// TODO check if toString() is really needed
if (blocks.length === 0){
bot.chat("not here (around 128 blocks)")
return
}
const pos = minmax(blocks).map(x => x.toString())
// bot.chat(`I found ${blocks.length} ${name} blocks in ${time} ms`)
bot.chat(`I found ${blocks.length} ${name} blocks at ${pos}`)
}
function minmax(coordsArray){
const min = coordsArray.reduce((x,y) => x.min(y))
const max = coordsArray.reduce((x,y) => x.max(y))
return [min, max]
}
const load = (config) => {
cfg = config
bot = cfg.bot
mcData = mcData(bot.version)
}
const unload = () => {
// bot.off("time", autoSleep)
}
module.exports = { load, unload, findBlocks}