4f1e510386
Dump of current working bot. Warning: somewhat messy code! Lints haven't been run, no tests, etc.
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
// 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} |