feat: update miner

nogameplay
jay 3 years ago
parent 149a01551c
commit 5ead6b7267
  1. 64
      lib/plugins/miner.js

@ -1,5 +1,6 @@
const mineflayer = require('mineflayer') // const mineflayer = require('mineflayer')
const pathfinder = require('mineflayer-pathfinder').pathfinder // const { pathfinder } = require('mineflayer-pathfinder')
let pathfinder
const { const {
gameplay, gameplay,
MoveTo, MoveTo,
@ -10,8 +11,7 @@ const {
Craft Craft
} = require('prismarine-gameplay') } = require('prismarine-gameplay')
// const { Gameplay } = require('prismarine-gameplay/lib/gameplay') // const { Gameplay } = require('prismarine-gameplay/lib/gameplay')
// const { Vec3 } = require('vec3') const { Vec3 } = require('vec3')
let mcData = require('minecraft-data')
let cfg = {} let cfg = {}
let bot = {} let bot = {}
@ -34,8 +34,9 @@ let bot = {}
// bot.on('chat', (username, message) => mine(username, message)) // bot.on('chat', (username, message) => mine(username, message))
function checkBlockExists(name){ function checkBlockExists(name){
if (mcData.blocksByName[name] === undefined) { const item = require('minecraft-data')(bot.version).findItemOrBlockByName(name)
bot.chat(`${name} is not a block name`) if (item === undefined) {
bot.chat(`${name} is not a block or item name`)
return false return false
} else { } else {
return true return true
@ -121,10 +122,11 @@ function miner(username, message) {
itemType: command[2], itemType: command[2],
count: parseInt(command[1]) count: parseInt(command[1])
}), logError) }), logError)
break break
case /^collect [a-zA-Z_]+$/.test(message): case /^collect [a-zA-Z_]+$/.test(message):
if(!checkBlockExists(command[2])) {return false} if (!checkBlockExists(command[1])) { return false }
bot.gameplay.solveFor( bot.gameplay.solveFor(
new ObtainItem({ new ObtainItem({
itemType: command[1] itemType: command[1]
@ -141,7 +143,7 @@ function miner(username, message) {
}), logError) }), logError)
break break
case /^craft [0-9]+ [a-zA-Z_]+$/.test(message): case /^craftmine [0-9]+ [a-zA-Z_]+$/.test(message):
if(!checkBlockExists(command[2])) {return false} if(!checkBlockExists(command[2])) {return false}
bot.gameplay.solveFor( bot.gameplay.solveFor(
new Craft({ new Craft({
@ -152,23 +154,36 @@ function miner(username, message) {
break break
case /^stop$/.test(message): case /^stop$/.test(message):
bot.chat("♪♪ can't stop me now!! ♪♪") cfg.quiet || bot.chat("♪♪ can't stop me now!! ♪♪")
bot.pathfinder.setGoal(null)
bot.stopDigging()
// player = bot.player.entity // player = bot.player.entity
if (player) { // if (player) {
bot.gameplay.solveFor( // bot.gameplay.solveFor(
new MoveTo({ // new MoveTo({
x: player.position.x, // x: player.position.x,
y: player.position.y, // y: player.position.y,
z: player.position.z // z: player.position.z
}), logError) // }), logError)
} // }
break break
} }
} }
function logError(err) { function logError(err) {
if (err) if (err) {
bot.chat(`Failed task: ${err.message}`) switch (err.message) {
case "No more solutions available!":
console.log("miner: failed")
cfg.quiet || bot.chat("miner: out of solutions")
break;
default:
console.log(err)
cfg.quiet || bot.chat("miner: unknown error, check logs")
break;
}
}
} }
@ -176,10 +191,15 @@ const load = (config) => {
cfg = config cfg = config
bot = cfg.bot bot = cfg.bot
mcData = mcData(bot.version) pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
bot.loadPlugin(pathfinder) // bot.loadPlugin(pathfinder)
cfg.plugins.mover.initMoves(bot)
bot.loadPlugin(gameplay) bot.loadPlugin(gameplay)
cfg.plugins.mover.initMoves(bot)
bot.on("chat", miner) bot.on("chat", miner)
// bot.pathfinder.canDig
} }
const unload = () => { const unload = () => {
@ -187,4 +207,4 @@ const unload = () => {
bot.off("chat", miner) bot.off("chat", miner)
} }
module.exports = { load, unload } module.exports = { load, unload, miner }
Loading…
Cancel
Save