diff --git a/lib/plugins/mover.js b/lib/plugins/mover.js index da91063..254a7fc 100644 --- a/lib/plugins/mover.js +++ b/lib/plugins/mover.js @@ -82,6 +82,27 @@ function follow(entity, dynamic = true, distance = 3) { 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) { bot.chat(`hitting ${entity.name || entity.type}`) } @@ -196,7 +217,7 @@ function command(message_parts, player) { break case "ride": case "mount": - bot.mount(bot.nearestEntity()) + ride() break case "w": case "f": @@ -260,4 +281,9 @@ const unload = () => { bot.off('goal_reached', goalReached) } -module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow } \ No newline at end of file +module.exports = { + load, unload, command, + stop, initMoves, + moveNear, moveXZ, moveY, follow, + ride +} \ No newline at end of file