mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

Wrong working is nearestEntity

Open olzx opened this issue 3 years ago • 2 comments

  • [x] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 3.11.2
  • server: vanilla 1.17
  • node: 15.10.0

Detailed description of a problem

I am trying to get the seeds in the world via nearestEntity on version 1.17. When there are really seeds, I get them, but when I pick them up, nearestEntity continues to return them. video problem

But when I changed the server version to 1.15.2 everything worked. I also tried it on version 1.16.5 - everything works. video work

It turns out a problem in the bot version - 1.17

Your current code


const mineflayer = require('mineflayer')

const bot = mineflayer.createBot({
    host: 'localhost',
    username: 'Bot',
})

let mcData
bot.once('inject_allowed', () => {
  mcData = require('minecraft-data')(bot.version)
})

bot.on('chat', (username, message) => {
    if (username === bot.username) return
  
    if (message === "!test") {
        const findItem = getItemDropWheat(bot, 15)
        if (findItem) {
            bot.chat(findItem.position.toString())
        }
  }
})

bot.on('kicked', console.log)
bot.on('error', console.log)


function getItemDropWheat(bot, maxDistance) {
    return bot.nearestEntity(entity => {
        if (entity.name !== 'item') return false

        const itemId = entity.metadata[entity.metadata.length - 1].itemId
        const seedId = mcData.itemsByName['wheat_seeds'].id
        const wheatId = mcData.itemsByName['wheat'].id

        const distance = entity.position.distanceTo(bot.entity.position)

        return (itemId === seedId || itemId === wheatId) && (distance <= maxDistance)
    })
}


Expected behavior

While the seeds are near the bot - we get them, as soon as they are not there - we do not get the coordinates.

olzx avatar Oct 09 '21 18:10 olzx

Can you try 1.17.1? Or does that exhibit the same behavior?

U5B avatar Oct 18 '21 16:10 U5B

Might be due to the server connection, is this issue still occuring?

Zn10plays avatar Feb 22 '22 17:02 Zn10plays