diff --git a/lib/plugins/enchantment_table.js b/lib/plugins/enchantment_table.js index 988bed4ce..0f4046616 100644 --- a/lib/plugins/enchantment_table.js +++ b/lib/plugins/enchantment_table.js @@ -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 (bot.majorVersion !== "1.8"){ + 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,37 @@ function inject (bot) { enchantmentTable.xpseed = packet.value } else if (packet.property < 7) { const slot = slots[packet.property - 4] - slot.expected.enchant = packet.value + 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 if (packet.property < 10) { const slot = slots[packet.property - 7] slot.expected.level = packet.value } - if (slots[0].level >= 0 && slots[1].level >= 0 && slots[2].level >= 0) { + 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 (readyCheck) { if (!ready) { ready = true - enchantmentTable.emit('ready') + //console.log('emitted ready') + //console.log(slots) + enchantmentTable.emit('ready') } } else { - ready = false + ready = false } } @@ -75,6 +108,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