Skip to content

Commit

Permalink
Make edit book function use a single feature enum
Browse files Browse the repository at this point in the history
  • Loading branch information
u9g authored Nov 7, 2024
1 parent 3d6e234 commit ab9e6a0
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions lib/plugins/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,50 @@ function inject (bot) {
const Item = require('prismarine-item')(bot.registry)

let editBook
if (bot.supportFeature('editBookIsPluginChannel')) {
bot._client.registerChannel('MC|BEdit', 'slot')
bot._client.registerChannel('MC|BSign', 'slot')
editBook = (book, pages, title, slot, 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')) {
if (bot.supportFeature('editBookPacketUsesNbt')) { // 1.13 - 1.17
editBook = (book, pages, title, slot, signing = false, hand = 0) => {
bot._client.write('edit_book', {
hand: slot,
pages,
title
})
switch (bot.supportFeature('editBookFunctionVersion')) {
case 0:
{
bot._client.registerChannel('MC|BEdit', 'slot')
bot._client.registerChannel('MC|BSign', 'slot')
editBook = (book, pages, title, slot, signing = false) => {
if (signing) bot._client.writeChannel('MC|BSign', Item.toNotch(book))
else bot._client.writeChannel('MC|BEdit', Item.toNotch(book))
}
break;
}
} else { // 1.18+
editBook = (book, pages, title, slot, signing = false, hand = 0) => {
bot._client.write('edit_book', {
new_book: Item.toNotch(book),
signing,
hand
})
case 1:
{
editBook = (book, pages, title, slot, signing = false, hand = 0) => {
bot._client.write('edit_book', {
hand: slot,
pages,
title
})
}
break;
}
case 2:
{
editBook = (book, pages, title, slot, signing = false, hand = 0) => {
bot._client.write('edit_book', {
new_book: Item.toNotch(book),
signing,
hand
})
}
break;
}
case 3:
{
editBook = (book, pages, title, slot, signing = false, hand = 0) => {
bot._client.write('edit_book', {
hand,
pages,
title
})
}
break;
}
}
}

async function write (slot, pages, author, title, signing) {
Expand Down

0 comments on commit ab9e6a0

Please sign in to comment.