Compare commits
No commits in common. "f8df1fa31974392db9f0779206f8087795d7bb1c" and "4f1e510386762e076cdd1401e2b92dd2f4e7853b" have entirely different histories.
f8df1fa319
...
4f1e510386
|
@ -6,7 +6,7 @@ let bot = {}
|
|||
// bot.chatAddPattern(new RegExp(`^hi|hello ${bot.username}`, "i"), 'greet', "General greeting")
|
||||
|
||||
function todo() {
|
||||
cfg.quiet && console.warn("not implemented") || bot.chat("not implemented yet")
|
||||
bot.chat("not implemented yet")
|
||||
}
|
||||
|
||||
function checkBlockExists(name) {
|
||||
|
@ -34,12 +34,7 @@ const events = {
|
|||
if (username === cfg.admin) {
|
||||
message = message.replace("\\", "@")
|
||||
console.info("whispered command", message)
|
||||
if (/^!/.test(message)) {
|
||||
command(username, message)
|
||||
} else {
|
||||
bot.chat(message)
|
||||
// bot.chat("/" + message)
|
||||
}
|
||||
bot.chat("/" + message)
|
||||
} else {
|
||||
bot.whisper(cfg.admin, `gossip ${username}: ${message}`)
|
||||
console.info(username, "whispered", message)
|
||||
|
@ -52,19 +47,6 @@ const events = {
|
|||
const events_registered = []
|
||||
|
||||
function command(username, message) {
|
||||
function fuzzyRespond(responses, probability = 1, timeout = 1) {
|
||||
if (Math.random() < probability) {
|
||||
const response = responses[Math.floor(Math.random() * responses.length)]
|
||||
return setTimeout(() => bot.chat(response), timeout * Math.random() * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
function swingArm(swung = 3) {
|
||||
if (swung > 0) {
|
||||
setTimeout(swingArm, 500 * Math.random(), --swung)
|
||||
bot.swingArm()
|
||||
}
|
||||
}
|
||||
|
||||
if (username === bot.username && !message.startsWith("!")) return
|
||||
|
||||
|
@ -77,29 +59,33 @@ function command(username, message) {
|
|||
return
|
||||
}
|
||||
|
||||
switch (message) {
|
||||
case "hi":
|
||||
case "hello":
|
||||
case "howdy":
|
||||
case "yo":
|
||||
bot.swingArm()
|
||||
return
|
||||
case "69":
|
||||
Math.random() > 0.5 && bot.chat("nice!")
|
||||
return
|
||||
case "awesome":
|
||||
case "cool":
|
||||
case "superb":
|
||||
case "nice":
|
||||
Math.random() > 0.1 && setTimeout(() => bot.chat("very nice!"), 1000)
|
||||
return
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (message.startsWith("!") || cfg.botAddress.test(message)) {
|
||||
message = cfg.botAddress.test(message) ? cfg.botAddress.exec(message)[1] : message
|
||||
|
||||
console.log(message)
|
||||
message = message.slice(1) // remove `!`
|
||||
// TODO command dispatchEvent, for aliases
|
||||
function subcommand(message) {
|
||||
const message_parts = message.split(/\s+/)
|
||||
|
||||
message = message.slice(1)
|
||||
message_parts = message.split(/\s+/)
|
||||
switch (message_parts[0]) {
|
||||
case "stop":
|
||||
bot.pathfinder && bot.pathfinder.setGoal(null)
|
||||
bot.stopDigging()
|
||||
bot.chat("ok")
|
||||
break;
|
||||
|
||||
case "mute":
|
||||
case "quiet":
|
||||
case "silent":
|
||||
cfg.quiet = !cfg.quiet
|
||||
cfg.quiet || bot.chat(`ok, ${cfg.quiet ? "" : "not "}being ${message_parts[0]}`)
|
||||
break;
|
||||
// case "follow":
|
||||
// // if(username === cfg.admin)
|
||||
// cfg.stateMachines.follow.transitions[4].trigger()
|
||||
|
@ -112,7 +98,7 @@ function command(username, message) {
|
|||
case "echo":
|
||||
// bot.chat(message_parts[1])
|
||||
// bot.chat(message.slice(1))
|
||||
cfg.quiet && bot.whisper(username, message) || bot.chat(message)
|
||||
bot.chat(message)
|
||||
break;
|
||||
case "autosleep":
|
||||
case "sleep":
|
||||
|
@ -156,133 +142,6 @@ function command(username, message) {
|
|||
case "wakeup":
|
||||
cfg.plugins.sleeper.wake()
|
||||
break;
|
||||
case "autoeat":
|
||||
case "eat":
|
||||
switch (message_parts[1]) {
|
||||
case "auto":
|
||||
cfg.eat.auto = !cfg.eat.auto
|
||||
bot.chat(`ok, ${cfg.eat.auto ? "" : "not "}auto eating `)
|
||||
break;
|
||||
case "at":
|
||||
case "set":
|
||||
const amount = parseInt(message_parts[2], 10)
|
||||
if (amount < 20 && amount > 0) {
|
||||
cfg.eat.startAt = amount
|
||||
cfg.eat.quiet || bot.chat(`ok, eating when hunger at ${amount}`)
|
||||
}
|
||||
break
|
||||
case "silent":
|
||||
case "quiet":
|
||||
cfg.eat.quiet = !!!cfg.eat.quiet
|
||||
break;
|
||||
default:
|
||||
cfg.plugins.eater.eat((err) => { if (err) { bot.chat(err.message) } })
|
||||
// bot.chat(`usage: !sleep [auto | quiet | timeout <mins>], or zzz for manual sleep`)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case "follow":
|
||||
subcommand("go follow me")
|
||||
break;
|
||||
case "come":
|
||||
subcommand("go follow once")
|
||||
break;
|
||||
case "move":
|
||||
case "go":
|
||||
// TODO move most of the subcommands into mover.js?
|
||||
const message_parts2 = message_parts.slice(2)
|
||||
switch (message_parts[1]) {
|
||||
case "init":
|
||||
cfg.plugins.mover.initMoves()
|
||||
break
|
||||
case "near":
|
||||
// message_parts2 = message_parts.slice(2)
|
||||
switch (message_parts2.length) {
|
||||
case 0:
|
||||
cfg.plugins.mover.moveNear(bot.nearestEntity().position)
|
||||
break
|
||||
case 1:
|
||||
switch (message_parts2[0]) {
|
||||
case "me":
|
||||
if (player) {
|
||||
cfg.plugins.mover.moveNear(player.position)
|
||||
} else {
|
||||
cfg.quiet || bot.chat("can't see you")
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
||||
if (aPlayer) {
|
||||
cfg.plugins.mover.moveNear(aPlayer.position)
|
||||
} else {
|
||||
cfg.quiet || bot.chat(`can't see ${message_parts[2]}`)
|
||||
}
|
||||
break;
|
||||
}
|
||||
break
|
||||
case 2:
|
||||
todo()
|
||||
// bot.lookAt({}) goalxz?
|
||||
break
|
||||
case 3:
|
||||
//TODO more checks
|
||||
cfg.plugins.mover.moveNear(message_parts2)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
break
|
||||
|
||||
case "follow":
|
||||
// message_parts2 = message_parts.slice(2)
|
||||
switch (message_parts2.length) {
|
||||
case 0:
|
||||
cfg.plugins.mover.follow(bot.nearestEntity())
|
||||
break
|
||||
case 1:
|
||||
switch (message_parts2[0]) {
|
||||
case "me":
|
||||
case "once":
|
||||
if (player) {
|
||||
cfg.plugins.mover.follow(player, message_parts2[0] !== "once")
|
||||
} else {
|
||||
cfg.quiet || bot.chat("can't see you")
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
||||
if (aPlayer) {
|
||||
cfg.plugins.mover.follow(aPlayer)
|
||||
} else {
|
||||
cfg.quiet || bot.chat(`can't see ${message_parts[2]}`)
|
||||
}
|
||||
break;
|
||||
}
|
||||
break
|
||||
// case 2:
|
||||
// bot.lookAt({}) goalxz?
|
||||
// break
|
||||
// case 3:
|
||||
//TODO more checks
|
||||
// cfg.plugins.mover.moveNear(message_parts2)
|
||||
// break
|
||||
default:
|
||||
todo()
|
||||
break
|
||||
}
|
||||
break
|
||||
case "stop":
|
||||
cfg.plugins.mover.stop()
|
||||
break
|
||||
default:
|
||||
return todo()
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case "attack":
|
||||
case "rage":
|
||||
case "ragemode":
|
||||
|
@ -334,41 +193,15 @@ function command(username, message) {
|
|||
case "lookat":
|
||||
// const coords = v(message_parts.splice(1))
|
||||
switch (message_parts.length) {
|
||||
case 1:
|
||||
bot.lookAt(bot.nearestEntity().position)
|
||||
break
|
||||
case 2:
|
||||
switch (message_parts[1]) {
|
||||
case "me":
|
||||
if (player) {
|
||||
bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
|
||||
} else {
|
||||
cfg.quiet || bot.chat("can't see you")
|
||||
}
|
||||
break;
|
||||
|
||||
case "this":
|
||||
// TODO lookat the block the user is looking at
|
||||
if (player) {
|
||||
bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
|
||||
todo()
|
||||
} else {
|
||||
cfg.quiet || bot.chat("can't see you")
|
||||
}
|
||||
break;
|
||||
break
|
||||
default:
|
||||
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
||||
if (aPlayer) bot.lookAt((new v.Vec3(0, 1, 0)).add(aPlayer.position))
|
||||
break;
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
todo()
|
||||
// bot.lookAt({})
|
||||
break
|
||||
case 1:
|
||||
bot.lookAt(bot.nearestEntity().position)
|
||||
break
|
||||
case 4:
|
||||
//TODO more checks
|
||||
bot.lookAt(v(message_parts.splice(1)))
|
||||
break
|
||||
default:
|
||||
|
@ -391,10 +224,7 @@ function command(username, message) {
|
|||
// bot.useOn(bot.nearestEntity())
|
||||
// break;
|
||||
|
||||
// // TODO move all inventory related tasks into inventory.js
|
||||
case "craft":
|
||||
cfg.plugins.inventory.craftItem(message_parts[1])
|
||||
break
|
||||
// // TODO move all inventory related tasks into own module
|
||||
// case "give":
|
||||
// // switch (message_parts[1]) {
|
||||
// // case "hand":
|
||||
|
@ -440,7 +270,6 @@ function command(username, message) {
|
|||
// }
|
||||
// break;
|
||||
case "location":
|
||||
// TODO put in /lib/location
|
||||
switch (message_parts[1]) {
|
||||
case "add":
|
||||
case "record":
|
||||
|
@ -454,15 +283,10 @@ function command(username, message) {
|
|||
case "where?":
|
||||
// TODO put in /lib/location
|
||||
console.log(bot.entity.position)
|
||||
if (cfg.mods.includes(username)) //anarchy
|
||||
bot.chat(
|
||||
bot.game.dimension.split(":", 2)[1].replace("_", " ")
|
||||
+ " " + bot.entity.position.floored().toString()
|
||||
)
|
||||
bot.chat(bot.entity.position.floored().toString())
|
||||
break;
|
||||
case "warp":
|
||||
// if(message_parts[1] == "spawn")
|
||||
// if (cfg.mods.includes(username)) //anarchy
|
||||
bot.chat("/" + message)
|
||||
break;
|
||||
|
||||
|
@ -470,65 +294,6 @@ function command(username, message) {
|
|||
if (cfg.mods.includes(username))
|
||||
bot.chat("/" + message)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
subcommand(message)
|
||||
} else {
|
||||
// TODO, maybe extract to a new function `fuzzychat`?, so can address direct messages
|
||||
switch (message) {
|
||||
case "wassup":
|
||||
case "what's cooking":
|
||||
case "what's new":
|
||||
case "what's up":
|
||||
case "whats cooking":
|
||||
case "whats new":
|
||||
case "whats up":
|
||||
case "sup":
|
||||
case "suh":
|
||||
fuzzyRespond([
|
||||
"jus chilin", "nothin", "random stuff"
|
||||
], 0.3, 3)
|
||||
case "hi":
|
||||
case "hey":
|
||||
case "hello":
|
||||
case "ola":
|
||||
case "howdy":
|
||||
case "heyo":
|
||||
case "yo":
|
||||
if (player) bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
|
||||
|
||||
// TODO sneak
|
||||
// function swingArm() {
|
||||
// if (swung > 0) {
|
||||
// setTimeout(swing, 500 * Math.random())
|
||||
// bot.p()
|
||||
// swung--
|
||||
// }
|
||||
// }
|
||||
|
||||
setTimeout(swingArm, 1000, 4) // or sneak greating
|
||||
return
|
||||
case "F":
|
||||
return fuzzyRespond(["F"], 0.9, 1)
|
||||
case "RIP":
|
||||
return fuzzyRespond(["F", "oh no"], 0.3, 2)
|
||||
case "69":
|
||||
case "cool":
|
||||
Math.random() < 0.5 && bot.chat("nice!")
|
||||
return
|
||||
case "awesome":
|
||||
case "superb":
|
||||
case "nice":
|
||||
case "nice!":
|
||||
return fuzzyRespond(["cool", "very nice!"], 0.3, 5)
|
||||
case "good bot":
|
||||
return fuzzyRespond(["thanks", "why, thank you!", ":)", "(:", "you're too kind!"], 1, 5)
|
||||
case "bad bot":
|
||||
case "not nice":
|
||||
return fuzzyRespond([":(", "):", "sorry"], 0.1, 10)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,10 @@ let cfg = {}
|
|||
let bot = {}
|
||||
let guardPos
|
||||
|
||||
const filterAllMobs = e => e.type === 'mob'
|
||||
const filterPlayers = e => e.type === 'player'
|
||||
const filterMods = e => e.type === 'player' && [cfg.mods].includes(e.username)
|
||||
const filterallMobs = e => e.type === 'mob'
|
||||
// const filterPlayers = e => e.type === 'player' && e.username !== 'Applezaus'
|
||||
// const filterPassiveMobs = e => e.kind === 'Passive mobs'
|
||||
const filterCreeper = e => e.mobType === 'Creeper'
|
||||
// const filterCreeperOrEndermen = e => ['Creeper', 'EndderMen'].includes(e.mobType) //TODO endmen hostile by default?
|
||||
const filterHostileMobs = e => e.kind === 'Hostile mobs'
|
||||
// // not needed if detecting by kind
|
||||
// && e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
|
||||
|
@ -62,56 +60,33 @@ function lookForMobs() {
|
|||
const filter = e => e.position.distanceTo(bot.entity.position) < 16 && filterHostileMobs(e)
|
||||
|
||||
const entityEnemy = bot.nearestEntity(filter)
|
||||
if (entityEnemy && !filterCreeper(entityEnemy)) {
|
||||
// if(filterCreeper(entityEnemy))
|
||||
if (entityEnemy) {
|
||||
if(filterCreeper(entityEnemy))
|
||||
// Start attacking
|
||||
// bot.off('time', lookForMobs)
|
||||
// bot.on('physicTick', lookForMobs)
|
||||
bot.pvp.movements.canDig = !!cfg.move && cfg.move.canDig
|
||||
bot.pvp.attack(entityEnemy)
|
||||
} else if (entityEnemy) {
|
||||
bot.lookAt(
|
||||
// (new v.Vec3(0, 1, 0)).add(
|
||||
entityEnemy.position
|
||||
// )
|
||||
)
|
||||
cfg.quiet || bot.chat("AH! A creeper! They creep me out!")
|
||||
}
|
||||
}
|
||||
|
||||
function guardSelf(entity) {
|
||||
if (!cfg.guard.self || entity !== bot.entity || guardPos) return // Do nothing
|
||||
// bot.chat("")
|
||||
const hurtMessages = [
|
||||
"ouch!", "oww!", "help", "monster!"
|
||||
]
|
||||
const hurtMessagesPlayer = [
|
||||
"leave me alone!", "don't hurt me!", "bully!", "go away!", "stop", "no stop", "stop it", "murderer!",
|
||||
"what have i ever done to you? :(",
|
||||
]
|
||||
console.info(bot.nearestEntity(filterAllMobs))
|
||||
bot.chat((
|
||||
() => { const a = ["ouch!", "oww!", "help", "", "", ""]; return a[Math.floor(Math.random() * a.length)] }
|
||||
)())
|
||||
|
||||
// Only look for mobs within 5 blocks
|
||||
// const filter = e => e.position.distanceTo(bot.entity.position) < 5 && filterHostileMobs(e) || filterPlayers(e) && !filterMods(e)//anarchy
|
||||
const filter = e => e.position.distanceTo(bot.entity.position) < 5 && filterHostileMobs(e)
|
||||
console.info(bot.nearestEntity(filterallMobs))
|
||||
|
||||
// Only look for mobs within 10 blocks
|
||||
const filter = e => e.position.distanceTo(bot.entity.position) < 10 && filterHostileMobs(e)
|
||||
|
||||
const entityEnemy = bot.nearestEntity(filter)
|
||||
|
||||
cfg.quiet || 0.2 < Math.random() && entityEnemy && bot.chat(
|
||||
// TODO use fuzzy message function
|
||||
filterPlayers(entityEnemy) ?
|
||||
hurtMessagesPlayer[Math.floor(Math.random() * hurtMessagesPlayer.length)]
|
||||
:
|
||||
hurtMessages[Math.floor(Math.random() * hurtMessages.length)]
|
||||
|
||||
)
|
||||
|
||||
if (entityEnemy && !filterCreeper(entityEnemy)) {
|
||||
// Start attacking
|
||||
// bot.off('time', lookForMobs)
|
||||
// bot.on('physicTick', lookForMobs)
|
||||
bot.pvp.attack(entityEnemy)
|
||||
bot.pvp.movements.canDig = !!cfg.move && cfg.move.canDig
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,18 +10,22 @@
|
|||
*/
|
||||
const mineflayer = require('mineflayer')
|
||||
|
||||
// if (process.argv.length < 4 || process.argv.length > 6) {
|
||||
// console.log('Usage : node inventory.js <host> <port> [<name>] [<password>]')
|
||||
// process.exit(1)
|
||||
// }
|
||||
|
||||
// const bot = mineflayer.createBot({
|
||||
// host: process.argv[2],
|
||||
// port: parseInt(process.argv[3]),
|
||||
// username: process.argv[4] ? process.argv[4] : 'inventory',
|
||||
// password: process.argv[5]
|
||||
// })
|
||||
|
||||
let cfg = {}
|
||||
let bot = {}
|
||||
// let mcd
|
||||
|
||||
const alt_destinations = {
|
||||
offhand: "off-hand",
|
||||
lefthand: "off-hand",
|
||||
shield: "off-hand",
|
||||
chest: "torso",
|
||||
}
|
||||
|
||||
function inventory(username, message) {
|
||||
if (username === bot.username) return
|
||||
const command = message.split(' ')
|
||||
|
@ -68,8 +72,8 @@ function inventory(username, message) {
|
|||
|
||||
function sayItems(items = bot.inventory.items()) {
|
||||
const output = items.map(itemToString).join(', ')
|
||||
console.info("inventory:", output)
|
||||
if (output) {
|
||||
console.info("inventory:", output)
|
||||
!cfg.quiet && bot.chat(output)
|
||||
} else {
|
||||
!cfg.quiet && bot.chat('empty')
|
||||
|
@ -100,20 +104,8 @@ function tossItem(name, amount) {
|
|||
|
||||
function equipItem(name, destination, quiet = false) {
|
||||
const item = itemByName(name)
|
||||
|
||||
if (item) {
|
||||
if (Object.keys(alt_destinations).includes(destination)) {
|
||||
destination = alt_destinations[destination]
|
||||
}
|
||||
try {
|
||||
bot.equip(item, destination, checkIfEquipped)
|
||||
} catch (error) {
|
||||
if (error.code == 'ERR_ASSERTION' && error.message.startsWith("invalid destination:")) {
|
||||
bot.chat(error.message)
|
||||
} else {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
!quiet && bot.chat(`I have no ${name}`)
|
||||
}
|
||||
|
@ -128,9 +120,6 @@ function equipItem(name, destination, quiet = false) {
|
|||
}
|
||||
|
||||
function unequipItem(destination) {
|
||||
if (Object.keys(alt_destinations).includes(destination)) {
|
||||
destination = alt_destinations[destination]
|
||||
}
|
||||
bot.unequip(destination, (err) => {
|
||||
if (err) {
|
||||
bot.chat(`cannot unequip: ${err.message}`)
|
||||
|
@ -145,54 +134,27 @@ function useEquippedItem() {
|
|||
bot.activateItem()
|
||||
}
|
||||
|
||||
function craftItem(name, amount = 1) {
|
||||
function craftItem(name, amount) {
|
||||
amount = parseInt(amount, 10)
|
||||
const mcData = require('minecraft-data')(bot.version)
|
||||
const item = mcData.findItemOrBlockByName(name)
|
||||
const item = require('minecraft-data')(bot.version).findItemOrBlockByName(name)
|
||||
const craftingTable = bot.findBlock({
|
||||
matching: mcData.blocksByName["crafting_table"].id
|
||||
matching: 58
|
||||
})
|
||||
|
||||
const recipesNoTable = bot.recipesFor(item.id)
|
||||
let recipes
|
||||
|
||||
if (recipesNoTable.length > 0) {
|
||||
bot.chat("can make without crafting table!")
|
||||
recipes = recipesNoTable
|
||||
} else if (craftingTable) {
|
||||
recipes = bot.recipesFor(item.id, null, null, craftingTable)
|
||||
} else {
|
||||
bot.chat("Couldn't find a crafting table. Maybe craft one?")
|
||||
}
|
||||
|
||||
if (item) {
|
||||
let craftSuccess
|
||||
recipes && cfg.quiet || bot.chat(`${recipes.length} recipes`)
|
||||
for (let recipe in recipes) {
|
||||
if (craftSuccess) {
|
||||
break
|
||||
}
|
||||
setTimeout(craftIt, Math.random() * 5000, recipes[recipe], amount, craftingTable)
|
||||
}
|
||||
function craftIt(recipe, amount, craftingTable) {
|
||||
cfg.quiet || bot.chat(`I can make ${name}`)
|
||||
console.log("craft:", recipe)
|
||||
console.time("craft recipe")
|
||||
bot.craft(recipe, amount, craftingTable, craftError)
|
||||
console.timeEnd("craft recipe")
|
||||
}
|
||||
function craftError(err) {
|
||||
const recipe = bot.recipesFor(item.id, null, 1, craftingTable)[0]
|
||||
if (recipe) {
|
||||
bot.chat(`I can make ${name}`)
|
||||
bot.craft(recipe, amount, craftingTable, (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
cfg.quiet || bot.chat(`error making ${name}: ${err.message}`)
|
||||
// continue
|
||||
bot.chat(`error making ${name}`)
|
||||
} else {
|
||||
craftSuccess = true
|
||||
bot.chat(`did the recipe for ${name} ${amount} times`)
|
||||
// break
|
||||
}
|
||||
})
|
||||
} else {
|
||||
bot.chat(`I cannot make ${name}`)
|
||||
}
|
||||
craftSuccess || cfg.quiet || bot.chat(`I couldn't make ${name}`)
|
||||
} else {
|
||||
bot.chat(`unknown item: ${name}`)
|
||||
}
|
||||
|
@ -225,4 +187,4 @@ const unload = () => {
|
|||
bot.off('chat', inventory)
|
||||
}
|
||||
|
||||
module.exports = { load, unload, equipItem, craftItem }
|
||||
module.exports = { load, unload, equipItem }
|
|
@ -1,6 +1,5 @@
|
|||
// const mineflayer = require('mineflayer')
|
||||
// const { pathfinder } = require('mineflayer-pathfinder')
|
||||
let pathfinder
|
||||
const mineflayer = require('mineflayer')
|
||||
const pathfinder = require('mineflayer-pathfinder').pathfinder
|
||||
const {
|
||||
gameplay,
|
||||
MoveTo,
|
||||
|
@ -11,7 +10,8 @@ const {
|
|||
Craft
|
||||
} = require('prismarine-gameplay')
|
||||
// const { Gameplay } = require('prismarine-gameplay/lib/gameplay')
|
||||
const { Vec3 } = require('vec3')
|
||||
// const { Vec3 } = require('vec3')
|
||||
let mcData = require('minecraft-data')
|
||||
|
||||
let cfg = {}
|
||||
let bot = {}
|
||||
|
@ -34,9 +34,8 @@ let bot = {}
|
|||
// bot.on('chat', (username, message) => mine(username, message))
|
||||
|
||||
function checkBlockExists(name){
|
||||
const item = require('minecraft-data')(bot.version).findItemOrBlockByName(name)
|
||||
if (item === undefined) {
|
||||
bot.chat(`${name} is not a block or item name`)
|
||||
if (mcData.blocksByName[name] === undefined) {
|
||||
bot.chat(`${name} is not a block name`)
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
|
@ -122,11 +121,10 @@ function miner(username, message) {
|
|||
itemType: command[2],
|
||||
count: parseInt(command[1])
|
||||
}), logError)
|
||||
|
||||
break
|
||||
|
||||
case /^collect [a-zA-Z_]+$/.test(message):
|
||||
if (!checkBlockExists(command[1])) { return false }
|
||||
if(!checkBlockExists(command[2])) {return false}
|
||||
bot.gameplay.solveFor(
|
||||
new ObtainItem({
|
||||
itemType: command[1]
|
||||
|
@ -143,7 +141,7 @@ function miner(username, message) {
|
|||
}), logError)
|
||||
break
|
||||
|
||||
case /^craftmine [0-9]+ [a-zA-Z_]+$/.test(message):
|
||||
case /^craft [0-9]+ [a-zA-Z_]+$/.test(message):
|
||||
if(!checkBlockExists(command[2])) {return false}
|
||||
bot.gameplay.solveFor(
|
||||
new Craft({
|
||||
|
@ -154,36 +152,23 @@ function miner(username, message) {
|
|||
break
|
||||
|
||||
case /^stop$/.test(message):
|
||||
cfg.quiet || bot.chat("♪♪ can't stop me now!! ♪♪")
|
||||
bot.pathfinder.setGoal(null)
|
||||
bot.stopDigging()
|
||||
bot.chat("♪♪ can't stop me now!! ♪♪")
|
||||
// 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (err)
|
||||
bot.chat(`Failed task: ${err.message}`)
|
||||
}
|
||||
|
||||
|
||||
|
@ -191,15 +176,10 @@ const load = (config) => {
|
|||
cfg = config
|
||||
bot = cfg.bot
|
||||
|
||||
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
|
||||
// bot.loadPlugin(pathfinder)
|
||||
cfg.plugins.mover.initMoves(bot)
|
||||
|
||||
mcData = mcData(bot.version)
|
||||
bot.loadPlugin(pathfinder)
|
||||
bot.loadPlugin(gameplay)
|
||||
cfg.plugins.mover.initMoves(bot)
|
||||
bot.on("chat", miner)
|
||||
|
||||
// bot.pathfinder.canDig
|
||||
}
|
||||
|
||||
const unload = () => {
|
||||
|
@ -207,4 +187,4 @@ const unload = () => {
|
|||
bot.off("chat", miner)
|
||||
}
|
||||
|
||||
module.exports = { load, unload, miner }
|
||||
module.exports = { load, unload }
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
let pathfinder
|
||||
//TODO replace with simple pathfinder motions
|
||||
const pathfinder = require('mineflayer-pathfinder').pathfinder
|
||||
const { Bot } = require('mineflayer')
|
||||
const {
|
||||
gameplay,
|
||||
MoveTo,
|
||||
|
@ -71,7 +71,6 @@ function sleep(quiet) {
|
|||
)
|
||||
// bot.chat('/afk')
|
||||
}
|
||||
bot.pathfinder.movements
|
||||
}
|
||||
|
||||
function wake() {
|
||||
|
@ -87,7 +86,7 @@ function wake() {
|
|||
function autoSleep() {
|
||||
if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
|
||||
sleep()
|
||||
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
|
||||
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout) // give 2 seconds for multiple events
|
||||
console.log("sleeping?", bot.isSleeping, bot.time)
|
||||
}
|
||||
}
|
||||
|
@ -99,11 +98,10 @@ const load = (config) => {
|
|||
auto: true,
|
||||
// timeout: 30 * 1000,
|
||||
timeout: 2 * 60 * 1000,
|
||||
quiet: !!cfg.quiet
|
||||
quiet: false
|
||||
}
|
||||
|
||||
pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder
|
||||
// bot.loadPlugin(pathfinder)
|
||||
bot.loadPlugin(pathfinder)
|
||||
bot.loadPlugin(gameplay)
|
||||
inv = cfg.plugins["inventory"]
|
||||
bot.on("time", autoSleep)
|
||||
|
|
Loading…
Reference in New Issue
Block a user