Compare commits

..

No commits in common. "288b7045b6189cd89935446fd2ced6488e89a8b3" and "086251bce60b9f98346432b501d2aa8c20e2c020" have entirely different histories.

5 changed files with 48 additions and 82 deletions

View File

@ -95,14 +95,13 @@ cfg.quiet = true
bot.once("spawn", () => { bot.once("spawn", () => {
plugins = { plugins = {
command: require('./plugins/command'), command: require('./plugins/command'),
eater: require('./plugins/eater'),
inventory: require('./plugins/inventory'),
informer: require('./plugins/informer'),
finder: require('./plugins/finder'),
sleeper: require('./plugins/sleeper'), sleeper: require('./plugins/sleeper'),
armor: require('./plugins/armor'), armor: require('./plugins/armor'),
mover: require('./plugins/mover'), mover: require('./plugins/mover'),
guard: require('./plugins/guard'), guard: require('./plugins/guard'),
inventory: require('./plugins/inventory'),
eater: require('./plugins/eater'),
finder: require('./plugins/finder'),
// miner: require('./plugins/miner.js'), // miner: require('./plugins/miner.js'),
// statemachine: require('./plugins/statemachine'), // statemachine: require('./plugins/statemachine'),
} }

View File

@ -1,5 +1,5 @@
const v = require('vec3') const v = require('vec3')
let mcData let mcData = require('minecraft-data')
let cfg = {} let cfg = {}
let bot = {} let bot = {}
@ -426,51 +426,29 @@ function command(username, message) {
// case "take": // case "take":
// // TODO take only what's requested, then throw all the rest // // TODO take only what's requested, then throw all the rest
// // TODO take all // // TODO take all
// case "toss":
// TODO move subcommands to cfg.plugins.inventory.itemByName // case "drop":
case "toss": // if (!message_parts[1]) { return false } // FIXME, works but ugly
case "drop": // if (!checkItemExists(message_parts[1])) { return false }
if (!message_parts[1]) { return false } // FIXME, works but ugly // switch (message_parts.length) {
// TODO use cfg.plugins.inventory.itemByName // case 2:
const item = cfg.plugins.inventory.itemByName(message_parts[1]) // bot.toss(mcData.blocksByName[message_parts[1]].id)
if (!mcData.findItemOrBlockByName(message_parts[1])) { // break
console.log("doesn't exist:", message_parts[1]) // case 3:
cfg.quiet || bot.chat(`item doesn't exist: ${message_parts[1]}`) // bot.tossStack(
return false // mcData.itemsByName[message_parts[1]].id,
} else if (!item) { // (err) => {
console.log("don't have:", message_parts[1]) // if (err) {
cfg.quiet || bot.chat(`don't have item: ${message_parts[1]}`) // console.log(err)
} // bot.chat(err)
switch (message_parts.length) { // }
case 2: // }
bot.tossStack( // )
item, // break
(err) => { // default:
if (err) { // break
console.error(err) // }
cfg.quiet || bot.chat(err.message) // break;
}
}
)
break
case 3:
const amount = parseInt(message_parts[2])
bot.toss(
item.type,
null, //metadata
amount,
(err) => {
if (err) {
console.error(err)
cfg.quiet || bot.chat(err.message)
}
}
)
break
default:
break
}
break;
case "location": case "location":
// TODO put in /lib/location // TODO put in /lib/location
switch (message_parts[1]) { switch (message_parts[1]) {
@ -569,12 +547,13 @@ const load = (config) => {
cfg = config cfg = config
bot = cfg.bot bot = cfg.bot
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version)) mcData = mcData(bot.version)
for (const [key, fn] of Object.entries(events)) { for (const [key, fn] of Object.entries(events)) {
events_registered.push( events_registered.push(
bot.on(key, fn) bot.on(key, fn)
) )
} }
mcData = require('minecraft-data')(bot.version)
} }
const unload = () => { const unload = () => {

View File

@ -1,22 +0,0 @@
let cfg
let bot
let mcData
function info() {
const block = bot.blockAtCursor()
console.log(block)
cfg.quiet || bot.chat([block.id, block.name])
}
const load = (config) => {
cfg = config
bot = cfg.bot
cfg.info = {
quiet: cfg.quiet,
}
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
}
const unload = () => {}
module.exports = { load, unload, info }

View File

@ -225,4 +225,4 @@ const unload = () => {
bot.off('chat', inventory) bot.off('chat', inventory)
} }
module.exports = { load, unload, equipItem, craftItem, itemByName } module.exports = { load, unload, equipItem, craftItem }

View File

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