From f336e3d73679e8a1bec382ac108af9c7bfb9edd1 Mon Sep 17 00:00:00 2001 From: jay Date: Thu, 28 Jan 2021 02:18:42 +0500 Subject: [PATCH] feat(mover): :sparkles: switch between moving and riding automatically for manual movement --- lib/plugins/mover.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/plugins/mover.js b/lib/plugins/mover.js index 9bf6b3a..3f1c51f 100644 --- a/lib/plugins/mover.js +++ b/lib/plugins/mover.js @@ -103,6 +103,16 @@ function ride(entity) { 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) { bot.chat(`hitting ${entity.name || entity.type}`) } @@ -221,19 +231,19 @@ function command(message_parts, player) { break case "w": case "f": - command(["forward"].concat(message_parts.slice(1))) + moveOrRide(0, -1, "forward", message_parts2) break case "s": case "b": - command(["back"].concat(message_parts.slice(1))) + moveOrRide(0, 1, "back", message_parts2) break case "a": case "l": - command(["right"].concat(message_parts.slice(1))) + moveOrRide(1, -1, "right", message_parts2) break case "d": case "r": - command(["left"].concat(message_parts.slice(1))) + moveOrRide(1, 1, "left", message_parts2) break case "back": case "forward":