Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the enchantment table "ready" event, which has been broken for years. #3120

Closed
wants to merge 14 commits into from
45 changes: 41 additions & 4 deletions lib/plugins/enchantment_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,65 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code

// console.log(packet.value)
if (packet.property < 3) {
const slot = slots[packet.property]
slot.level = packet.value
} else if (packet.property === 3) {
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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use support feature

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
}
}

Expand All @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code


// console.log('enchanting choice '+choice)
bot._client.write('enchant_item', {
windowId: enchantmentTable.id,
enchantment: choice
Expand Down
Loading