Skip to content

Commit

Permalink
implement bot.heldItem with getter function
Browse files Browse the repository at this point in the history
  • Loading branch information
szdytom committed Nov 1, 2023
1 parent 08208e2 commit 0594bce
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/plugins/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ function inject (bot, { hideErrors }) {
bot.quickBarSlot = null
bot.inventory = windows.createWindow(0, 'minecraft:inventory', 'Inventory')
bot.currentWindow = null
bot.heldItem = null
bot.usingHeldItem = false
Object.defineProperty(o, 'heldItem', {
get: function () {
return bot.inventory.slots[bot.QUICK_BAR_START + bot.quickBarSlot]
},
})

bot._client.on('entity_status', (packet) => {
if (packet.entityId === bot.entity.id && packet.entityStatus === 9 && !eatingTask.done) {
Expand Down Expand Up @@ -364,9 +368,7 @@ function inject (bot, { hideErrors }) {
}

function updateHeldItem () {
bot.heldItem = bot.inventory.slots[bot.QUICK_BAR_START + bot.quickBarSlot]
bot.entity.heldItem = bot.heldItem
bot.emit('heldItemChanged', bot.entity.heldItem)
bot.emit('heldItemChanged', bot.heldItem)
}

function closeWindow (window) {
Expand Down

0 comments on commit 0594bce

Please sign in to comment.