Skip to content

getDroppedItem may throw error on some entities #37

@IceTank

Description

@IceTank

I used getDroppedItem on entities in the bots render distance and got this error once

TypeError: Cannot read properties of undefined (reading 'blockId')
     at Function.fromNotch (/home/pi/Documents/mineflayer-auto-shepherd/node_modules/prismarine-item/index.js:81:18)
     at Entity.getDroppedItem (/home/pi/Documents/mineflayer-auto-shepherd/node_modules/prismarine-entity/index.js:44:19)
     at /home/pi/Documents/mineflayer-auto-shepherd/dist/plugins/autoShepherd.js:27:98
     at Array.filter (<anonymous>)

The server is running on paper 1.12.2 and there should not be any weird entities around.
I don't know how to reproduce that error as it only happened once
The code calling the function looks like this

const droppedItems = Object.values(bot.entities).filter(e => {
  return e.name === 'item' && e.position.distanceTo(bot.entity.position) < 30 && e.getDroppedItem()?.name?.includes('wool')
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions