Skip to content

Commit

Permalink
Handle hand swap entity status (#3097)
Browse files Browse the repository at this point in the history
  • Loading branch information
PondWader committed Jul 22, 2023
1 parent 5a55744 commit a80d69a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
- ["entityTamed" (entity)](#entitytamed-entity)
- ["entityShakingOffWater" (entity)](#entityshakingoffwater-entity)
- ["entityEatingGrass" (entity)](#entityeatinggrass-entity)
- ["entityHandSwap" (entity)](#entityhandswap-entity)
- ["entityWake" (entity)](#entitywake-entity)
- ["entityEat" (entity)](#entityeat-entity)
- ["entityCriticalEffect" (entity)](#entitycriticaleffect-entity)
Expand Down Expand Up @@ -1290,6 +1291,7 @@ Fires when an attribute of an entity changes.
#### "entityTamed" (entity)
#### "entityShakingOffWater" (entity)
#### "entityEatingGrass" (entity)
#### "entityHandSwap" (entity)
#### "entityWake" (entity)
#### "entityEat" (entity)
#### "entityCriticalEffect" (entity)
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface BotEvents {
entityTamed: (entity: Entity) => Promise<void> | void
entityShakingOffWater: (entity: Entity) => Promise<void> | void
entityEatingGrass: (entity: Entity) => Promise<void> | void
entityHandSwap: (entity: Entity) => Promise<void> | void
entityWake: (entity: Entity) => Promise<void> | void
entityEat: (entity: Entity) => Promise<void> | void
entityCriticalEffect: (entity: Entity) => Promise<void> | void
Expand Down
9 changes: 8 additions & 1 deletion lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const entityStatusEvents = {
6: 'entityTaming',
7: 'entityTamed',
8: 'entityShakingOffWater',
10: 'entityEatingGrass'
10: 'entityEatingGrass',
55: 'entityHandSwap'
}

function inject (bot) {
Expand Down Expand Up @@ -338,6 +339,12 @@ function inject (bot) {
// entity status
const entity = fetchEntity(packet.entityId)
const eventName = entityStatusEvents[packet.entityStatus]

if (eventName === 'entityHandSwap' && entity.equipment) {
[entity.equipment[0], entity.equipment[1]] = [entity.equipment[1], entity.equipment[0]]
entity.heldItem = entity.equipment[0] // Update held item like prismarine-entity does upon equipment updates
}

if (eventName) bot.emit(eventName, entity)
})

Expand Down

0 comments on commit a80d69a

Please sign in to comment.