mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

entityHurt event doesn't work

Open shanodis opened this issue 1 year ago • 8 comments

  • [x] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.13.0
  • server: vanilla/spigot/paper 1.20.1
  • node: 18.15.0

Detailed description of a problem

The entityHurt event is not called when attacking mobs.

What did you try yet?

I tried to:

  1. updating packages
  2. reinstalling node_modules
  3. updating/reinstalling paper server

Your current code


const bot = createBot({
  host: 'localhost',
  username: 'George',
});

bot.on('entityHurt', (entity) => {
  console.log('test')
});

Expected behavior

The entityHurt event should be called when attacking enemies or when player hurts himself.

shanodis avatar Sep 02 '23 07:09 shanodis

vanilla/spigot/paper which one is it

On Sat, Sep 2, 2023, 09:55 Dominik Grudzień @.***> wrote:

Versions

  • mineflayer: 4.13.0
  • server: vanilla/spigot/paper 1.20.1
  • node: 18.15.0

Detailed description of a problem

The entityHurt event is not called when attacking mobs. What did you try yet?

I tried to:

  1. updating packages
  2. reinstalling node_modules
  3. updating/reinstalling paper server

Your current code

const bot = createBot({ host: 'localhost', username: 'George',}); bot.on('entityHurt', (entity) => { console.log('test')});

Expected behavior

The entityHurt event should be called when attacking enemies or when player hurts himself.

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/3184, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SYQZKQZVIGB7TFE2DXYLQ5XANCNFSM6AAAAAA4INZOFI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rom1504 avatar Sep 02 '23 08:09 rom1504

the paper server

shanodis avatar Sep 02 '23 10:09 shanodis

bot._client.on("hurt_animation", (packet) => {
  const entity = this.bot.entities[packet.entityId]
  if (!entity) return
  console.log(entity.name, "hurt")
})

or

bot._client.on("damage_event", (packet) => {
  console.log(packet.entityId, packet.sourceTypeId, packet.sourceCauseId, packet.sourceDirectId, packet.sourcePosition)
})

honestly cba to make a pr

WhoTho avatar Sep 10 '23 18:09 WhoTho

@WhoTho both examples don't work

shanodis avatar Sep 11 '23 16:09 shanodis

Same on Vanilla 1.20.

carloslfu avatar Jan 27 '24 22:01 carloslfu

bot._client.on("hurt_animation", (packet) => {
  const entity = this.bot.entities[packet.entityId]
  if (!entity) return
  console.log(entity.name, "hurt")
})

or

bot._client.on("damage_event", (packet) => {
  console.log(packet.entityId, packet.sourceTypeId, packet.sourceCauseId, packet.sourceDirectId, packet.sourcePosition)
})

honestly cba to make a pr

It works on Vanilla 1.20.4.

I use mineflayer of Python version to get the packet from the protected member bot._client.

@On(bot._client, 'damage_event')
def handle2(this, packet, *args):
    print(packet)

And there are the outputs:

{'entityId': 3595, 'sourceTypeId': 31, 'sourceCauseId': 124, 'sourceDirectId': 124}

However, entityHurt event is not emitted.

AkagawaTsurunaki avatar Mar 15 '24 07:03 AkagawaTsurunaki

the entities plugin seems to not know about the damage_event packet and the older packets used to catch an entity being hurt are no longer called in the newer version (with the right arguments to cause a entityHurt even to be emitted)

Looks like a simple fix, just someone needs to do it.

wgaylord avatar Mar 15 '24 16:03 wgaylord