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:
		| @@ -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 } | ||||
| module.exports = { | ||||
|     load, unload, command, | ||||
|     stop, initMoves, | ||||
|     moveNear, moveXZ, moveY, follow, | ||||
|     ride | ||||
| } | ||||
		Reference in New Issue
	
	Block a user