-
-
Notifications
You must be signed in to change notification settings - Fork 913
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
entityHurt event doesn't work #3184
Comments
vanilla/spigot/paper which one is it
…On Sat, Sep 2, 2023, 09:55 Dominik Grudzień ***@***.***> wrote:
- The FAQ
<https://github.com/PrismarineJS/mineflayer/blob/master/docs/FAQ.md>
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.
—
Reply to this email directly, view it on GitHub
<#3184>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR437SYQZKQZVIGB7TFE2DXYLQ5XANCNFSM6AAAAAA4INZOFI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
the paper server |
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 both examples don't work |
Same on Vanilla 1.20. |
It works on Vanilla 1.20.4. I use @On(bot._client, 'damage_event')
def handle2(this, packet, *args):
print(packet) And there are the outputs:
However, |
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. |
I have reimplemented the flow of handling Note: I didn't make any changes to the source code of Re-implement Damage EventFirst, the interface export interface ExtendedBotEvents extends BotEvents {
damageEvent: (entity: Entity,
sourceType: DamageType,
sourceCause: Entity | null,
sourceDirect: Entity | null)
=> Promise<void> | void
} Then create a function that starts the damageEvent listener. /**
* See: https://wiki.vg/Protocol#Damage_Event
*/
export function startDamageEvent() {
bot._client.on('damage_event', async (packet) => {
// The ID of the entity taking damage.
const entityId = packet.entityId;
// The entity taking damage.
const entity = bot.entities[entityId];
// The type of damage in the minecraft:damage_type registry, defined by the Registry Data packet.
const sourceTypeId = packet.sourceTypeId;
const sourceType = damageTypeMap.get(sourceTypeId);
assert(sourceType, `Server should not send this damage type id: ${sourceTypeId}`)
// The ID + 1 of the entity responsible for the damage, if present. If not present, the value is 0
const sourceCauseId = packet.sourceCauseId;
const sourceCause = sourceCauseId === 0 ? null : bot.entities[sourceCauseId - 1];
// The ID + 1 of the entity that directly dealt the damage, if present. If not present, the value is 0.
// If this field is present:
// - and damage was dealt indirectly, such as by the use of a projectile, this field will contain the ID of such projectile;
// - and damage was dealt directly, such as by manually attacking, this field will contain the same value as Source Cause ID.
const sourceDirectId = packet.sourceDirectId;
const sourceDirect = bot.entities[sourceDirectId - 1];
// Enhance the raw damage_event event emitter.
myEmitter.emit("damageEvent", entity, sourceType, sourceCause, sourceDirect)
// Replace the original entityHurt event emitter.
myEmitter.emit("entityHurt", entity)
})
} Finally, login the game and test the bot. myEmitter.on("damageEvent", (entity: Entity,
sourceType: DamageType,
sourceCause: Entity | null,
sourceDirect: Entity | null) => {
if (entity.type === "player" && entity.username === bot.username) {
console.log(`${entity.username} got ${sourceType.name} damage by ${sourceDirect?.name} from ${sourceCause?.name}.`)
if (sourceType.name === "arrow") {
bot.chat("Ouch... Take care of your bow and arrows!!!")
}
}
}) I'm just showing the most important part here, if you need the full code, I've put it in a zip package re-implement-damage-event.zip and you can run it with It's worth noting that the Version Information
Relative Links
|
Versions
Detailed description of a problem
The
entityHurt
event is not called when attacking mobs.What did you try yet?
I tried to:
Your current code
Expected behavior
The
entityHurt
event should be called when attacking enemies or when player hurts himself.The text was updated successfully, but these errors were encountered: