Replies: 4 comments
-
I agree to this, There would many good uses for being able to get the entity. But not only that, it would be useful maybe to be able to get the damageCause, for things like fire, entity, custom etc.. Until this is implemented, the LastDamageCause should work though. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure there's a simple way to do this. First of all, what is considered "caused by an entity"? If I use shears on a mooshroom, it takes durability, is that "caused by an entity"? For that matter, a player using a tool is also "caused by an entity", itself. What about food on sticks be "used" to point pigs or striders in a direction? Then secondly, it'd be a kinda large refactor to move stuff around to have access to the entity causing (whatever that means) the durability to change. |
Beta Was this translation helpful? Give feedback.
-
I think they are more pointing towards something like shields. If a zombie or something attacked the player and they blocked the attack with a shield etc.. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the input @OmegaWeaponDev and @Machine-Maker, I don't think using a tool against an entity should fire this event, it should only be one-way: when an entity does something to a player which causes them to damage one of the player's items, e.g. hitting a player wearing armour. Players should fire this event too, since they are entities. |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem?
Currently, AFAIK, there is no way to retrieve which Entity could have caused a
PlayerItemDamageEvent
to fire, such as when an entity hits a player who is currently using a shield which loses durability for doing so.In my plugin LevelledMobs, I would like to add a feature where higher-level mobs are able to inflict more durability damage to players' shields so that they are less effective against those mobs.
Describe the solution you'd like.
I think a great way to go about solving this is to add a new event -
PlayerItemDamageByEntityEvent
. This event extendsPlayerItemDamageEvent
, and is fired when an entity causesPlayerItemDamageEvent
to fire, i.e., during combat.This event contains a method which references which entity caused the event to fire.
This event could also contain a reference to a linked
EntityDamageByEntityEvent
which caused thePlayerItemDamageByEntityEvent
to fire.Describe alternatives you've considered.
I have thought about using a bit of hack-ish code to get around it, but I'd rather not
since it could cause weird side-effects. For instance, applying a 1-tick-expiry
temporary metadata value to the defending player in EntityDamageByEntityEvent with the shield breaker multiplier value, and then referencing
that in the PlayerItemDamageEvent by changing the damage value to be multiplied by the multiplier stored in the metadata.
There's also
player#getLastDamageCause.getEntity()
- although close, that would still be a hack-ish workaround: there is no guarantee that it would return the entity which has caused the particularPlayerItemDamageEvent
to fire. Imagine that an entity hit a player 20 minutes ago, and then the player's item was damaged 20 minutes later. That method would return the entity from 20 minutes ago which was completely unrelated.Other
No response
Beta Was this translation helpful? Give feedback.
All reactions