95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
|
// import { EntityFilters } from "mineflayer-statemachine"
|
||
|
// import v from "vec3"
|
||
|
|
||
|
// import { Movements } from "mineflayer-pathfinder"
|
||
|
|
||
|
// const mineflayer = require('mineflayer')
|
||
|
const { Movements } = require('mineflayer-pathfinder')
|
||
|
// const { GoalBLah } = require('mineflayer-pathfinder').goals
|
||
|
const v = require('vec3')
|
||
|
|
||
|
let cfg = {}
|
||
|
let bot = {}
|
||
|
// let moving
|
||
|
let pathfinder
|
||
|
let movements = []
|
||
|
|
||
|
|
||
|
function initMoves(bot = bot, mcData = require('minecraft-data')(bot.version)) {
|
||
|
let defaultMove = new Movements(bot, mcData)
|
||
|
defaultMove.canDig = false
|
||
|
defaultMove.scafoldingBlocks.push(mcData.blocksByName.slime_block.id)
|
||
|
// defaultMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
|
||
|
// defaultMove.blocksToAvoid.add(mcData.blocksByName.magma.id)
|
||
|
movements.defaultMove = defaultMove
|
||
|
|
||
|
bot.pathfinder.setMovements(defaultMove)
|
||
|
}
|
||
|
|
||
|
|
||
|
function moveNear(pos, distance = 3) {
|
||
|
const { GoalNear } = require('mineflayer-pathfinder').goals
|
||
|
cfg.quiet || bot.chat(`moving to ${pos}`)
|
||
|
|
||
|
pos = v(pos)
|
||
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||
|
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, distance))
|
||
|
}
|
||
|
|
||
|
function follow(entity, dynamic = true) {
|
||
|
console.assert(entity)
|
||
|
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
||
|
|
||
|
|
||
|
|
||
|
cfg.quiet && console.log(entity)
|
||
|
|| bot.chat(
|
||
|
`following ${entity.type
|
||
|
}: ${entity.username || entity.displayName
|
||
|
}${dynamic ? "" : " once"}`
|
||
|
)
|
||
|
|
||
|
entity = entity.entity ? entity.entity : entity
|
||
|
|
||
|
// console.log(entity)
|
||
|
|
||
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||
|
bot.pathfinder.setGoal(new GoalFollow(entity, 3), dynamic)
|
||
|
}
|
||
|
|
||
|
function hit(blockOrEntity) {
|
||
|
bot.chat(`hitting ${entity.name || entity.type}`)
|
||
|
}
|
||
|
|
||
|
function stop() {
|
||
|
bot.pathfinder.setGoal(null)
|
||
|
bot.stopDigging()
|
||
|
}
|
||
|
|
||
|
const load = (config) => {
|
||
|
cfg = config
|
||
|
bot = cfg.bot
|
||
|
cfg.move = {
|
||
|
// auto: true,
|
||
|
canDig: false,
|
||
|
// list: ["hello", "wassup"],
|
||
|
quiet: !!cfg.quiet,
|
||
|
movements: []
|
||
|
}
|
||
|
|
||
|
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
|
||
|
|
||
|
// initMoves(bot, mcData)
|
||
|
setTimeout(initMoves, 500, bot)
|
||
|
|
||
|
// bot.loadPlugin(pathfinder)
|
||
|
|
||
|
// bot.on('time', hello)
|
||
|
|
||
|
}
|
||
|
|
||
|
const unload = () => {
|
||
|
// TODO stop pathfinding maybe?
|
||
|
}
|
||
|
|
||
|
module.exports = { load, unload, stop, initMoves, moveNear, follow }
|