PrismarineJS / mineflayer

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

When is a results block position null in bot.findBlock() ? #1437

Closed flowl closed 3 years ago

flowl commented 3 years ago

Why could block.position possibly be null? I'm trying the following and don't understand why position is not set.

The bot is assured to be spawned.

// Somewhere after `bot.once('spawn', ())` 
const options = {
    matching: (block: Block) => {
        const isSign = /_sign$/.test(block.name)
        if (isSign) console.log(block)
    },
   maxDistance: 24.0
}
const results = bot.findBlock(options)

Prints for example:

Block {
  type: 166,
  metadata: 3,
  light: 0,
  skyLight: 0,
  biome: {
    id: 0,
    name: 'ocean',
    displayName: 'Ocean',
    rainfall: 0.5,
    temperature: 0.5
  },
  position: null,
  stateId: 3746,
  name: 'spruce_wall_sign',
  hardness: 1,
  displayName: 'Spruce Wall Sign',
  shapes: [],
  boundingBox: 'empty',
  transparent: true,
  diggable: true,
  material: 'wood',
  harvestTools: undefined,
  drops: [ 653 ]
}

I'm using all most current stable versions.

flowl commented 3 years ago

The position of the entity is not set in the matcher function, but afterwards, at the end of findBlock when blockAt() is called.

See https://github.com/PrismarineJS/mineflayer/blob/229ae9443e0f849cfbdb3dd1a896d475e6afd0b7/lib/plugins/blocks.js#L215

rom1504 commented 3 years ago

Indeed