Skip to content

Commit 5688f18

Browse files
authored
Add Entity Attacker Detection into EntityHurt emitter (#3631)
* Added Source Entity to Entity Hurt Event added a attack source entity emitter into the entityhurt event * Added the sourceid packet added the SourceCauseId into EntityHurt emit
1 parent 52c622a commit 5688f18

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface BotEvents {
8181
health: () => Promise<void> | void
8282
breath: () => Promise<void> | void
8383
entitySwingArm: (entity: Entity) => Promise<void> | void
84-
entityHurt: (entity: Entity) => Promise<void> | void
84+
entityHurt: (entity: Entity, source: Entity) => Promise<void> | void
8585
entityDead: (entity: Entity) => Promise<void> | void
8686
entityTaming: (entity: Entity) => Promise<void> | void
8787
entityTamed: (entity: Entity) => Promise<void> | void

lib/plugins/entities.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ function inject (bot) {
374374

375375
bot._client.on('damage_event', (packet) => { // 1.20+
376376
const entity = bot.entities[packet.entityId]
377-
bot.emit('entityHurt', entity)
377+
const source = bot.entities[packet.sourceCauseId - 1] // damage_event : SourceCauseId : The ID + 1 of the entity responsible for the damage, if present. If not present, the value is 0
378+
bot.emit('entityHurt', entity, source)
378379
})
379380

380381
bot._client.on('attach_entity', (packet) => {

0 commit comments

Comments
 (0)