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

bot.moveSlotItem returns with error #488

Closed plexigras closed 7 years ago

plexigras commented 7 years ago
assert.ok(bot.inventory.slots[slot], `no item in slot ${slot}`)
bot.moveSlotItem(slot, 36, console.log)

returns an error

Error: Server rejected transaction.

at line 467 of inventory.js

rom1504 commented 7 years ago

well, is there something on slot 36 ?

plexigras commented 7 years ago

yes but this should handel that. right?

rom1504 commented 7 years ago

No, that handles the case when you're holding an item https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/inventory.js#L491

rom1504 commented 7 years ago

ah well, maybe it would handle it

rom1504 commented 7 years ago

@plexigras are you waiting for the callback ?

plexigras commented 7 years ago

yes

rom1504 commented 7 years ago

I mean, what you put in the first post of the issue is your whole code ?

plexigras commented 7 years ago

no i'm trying out my book implementation https://gist.github.com/a21fe04c58aeca16447edb9ff872c3cd

but i'm gonna give the code above a try

plexigras commented 7 years ago

oh wait somehow this works:

bot.once('login', () => console.log('loged in'))
bot._client.once('window_items', () => {
  console.log('got items');
  print();
  var [ book ] = bot.inventory.items().filter(({ name }) => name === 'writable_book')
  var slot = book.slot;
  assert.ok(bot.inventory.slots[slot], `no item in slot ${slot}`)
  bot.moveSlotItem(slot, 36, (err) => {
    console.log('err:',err);
    print();
  })
});

function print() {
  var books = bot.inventory.items().filter(({ name }) => name === 'writable_book')
  console.log('books:',books.length);
  console.log('slots:',books.map(book => book.slot));
}