Compare commits

..

8 Commits

Author SHA1 Message Date
jay
2f88eedce9 fix(mover): lessen move duration for more precise control 2021-01-28 03:52:12 +05:00
jay
a0893f2b29 feat(mover): allow riding specific entity by name 2021-01-28 02:50:08 +05:00
jay
b1a592dbbd fix(mover): 🐛 workaround for vehicle not being removed in api on dismount
`bot.vehicle` isn't removed on dismount, so this done manually
2021-01-28 02:24:59 +05:00
jay
f336e3d736 feat(mover): switch between moving and riding automatically for manual movement 2021-01-28 02:18:42 +05:00
jay
d953bd4cf6 fix(mover): 🎨 fix quiet not being "followed" 2021-01-28 02:10:52 +05:00
jay
fc43985337 fix(mover): 🐛 fix crash when no mobs nearby while searching for rides 2021-01-28 01:28:37 +05:00
jay
6b1157147d feat(mover): implement more featureful and robust ride command
Now does the following:
- finds entities (both vehicles and animals) which are suitable for riding.
- moves to get into range.

However:
- while in a vehicle, pathfinder doesn't appear to detec coords.
- `bot.moveVehicle` doesn't work, so bot doesn't move when riding
2021-01-28 00:48:45 +05:00
jay
e6d29576e7 refactor(command): 🚚 move vehicle commands near other moves
Move the following:
- vehicle commands next to other movement related commands like `go`.
- move `ride` / `mount` command functionality into mover plugin
2021-01-26 22:49:23 +05:00
2 changed files with 64 additions and 24 deletions

View File

@ -217,6 +217,17 @@ function command(username, message) {
subcommand("go follow once") subcommand("go follow once")
} }
break; 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 "move":
case "go": case "go":
cfg.plugins.mover.command(message_parts.slice(1), player) cfg.plugins.mover.command(message_parts.slice(1), player)
@ -318,18 +329,6 @@ function command(username, message) {
case "info": case "info":
cfg.plugins.informer.command(message_parts.splice(1)) cfg.plugins.informer.command(message_parts.splice(1))
break break
case "ride":
case "mount":
bot.mount(bot.nearestEntity())
break
case "getoff":
case "unmount":
case "dismount":
bot.dismount()
break
case "go":
bot.moveVehicle(0, 10)
break
// case "use": // case "use":
// bot.useOn(bot.nearestEntity()) // bot.useOn(bot.nearestEntity())
// break; // break;

View File

@ -67,8 +67,8 @@ 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
cfg.quiet && console.log(entity) // console.log(entity)
|| bot.chat( cfg.quiet || bot.chat(
`following ${entity.type `following ${entity.type
}: ${entity.username || entity.displayName }: ${entity.username || entity.displayName
}${dynamic ? "" : " once"}` }${dynamic ? "" : " once"}`
@ -82,6 +82,38 @@ function follow(entity, dynamic = true, distance = 3) {
bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic) bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic)
} }
function ride(entity) {
entity = entity?.entity || entity
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(" ")
return e.kind == "Vehicles"
|| ridableMobs.includes(e.mobType)
|| maybeRidableMob && ridableMobs.includes(maybeRidableMob[maybeRidableMob.length - 1])
})
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) { function hit(blockOrEntity) {
bot.chat(`hitting ${entity.name || entity.type}`) bot.chat(`hitting ${entity.name || entity.type}`)
} }
@ -194,21 +226,25 @@ function command(message_parts, player) {
break break
} }
break break
case "ride":
case "mount":
ride(message_parts2[0])
break
case "w": case "w":
case "f": case "f":
command(["forward"].concat(message_parts.slice(1))) moveOrRide(0, -1, "forward", message_parts2)
break break
case "s": case "s":
case "b": case "b":
command(["back"].concat(message_parts.slice(1))) moveOrRide(0, 1, "back", message_parts2)
break break
case "a": case "a":
case "l": case "l":
command(["right"].concat(message_parts.slice(1))) moveOrRide(1, -1, "right", message_parts2)
break break
case "d": case "d":
case "r": case "r":
command(["left"].concat(message_parts.slice(1))) moveOrRide(1, 1, "left", message_parts2)
break break
case "back": case "back":
case "forward": case "forward":
@ -220,7 +256,7 @@ function command(message_parts, player) {
console.info(bot.controlState[message_parts[0]], bot.entity.position.floored()) console.info(bot.controlState[message_parts[0]], bot.entity.position.floored())
bot.setControlState(message_parts[0], true) bot.setControlState(message_parts[0], true)
console.info(bot.controlState[message_parts[0]]) console.info(bot.controlState[message_parts[0]])
setTimeout(bot.setControlState, 200 * (message_parts[1] || 1), message_parts[0], false) 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()) setTimeout(console.info, 5000, bot.controlState[message_parts[0]], bot.entity.position.floored())
break break
case "stop": case "stop":
@ -256,4 +292,9 @@ const unload = () => {
bot.off('goal_reached', goalReached) bot.off('goal_reached', goalReached)
} }
module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow } module.exports = {
load, unload, command,
stop, initMoves,
moveNear, moveXZ, moveY, follow,
ride
}