minecraft-inventory 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -147,6 +147,14 @@ function isEnchantmentTableWindow(win: unknown): win is { enchant: (choice: numb
|
|
|
147
147
|
return win != null && typeof (win as Record<string, unknown>).enchant === 'function'
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/** Registry property keys for the three enchant rows (craft_progress_bar data slots 0–2). */
|
|
151
|
+
const ENCHANT_OPTION_LEVEL_KEYS = ['topEnchantLevel', 'middleEnchantLevel', 'bottomEnchantLevel'] as const
|
|
152
|
+
|
|
153
|
+
function isEnchantingTableWindowType(type: string | undefined | null): boolean {
|
|
154
|
+
if (!type) return false
|
|
155
|
+
return getInventoryType(type)?.name === 'enchanting_table'
|
|
156
|
+
}
|
|
157
|
+
|
|
150
158
|
function isAnvilWindow(
|
|
151
159
|
win: unknown
|
|
152
160
|
): win is {
|
|
@@ -641,10 +649,55 @@ export function createMineflayerConnector(bot: MineflayerBot, options?: Mineflay
|
|
|
641
649
|
return
|
|
642
650
|
}
|
|
643
651
|
|
|
644
|
-
if (action.type === 'enchant'
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
652
|
+
if (action.type === 'enchant') {
|
|
653
|
+
if (!win) {
|
|
654
|
+
logActionEvent('connector.action.skipped', action, { reason: 'no_open_window' })
|
|
655
|
+
return
|
|
656
|
+
}
|
|
657
|
+
if (!isEnchantingTableWindowType(win.type)) {
|
|
658
|
+
logActionEvent('connector.action.skipped', action, {
|
|
659
|
+
reason: 'not_enchanting_table',
|
|
660
|
+
windowType: win.type,
|
|
661
|
+
})
|
|
662
|
+
return
|
|
663
|
+
}
|
|
664
|
+
const choice = action.enchantIndex
|
|
665
|
+
if (!Number.isInteger(choice) || choice < 0 || choice > 2) {
|
|
666
|
+
logActionEvent('connector.action.skipped', action, { reason: 'invalid_enchant_index' })
|
|
667
|
+
return
|
|
668
|
+
}
|
|
669
|
+
const optionLevel = windowProperties[ENCHANT_OPTION_LEVEL_KEYS[choice]] ?? -1
|
|
670
|
+
if (optionLevel <= 0) {
|
|
671
|
+
logActionEvent('connector.action.skipped', action, {
|
|
672
|
+
reason: 'enchant_option_unavailable',
|
|
673
|
+
level: optionLevel,
|
|
674
|
+
})
|
|
675
|
+
return
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Direct enchant_item packet — same as mineflayer/lib/plugins/enchantment_table.js.
|
|
679
|
+
// Does not require bot.openEnchantmentTable() (win.enchant is optional).
|
|
680
|
+
if (ext._client) {
|
|
681
|
+
const packet = {
|
|
682
|
+
windowId: win.id,
|
|
683
|
+
enchantment: choice,
|
|
684
|
+
}
|
|
685
|
+
logPacketWrite('enchant_item', packet)
|
|
686
|
+
ext._client.write('enchant_item', packet)
|
|
687
|
+
scheduleSlotUpdate()
|
|
688
|
+
logActionEvent('connector.action.success', action)
|
|
689
|
+
return
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (isEnchantmentTableWindow(win)) {
|
|
693
|
+
logHelperIntent(action, 'window.enchant', { enchantIndex: choice })
|
|
694
|
+
await win.enchant(choice)
|
|
695
|
+
onSetSlot()
|
|
696
|
+
logActionEvent('connector.action.success', action)
|
|
697
|
+
return
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
logActionEvent('connector.action.skipped', action, { reason: 'missing_client' })
|
|
648
701
|
return
|
|
649
702
|
}
|
|
650
703
|
|