From 6b1157147d5a3ae308862b10f785ec29ae51caf5 Mon Sep 17 00:00:00 2001 From: jay Date: Thu, 28 Jan 2021 00:48:45 +0500 Subject: [PATCH] feat(mover): :sparkles: 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 --- lib/plugins/mover.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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