[SPIGOT-5553] Ability to get the velocity added to the entity in EntityDamageEvent Created: 29/Jan/20  Updated: 27/Jan/24  Resolved: 27/Jan/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Perzan Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: EntityDamageEvent, Feature, Method, velocity
Environment:

Processor: Intel(R) Core(TM) i9-9900KS CPU @ 4.00GHz 4.01 GHz
Installed RAM: 64.0 GB
System type: 64-bit operating system, x64-based processor
Java version: 1.8.0_241
OS Edition: Windows 10 Pro
OS Version: 1909
OS build: 18363.592


Version: git-Spigot-037559e-5c6b0dc (MC: 1.15.1) (Implementing API version 1.15.1-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

A suggested method for EntityDamageEvent:
getAddedVelocity(): Vector

This represents the velocity that was added to the victim's velocity when they were damaged.

I suggest this method since I am working on a plugin that involves consistently multiplying the knock-back that one player does to another. I want to multiply the knock-back because:

  • The player will have a power-level
  • They can have various weapons that contribute to the knock-back
  • The victim can have an attribute modifier that reduces their knock-back

If John acquires a Knockback-2 sword and his "power level" multiplies his abilities by 10, his power level will enhance the knock-back energy delivered by the sword by ten-times. It will not add. This is why it can sometimes be important to know how much velocity is added to the entity when it is damaged.

I am unsure as to how this can apply to EntityDamageEvent aside from EntityDamageByEntityEvent. I have tried to think about cases where anything that isn't an entity can knock an entity back by damaging it, but I don't seem to recall any. Damage sources such as lava, magma blocks, sweet berry bushes, etc will just return 0 for this method? Maybe in the future these causes might contribute knockback for some reason.



 Comments   
Comment by md_5 [ 27/Jan/24 ]

Addressed by EntityKnockbackEvent

Comment by Perzan [ 29/Jan/20 ]

I see that PlayerVelocityEvent exists, but not EntityVelocityEvent. If EntityVelocityEvent existed, PlayerVelocityEvent might not be able to extend it because it is based on PlayerEvent which has "getPlayer()" rather than "getEntity()". I'm sure a refactoring of this system is the last thing anyone wants, but perhaps maybe have EntityVelocityEvent as a separate event? Nothing will get extended here, but it might have a method like "getCause()" which returns a constant from an enum called "VelocityCause". VelocityCause might have some of these:

  1. PISTON
  2. PISTON_BLOCK
  3. ENTITY_PUSH
  4. DAMAGE
  5. EXPLOSION

I will put more thought into what these enum names should be tomorrow since it's late for me.
Thank you for your time.

Comment by md_5 [ 29/Jan/20 ]

Extremely unlikely to go in the damage event, that event is impossible to maintain. Could be a separate event.

Generated at Tue Apr 15 11:10:00 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.