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
This commit is contained in:
jay 2021-01-28 00:48:45 +05:00
parent e6d29576e7
commit 6b1157147d

View File

@ -82,6 +82,27 @@ 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 ? entity : bot.nearestEntity(e => {
const maybeRidableMob = e.mobType?.split(" ")
return e.kind == "Vehicles"
|| ridableMobs.includes(e.mobType)
|| ridableMobs.includes(maybeRidableMob[maybeRidableMob.length - 1])
})
if (!vehicle) {
return cfg.quiet || bot.chat(`Nothing to ${message_parts[0]}`)
} 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 hit(blockOrEntity) { function hit(blockOrEntity) {
bot.chat(`hitting ${entity.name || entity.type}`) bot.chat(`hitting ${entity.name || entity.type}`)
} }
@ -196,7 +217,7 @@ function command(message_parts, player) {
break break
case "ride": case "ride":
case "mount": case "mount":
bot.mount(bot.nearestEntity()) ride()
break break
case "w": case "w":
case "f": case "f":
@ -260,4 +281,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
}