From 43e4b15c3fad468a2397a8f3792f244343e1bf01 Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:55:29 +0300 Subject: [PATCH 01/11] Update enchantment_table.js made expected enchant be a string and not an id --- lib/plugins/enchantment_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index e6c4df937..3dac4ea67 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -40,7 +40,7 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - slot.expected.enchant = packet.value + slot.expected.enchant = bot.registry.enchantments[packet.value].name } else if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value From e7cb4b8251b0ea051f89e1a14f40f8f88c781b7e Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Wed, 26 Jul 2023 17:05:34 +0300 Subject: [PATCH 02/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 3dac4ea67..220a813de 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -40,7 +40,10 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - slot.expected.enchant = bot.registry.enchantments[packet.value].name + if (packet.value === -1) { slot.expected.enchant = -1 } + else { + slot.expected.enchant = bot.registry.enchantments[packet.value].name + } } else if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value From 64aeef6166dbbd7d09536e5453b9cee54d369c57 Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Wed, 26 Jul 2023 17:07:17 +0300 Subject: [PATCH 03/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 220a813de..b19cc025c 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -40,7 +40,7 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - if (packet.value === -1) { slot.expected.enchant = -1 } + if (packet.value === -1) { slot.expected.enchant = null } else { slot.expected.enchant = bot.registry.enchantments[packet.value].name } From 919deb4253baa08f0e0beb09d79ac95a4ae49c1c Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Wed, 26 Jul 2023 17:19:28 +0300 Subject: [PATCH 04/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index b19cc025c..acb1f0fa6 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -49,7 +49,7 @@ function inject (bot) { slot.expected.level = packet.value } - if (slots[0].level >= 0 && slots[1].level >= 0 && slots[2].level >= 0) { + if (slots[0].level > 0 && slots[1].level > 0 && slots[2].level > 0) { if (!ready) { ready = true enchantmentTable.emit('ready') From 00173ca180e1e271a01201ade637471b6828562b Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Wed, 26 Jul 2023 17:53:27 +0300 Subject: [PATCH 05/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index acb1f0fa6..591d242c3 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -49,7 +49,7 @@ function inject (bot) { slot.expected.level = packet.value } - if (slots[0].level > 0 && slots[1].level > 0 && slots[2].level > 0) { + if (slots[0].expected.level > 0 && slots[1].expected.level > 0 && slots[2].expected.level > 0) { if (!ready) { ready = true enchantmentTable.emit('ready') From eae93d7782593b4853cedafd98c7c9bd324b3b1f Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:48:25 +0300 Subject: [PATCH 06/11] reverted structure change --- lib/plugins/enchantment_table.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 591d242c3..27da3146d 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -40,10 +40,7 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - if (packet.value === -1) { slot.expected.enchant = null } - else { - slot.expected.enchant = bot.registry.enchantments[packet.value].name - } + slot.expected.enchant = packet.value } else if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value From c700a21415cd918bf5bff6eb8bf1246c4ab2860f Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:15:18 +0300 Subject: [PATCH 07/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 39 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 27da3146d..b08da6a0d 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { once } = require('events') +const { once } = require('../promise_utils') module.exports = inject @@ -9,7 +9,7 @@ function inject (bot) { let ready = false const enchantmentTable = await bot.openBlock(enchantmentTableBlock) if (!enchantmentTable.type.startsWith('minecraft:enchant')) { - throw new Error('This is not an enchantment table') + throw new Error('Expected minecraft:enchant when opening table but got ' + enchantmentTable.type) } resetEnchantmentOptions() @@ -27,12 +27,27 @@ function inject (bot) { return enchantmentTable + function onUpdateWindowProperty (packet) { if (packet.windowId !== enchantmentTable.id) return assert.ok(packet.property >= 0) const slots = enchantmentTable.enchantments + + if (packet.property === 4){ + for (let i=0;i<3;i++) { + // console.log('setting appropriate slots') + if (slots[i].level === 0) { + slots[i].level = 0 + slots[i].expected.enchant = null + slots[i].expected.level = 0 + } + } + } + + // console.log(packet.property) + // console.log(packet.value) if (packet.property < 3) { const slot = slots[packet.property] slot.level = packet.value @@ -40,19 +55,27 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - slot.expected.enchant = packet.value + if (packet.value === -1) { slot.expected.enchant = null } + else { + slot.expected.enchant = bot.registry.enchantments[packet.value].name + } } else if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value } - if (slots[0].expected.level > 0 && slots[1].expected.level > 0 && slots[2].expected.level > 0) { + + + // console.log(slots) + if (slots[0].expected.level > 0 && slots[1].expected.level >= 0 && slots[2].expected.level >=0 ) { if (!ready) { ready = true - enchantmentTable.emit('ready') + //console.log('emitted ready') + //console.log(slots) + enchantmentTable.emit('ready') } } else { - ready = false + ready = false } } @@ -75,6 +98,10 @@ function inject (bot) { if (!ready) await once(enchantmentTable, 'ready') choice = parseInt(choice, 10) // allow string argument assert.notStrictEqual(enchantmentTable.enchantments[choice].level, -1) + + // if (enchantmentTable.enchantments[choice].level>bot.experience.level) throw new Error('insufficient xp to enchant') + + // console.log('enchanting choice '+choice) bot._client.write('enchant_item', { windowId: enchantmentTable.id, enchantment: choice From ba16c30c1cb658e7ddef9b0dc8d55d51293b2aa7 Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:26:16 +0300 Subject: [PATCH 08/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index b08da6a0d..c707c775a 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -34,7 +34,7 @@ function inject (bot) { const slots = enchantmentTable.enchantments - + if (bot.majorVersion === "1.8"){ if (packet.property === 4){ for (let i=0;i<3;i++) { // console.log('setting appropriate slots') @@ -44,7 +44,7 @@ function inject (bot) { slots[i].expected.level = 0 } } - } + }} // console.log(packet.property) // console.log(packet.value) @@ -55,7 +55,9 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] + if (bpt.majorVersion === "1.8" ) {slot.expected.enchant = packet.value} else { if (packet.value === -1) { slot.expected.enchant = null } + } else { slot.expected.enchant = bot.registry.enchantments[packet.value].name } @@ -64,10 +66,17 @@ function inject (bot) { slot.expected.level = packet.value } - + let readycheck; + + if (bot.majorVersion === "1.8") { + readyCheck = slots[0].level >= 0 && slots[1].level >= 0 && slots[2].level >= 0 + } else + { + readyCheck = slots[0].expected.level > 0 && slots[1].expected.level >= 0 && slots[2].expected.level >=0 + } // console.log(slots) - if (slots[0].expected.level > 0 && slots[1].expected.level >= 0 && slots[2].expected.level >=0 ) { + if (readyCheck) { if (!ready) { ready = true //console.log('emitted ready') From bd3998e3ab1ccbf93eaac52d5bc76b882fd91d60 Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:27:17 +0300 Subject: [PATCH 09/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index c707c775a..daa735273 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -34,7 +34,7 @@ function inject (bot) { const slots = enchantmentTable.enchantments - if (bot.majorVersion === "1.8"){ + if (bot.majorVersion !== "1.8"){ if (packet.property === 4){ for (let i=0;i<3;i++) { // console.log('setting appropriate slots') From 5ac33720af0d0f479eb8e06a49c4c1b99ace4278 Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:27:57 +0300 Subject: [PATCH 10/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index daa735273..3fa1c2427 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -55,7 +55,8 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - if (bpt.majorVersion === "1.8" ) {slot.expected.enchant = packet.value} else { + if (bot.majorVersion === "1.8" ) { slot.expected.enchant = packet.value } + else { if (packet.value === -1) { slot.expected.enchant = null } } else { From d144456fad4c6679060b9093765eb129fb850f4b Mon Sep 17 00:00:00 2001 From: Has Name <65046191+zisis912@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:29:15 +0300 Subject: [PATCH 11/11] Update enchantment_table.js --- lib/plugins/enchantment_table.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 3fa1c2427..0f4046616 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -57,11 +57,11 @@ function inject (bot) { const slot = slots[packet.property - 4] if (bot.majorVersion === "1.8" ) { slot.expected.enchant = packet.value } else { + if (packet.value === -1) { slot.expected.enchant = null } - } - else { - slot.expected.enchant = bot.registry.enchantments[packet.value].name - } + else { slot.expected.enchant = bot.registry.enchantments[packet.value].name } + + } } else if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value