Skip to content

Expose die method of LivingEntity directly or in setHealth #13666

@Clexus

Description

@Clexus

Is your feature request related to a problem?

below is the setHealth method

public void setHealth(double health) {
    health = (float) health;
    // Paper start - Be more informative
    Preconditions.checkArgument(health >= 0 && health <= this.getMaxHealth(),
        "Health value (%s) must be between 0 and %s. (attribute base value: %s%s)",
        health, this.getMaxHealth(), this.getHandle().getAttribute(Attributes.MAX_HEALTH).getBaseValue(), this instanceof CraftPlayer ? ", player: " + this.getName() : ""
    );
    // Paper end

    // during world generation, we don't want to run logic for dropping items and xp
    if (this.getHandle().generation && health == 0) {
        this.getHandle().discard(null); // Add Bukkit remove cause
        return;
    }

    this.getHandle().setHealth((float) health);

    if (health == 0) {
        this.getHandle().die(this.getHandle().damageSources().generic());
    }
}

When I need to set an entity's health to 0 and provide a valid damage source, I have to reinvent the method myself with nms codes or the death will be sourceless, and many plugins tracking it will miss the "killer".
There are many rpg servers have the same problem with me, they probably have the "true damage" mechanic that do damage which ignores entity's defenses. Then they'll use sethealth but they can't set damagesource in the death event.

Describe the solution you'd like.

expose the damage source parameter in die method so you can do things like setHealth(0, source)

Describe alternatives you've considered.

use nms codes

Other

No response

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions