PrismarineJS / mineflayer

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

TypeError: Cannot read properties of undefined (reading 'offset') #2742

Closed eeoms closed 2 years ago

eeoms commented 2 years ago

Versions

Detailed description of a problem

Im trying to make a bot simply break blocks while going to the left.

What did you try yet?

Did you try any method from the API? Did you try any example? Any error from those?

Your current code

const mineflayer = require('mineflayer');

const bot = mineflayer.createBot({
    host: 'mc.hypixel.net',
    port: 25565,
    username: '#####',
    password: '#####',
    version: "1.16.4",
    auth: 'microsoft'
})

setTimeout(async () => {
  bot.chat('/play sb')
}, 3000);

setTimeout(async () => {
  bot.chat('/is')
}, 4000);

setTimeout(async () => {
  bot.dig(true)
  bot.setControlState('left', true)
}, 5000);

/* C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:91 await bot.lookAt(block.position.offset(0.5, 0.5, 0.5), forceLook) ^

TypeError: Cannot read properties of undefined (reading 'offset') at EventEmitter.dig (C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:91:41) at Timeout._onTimeout (C:\Users\Max\OneDrive\Desktop\MC bot\index.js:21:13) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) */

Expected behavior

it digs while going left

Additional context

Add any other context about the problem here.

amoraschi commented 2 years ago

You need to pass a Block instance to bot.dig, and await it

You can get the Block instance with bot.blockAtCursor

eeoms commented 2 years ago

You need to pass a Block instance to bot.dig, and await it

You can get the Block instance with bot.blockAtCursor


setTimeout(async () => {
  const block = bot.blockAtCursor

  await bot.dig(block, true)

  bot.setControlState('left', true)
}, 5000);```
eeoms commented 2 years ago

You need to pass a Block instance to bot.dig, and await it

You can get the Block instance with bot.blockAtCursor


setTimeout(async () => {
const block = bot.blockAtCursor(8)

await bot.dig(block, false);

bot.setControlState('left', true) }, 5000);


C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19
      throw new Error('dig was called with an undefined or null block')
            ^

Error: dig was called with an undefined or null block
    at EventEmitter.dig (C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19:13)
    at Timeout._onTimeout (C:\Users\Max\OneDrive\Desktop\MC bot\index.js:23:13)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
eeoms commented 2 years ago

You need to pass a Block instance to bot.dig, and await it You can get the Block instance with bot.blockAtCursor

setTimeout(async () => {
  const block = bot.blockAtCursor(8)

  await bot.dig(block, false);

  bot.setControlState('left', true)
}, 5000);

C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19 throw new Error('dig was called with an undefined or null block') ^

Error: dig was called with an undefined or null block at EventEmitter.dig (C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19:13) at Timeout._onTimeout (C:\Users\Max\OneDrive\Desktop\MC bot\index.js:23:13) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)

eeoms commented 2 years ago

Author

setTimeout(async () => {
  bot.chat('/play sb')
}, 3000);

setTimeout(async () => {
  bot.chat('/is')
}, 4000);

setTimeout(async () => {
  const block = bot.blockAtCursor(8, false);
  await bot.dig(block, true);

  bot.setControlState('left', true)
}, 5000);

error : C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19 throw new Error('dig was called with an undefined or null block') ^

Error: dig was called with an undefined or null block at EventEmitter.dig (C:\Users\Max\OneDrive\Desktop\MC bot\node_modules\mineflayer\lib\plugins\digging.js:19:13) at Timeout._onTimeout (C:\Users\Max\OneDrive\Desktop\MC bot\index.js:22:13) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)

@amoraschi