PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.92k stars 904 forks source link

(1.18.2) Bot cannot build to me #3045

Closed SonicandTailsCD closed 1 year ago

SonicandTailsCD commented 1 year ago

Discussed in https://github.com/PrismarineJS/mineflayer/discussions/3009

Originally posted by **SonicandTailsCD** April 2, 2023 - ☑️ The [FAQ](https://github.com/PrismarineJS/mineflayer/blob/master/docs/FAQ.md) doesn't contain a resolution to my issue ## Versions - mineflayer: 8.1.0 - server: Spigot 1.18 - node: 19.6.0 (Termux) ## Detailed description of a problem A clear and concise description of what the problem is, with as much context as possible. Previously the bot would be able to build to me when it has blocks but now it doesn't and says "No path to goal". What are you building? A bot that follows me and does a few more things What problem are you trying to solve? Bot cannot build to me ## What did you try yet? Did you try any method from the API? There isn't one. Did you try any example? Yeah Any error from those? Not at all ## Your current code ```js // bot.js // Here I tell node.js mineflayer and a few other plugins are required to load import { createBot } from 'mineflayer' import pathfinderPkg from 'mineflayer-pathfinder' import { commands, setup as setupCmds } from './lib/commands.js' import { setup as setupMfUtils } from './lib/mineflayer-utils.js' const { pathfinder, Movements } = pathfinderPkg // Here, we set up the server connection (in this case, my skin plugin server) export const bot = createBot({ host: 'SonicJavaBots.aternos.me', port: '37867', username: 'SonicandTailsCDb', version: '1.18.2' }) setupMfUtils(bot) setupCmds(bot) const mcData = (await import('minecraft-data')).default(bot.version) // Setup pathfinder bot.loadPlugin(pathfinder) bot.pathfinder.setMovements(new Movements(bot, mcData)) // And now, we work on the AI here! // Here's all of the functions: // One note tho: All functions are placeholders. function onPhysicsTick () {} function onSpawn () { bot.chat('/skin set SonicandTailsCDb robot1_alextest') bot.chat("Hey! I'm working properly :D") bot.on('chat', (daname, msg) => { if (daname === "SonicandTailsCDb") return if (daname === "SkinsRestorer") return console.log(daname + " said: " + msg) if (msg === 'follow me') { commands.followMe(daname) console.log("I started following " + daname) return } if (msg === 'Come here, sleep with me!') { commands.sleep() } if (msg === 'hey') { bot.chat("what you want?") console.log("I said: what you want?") } if (msg === 'stop following me') { commands.unFollowMe() console.log("I stopped following " + daname) } }) } // I'm unsure on how am I gonna use onPhysicsTick function but I'll leave it there in case me or @678435021 wanna use it. bot.on('physicsTick', onPhysicsTick) // Next, I'm gonna set spawn actions. bot.once('spawn', onSpawn) // And here's commands.js: import { lookAtEntity } from './mineflayer-utils.js' import { sleep } from './sleep.js' import pathfinderPkg from 'mineflayer-pathfinder' const { goals } = pathfinderPkg let bot export function setup (_bot) { bot = _bot } // Add more here when needed export const botStates = { moving: false, looking: false } export const commands = { async sleep () { console.log("Sleeping!") bot.chat("I'm coming :D") let bed = bot.findBlock({matching: block=>bot.isABed(block)}); if (!bed) { console.log("Sorry, I can't find a bed!"); return } await bot.sleep(bed) }, async followMe (daname) { this.followMe.following = true const player = bot.players[daname] if (botStates.moving) { bot.chat("Sorry, can't run this command more than once!") } botStates.moving = true if (!player?.entity) { bot.chat("I can't see you, " + daname) return } bot.chat('Okay ' + daname) const range = 4 while (this.followMe.following) { if (bot.entity.position.distanceTo(player.entity.position) + 0.15 <= range) { lookAtEntity(player.entity, true) } await sleep(200) const goal = new goals.GoalFollow(player.entity, range) try { await bot.pathfinder.goto(goal) } catch (err) { bot.chat(String(err?.message)) } } }, unFollowMe () { if (!botStates.moving) { return } botStates.moving = false this.followMe.following = false bot.pathfinder.stop() } } ``` ## Expected behavior A clear and concise description of what you expected to happen. After the bot joins it would build directly to me ## Additional context Add any other context about the problem here. NO. Thanks :)

No one is answering my request, I had to remake this issue… :( And yeah, I have the same bug.

amoraschi commented 1 year ago

You have extra functions like lookAtEntity probably interfering with pathfinder, start by removing those, and also narrow down the issue in your code

SonicandTailsCD commented 1 year ago

You have extra functions like lookAtEntity probably interfering with pathfinder, start by removing those, and also narrow down the issue in your code

No, I think the issue is in the plugin itself! It does build to me with dirt but anything else will not.

amoraschi commented 1 year ago

Screenshot_2023-05-14-00-41-10-750_com.github.android-edit.jpg

Then that's a different thing than what you mentioned in the "Detailed description"

Take a look at this property in the Movements class in mineflayer-pathfinder: https://github.com/PrismarineJS/mineflayer-pathfinder#scafoldingblocks

That Array should contain the IDs for the blocks that can be used to scaffold