From ab9e6a09344c4e3746299c4cf0c8a9af260102a4 Mon Sep 17 00:00:00 2001 From: u9g Date: Thu, 7 Nov 2024 14:50:38 -0500 Subject: [PATCH] Make edit book function use a single feature enum --- lib/plugins/book.js | 65 +++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/lib/plugins/book.js b/lib/plugins/book.js index 9c1616979..9961af491 100644 --- a/lib/plugins/book.js +++ b/lib/plugins/book.js @@ -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) {