MCPcopy
hub / github.com/PrismarineJS/mineflayer / clickWindow

Function clickWindow

lib/plugins/inventory.js:543–646  ·  view source on GitHub ↗
(slot, mouseButton, mode)

Source from the content-addressed store, hash-verified

541 }
542
543 async function clickWindow (slot, mouseButton, mode) {
544 // if you click on the quick bar and have dug recently,
545 // wait a bit
546 if (slot >= bot.QUICK_BAR_START && bot.lastDigTime != null) {
547 let timeSinceLastDig
548 while ((timeSinceLastDig = new Date() - bot.lastDigTime) < DIG_CLICK_TIMEOUT) {
549 await sleep(DIG_CLICK_TIMEOUT - timeSinceLastDig)
550 }
551 }
552 const window = bot.currentWindow || bot.inventory
553
554 assert.ok(mode >= 0 && mode <= 6)
555 const actionId = createActionNumber()
556
557 const click = {
558 slot,
559 mouseButton,
560 mode,
561 id: actionId,
562 windowId: window.id,
563 item: slot === -999 ? null : window.slots[slot]
564 }
565
566 let changedSlots
567 if (bot.supportFeature('transactionPacketExists')) {
568 windowClickQueue.push(click)
569 } else {
570 if (
571 // this array indicates the clicks that return changedSlots
572 [
573 0,
574 // 1,
575 // 2,
576 3,
577 4
578 // 5,
579 // 6
580 ].includes(click.mode)) {
581 changedSlots = window.acceptClick(click)
582 } else {
583 // this is used as a fallback
584 const oldSlots = JSON.parse(JSON.stringify(window.slots))
585
586 window.acceptClick(click)
587
588 changedSlots = getChangedSlots(oldSlots, window.slots)
589 }
590
591 changedSlots = changedSlots.map(slot => {
592 return {
593 location: slot,
594 item: Item.toNotch(window.slots[slot])
595 }
596 })
597 }
598
599 // WHEN ADDING SUPPORT FOR OTHER CLICKS, MAKE SURE TO CHANGE changedSlots TO SUPPORT THEM
600 if (bot.supportFeature('stateIdUsed')) { // 1.17.1 +

Callers 6

putSelectedItemRangeFunction · 0.85
tossLeftoverFunction · 0.85
transferOneFunction · 0.85
clickDestFunction · 0.85
putAwayFunction · 0.85
moveSlotItemFunction · 0.85

Calls 7

createActionNumberFunction · 0.85
getChangedSlotsFunction · 0.85
onceFunction · 0.85
confirmTransactionFunction · 0.85
withTimeoutFunction · 0.85
waitForWindowUpdateFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…