Skip to content

fix firing heldItemChanged, add type #3625

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export interface BotEvents {
bossBarDeleted: (bossBar: BossBar) => Promise<void> | void
bossBarUpdated: (bossBar: BossBar) => Promise<void> | void
resourcePack: (url: string, hash?: string, uuid?: string) => Promise<void> | void
heldItemChanged: (newItem: Item | null) => Promise<void> | void
particle: (particle: Particle) => Promise<void> | void
}

Expand Down Expand Up @@ -386,8 +387,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
times?: number
) => Promise<void>



setCommandBlock: (pos: Vec3, command: string, options: CommandBlockOptions) => void

clickWindow: (
Expand Down
7 changes: 6 additions & 1 deletion lib/plugins/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function inject (bot, { hideErrors }) {
}
const window = bot.currentWindow || bot.inventory

assert.ok(mode >= 0 && mode <= 4)
assert.ok(mode >= 0 && mode <= 6)
const actionId = createActionNumber()

const click = {
Expand Down Expand Up @@ -728,6 +728,11 @@ function inject (bot, { hideErrors }) {
const newItem = Item.fromNotch(packet.item)
bot._setSlot(packet.slot, newItem, window)
})
bot.inventory.on('updateSlot', (index) => {
if (index === bot.quickBarSlot + bot.inventory.hotbarStart) {
bot.emit('heldItemChanged')
}
})
bot._client.on('window_items', (packet) => {
const window = packet.windowId === 0 ? bot.inventory : bot.currentWindow
if (!window || window.id !== packet.windowId) {
Expand Down
Loading