Compare commits

..

No commits in common. "1d361e04a603d927e43a1bb13408abdddb159c50" and "b1dab1968c76c502fc078292ea77a49ba009be01" have entirely different histories.

6 changed files with 119 additions and 275 deletions

View File

@ -1,8 +0,0 @@
{
"conventionalCommits.scopes": [
"command",
"mover",
"sleeper",
"informer"
]
}

View File

@ -193,15 +193,7 @@ function command(username, message) {
break; break;
case "follow": case "follow":
switch (message_parts.length) { subcommand("go follow " + message_parts.slice(1).join(" "))
case 1:
subcommand("go follow me")
break;
default:
subcommand("go " + message)
break;
}
break; break;
case "come": case "come":
switch (message_parts[1]) { switch (message_parts[1]) {
@ -209,17 +201,106 @@ function command(username, message) {
case "closer": case "closer":
subcommand("go follow close") subcommand("go follow close")
break break
case "up":
case "down":
cfg.plugins.mover.moveY(player.position)
break
default: default:
subcommand("go follow once") subcommand("go follow once")
} }
break; break;
case "move": case "move":
case "go": case "go":
cfg.plugins.mover.command(message_parts.slice(1), player) // 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;
}
break; break;
case "attack": case "attack":

View File

@ -1,84 +1,20 @@
let cfg let cfg
let bot let bot
let mcData let mcData
const v = require('vec3')
function block(pos) { function block() {
const block = pos ? bot.blockAt(v(pos)) : bot.blockAtCursor() const block = bot.blockAtCursor()
console.log(block, block && block.getProperties()) console.log(block)
if (!block) {
cfg.quiet || bot.chat("empty block")
return block
}
let info = [block.type, block.name] let info = [block.type, block.name]
if (block.metadata) info.push(Object.entries(block.getProperties())) if (block.metadata) info.push(block.metadata)
cfg.quiet || bot.chat(info.join(": ")) 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) { function command(message_parts) {
switch (message_parts.length) { switch (message_parts.length) {
case 0: case 0:
// TODO most recent command?
block()
break;
case 1: case 1:
switch (message_parts[0]) { switch (message_parts[0]) {
case "item":
item()
break
case "entity":
entity()
break
case "block": case "block":
default: default:
block() block()
@ -87,28 +23,6 @@ function command(message_parts) {
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: default:
break; break;
} }
@ -125,4 +39,4 @@ const load = (config) => {
const unload = () => {} const unload = () => {}
module.exports = { load, unload, command, block, item, entity } module.exports = { load, unload, command, block }

View File

@ -30,39 +30,13 @@ function initMoves(bot = bot, mcData = bot.mcData) {
function moveNear(pos, distance = 3) { function moveNear(pos, distance = 3) {
const { GoalNear } = require('mineflayer-pathfinder').goals const { GoalNear } = require('mineflayer-pathfinder').goals
cfg.quiet || bot.chat(`moving to ${pos}`)
pos = v(pos) pos = v(pos)
cfg.quiet || bot.chat(`moving to ${pos.floored()}`)
bot.pathfinder.setMovements(movements.defaultMove) bot.pathfinder.setMovements(movements.defaultMove)
bot.pathfinder.setGoal(new GoalNear(pos.x, pos.y, pos.z, distance)) 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) { function follow(entity, dynamic = true, distance = 3) {
console.assert(entity) console.assert(entity)
const { GoalFollow } = require('mineflayer-pathfinder').goals const { GoalFollow } = require('mineflayer-pathfinder').goals
@ -86,123 +60,11 @@ function hit(blockOrEntity) {
bot.chat(`hitting ${entity.name || entity.type}`) 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() { function stop() {
bot.pathfinder.setGoal(null) bot.pathfinder.setGoal(null)
bot.stopDigging() 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) => { const load = (config) => {
cfg = config cfg = config
bot = cfg.bot bot = cfg.bot
@ -219,13 +81,11 @@ const load = (config) => {
// initMoves(bot, mcData) // initMoves(bot, mcData)
setTimeout(initMoves, 500, bot, mcData) setTimeout(initMoves, 500, bot, mcData)
bot.on('goal_reached', goalReached)
} }
const unload = () => { const unload = () => {
stop() stop()
bot.off('goal_reached', goalReached)
} }
module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow } module.exports = { load, unload, stop, initMoves, moveNear, follow }

View File

@ -33,20 +33,17 @@ function sleep(quiet = cfg.sleep.quiet) {
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2) cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
bot.once('goal_reached', (goal) => { bot.once('goal_reached', (goal) => {
console.info(goal) console.info(goal)
try {
bot.sleep(bed, (err) => { bot.sleep(bed, (err) => {
if (err) { if (err) {
!quiet && bot.chat(`can't sleep: ${err.message}`) !quiet && bot.chat(`can't sleep: ${err.message}`)
} else { } else {
!quiet && bot.chat("zzz") !quiet && bot.chat("zzz")
// apparently, `bot.isSleeping = true` takes a while
// maybe it's async
console.log("sleeping? ", bot.isSleeping) console.log("sleeping? ", bot.isSleeping)
// hack until this is fixed
// TODO confirm this is fixed
// bot.isSleeping = true
} }
}) })
} catch (error) {
console.error(error)
}
}) })
}) })
} else if (bed = bot.inventory.items().filter(bot.isABed)[0]) { } else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {

View File

@ -35,16 +35,16 @@
}, },
"dependencies": { "dependencies": {
"dotenv-packed": "^1.2.1", "dotenv-packed": "^1.2.1",
"minecraft-data": "^2.73.1", "minecraft-data": "^2.70.2",
"mineflayer": "^2.40.1", "mineflayer": "^2.39.2",
"mineflayer-armor-manager": "^1.4.0", "mineflayer-armor-manager": "^1.3.0",
"mineflayer-pathfinder": "^1.3.6", "mineflayer-pathfinder": "^1.2.3",
"mineflayer-pvp": "^1.0.2", "mineflayer-pvp": "^1.0.2",
"prismarine-block": "^1.7.3", "prismarine-block": "^1.7.2",
"prismarine-chat": "^1.0.3", "prismarine-chat": "^1.0.3",
"prismarine-entity": "^1.1.0", "prismarine-entity": "^1.1.0",
"prismarine-item": "^1.5.0", "prismarine-item": "^1.5.0",
"prismarine-nbt": "^1.4.0", "prismarine-nbt": "^1.3.0",
"prismarine-recipe": "^1.1.0", "prismarine-recipe": "^1.1.0",
"typescript": "^4.1.3", "typescript": "^4.1.3",
"vec3": "^0.1.7" "vec3": "^0.1.7"