PrismarineJS / mineflayer

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

window.containerItems is not a function #706

Closed unixfox closed 6 years ago

unixfox commented 6 years ago

I'm trying to activate the item that the bot will get when spawning on the minecraft server (us.stratus.network) and then print the items of the window opened by the server to the console.

This my code:

const mineflayer = require('mineflayer');

const windows = require('prismarine-windows').windows;

const Item=require("prismarine-item");

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node bot.js <host> <port> [<name>] [<password>]')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'ansi',
  password: process.argv[5],
  verbose: true,
  version:"1.8"
})

bot.once('spawn', () => {
  bot.activateItem();
});

bot.once('windowOpen', function(window) {
  console.log(window.containerItems());
});

I get this error when I launch it:

/home/emilien/Documents/botmc/bot.js:50
  console.log(window.containerItems());
                              ^

TypeError: window.containerItems is not a function
    at Bot.<anonymous> (/home/emilien/Documents/botmc/bot.js:50:31)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Bot.emit (events.js:211:7)
    at Bot.bot.once (/home/emilien/Documents/botmc/node_modules/mineflayer/lib/plugins/inventory.js:518:13)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Bot.emit (events.js:208:7)
    at Client.bot._client.on (/home/emilien/Documents/botmc/node_modules/mineflayer/lib/plugins/inventory.js:563:9)
    at emitTwo (events.js:126:13)

I tried to downgrade to mineflayer 1.5.1 when prismarine-windows was a library inside the mineflayer repository but that doesn't resolve the issue.

What did I do wrong?

plexigras commented 6 years ago

what is the window variable?

console.log(window)

what is the mineflayer and prismarine-windows version?

npm info mineflayer version
npm info prismarine-window version
plexigras commented 6 years ago

i also just noticed that the error is happening in line 50 but the script is only 27 lines long.

rom1504 commented 6 years ago

https://github.com/PrismarineJS/prismarine-windows/blob/master/lib/windows.js

rom1504 commented 6 years ago

re-open if you still have the issue