diff --git a/docs/api.md b/docs/api.md index e14046ac9..1cffc7fbb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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) @@ -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) diff --git a/index.d.ts b/index.d.ts index d73e962e1..1b83acbc7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -82,6 +82,7 @@ export interface BotEvents { entityTamed: (entity: Entity) => Promise | void entityShakingOffWater: (entity: Entity) => Promise | void entityEatingGrass: (entity: Entity) => Promise | void + entityHandSwap: (entity: Entity) => Promise | void entityWake: (entity: Entity) => Promise | void entityEat: (entity: Entity) => Promise | void entityCriticalEffect: (entity: Entity) => Promise | void diff --git a/lib/plugins/entities.js b/lib/plugins/entities.js index 27dd4b2de..7059c1276 100644 --- a/lib/plugins/entities.js +++ b/lib/plugins/entities.js @@ -21,7 +21,8 @@ const entityStatusEvents = { 6: 'entityTaming', 7: 'entityTamed', 8: 'entityShakingOffWater', - 10: 'entityEatingGrass' + 10: 'entityEatingGrass', + 55: 'entityHandSwap' } function inject (bot) { @@ -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) })