Compare commits
57 Commits
de0af4d2ac
...
cover
Author | SHA1 | Date | |
---|---|---|---|
|
6a1ab4dd91 | ||
|
2f88eedce9 | ||
|
a0893f2b29 | ||
|
b1a592dbbd | ||
|
f336e3d736 | ||
|
d953bd4cf6 | ||
|
fc43985337 | ||
|
6b1157147d | ||
|
e6d29576e7 | ||
|
974d460061 | ||
|
1d361e04a6 | ||
|
7597620626 | ||
|
e5faa6f022 | ||
|
cc18ac5c2e | ||
|
7050a1621b | ||
|
7cbfa16476 | ||
|
63849e0729 | ||
|
4e7f8d59fd | ||
|
7b2b936f81 | ||
|
8a39596b1d | ||
|
2601b7cfb1 | ||
|
67932b2f6a | ||
|
9a6e684b11 | ||
|
3488a94233 | ||
|
4d21327086 | ||
|
e74d796124 | ||
|
3d5ffe38cd | ||
|
b519913355 | ||
|
b1dab1968c | ||
|
3219ec6155 | ||
|
f38ad8c819 | ||
|
4b8a39d38c | ||
|
6b71de0356 | ||
|
96214ffe37 | ||
|
034f8d331a | ||
|
69d0f5830d | ||
|
8e719d5ccf | ||
|
112eb04a8d | ||
|
ba7c53be0c | ||
|
5b4718fa5d | ||
|
902732c6dd | ||
|
65d13a3379 | ||
|
288b7045b6 | ||
|
94574a4296 | ||
|
68e60921b1 | ||
|
f2281a7cb3 | ||
|
e9f2080556 | ||
|
086251bce6 | ||
|
0ae961521f | ||
|
eae4e95803 | ||
|
fb066ee8a5 | ||
|
f4445749e6 | ||
|
bf45a53f08 | ||
|
a7ccb08d43 | ||
|
8e4eb7748f | ||
|
47a944fe2a | ||
|
1a3c345017 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
|
56
.vscode/launch.json
vendored
56
.vscode/launch.json
vendored
@@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Hover to view descriptions of existing attributes.
|
// Hover to view descriptions of existing attributes.
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "protospace",
|
"name": "protospace",
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/lib/index.js",
|
"program": "${workspaceFolder}/lib/index.js",
|
||||||
"args": ["games.protospace.ca"]
|
"args": ["games.protospace.ca"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Launch Program",
|
"name": "Launch Program",
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/lib/index.js",
|
"program": "${workspaceFolder}/lib/index.js",
|
||||||
// port may need to be changed for each session
|
// port may need to be changed for each session
|
||||||
"args": ["localhost", "56901"]
|
"args": ["localhost", "56901"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"conventionalCommits.scopes": [
|
||||||
|
"command",
|
||||||
|
"mover",
|
||||||
|
"sleeper",
|
||||||
|
"informer"
|
||||||
|
]
|
||||||
|
}
|
42
lib/index.js
42
lib/index.js
@@ -9,19 +9,22 @@ let cfg = {
|
|||||||
const mineflayer = require("mineflayer");
|
const mineflayer = require("mineflayer");
|
||||||
// const { createGetAccessor } = require('typescript');
|
// const { createGetAccessor } = require('typescript');
|
||||||
|
|
||||||
const bot =
|
const options = !isNaN(parseInt(process.argv[3])) && parseInt(process.argv[3]) > 1e2 ?
|
||||||
!isNaN(parseInt(process.argv[3])) && parseInt(process.argv[3]) > 1e2 ?
|
{
|
||||||
mineflayer.createBot({
|
host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost', // Change this to the ip you want.
|
||||||
host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost', // Change this to the ip you want.
|
port: parseInt(process.argv[3]) || process.env.MINECRAFT_PORT || env.MINECRAFT_PORT // || 58471,
|
||||||
port: parseInt(process.argv[3]) || process.env.MINECRAFT_PORT || env.MINECRAFT_PORT // || 58471,
|
}
|
||||||
})
|
:
|
||||||
:
|
{
|
||||||
mineflayer.createBot({
|
host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost', // Change this to the ip you want.
|
||||||
host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost', // Change this to the ip you want.
|
username: process.argv[3] || process.env.MINECRAFT_USER || env.MINECRAFT_USER,
|
||||||
username: process.argv[3] || process.env.MINECRAFT_USER || env.MINECRAFT_USER,
|
password: process.argv[4] || process.env.MINECRAFT_PASS || env.MINECRAFT_PASS,
|
||||||
password: process.argv[4] || process.env.MINECRAFT_PASS || env.MINECRAFT_PASS,
|
// port: process.argv[5] || process.env.MINECRAFT_PORT || 58471,
|
||||||
// port: process.argv[5] || process.env.MINECRAFT_PORT || 58471,
|
}
|
||||||
})
|
|
||||||
|
const bot = mineflayer.createBot(options)
|
||||||
|
|
||||||
|
cfg.botOptions = options
|
||||||
|
|
||||||
|
|
||||||
let plugins = {}
|
let plugins = {}
|
||||||
@@ -29,7 +32,7 @@ let plugins = {}
|
|||||||
function loadplugin(pluginname, pluginpath) {
|
function loadplugin(pluginname, pluginpath) {
|
||||||
try {
|
try {
|
||||||
plugins[pluginname] = require(pluginpath)
|
plugins[pluginname] = require(pluginpath)
|
||||||
plugins[pluginname]?.load(cfg)
|
plugins[pluginname].load(cfg)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code == 'MODULE_NOT_FOUND') {
|
if (error.code == 'MODULE_NOT_FOUND') {
|
||||||
console.warn('plugin not used:', pluginpath)
|
console.warn('plugin not used:', pluginpath)
|
||||||
@@ -44,7 +47,7 @@ function unloadplugin(pluginname, pluginpath) {
|
|||||||
const plugin = require.resolve(pluginpath)
|
const plugin = require.resolve(pluginpath)
|
||||||
try {
|
try {
|
||||||
if (plugin && require.cache[plugin]) {
|
if (plugin && require.cache[plugin]) {
|
||||||
require.cache[plugin].exports?.unload()
|
require.cache[plugin].exports.unload()
|
||||||
delete plugins[pluginname]
|
delete plugins[pluginname]
|
||||||
delete require.cache[plugin]
|
delete require.cache[plugin]
|
||||||
}
|
}
|
||||||
@@ -92,14 +95,15 @@ 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'),
|
// miner: require('./plugins/miner.js'),
|
||||||
eater: require('./plugins/eater'),
|
|
||||||
finder: require('./plugins/finder'),
|
|
||||||
miner: require('./plugins/miner'),
|
|
||||||
// statemachine: require('./plugins/statemachine'),
|
// statemachine: require('./plugins/statemachine'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
const v = require('vec3')
|
const v = require('vec3')
|
||||||
let mcData = require('minecraft-data')
|
let mcData
|
||||||
|
|
||||||
let cfg = {}
|
let cfg = {}
|
||||||
let bot = {}
|
let bot = {}
|
||||||
@@ -46,7 +46,17 @@ const events = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
, chat: command
|
, chat: command
|
||||||
, kicked: (reason, loggedIn) => console.warn(reason, loggedIn)
|
, kicked: function rejoin(reason, loggedIn) {
|
||||||
|
console.warn(reason, loggedIn && "logged_in")
|
||||||
|
if (reason.extra && reason.extra[0].text === "Server closed") {
|
||||||
|
bot.quit()
|
||||||
|
bot.end()
|
||||||
|
// TODO implement all startup features (maybe refactor all into a single function / module?)
|
||||||
|
setTimeout((bot, cfg) => {
|
||||||
|
bot = mineflayer.createBot(cfg.botOptions)
|
||||||
|
}, 15 * 60 * 1000, bot, cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const events_registered = []
|
const events_registered = []
|
||||||
@@ -183,105 +193,45 @@ function command(username, message) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "follow":
|
case "follow":
|
||||||
subcommand("go follow me")
|
switch (message_parts.length) {
|
||||||
break;
|
case 1:
|
||||||
case "come":
|
subcommand("go follow me")
|
||||||
subcommand("go follow once")
|
break;
|
||||||
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:
|
default:
|
||||||
return todo()
|
subcommand("go " + message)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "come":
|
||||||
|
switch (message_parts[1]) {
|
||||||
|
case "close":
|
||||||
|
case "closer":
|
||||||
|
subcommand("go follow close")
|
||||||
|
break
|
||||||
|
case "up":
|
||||||
|
case "down":
|
||||||
|
cfg.plugins.mover.moveY(player.position)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
subcommand("go follow once")
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "ride":
|
||||||
|
case "mount":
|
||||||
|
cfg.plugins.mover.command(message_parts)
|
||||||
|
break
|
||||||
|
case "unride":
|
||||||
|
case "getoff":
|
||||||
|
case "unmount":
|
||||||
|
case "dismount":
|
||||||
|
bot.dismount()
|
||||||
|
bot.vehicle = void 0
|
||||||
|
break
|
||||||
|
case "move":
|
||||||
|
case "go":
|
||||||
|
cfg.plugins.mover.command(message_parts.slice(1), player)
|
||||||
|
break;
|
||||||
|
|
||||||
case "attack":
|
case "attack":
|
||||||
case "rage":
|
case "rage":
|
||||||
@@ -331,6 +281,8 @@ function command(username, message) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
// TODO move look (and maybe find) to informer plugin?
|
||||||
|
case "look":
|
||||||
case "lookat":
|
case "lookat":
|
||||||
// const coords = v(message_parts.splice(1))
|
// const coords = v(message_parts.splice(1))
|
||||||
switch (message_parts.length) {
|
switch (message_parts.length) {
|
||||||
@@ -349,13 +301,12 @@ function command(username, message) {
|
|||||||
|
|
||||||
case "this":
|
case "this":
|
||||||
// TODO lookat the block the user is looking at
|
// TODO lookat the block the user is looking at
|
||||||
|
// Currently looks player position
|
||||||
if (player) {
|
if (player) {
|
||||||
bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
|
bot.lookAt(player.position)
|
||||||
todo()
|
|
||||||
} else {
|
} else {
|
||||||
cfg.quiet || bot.chat("can't see you")
|
cfg.quiet || bot.chat("can't see you")
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
||||||
@@ -375,17 +326,8 @@ function command(username, message) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "ride":
|
case "info":
|
||||||
case "mount":
|
cfg.plugins.informer.command(message_parts.splice(1))
|
||||||
bot.mount(bot.nearestEntity())
|
|
||||||
break
|
|
||||||
case "getoff":
|
|
||||||
case "unmount":
|
|
||||||
case "dismount":
|
|
||||||
bot.dismount()
|
|
||||||
break
|
|
||||||
case "go":
|
|
||||||
bot.moveVehicle(0, 10)
|
|
||||||
break
|
break
|
||||||
// case "use":
|
// case "use":
|
||||||
// bot.useOn(bot.nearestEntity())
|
// bot.useOn(bot.nearestEntity())
|
||||||
@@ -416,29 +358,52 @@ 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":
|
|
||||||
// case "drop":
|
// TODO move subcommands to cfg.plugins.inventory.itemByName
|
||||||
// if (!message_parts[1]) { return false } // FIXME, works but ugly
|
case "toss":
|
||||||
// if (!checkItemExists(message_parts[1])) { return false }
|
case "drop":
|
||||||
// switch (message_parts.length) {
|
if (!message_parts[1]) { return false } // FIXME, works but ugly
|
||||||
// case 2:
|
if (!mcData.findItemOrBlockByName(message_parts[1])) {
|
||||||
// bot.toss(mcData.blocksByName[message_parts[1]].id)
|
console.log("doesn't exist:", message_parts[1])
|
||||||
// break
|
cfg.quiet || bot.chat(`item doesn't exist: ${message_parts[1]}`)
|
||||||
// case 3:
|
return false
|
||||||
// bot.tossStack(
|
}
|
||||||
// mcData.itemsByName[message_parts[1]].id,
|
const item = cfg.plugins.inventory.itemByName(message_parts[1])
|
||||||
// (err) => {
|
if (!item) {
|
||||||
// if (err) {
|
console.log("don't have:", message_parts[1])
|
||||||
// console.log(err)
|
cfg.quiet || bot.chat(`don't have item: ${message_parts[1]}`)
|
||||||
// bot.chat(err)
|
return false
|
||||||
// }
|
}
|
||||||
// }
|
switch (message_parts.length) {
|
||||||
// )
|
case 2:
|
||||||
// break
|
bot.tossStack(
|
||||||
// default:
|
item,
|
||||||
// break
|
(err) => {
|
||||||
// }
|
if (err) {
|
||||||
// break;
|
console.error(err)
|
||||||
|
cfg.quiet || bot.chat(err.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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]) {
|
||||||
@@ -537,13 +502,12 @@ const load = (config) => {
|
|||||||
cfg = config
|
cfg = config
|
||||||
bot = cfg.bot
|
bot = cfg.bot
|
||||||
|
|
||||||
mcData = mcData(bot.version)
|
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(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 = () => {
|
||||||
|
@@ -1,113 +1,113 @@
|
|||||||
let cfg = {}
|
let cfg = {}
|
||||||
let bot = {}
|
let bot = {}
|
||||||
let isEating = false
|
let isEating = false
|
||||||
|
|
||||||
function callbackHandle(err) {
|
function callbackHandle(err) {
|
||||||
if (err) console.error(err)
|
if (err) console.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
function eat(callback) {
|
function eat(callback) {
|
||||||
isEating = true
|
isEating = true
|
||||||
|
|
||||||
const foodNames = require('minecraft-data')(bot.version).foodsArray.map((item) => item.name)
|
const foodNames = require('minecraft-data')(bot.version).foodsArray.map((item) => item.name)
|
||||||
|
|
||||||
let available_food = bot.inventory
|
let available_food = bot.inventory
|
||||||
.items()
|
.items()
|
||||||
.filter((item) => foodNames.includes(item.name))
|
.filter((item) => foodNames.includes(item.name))
|
||||||
|
|
||||||
if (available_food.length === 0 || !available_food) {
|
if (available_food.length === 0 || !available_food) {
|
||||||
isEating = false
|
isEating = false
|
||||||
return callback(new Error('No food found.'))
|
return callback(new Error('No food found.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.eat.bannedFood.length > 0) {
|
if (cfg.eat.bannedFood.length > 0) {
|
||||||
available_food = available_food.filter(
|
available_food = available_food.filter(
|
||||||
(item) => !cfg.eat.bannedFood.includes(item.name)
|
(item) => !cfg.eat.bannedFood.includes(item.name)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let priority = cfg.eat.priority
|
let priority = cfg.eat.priority
|
||||||
let best_food = available_food.reduce((prev, current) => (prev[priority] > current[priority]) ? prev : current)
|
let best_food = available_food.reduce((prev, current) => (prev[priority] > current[priority]) ? prev : current)
|
||||||
|
|
||||||
if (!best_food) {
|
if (!best_food) {
|
||||||
isEating = false
|
isEating = false
|
||||||
return callback(new Error('No best food has been found.'))
|
return callback(new Error('No best food has been found.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.emit('eat_start')
|
bot.emit('eat_start')
|
||||||
|
|
||||||
bot.equip(best_food, 'hand', function (error) {
|
bot.equip(best_food, 'hand', function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
isEating = false
|
isEating = false
|
||||||
bot.emit('eat_stop')
|
bot.emit('eat_stop')
|
||||||
} else {
|
} else {
|
||||||
bot.consume(function (err) {
|
bot.consume(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
isEating = false
|
isEating = false
|
||||||
bot.emit('eat_stop')
|
bot.emit('eat_stop')
|
||||||
return callback(err)
|
return callback(err)
|
||||||
} else {
|
} else {
|
||||||
isEating = false
|
isEating = false
|
||||||
bot.emit('eat_stop')
|
bot.emit('eat_stop')
|
||||||
callback(null)
|
callback(null)
|
||||||
if (!bot.food === 20) eat(callbackHandle)
|
if (!bot.food === 20) eat(callbackHandle)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFood() {
|
function checkFood() {
|
||||||
console.info("eater: "
|
console.info("eater: "
|
||||||
// , " status: ", !isEating
|
// , " status: ", !isEating
|
||||||
, cfg.eat.auto && "auto"
|
, cfg.eat.auto && "auto"
|
||||||
, bot.food < cfg.eat.startAt && "hungry"
|
, bot.food < cfg.eat.startAt && "hungry"
|
||||||
, "hunger:", bot.food
|
, "hunger:", bot.food
|
||||||
, "at:", cfg.eat.startAt)
|
, "at:", cfg.eat.startAt)
|
||||||
if (
|
if (
|
||||||
!isEating
|
!isEating
|
||||||
&& cfg.eat.auto
|
&& cfg.eat.auto
|
||||||
&& bot.food < cfg.eat.startAt
|
&& bot.food < cfg.eat.startAt
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
(bot.pathfinder
|
(bot.pathfinder
|
||||||
&& !(bot.pathfinder.isMining() || bot.pathfinder.isBuilding())
|
&& !(bot.pathfinder.isMining() || bot.pathfinder.isBuilding())
|
||||||
// TODO implement better idle state
|
// TODO implement better idle state
|
||||||
) || true // idle most likely
|
) || true // idle most likely
|
||||||
) {
|
) {
|
||||||
eat(callbackHandle)
|
eat(callbackHandle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetEat(value) {
|
function resetEat(value) {
|
||||||
// to prevent the plugin from breaking if the bot gets killed while eating btw
|
// to prevent the plugin from breaking if the bot gets killed while eating btw
|
||||||
isEating = !!value // false
|
isEating = !!value // false
|
||||||
}
|
}
|
||||||
|
|
||||||
const load = (config) => {
|
const load = (config) => {
|
||||||
cfg = config
|
cfg = config
|
||||||
bot = cfg.bot
|
bot = cfg.bot
|
||||||
cfg.eat = {
|
cfg.eat = {
|
||||||
priority: 'saturation', //'foodPoints', //
|
priority: 'saturation', //'foodPoints', //
|
||||||
// startAt: 19, //anarchy
|
// startAt: 19, //anarchy
|
||||||
// startAt: 18,
|
// startAt: 18,
|
||||||
startAt: 14,
|
startAt: 14,
|
||||||
bannedFood: [
|
bannedFood: [
|
||||||
"enchanted_golden_apple", "golden_apple", "pufferfish", "chorus_fruit"
|
"enchanted_golden_apple", "golden_apple", "pufferfish", "chorus_fruit"
|
||||||
],
|
],
|
||||||
auto: true
|
auto: true
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.on('health', checkFood)
|
bot.on('health', checkFood)
|
||||||
bot.on('spawn', resetEat)
|
bot.on('spawn', resetEat)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const unload = () => {
|
const unload = () => {
|
||||||
bot.off('health', checkFood)
|
bot.off('health', checkFood)
|
||||||
bot.off('spawn', resetEat)
|
bot.off('spawn', resetEat)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { load, unload, eat, resetEat }
|
module.exports = { load, unload, eat, resetEat }
|
128
lib/plugins/informer.js
Normal file
128
lib/plugins/informer.js
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
let cfg
|
||||||
|
let bot
|
||||||
|
let mcData
|
||||||
|
const v = require('vec3')
|
||||||
|
|
||||||
|
function block(pos) {
|
||||||
|
const block = pos ? bot.blockAt(v(pos)) : bot.blockAtCursor()
|
||||||
|
console.log(block, block && block.getProperties())
|
||||||
|
if (!block) {
|
||||||
|
cfg.quiet || bot.chat("empty block")
|
||||||
|
return block
|
||||||
|
}
|
||||||
|
let info = [block.type, block.name]
|
||||||
|
if (block.metadata) info.push(Object.entries(block.getProperties()))
|
||||||
|
cfg.quiet || bot.chat(info.join(": "))
|
||||||
|
}
|
||||||
|
|
||||||
|
function item(
|
||||||
|
slot,
|
||||||
|
entity = bot.entity
|
||||||
|
) {
|
||||||
|
const item = slot ?
|
||||||
|
bot.inventory.slots[parseInt(slot) + bot.QUICK_BAR_START] :
|
||||||
|
entity.heldItem
|
||||||
|
console.log(item)
|
||||||
|
if (!item) {
|
||||||
|
cfg.quiet || bot.chat("no item")
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
let info = [item.type, item.name]
|
||||||
|
if (item.metadata) info.push("meta: " + item.metadata.length)
|
||||||
|
if (item.nbt) {
|
||||||
|
info.push(compound_value(item.nbt))
|
||||||
|
}
|
||||||
|
cfg.quiet || bot.chat(info.join("; "))
|
||||||
|
function compound_value(obj) {
|
||||||
|
if (typeof obj.value == "object") {
|
||||||
|
return compound_value(obj.value)
|
||||||
|
} else if (obj.value) {
|
||||||
|
return obj.value
|
||||||
|
} else if (typeof obj == "object") {
|
||||||
|
const keys = Object.keys(obj)
|
||||||
|
return keys.map(key => {
|
||||||
|
return `${key}: ${compound_value(obj[key])}`
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
function entity(name) {
|
||||||
|
const entity = bot.nearestEntity((entity) => {
|
||||||
|
const ename = entity.name || entity.username
|
||||||
|
return name && ename ? ename == name : true
|
||||||
|
})
|
||||||
|
console.log(entity)
|
||||||
|
if (!entity) {
|
||||||
|
cfg.quiet || bot.chat("no entity")
|
||||||
|
return entity
|
||||||
|
}
|
||||||
|
let info = [entity.type, entity.name || entity.username]
|
||||||
|
if (entity.metadata) info.push("len: " + entity.metadata.length)
|
||||||
|
cfg.quiet || bot.chat(info.join("; "))
|
||||||
|
}
|
||||||
|
|
||||||
|
function command(message_parts) {
|
||||||
|
switch (message_parts.length) {
|
||||||
|
case 0:
|
||||||
|
// TODO most recent command?
|
||||||
|
block()
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
switch (message_parts[0]) {
|
||||||
|
case "item":
|
||||||
|
item()
|
||||||
|
break
|
||||||
|
case "entity":
|
||||||
|
entity()
|
||||||
|
break
|
||||||
|
case "block":
|
||||||
|
default:
|
||||||
|
block()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
switch (message_parts[0]) {
|
||||||
|
case "item":
|
||||||
|
item(message_parts[1])
|
||||||
|
break
|
||||||
|
case "entity":
|
||||||
|
default:
|
||||||
|
entity(message_parts[1])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
switch (message_parts[0]) {
|
||||||
|
case "block":
|
||||||
|
default:
|
||||||
|
block(message_parts.slice(1))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, command, block, item, entity }
|
@@ -225,4 +225,4 @@ const unload = () => {
|
|||||||
bot.off('chat', inventory)
|
bot.off('chat', inventory)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { load, unload, equipItem, craftItem }
|
module.exports = { load, unload, equipItem, craftItem, itemByName }
|
@@ -1,95 +1,300 @@
|
|||||||
// import { EntityFilters } from "mineflayer-statemachine"
|
|
||||||
// import v from "vec3"
|
const { Movements } = require('mineflayer-pathfinder')
|
||||||
|
const v = require('vec3')
|
||||||
// import { Movements } from "mineflayer-pathfinder"
|
|
||||||
|
let cfg = {}
|
||||||
// const mineflayer = require('mineflayer')
|
let bot = {}
|
||||||
const { Movements } = require('mineflayer-pathfinder')
|
// let moving
|
||||||
// const { GoalBLah } = require('mineflayer-pathfinder').goals
|
let pathfinder
|
||||||
const v = require('vec3')
|
let mcData
|
||||||
|
let movements = []
|
||||||
let cfg = {}
|
|
||||||
let bot = {}
|
|
||||||
// let moving
|
function initMoves(bot = bot, mcData = bot.mcData) {
|
||||||
let pathfinder
|
console.info(movements)
|
||||||
let movements = []
|
if (movements.length > 0) {
|
||||||
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
|
return console.warn("movements already initialized!")
|
||||||
function initMoves(bot = bot, mcData = require('minecraft-data')(bot.version)) {
|
}
|
||||||
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.id)
|
defaultMove.blocksToAvoid.add(mcData.blocksByName.magma_block.id)
|
||||||
movements.defaultMove = defaultMove
|
movements.push(defaultMove)
|
||||||
|
movements.defaultMove = movements[0]
|
||||||
bot.pathfinder.setMovements(defaultMove)
|
|
||||||
}
|
bot.pathfinder.setMovements(defaultMove)
|
||||||
|
}
|
||||||
|
|
||||||
function moveNear(pos, distance = 3) {
|
|
||||||
const { GoalNear } = require('mineflayer-pathfinder').goals
|
function moveNear(pos, distance = 3) {
|
||||||
cfg.quiet || bot.chat(`moving to ${pos}`)
|
const { GoalNear } = require('mineflayer-pathfinder').goals
|
||||||
|
|
||||||
pos = v(pos)
|
pos = v(pos)
|
||||||
bot.pathfinder.setMovements(movements.defaultMove)
|
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||||
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, distance))
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
}
|
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, distance))
|
||||||
|
}
|
||||||
function follow(entity, dynamic = true) {
|
|
||||||
console.assert(entity)
|
function moveXZ(pos) {
|
||||||
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
const { GoalXZ } = require('mineflayer-pathfinder').goals
|
||||||
|
|
||||||
|
if (Array.isArray(pos) && pos.length == 2) {
|
||||||
|
pos = v(pos[0], 0, pos[1])
|
||||||
cfg.quiet && console.log(entity)
|
}
|
||||||
|| bot.chat(
|
pos = v(pos)
|
||||||
`following ${entity.type
|
console.log(pos)
|
||||||
}: ${entity.username || entity.displayName
|
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||||
}${dynamic ? "" : " once"}`
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
)
|
bot.pathfinder.setGoal(new GoalXZ(pos.x, pos.z))
|
||||||
|
}
|
||||||
entity = entity.entity ? entity.entity : entity
|
|
||||||
|
function moveY(pos) {
|
||||||
// console.log(entity)
|
const { GoalY } = require('mineflayer-pathfinder').goals
|
||||||
|
|
||||||
bot.pathfinder.setMovements(movements.defaultMove)
|
if (Array.isArray(pos) && pos.length == 1) {
|
||||||
bot.pathfinder.setGoal(new GoalFollow(entity, 3), dynamic)
|
pos = v(null, pos[0], null)
|
||||||
}
|
}
|
||||||
|
pos = v(pos)
|
||||||
function hit(blockOrEntity) {
|
console.log(pos)
|
||||||
bot.chat(`hitting ${entity.name || entity.type}`)
|
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||||
}
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
|
bot.pathfinder.setGoal(new GoalY(pos.y))
|
||||||
function stop() {
|
}
|
||||||
bot.pathfinder.setGoal(null)
|
|
||||||
bot.stopDigging()
|
function follow(entity, dynamic = true, distance = 3) {
|
||||||
}
|
console.assert(entity)
|
||||||
|
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
||||||
const load = (config) => {
|
|
||||||
cfg = config
|
// console.log(entity)
|
||||||
bot = cfg.bot
|
cfg.quiet || bot.chat(
|
||||||
cfg.move = {
|
`following ${entity.type
|
||||||
// auto: true,
|
}: ${entity.username || entity.displayName
|
||||||
canDig: false,
|
}${dynamic ? "" : " once"}`
|
||||||
// list: ["hello", "wassup"],
|
)
|
||||||
quiet: !!cfg.quiet,
|
|
||||||
movements: []
|
entity = entity.entity ? entity.entity : entity
|
||||||
}
|
|
||||||
|
// console.log(entity)
|
||||||
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
|
|
||||||
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
// initMoves(bot, mcData)
|
bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic)
|
||||||
setTimeout(initMoves, 500, bot)
|
}
|
||||||
|
|
||||||
// bot.loadPlugin(pathfinder)
|
function ride(entity) {
|
||||||
|
entity = entity?.entity || entity
|
||||||
// bot.on('time', hello)
|
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider"]
|
||||||
|
const vehicle = entity && typeof entity !== "string" ? entity : bot.nearestEntity(e => {
|
||||||
}
|
if (typeof entity === "string") return e.name === entity
|
||||||
|
const maybeRidableMob = e.mobType?.split(" ")
|
||||||
const unload = () => {
|
return e.kind == "Vehicles"
|
||||||
// TODO stop pathfinding maybe?
|
|| ridableMobs.includes(e.mobType)
|
||||||
}
|
|| maybeRidableMob && ridableMobs.includes(maybeRidableMob[maybeRidableMob.length - 1])
|
||||||
|
})
|
||||||
module.exports = { load, unload, stop, initMoves, moveNear, follow }
|
if (!vehicle) {
|
||||||
|
return cfg.quiet || bot.chat(`nothing to ride!`)
|
||||||
|
} else if ((dist = bot.entity.position.distanceSquared(vehicle.position)) > 36) {
|
||||||
|
bot.lookAt(vehicle.position)
|
||||||
|
follow(vehicle, false)
|
||||||
|
bot.once('goal_reached', ride)
|
||||||
|
return cfg.quiet || bot.chat(`${vehicle.name} bit far`)
|
||||||
|
}
|
||||||
|
console.log("vehicle:", vehicle)
|
||||||
|
bot.mount(vehicle)
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveOrRide(turn = false, reverse = -1, directionLabel, message_parts2) {
|
||||||
|
// bot.once("attach", state = "vehiccel")
|
||||||
|
if (bot.vehicle) {
|
||||||
|
const amount = parseInt(message_parts2[0]) || 10 * -reverse
|
||||||
|
bot.moveVehicle(turn && amount || 0, !turn && amount || 0)
|
||||||
|
} else {
|
||||||
|
command([directionLabel].concat(message_parts2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hit(blockOrEntity) {
|
||||||
|
bot.chat(`hitting ${entity.name || entity.type}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function goalReached(goal) {
|
||||||
|
console.log(goal)
|
||||||
|
const entity = goal?.entity
|
||||||
|
let entityInfo = ""
|
||||||
|
if (entity) {
|
||||||
|
entityInfo += entity.type + ": "
|
||||||
|
switch (entity.type) {
|
||||||
|
case "player":
|
||||||
|
entityInfo += entity.username
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg.quiet || bot.chat(`goal reached: ${entityInfo}; pos: [x:${goal?.x}, y:${goal?.y}, z:${goal?.z}]`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
bot.pathfinder.setGoal(null)
|
||||||
|
bot.stopDigging()
|
||||||
|
}
|
||||||
|
|
||||||
|
function command(message_parts, player) {
|
||||||
|
const message_parts2 = message_parts.slice(1)
|
||||||
|
switch (message_parts[0]) {
|
||||||
|
case "init":
|
||||||
|
initMoves()
|
||||||
|
break
|
||||||
|
case "near":
|
||||||
|
switch (message_parts2.length) {
|
||||||
|
case 0:
|
||||||
|
moveNear(bot.nearestEntity().position)
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
switch (message_parts2[0]) {
|
||||||
|
case "me":
|
||||||
|
if (player) {
|
||||||
|
moveNear(player.position)
|
||||||
|
} else {
|
||||||
|
cfg.quiet || bot.chat("can't see you")
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
const aPlayer = bot.players[message_parts2[0]] ? bot.players[message_parts2[0]].entity : null
|
||||||
|
if (aPlayer) {
|
||||||
|
moveNear(aPlayer.position)
|
||||||
|
} else {
|
||||||
|
cfg.quiet || bot.chat(`can't see ${message_parts2[0]}`)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
//TODO this isn't near
|
||||||
|
moveXZ(message_parts2)
|
||||||
|
break
|
||||||
|
case 3:
|
||||||
|
//TODO more checks
|
||||||
|
moveNear(message_parts2)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case "follow":
|
||||||
|
// message_parts2 = message_parts.slice(2)
|
||||||
|
switch (message_parts2.length) {
|
||||||
|
case 0:
|
||||||
|
follow(bot.nearestEntity())
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
let dist = 3
|
||||||
|
switch (message_parts2[0]) {
|
||||||
|
case "close":
|
||||||
|
dist = 1
|
||||||
|
case "me":
|
||||||
|
case "once":
|
||||||
|
if (player) {
|
||||||
|
follow(player, message_parts2[0] === "me", dist)
|
||||||
|
} else {
|
||||||
|
cfg.quiet || bot.chat("can't see you")
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
const aPlayer = bot.players[message_parts2[0]] ? bot.players[message_parts2[0]].entity : null
|
||||||
|
if (aPlayer) {
|
||||||
|
follow(aPlayer)
|
||||||
|
} else {
|
||||||
|
cfg.quiet || bot.chat(`can't see ${message_parts2[0]}`)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break
|
||||||
|
// case 2:
|
||||||
|
// bot.lookAt({}) goalxz?
|
||||||
|
// break
|
||||||
|
// case 3:
|
||||||
|
//TODO more checks
|
||||||
|
// moveNear(message_parts2)
|
||||||
|
// break
|
||||||
|
default:
|
||||||
|
cfg.quiet || bot.chat("unknown or bad command")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "ride":
|
||||||
|
case "mount":
|
||||||
|
ride(message_parts2[0])
|
||||||
|
break
|
||||||
|
case "w":
|
||||||
|
case "f":
|
||||||
|
moveOrRide(0, -1, "forward", message_parts2)
|
||||||
|
break
|
||||||
|
case "s":
|
||||||
|
case "b":
|
||||||
|
moveOrRide(0, 1, "back", message_parts2)
|
||||||
|
break
|
||||||
|
case "a":
|
||||||
|
case "l":
|
||||||
|
moveOrRide(1, -1, "right", message_parts2)
|
||||||
|
break
|
||||||
|
case "d":
|
||||||
|
case "r":
|
||||||
|
moveOrRide(1, 1, "left", message_parts2)
|
||||||
|
break
|
||||||
|
case "back":
|
||||||
|
case "forward":
|
||||||
|
case "jump":
|
||||||
|
case "left":
|
||||||
|
case "right":
|
||||||
|
case "sneak":
|
||||||
|
case "sprint":
|
||||||
|
console.info(bot.controlState[message_parts[0]], bot.entity.position.floored())
|
||||||
|
bot.setControlState(message_parts[0], true)
|
||||||
|
console.info(bot.controlState[message_parts[0]])
|
||||||
|
setTimeout(bot.setControlState, 100 * (message_parts[1] || 2), message_parts[0], false)
|
||||||
|
setTimeout(console.info, 5000, bot.controlState[message_parts[0]], bot.entity.position.floored())
|
||||||
|
break
|
||||||
|
case "stop":
|
||||||
|
stop()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return cfg.quiet || bot.chat(`unknown command ${message_parts[0]}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const load = (config) => {
|
||||||
|
cfg = config
|
||||||
|
bot = cfg.bot
|
||||||
|
cfg.move = {
|
||||||
|
// auto: true,
|
||||||
|
canDig: false,
|
||||||
|
// list: ["hello", "wassup"],
|
||||||
|
quiet: !!cfg.quiet,
|
||||||
|
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, mcData)
|
||||||
|
bot.on('goal_reached', goalReached)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const unload = () => {
|
||||||
|
stop()
|
||||||
|
bot.off('goal_reached', goalReached)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
load, unload, command,
|
||||||
|
stop, initMoves,
|
||||||
|
moveNear, moveXZ, moveY, follow,
|
||||||
|
ride
|
||||||
|
}
|
217
lib/plugins/mycellium.js
Normal file
217
lib/plugins/mycellium.js
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
|
||||||
|
// const mineflayer = require('mineflayer')
|
||||||
|
// let pathfinder
|
||||||
|
// const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
|
||||||
|
const { Vec3 } = require('vec3')
|
||||||
|
// const { GoalFollow, GoalNear } = goals
|
||||||
|
let GoalFollow, GoalNear
|
||||||
|
// const mcData = require('minecraft-data')('1.16.5')
|
||||||
|
let mcData
|
||||||
|
|
||||||
|
// let bot = mineflayer.createBot()
|
||||||
|
let bot
|
||||||
|
let cfg = { bot: null }
|
||||||
|
let timer
|
||||||
|
let movements
|
||||||
|
|
||||||
|
/* let mcData
|
||||||
|
bot.once('spawn', () => {
|
||||||
|
mcData = require('minecraft-data')(bot.version)
|
||||||
|
}) */
|
||||||
|
|
||||||
|
function stopCovering(quiet = cfg.quiet, resetGoal = true) { // This is a function to stop the cover() loop when called
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
if (resetGoal) bot.pathfinder.setGoal(null)
|
||||||
|
bot.stopDigging()
|
||||||
|
quiet || bot.chat("stopped covering")
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const { Movements, goals } = require('mineflayer-pathfinder')
|
||||||
|
GoalFollow = goals.GoalFollow
|
||||||
|
GoalNear = goals.GoalNear
|
||||||
|
movements = new Movements(bot, mcData)
|
||||||
|
movements.canDig = true // Lets the bot dig
|
||||||
|
bot.pathfinder.setMovements(movements)
|
||||||
|
|
||||||
|
console.info("mycelium start")
|
||||||
|
stopCovering(true)
|
||||||
|
bot.waitForChunksToLoad(cover)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cover(timeInt = 1000) {
|
||||||
|
if (!Number.isSafeInteger(timeInt)) {
|
||||||
|
console.log("cover int maybe goal?", timeInt)
|
||||||
|
switch (timeInt.message) {
|
||||||
|
case "No path to the goal!":
|
||||||
|
console.info("Cover: can't reach")
|
||||||
|
cfg.quiet || bot.chat("can't reach")
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (timeInt) {
|
||||||
|
timeInt = 5000
|
||||||
|
}
|
||||||
|
} else if (timeInt < 300) {
|
||||||
|
timeInt = 1000
|
||||||
|
}
|
||||||
|
const wool = "white_wool"
|
||||||
|
const wool_item = mcData.itemsByName[wool]
|
||||||
|
const inventoryWool = bot.inventory.findInventoryItem(wool_item.id)
|
||||||
|
// console.info(wool_item.id, inventoryWool)
|
||||||
|
// if (!inventoryWool) return
|
||||||
|
// bot.loadPlugin(pathfinder)
|
||||||
|
|
||||||
|
const myceliumClean = bot.findBlock({ // Const that is a brown_mushroom
|
||||||
|
maxDistance: 6,
|
||||||
|
matching: (block) => {
|
||||||
|
// First check the type
|
||||||
|
// lol
|
||||||
|
// const { brown_mushroom, red_mushroom, white_wool } = mcData.blocksByName
|
||||||
|
// if ([brown_mushroom.id, red_mushroom.id, white_wool.id].includes(block?.type)) {
|
||||||
|
const { brown_mushroom, red_mushroom, } = mcData.blocksByName
|
||||||
|
if ([brown_mushroom.id, red_mushroom.id,].includes(block?.type)) {
|
||||||
|
// If position is defined, you can refine the search
|
||||||
|
if (block.position) {
|
||||||
|
const blockBelow = bot.blockAt(block.position.offset(0, -1, 0))
|
||||||
|
return blockBelow?.type === mcData.blocksByName.mycelium.id || blockBelow?.type === mcData.blocksByName.spruce_fence.id // Makes sure there is mycelium below
|
||||||
|
}
|
||||||
|
return true // otherwise return always true (there is water in the section so it should be checked)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function findMycelium(dist = 5) {
|
||||||
|
return bot.findBlock({
|
||||||
|
maxDistance: dist,
|
||||||
|
matching: (block) => {
|
||||||
|
// First check the type
|
||||||
|
if (block?.type === mcData.blocksByName.mycelium.id) { // Const that is a mycelium block
|
||||||
|
// If position is defined, you can refine the search
|
||||||
|
if (block.position) {
|
||||||
|
const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))
|
||||||
|
return !blockAbove || blockAbove?.type === mcData.blocksByName.air.id // Makes sure there is nothing above
|
||||||
|
}
|
||||||
|
return true // otherwise return always true (there is water in the section so it should be checked)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
let mycelium = findMycelium()
|
||||||
|
|
||||||
|
if (myceliumClean) {
|
||||||
|
// bot.dig(myceliumClean, true)
|
||||||
|
bot.dig(myceliumClean)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mycelium) {
|
||||||
|
timeInt = 500
|
||||||
|
if (bot.heldItem?.type !== wool_item.id) { // Equips wool if not already
|
||||||
|
if (!inventoryWool || inventoryWool.count < 10) { // Checks if there is less than 10 wool in the bots inventory
|
||||||
|
timeInt = 5000
|
||||||
|
console.warn("no wool")
|
||||||
|
// const chestLocation = new Vec3(10614, 70, 5350) // Sets chest location
|
||||||
|
const chestLocation = bot.findBlock({
|
||||||
|
maxDistance: 100,
|
||||||
|
matching: block => block && block.type === mcData.blocksByName.chest.id
|
||||||
|
})?.position // Sets chest location
|
||||||
|
const chestGoal = new GoalNear(chestLocation.x, chestLocation.y, chestLocation.z, 6) // Sets goal to chest location
|
||||||
|
return bot.pathfinder.goto(chestGoal, () => { // Run code below when it gets to the chest
|
||||||
|
bot.lookAt(chestLocation, true) // Looks at chest
|
||||||
|
const chest = bot.openChest(bot.blockAt(chestLocation)) // Sets const to for opening chest
|
||||||
|
chest.once('open', (err) => { // Opens chest
|
||||||
|
if (err) {
|
||||||
|
return console.error('Chest error', err)
|
||||||
|
}
|
||||||
|
const chest_item = chest.items().filter(item => item.type === wool_item.id)
|
||||||
|
console.info(chest, chest_item)
|
||||||
|
if (chest_item.length > 0) { // Checks that there is stuff in chest
|
||||||
|
try {
|
||||||
|
// Pulls out a chest (27 stack) of wool
|
||||||
|
// chest.withdraw(chest_item[0].type, null, 64 * 27)
|
||||||
|
chest.withdraw(chest_item[0].type, null, 64 * 3)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Chest withdraw error', error)
|
||||||
|
}
|
||||||
|
bot.once("close", cover)
|
||||||
|
} else {
|
||||||
|
console.log('Chest dont have', wool_item)
|
||||||
|
cfg.quiet || bot.chat(`Not enough ${wool} in chest`)
|
||||||
|
stopCovering()
|
||||||
|
}
|
||||||
|
setTimeout(chest.close, timeInt)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
bot.equip(wool_item.id, "hand")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const pos = mycelium.position
|
||||||
|
bot.lookAt(pos, true)
|
||||||
|
// let tryCount = 0
|
||||||
|
const flooredPos = bot.entity.position.floored()
|
||||||
|
if (flooredPos.offset(0, 1, 0).distanceTo(pos) <= 2) {
|
||||||
|
bot.setControlState('jump', true)
|
||||||
|
if (bot.entity.position.y > mycelium.position.y) {
|
||||||
|
bot.placeBlock(mycelium, new Vec3(0, 1, 0), (err) => {
|
||||||
|
setTimeout(bot.setControlState, 2000, 'jump', false)
|
||||||
|
if (err) {
|
||||||
|
console.error('Place (jumped)', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bot.placeBlock(mycelium, new Vec3(0, 1, 0), (err) => {
|
||||||
|
if (err) {
|
||||||
|
if (err.message !== `No block has been placed : the block is still ${wool}`) {
|
||||||
|
return console.error('Place (normal)', err)
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mycelium = findMycelium(100)
|
||||||
|
if (mycelium) {
|
||||||
|
const pos = mycelium.position
|
||||||
|
const goal = new GoalNear(pos.x, pos.y, pos.z, 3)
|
||||||
|
stopCovering(true)
|
||||||
|
timeInt = 2000
|
||||||
|
return bot.pathfinder.goto(goal, cover)
|
||||||
|
} else {
|
||||||
|
stopCovering(true)
|
||||||
|
return cfg.quiet || bot.chat("no uncovered mycelium nearby")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timer = setTimeout(cover, timeInt, timeInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
function command(params) {
|
||||||
|
stopCovering(true)
|
||||||
|
cover()
|
||||||
|
}
|
||||||
|
|
||||||
|
const load = (config) => {
|
||||||
|
cfg = config
|
||||||
|
bot = cfg.bot
|
||||||
|
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
|
||||||
|
|
||||||
|
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
const unload = () => {
|
||||||
|
stopCovering(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { load, unload, command, cover, stopCovering }
|
@@ -1,74 +1,87 @@
|
|||||||
|
|
||||||
let pathfinder
|
let pathfinder
|
||||||
//TODO replace with simple pathfinder motions
|
//TODO replace with simple pathfinder motions
|
||||||
const {
|
|
||||||
gameplay,
|
|
||||||
MoveTo,
|
|
||||||
MoveToInteract,
|
|
||||||
ObtainItem,
|
|
||||||
// Craft
|
|
||||||
} = require('prismarine-gameplay')
|
|
||||||
|
|
||||||
let cfg = {}
|
let cfg = {}
|
||||||
let bot = {}
|
let bot = {}
|
||||||
let inv
|
let inv
|
||||||
// cfg.autosleep = false
|
// cfg.autosleep = false
|
||||||
|
|
||||||
function sleep(quiet) {
|
function sleep(quiet = cfg.sleep.quiet) {
|
||||||
quiet = quiet !== undefined ? quiet : cfg.sleep.quiet
|
|
||||||
if(bot.game.dimension !== "minecraft:overworld" || cfg.sleep.force){
|
if(bot.game.dimension !== "minecraft:overworld" || cfg.sleep.force){
|
||||||
!quiet && bot.chat("can't sleep, not in overworld now")
|
!quiet && bot.chat("can't sleep, not in overworld now")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (bot.isSleeping && !cfg.sleep.force) {
|
||||||
|
!quiet && bot.chat("already in bed!")
|
||||||
|
return
|
||||||
|
}
|
||||||
let bed = bot.findBlock({
|
let bed = bot.findBlock({
|
||||||
matching: block => bot.isABed(block)
|
matching: block => bot.isABed(block)
|
||||||
})
|
})
|
||||||
let bedstatus = bed && bot.parseBedMetadata(bed).occupied ? "n unoccupied" : ""
|
let bed_occupied = bed && bot.parseBedMetadata(bed).occupied
|
||||||
if(bed && bedstatus == "n unoccupied"){
|
if (bed && bed_occupied) {
|
||||||
bot.lookAt(bed.position)
|
bot.lookAt(bed.position)
|
||||||
bed = bot.findBlock({
|
bed = bot.findBlock({
|
||||||
matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
|
matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
|
||||||
}) || bed
|
}) || bed
|
||||||
bedstatus = bot.parseBedMetadata(bed).occupied ? "n unoccupied" : ""
|
bed_occupied = bot.parseBedMetadata(bed).occupied
|
||||||
}
|
}
|
||||||
if (bed && bedstatus == "") {
|
if (bed && !bed_occupied) {
|
||||||
bot.lookAt(bed.position)
|
bot.lookAt(bed.position)
|
||||||
// const nearbed =
|
bot.waitForChunksToLoad(() => {
|
||||||
bot.gameplay.solveFor(
|
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
|
||||||
new MoveTo((bed.position.range = 2) && bed.position), (err) => {
|
bot.once('goal_reached', (goal) => {
|
||||||
// new MoveTo(bed.position), (err) => {
|
console.info(goal)
|
||||||
// new MoveToInteract(bed.position), (err) => {
|
try {
|
||||||
if (err) {
|
bot.sleep(bed, (err) => {
|
||||||
!quiet && bot.chat(`can't reach bed: ${err.message}`)
|
if (err) {
|
||||||
} else {
|
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
||||||
bot.waitForChunksToLoad(() => {
|
} else {
|
||||||
bot.sleep(bed, (err) => {
|
!quiet && bot.chat("zzz")
|
||||||
if (err) {
|
// apparently, `bot.isSleeping = true` takes a while
|
||||||
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
// maybe it's async
|
||||||
} else {
|
console.log("sleeping? ", bot.isSleeping)
|
||||||
!quiet && bot.chat("zzz")
|
}
|
||||||
console.log("sleeping? ", bot.isSleeping)
|
|
||||||
// hack until this is fixed
|
|
||||||
// bot.isSleeping = bot.isSleeping ? bot.isSleeping : true
|
|
||||||
bot.isSleeping = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// } else if (bed){
|
})
|
||||||
} else if (inv && inv.equipItem("red_bed", "hand", true)) {
|
} else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {
|
||||||
// doesn't work fortunately
|
const v = require('vec3')
|
||||||
// FIXME: DONT IMPLEMENT until it is detected as NOT NETHER
|
bot.equip(bed, "hand", (err) => { if (err) console.error(err) })
|
||||||
bot.placeBlock()
|
bot.waitForChunksToLoad(() => {
|
||||||
|
let refBlock =
|
||||||
|
// FIXME hack to get around findBlock returning null
|
||||||
|
bot.blockAt(bot.entity.position.offset(1, 0, 1), false)
|
||||||
|
// bot.findBlock({
|
||||||
|
// matching: (block) => {
|
||||||
|
// // if (block && block.type !== 0 && block.position) {
|
||||||
|
// if (block && block.position) {
|
||||||
|
// console.info("found", block)
|
||||||
|
// const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))
|
||||||
|
// return !blockAbove || blockAbove.type === 0
|
||||||
|
// }
|
||||||
|
// // console.info("not found", block)
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
// , maxDistance: 10
|
||||||
|
// })
|
||||||
|
console.log(refBlock)
|
||||||
|
bot.placeBlock(refBlock, new v.Vec3(0, 1, 0), console.error)
|
||||||
|
setTimeout(sleep, 3000, true)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
bot.gameplay.solveFor(
|
// TODO: use mover
|
||||||
new ObtainItem("bed"), (err) => {
|
// bot.gameplay.solveFor(
|
||||||
if (err) {
|
// new ObtainItem("bed"), (err) => {
|
||||||
!quiet && bot.chat(`need a${bedstatus} bed: may not see if just placed`)
|
// if (err) {
|
||||||
}
|
!quiet && bot.chat(`need a${bed_occupied ? "n unoccupied" : ""} bed: may not see if just placed`)
|
||||||
}
|
// }
|
||||||
)
|
// }
|
||||||
|
// )
|
||||||
// bot.chat('/afk')
|
// bot.chat('/afk')
|
||||||
}
|
}
|
||||||
bot.pathfinder.movements
|
bot.pathfinder.movements
|
||||||
@@ -88,7 +101,7 @@ function autoSleep() {
|
|||||||
if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
|
if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
|
||||||
sleep()
|
sleep()
|
||||||
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
|
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
|
||||||
console.log("sleeping?", bot.isSleeping, bot.time)
|
console.log("sleeping?", bot.isSleeping, bot.time.isDay, bot.time.timeOfDay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +117,6 @@ const load = (config) => {
|
|||||||
|
|
||||||
pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder
|
pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder
|
||||||
// bot.loadPlugin(pathfinder)
|
// bot.loadPlugin(pathfinder)
|
||||||
bot.loadPlugin(gameplay)
|
|
||||||
inv = cfg.plugins["inventory"]
|
inv = cfg.plugins["inventory"]
|
||||||
bot.on("time", autoSleep)
|
bot.on("time", autoSleep)
|
||||||
|
|
||||||
|
25
package.json
25
package.json
@@ -34,21 +34,20 @@
|
|||||||
"require-self": "^0.2.3"
|
"require-self": "^0.2.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minecraft-data": "^2.70.2",
|
"dotenv-packed": "^1.2.1",
|
||||||
"mineflayer": "^2.34.0",
|
"minecraft-data": "^2.73.1",
|
||||||
"mineflayer-armor-manager": "^1.3",
|
"mineflayer": "^2.40.1",
|
||||||
"mineflayer-pathfinder": "^1.1",
|
"mineflayer-armor-manager": "^1.4.0",
|
||||||
"mineflayer-pvp": "^1",
|
"mineflayer-pathfinder": "^1.3.6",
|
||||||
"prismarine-block": "^1",
|
"mineflayer-pvp": "^1.0.2",
|
||||||
"prismarine-chat": "^1",
|
"prismarine-block": "^1.7.3",
|
||||||
|
"prismarine-chat": "^1.0.3",
|
||||||
"prismarine-entity": "^1.1.0",
|
"prismarine-entity": "^1.1.0",
|
||||||
"prismarine-gameplay": "github:TheDudeFromCI/prismarine-gameplay#crafting",
|
|
||||||
"prismarine-item": "^1.5.0",
|
"prismarine-item": "^1.5.0",
|
||||||
"prismarine-nbt": "^1.3",
|
"prismarine-nbt": "^1.4.0",
|
||||||
"prismarine-recipe": "^1",
|
"prismarine-recipe": "^1.1.0",
|
||||||
"typescript": "^4",
|
"typescript": "^4.1.3",
|
||||||
"vec3": "^0.1",
|
"vec3": "^0.1.7"
|
||||||
"dotenv-packed": "^1.2"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/**/*"
|
"lib/**/*"
|
||||||
|
Reference in New Issue
Block a user