refactor(mover): 🔥 remove unused code + comments, minor fixes

Refactoring and fixing code.
 No major functionality change.
 Probably will have less bugs.
 - carry over how mcData is loaded
 - stop bot on unload
 - fix wrong magma block name
This commit is contained in:
jay 2020-12-24 19:57:45 +05:00
parent f2281a7cb3
commit 68e60921b1

View File

@ -1,31 +1,26 @@
// 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 mcData
let movements = []
function initMoves(bot = bot, mcData = require('minecraft-data')(bot.version)) {
function initMoves(bot = bot, mcData = bot.mcData) {
console.info(movements)
if (movements.length > 0) {
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setMovements(movements.defaultMove)
return console.warn("movements already initialized!")
}
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)
defaultMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
defaultMove.blocksToAvoid.add(mcData.blocksByName.magma_block.id)
movements.push(defaultMove)
movements.defaultMove = movements[0]
@ -46,8 +41,6 @@ function follow(entity, dynamic = true) {
console.assert(entity)
const { GoalFollow } = require('mineflayer-pathfinder').goals
cfg.quiet && console.log(entity)
|| bot.chat(
`following ${entity.type
@ -83,19 +76,16 @@ const load = (config) => {
movements: []
}
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
// initMoves(bot, mcData)
setTimeout(initMoves, 500, bot)
// bot.loadPlugin(pathfinder)
// bot.on('time', hello)
setTimeout(initMoves, 500, bot, mcData)
}
const unload = () => {
// TODO stop pathfinding maybe?
stop()
}
module.exports = { load, unload, stop, initMoves, moveNear, follow }