feat(mover): switch between moving and riding automatically for manual movement

This commit is contained in:
jay 2021-01-28 02:18:42 +05:00
parent d953bd4cf6
commit f336e3d736

View File

@ -103,6 +103,16 @@ function ride(entity) {
bot.mount(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}`)
} }
@ -221,19 +231,19 @@ function command(message_parts, player) {
break 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":