From 8b7c786de73e92b5c16761cd97222a0f6fb04e32 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 09:31:33 -0400 Subject: [PATCH 1/7] updating activateItem --- lib/plugins/inventory.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 497021841..104ee6990 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -26,6 +26,7 @@ function inject (bot, { hideErrors }) { const windows = require('prismarine-windows')(bot.version) let eatingTask = createDoneTask() + let lastUsedIsOffhand = false let nextActionNumber = 0 // < 1.17 let stateId = -1 @@ -43,6 +44,7 @@ function inject (bot, { hideErrors }) { bot.inventory = windows.createWindow(0, 'minecraft:inventory', 'Inventory') bot.currentWindow = null bot.usingHeldItem = false + Object.defineProperty(bot, 'heldItem', { get: function () { return bot.inventory.slots[bot.QUICK_BAR_START + bot.quickBarSlot] @@ -122,17 +124,27 @@ function inject (bot, { hideErrors }) { }) } else if (bot.supportFeature('useItemWithOwnPacket')) { bot._client.write('use_item', { - hand: offHand ? 1 : 0 + hand: offHand ? 1 : 0, + sequence: 1 }) + + lastUsedIsOffhand = offHand } } function deactivateItem () { - bot._client.write('block_dig', { - status: 5, - location: new Vec3(0, 0, 0), - face: 5 - }) + if (bot.supportFeature('useItemWithBlockPlace')) { + bot._client.write('block_dig', { + status: 5, + location: new Vec3(0, 0, 0), + face: 5 + }) + } else if (bot.supportFeature('useItemWithOwnPacket')) { + bot._client.write('use_item', { + hand: lastUsedIsOffhand ? 1 : 0, + sequence: 2 + }) + } bot.usingHeldItem = false } From 829089c766416e96caf388739569f84636550921 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 09:47:03 -0400 Subject: [PATCH 2/7] updating activateItem --- lib/plugins/inventory.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 104ee6990..029a3699c 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -27,6 +27,7 @@ function inject (bot, { hideErrors }) { let eatingTask = createDoneTask() let lastUsedIsOffhand = false + let sequence = 0; let nextActionNumber = 0 // < 1.17 let stateId = -1 @@ -125,26 +126,28 @@ function inject (bot, { hideErrors }) { } else if (bot.supportFeature('useItemWithOwnPacket')) { bot._client.write('use_item', { hand: offHand ? 1 : 0, - sequence: 1 + sequence: ++sequence }) lastUsedIsOffhand = offHand + } } function deactivateItem () { - if (bot.supportFeature('useItemWithBlockPlace')) { - bot._client.write('block_dig', { - status: 5, - location: new Vec3(0, 0, 0), - face: 5 - }) - } else if (bot.supportFeature('useItemWithOwnPacket')) { - bot._client.write('use_item', { - hand: lastUsedIsOffhand ? 1 : 0, - sequence: 2 - }) + const body = { + status: 5, + location: new Vec3(0, 0, 0), + face: 5 + } + + if (bot.supportFeature('useItemWithOwnPacket')) { + body.face = 0; + body.sequence = 0; } + + bot._client.write('block_dig', body) + bot.usingHeldItem = false } From f78cebb6eeca0ddc23d1a188f71fa672bf19fae3 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 09:49:13 -0400 Subject: [PATCH 3/7] fix lint --- lib/plugins/inventory.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 029a3699c..3aa7fef41 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -26,8 +26,7 @@ function inject (bot, { hideErrors }) { const windows = require('prismarine-windows')(bot.version) let eatingTask = createDoneTask() - let lastUsedIsOffhand = false - let sequence = 0; + let sequence = 0 let nextActionNumber = 0 // < 1.17 let stateId = -1 @@ -128,9 +127,6 @@ function inject (bot, { hideErrors }) { hand: offHand ? 1 : 0, sequence: ++sequence }) - - lastUsedIsOffhand = offHand - } } @@ -142,12 +138,12 @@ function inject (bot, { hideErrors }) { } if (bot.supportFeature('useItemWithOwnPacket')) { - body.face = 0; - body.sequence = 0; + body.face = 0 + body.sequence = 0 } bot._client.write('block_dig', body) - + bot.usingHeldItem = false } From b109211c777b9738efa0d2f77a730b970676e139 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 21:51:47 -0400 Subject: [PATCH 4/7] moved sequence upward --- lib/plugins/inventory.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 3aa7fef41..53c9051d2 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -123,9 +123,10 @@ function inject (bot, { hideErrors }) { cursorZ: -1 }) } else if (bot.supportFeature('useItemWithOwnPacket')) { + sequence++ bot._client.write('use_item', { hand: offHand ? 1 : 0, - sequence: ++sequence + sequence }) } } From 177e3ab9fc995f4d36804b04dd878e740e8f182d Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 22:14:35 -0400 Subject: [PATCH 5/7] moved sequence upward --- lib/plugins/inventory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 53c9051d2..4ba6070a5 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -123,7 +123,7 @@ function inject (bot, { hideErrors }) { cursorZ: -1 }) } else if (bot.supportFeature('useItemWithOwnPacket')) { - sequence++ + sequence++ // comment to force actions bot._client.write('use_item', { hand: offHand ? 1 : 0, sequence From c7a814a456ea0efa6528aa641635d8415976c0c8 Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 22:20:00 -0400 Subject: [PATCH 6/7] removed comment, these tests passing feel like roulette. --- lib/plugins/inventory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index 4ba6070a5..53c9051d2 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -123,7 +123,7 @@ function inject (bot, { hideErrors }) { cursorZ: -1 }) } else if (bot.supportFeature('useItemWithOwnPacket')) { - sequence++ // comment to force actions + sequence++ bot._client.write('use_item', { hand: offHand ? 1 : 0, sequence From a12030c6380cdb0c6f6c0ad0f81511bf12043ebf Mon Sep 17 00:00:00 2001 From: GenerelSchwerz Date: Tue, 20 Aug 2024 22:34:30 -0400 Subject: [PATCH 7/7] reorganized --- lib/plugins/inventory.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index e5835dc4c..cc4f2f062 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -113,6 +113,8 @@ function inject (bot, { hideErrors }) { function activateItem (offHand = false) { bot.usingHeldItem = true + sequence++ + if (bot.supportFeature('useItemWithBlockPlace')) { bot._client.write('block_place', { location: new Vec3(-1, 255, -1), @@ -123,7 +125,6 @@ function inject (bot, { hideErrors }) { cursorZ: -1 }) } else if (bot.supportFeature('useItemWithOwnPacket')) { - sequence++ bot._client.write('use_item', { hand: offHand ? 1 : 0, sequence