Skip to content

Commit e5b5eee

Browse files
kaduvertrom1504
andauthored
Import changedSlots computation from prismarine-windows (#3134)
* copy changedSlots logic from prismarine-windows * added possibility for returning slots directly * lint fix * fix lint * depend on other pr for tests * fix slot comparing * fix * Update package.json --------- Co-authored-by: Romain Beaumont <[email protected]>
1 parent bbdd93a commit e5b5eee

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/plugins/inventory.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,20 @@ function inject (bot, { hideErrors }) {
479479
}
480480
}
481481

482+
function getChangedSlots (oldSlots, newSlots) {
483+
assert.equal(oldSlots.length, newSlots.length)
484+
485+
const changedSlots = []
486+
487+
for (let i = 0; i < newSlots.length; i++) {
488+
if (!Item.equal(oldSlots[i], newSlots[i])) {
489+
changedSlots.push(i)
490+
}
491+
}
492+
493+
return changedSlots
494+
}
495+
482496
async function clickWindow (slot, mouseButton, mode) {
483497
// if you click on the quick bar and have dug recently,
484498
// wait a bit
@@ -506,7 +520,33 @@ function inject (bot, { hideErrors }) {
506520
if (bot.supportFeature('transactionPacketExists')) {
507521
windowClickQueue.push(click)
508522
} else {
509-
changedSlots = window.acceptClick(click)
523+
if (
524+
// this array indicates the clicks that return changedSlots
525+
[
526+
0,
527+
// 1,
528+
// 2,
529+
3,
530+
4
531+
// 5,
532+
// 6
533+
].includes(click.mode)) {
534+
changedSlots = window.acceptClick(click)
535+
} else {
536+
// this is used as a fallback
537+
const oldSlots = JSON.parse(JSON.stringify(window.slots))
538+
539+
window.acceptClick(click)
540+
541+
changedSlots = getChangedSlots(oldSlots, window.slots)
542+
}
543+
544+
changedSlots = changedSlots.map(slot => {
545+
return {
546+
location: slot,
547+
item: Item.toNotch(window.slots[slot])
548+
}
549+
})
510550
}
511551

512552
// WHEN ADDING SUPPORT FOR OTHER CLICKS, MAKE SURE TO CHANGE changedSlots TO SUPPORT THEM

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"prismarine-physics": "^1.7.0",
3434
"prismarine-recipe": "^1.3.0",
3535
"prismarine-registry": "^1.5.0",
36-
"prismarine-windows": "^2.5.0",
36+
"prismarine-windows": "^2.8.0",
3737
"prismarine-world": "^3.6.0",
3838
"protodef": "^1.14.0",
3939
"typed-emitter": "^1.0.0",

0 commit comments

Comments
 (0)