Compare commits
18 Commits
b1dab1968c
...
1d361e04a6
Author | SHA1 | Date | |
---|---|---|---|
|
1d361e04a6 | ||
|
7597620626 | ||
|
e5faa6f022 | ||
|
cc18ac5c2e | ||
|
7050a1621b | ||
|
7cbfa16476 | ||
|
63849e0729 | ||
|
4e7f8d59fd | ||
|
7b2b936f81 | ||
|
8a39596b1d | ||
|
2601b7cfb1 | ||
|
67932b2f6a | ||
|
9a6e684b11 | ||
|
3488a94233 | ||
|
4d21327086 | ||
|
e74d796124 | ||
|
3d5ffe38cd | ||
|
b519913355 |
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"conventionalCommits.scopes": [
|
||||
"command",
|
||||
"mover",
|
||||
"sleeper",
|
||||
"informer"
|
||||
]
|
||||
}
|
|
@ -193,7 +193,15 @@ function command(username, message) {
|
|||
break;
|
||||
|
||||
case "follow":
|
||||
subcommand("go follow " + message_parts.slice(1).join(" "))
|
||||
switch (message_parts.length) {
|
||||
case 1:
|
||||
subcommand("go follow me")
|
||||
break;
|
||||
|
||||
default:
|
||||
subcommand("go " + message)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "come":
|
||||
switch (message_parts[1]) {
|
||||
|
@ -201,106 +209,17 @@ function command(username, message) {
|
|||
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 "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:
|
||||
let dist = 3
|
||||
switch (message_parts2[0]) {
|
||||
case "close":
|
||||
dist = 1
|
||||
case "me":
|
||||
case "once":
|
||||
if (player) {
|
||||
cfg.plugins.mover.follow(player, message_parts2[0] === "me", dist)
|
||||
} 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;
|
||||
}
|
||||
cfg.plugins.mover.command(message_parts.slice(1), player)
|
||||
break;
|
||||
|
||||
case "attack":
|
||||
|
|
|
@ -1,20 +1,84 @@
|
|||
let cfg
|
||||
let bot
|
||||
let mcData
|
||||
const v = require('vec3')
|
||||
|
||||
function block() {
|
||||
const block = bot.blockAtCursor()
|
||||
console.log(block)
|
||||
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(block.metadata)
|
||||
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()
|
||||
|
@ -23,6 +87,28 @@ function command(message_parts) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -39,4 +125,4 @@ const load = (config) => {
|
|||
|
||||
const unload = () => {}
|
||||
|
||||
module.exports = { load, unload, command, block }
|
||||
module.exports = { load, unload, command, block, item, entity }
|
|
@ -30,13 +30,39 @@ function initMoves(bot = bot, mcData = bot.mcData) {
|
|||
|
||||
function moveNear(pos, distance = 3) {
|
||||
const { GoalNear } = require('mineflayer-pathfinder').goals
|
||||
cfg.quiet || bot.chat(`moving to ${pos}`)
|
||||
|
||||
pos = v(pos)
|
||||
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||
bot.pathfinder.setMovements(movements.defaultMove)
|
||||
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, distance))
|
||||
}
|
||||
|
||||
function moveXZ(pos) {
|
||||
const { GoalXZ } = require('mineflayer-pathfinder').goals
|
||||
|
||||
if (Array.isArray(pos) && pos.length == 2) {
|
||||
pos = v(pos[0], 0, pos[1])
|
||||
}
|
||||
pos = v(pos)
|
||||
console.log(pos)
|
||||
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||
bot.pathfinder.setMovements(movements.defaultMove)
|
||||
bot.pathfinder.setGoal(new GoalXZ(pos.x, pos.z))
|
||||
}
|
||||
|
||||
function moveY(pos) {
|
||||
const { GoalY } = require('mineflayer-pathfinder').goals
|
||||
|
||||
if (Array.isArray(pos) && pos.length == 1) {
|
||||
pos = v(null, pos[0], null)
|
||||
}
|
||||
pos = v(pos)
|
||||
console.log(pos)
|
||||
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
|
||||
bot.pathfinder.setMovements(movements.defaultMove)
|
||||
bot.pathfinder.setGoal(new GoalY(pos.y))
|
||||
}
|
||||
|
||||
function follow(entity, dynamic = true, distance = 3) {
|
||||
console.assert(entity)
|
||||
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
||||
|
@ -60,11 +86,123 @@ 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 "stop":
|
||||
stop()
|
||||
break
|
||||
default:
|
||||
return cfg.quiet || bot.chat(`unknown command ${message_parts[0]}`)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const load = (config) => {
|
||||
cfg = config
|
||||
bot = cfg.bot
|
||||
|
@ -81,11 +219,13 @@ const load = (config) => {
|
|||
|
||||
// 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, stop, initMoves, moveNear, follow }
|
||||
module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow }
|
|
@ -33,17 +33,20 @@ function sleep(quiet = cfg.sleep.quiet) {
|
|||
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
|
||||
bot.once('goal_reached', (goal) => {
|
||||
console.info(goal)
|
||||
bot.sleep(bed, (err) => {
|
||||
if (err) {
|
||||
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
||||
} else {
|
||||
!quiet && bot.chat("zzz")
|
||||
console.log("sleeping? ", bot.isSleeping)
|
||||
// hack until this is fixed
|
||||
// TODO confirm this is fixed
|
||||
// bot.isSleeping = true
|
||||
}
|
||||
})
|
||||
try {
|
||||
bot.sleep(bed, (err) => {
|
||||
if (err) {
|
||||
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
||||
} else {
|
||||
!quiet && bot.chat("zzz")
|
||||
// apparently, `bot.isSleeping = true` takes a while
|
||||
// maybe it's async
|
||||
console.log("sleeping? ", bot.isSleeping)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {
|
||||
|
|
12
package.json
12
package.json
|
@ -35,16 +35,16 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"dotenv-packed": "^1.2.1",
|
||||
"minecraft-data": "^2.70.2",
|
||||
"mineflayer": "^2.39.2",
|
||||
"mineflayer-armor-manager": "^1.3.0",
|
||||
"mineflayer-pathfinder": "^1.2.3",
|
||||
"minecraft-data": "^2.73.1",
|
||||
"mineflayer": "^2.40.1",
|
||||
"mineflayer-armor-manager": "^1.4.0",
|
||||
"mineflayer-pathfinder": "^1.3.6",
|
||||
"mineflayer-pvp": "^1.0.2",
|
||||
"prismarine-block": "^1.7.2",
|
||||
"prismarine-block": "^1.7.3",
|
||||
"prismarine-chat": "^1.0.3",
|
||||
"prismarine-entity": "^1.1.0",
|
||||
"prismarine-item": "^1.5.0",
|
||||
"prismarine-nbt": "^1.3.0",
|
||||
"prismarine-nbt": "^1.4.0",
|
||||
"prismarine-recipe": "^1.1.0",
|
||||
"typescript": "^4.1.3",
|
||||
"vec3": "^0.1.7"
|
||||
|
|
Loading…
Reference in New Issue
Block a user