Skip to content

Commit

Permalink
Added support for new edit book packet (PrismarineJS#3204)
Browse files Browse the repository at this point in the history
  • Loading branch information
unlimitedcoder2 committed May 7, 2024
1 parent ec76468 commit d7beeac
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/plugins/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ function inject (bot) {
if (bot.supportFeature('editBookIsPluginChannel')) {
bot._client.registerChannel('MC|BEdit', 'slot')
bot._client.registerChannel('MC|BSign', 'slot')
editBook = (book, signing = false) => {
editBook = (book, pages, title, signing = false) => {
if (signing) bot._client.writeChannel('MC|BSign', Item.toNotch(book))
else bot._client.writeChannel('MC|BEdit', Item.toNotch(book))
}
} else if (bot.supportFeature('hasEditBookPacket')) {
editBook = (book, signing = false, hand = 0) => {
editBook = (book, pages, title, signing = false, hand = 0) => {
bot._client.write('edit_book', {
new_book: Item.toNotch(book),
signing,
hand
})
}
} else if (bot.supportFeature('hasNonNbtEditBookPacket')) {
editBook = (book, pages, title, signing = false, hand = 0) => {
bot._client.write('edit_book', {
hand,
pages,
title
})
}
}

async function write (slot, pages, author, title, signing) {
Expand All @@ -38,7 +46,7 @@ function inject (bot) {
bot.setQuickBarSlot(moveToQuickBar ? 0 : slot - 36)

const modifiedBook = await modifyBook(moveToQuickBar ? 36 : slot, pages, author, title, signing)
editBook(modifiedBook, signing)
editBook(modifiedBook, pages, title, signing)
await once(bot.inventory, `updateSlot:${moveToQuickBar ? 36 : slot}`)

bot.setQuickBarSlot(quickBarSlot)
Expand Down Expand Up @@ -88,4 +96,4 @@ function inject (bot) {
bot.signBook = async (slot, pages, author, title) => {
await write(slot, pages, author, title, true)
}
}
}

0 comments on commit d7beeac

Please sign in to comment.