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 pathfinder = require('mineflayer-pathfinder').pathfinder
// const mineflayer = require('mineflayer')
// const { pathfinder } = require('mineflayer-pathfinder')
let pathfinder
const {
gameplay,
MoveTo,
@ -10,8 +11,7 @@ const {
Craft
} = require('prismarine-gameplay')
// const { Gameplay } = require('prismarine-gameplay/lib/gameplay')
// const { Vec3 } = require('vec3')
let mcData = require('minecraft-data')
const { Vec3 } = require('vec3')
let cfg = {}
let bot = {}
@ -34,8 +34,9 @@ let bot = {}
// bot.on('chat', (username, message) => mine(username, message))
function checkBlockExists(name){
if (mcData.blocksByName[name] === undefined) {
bot.chat(`${name} is not a block name`)
const item = require('minecraft-data')(bot.version).findItemOrBlockByName(name)
if (item === undefined) {
bot.chat(`${name} is not a block or item name`)
return false
} else {
return true
@ -121,10 +122,11 @@ function miner(username, message) {
itemType: command[2],
count: parseInt(command[1])
}), logError)
break
case /^collect [a-zA-Z_]+$/.test(message):
if(!checkBlockExists(command[2])) {return false}
if (!checkBlockExists(command[1])) { return false }
bot.gameplay.solveFor(
new ObtainItem({
itemType: command[1]
@ -141,7 +143,7 @@ function miner(username, message) {
}), logError)
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}
bot.gameplay.solveFor(
new Craft({
@ -152,23 +154,36 @@ function miner(username, message) {
break
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
if (player) {
bot.gameplay.solveFor(
new MoveTo({
x: player.position.x,
y: player.position.y,
z: player.position.z
}), logError)
}
// if (player) {
// bot.gameplay.solveFor(
// new MoveTo({
// x: player.position.x,
// y: player.position.y,
// z: player.position.z
// }), logError)
// }
break
}
}
function logError(err) {
if (err)
bot.chat(`Failed task: ${err.message}`)
if (err) {
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
bot = cfg.bot
mcData = mcData(bot.version)
bot.loadPlugin(pathfinder)
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
// bot.loadPlugin(pathfinder)
cfg.plugins.mover.initMoves(bot)
bot.loadPlugin(gameplay)
cfg.plugins.mover.initMoves(bot)
bot.on("chat", miner)
// bot.pathfinder.canDig
}
const unload = () => {
@ -187,4 +207,4 @@ const unload = () => {
bot.off("chat", miner)
}
module.exports = { load, unload }
module.exports = { load, unload, miner }
Loading…
Cancel
Save