PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

entityHit - request to add entity hit check. #3138

Closed 1ProCrafters closed 1 year ago

1ProCrafters commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to be able to check when a entity hit another entity, this will make it able to make bodyguards.

Describe the solution you'd like

A check that is able to check when a entity hit another entity.

Describe alternatives you've considered

I have implemented it so that the closest entity is considered the one that hit the other entity but it isnt always accurate.

Additional context

Code: `//When an entity gets harmed bots[0].on('entityHurt', (entity) => { //Ignore if the harmed entity is not the boss if (entity.username != bossName) return;

        //Select the entity that hurt the boss, by selecting the nearest entity that is not the boss or another Guard
        //This needs work :/
        target = bots[0].nearestEntity((entity) => {
            return (entity.username != bossName && !(entity.username || '').startsWith(prefix));
        });
    });`
PondWader commented 1 year ago

Mineflayer can only use information it gets from the server, the vanilla Minecraft server does not tell the clients who hit who so this is not possible. You are only able to guess using methods such as the one you've implemented.

extremeheat commented 1 year ago

It could be possible to write a plugin to infer the last damager by looking at the nearest player swing in their direction, but yeah it seems like this information is not sent by the server to the client at present so it can't be known/exposed by mineflayer.