mineflayer
mineflayer copied to clipboard
Wrong working is nearestEntity
- [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.
Can you try 1.17.1? Or does that exhibit the same behavior?
Might be due to the server connection, is this issue still occuring?