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
Alex Howe committed May 7, 2024
1 parent ec76468 commit 7cb6399
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 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

0 comments on commit 7cb6399

Please sign in to comment.