Compare commits

...

4 Commits

Author SHA1 Message Date
jay
afd2e002df feat(mover): add new pathfinder Movements
- safeMove without parkour
- aggresiveMove that digs
2021-04-19 13:34:22 +05:00
jay
3c5ec6b360 fix(mover): ✏️ fix !go up moving left instead 2021-04-19 13:31:36 +05:00
jay
b71728e503 feat(mover): add Mule to ridable mobs 2021-04-19 13:25:04 +05:00
jay
d001280383 fix: 🥅 fix a plugin loading error
While reloading, plugin cache may not be deleted.
This happens when a loaded plugin encounters an error during reload.
This causes a deadlock in the unloading code.

So make sure cache is always deleted:
- ignore when an `unload()` function doesn't exist
- delete cache even if there are no `exports`
2021-04-19 13:15:25 +05:00
2 changed files with 18 additions and 3 deletions

View File

@ -47,7 +47,9 @@ function unloadplugin(pluginname, pluginpath) {
const plugin = require.resolve(pluginpath)
try {
if (plugin && require.cache[plugin]) {
require.cache[plugin].exports.unload()
// `unload()` isn't exported sometimes,
// when plugin isn't properly loaded
require.cache[plugin].exports?.unload?.()
delete plugins[pluginname]
delete require.cache[plugin]
}

View File

@ -23,6 +23,19 @@ function initMoves(bot = bot, mcData = bot.mcData) {
movements.push(normalMove)
movements.defaultMove = movements[0]
const aggresiveMove = new Movements(bot, mcData)
//Object.create or assign?
Object.assign(aggresiveMove, normalMove)
aggresiveMove.canDig = true
movements.push(aggresiveMove)
const safeMove = new Movements(bot, mcData)
Object.assign(safeMove, normalMove)
safeMove.allowParkour = false
safeMove.canDig = false
movements.push(safeMove)
// console.info("go init: moves:", movements)
bot.pathfinder.setMovements(normalMove)
}
@ -143,7 +156,7 @@ function away(entity = bot.nearestEntity(), invertInvert = true, dynamic = true,
function ride(entity) {
entity = entity?.entity || entity
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider"]
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider", "Mule"]
const vehicle = entity && typeof entity !== "string" ? entity : bot.nearestEntity(e => {
if (typeof entity === "string") return e.name === entity
const maybeRidableMob = e.mobType?.split(" ")
@ -314,7 +327,7 @@ function command(message_parts, player) {
case "up":
case "u":
case "j":
moveOrRide(1, 1, "left", message_parts2)
moveOrRide(1, 1, "jump", message_parts2)
break
case "back":
case "forward":