1.15.2 Damaging an entity with specific damage cause

Discussion in 'Spigot Plugin Development' started by NeumimTo, Jan 30, 2020.

  1. How can i damage an entity with specific damage cause?

    Like for example i want to damage an entity specifically with damage cause DamageCause.FIRE, or LIGHTNING , or any other type, so the next DamageEntityByEntityEvent, which is fired during method call Entity#damage is going to have set its damage cause to the one i specified earlier.
     
    • Like Like x 1
  2. As @jaylawl said, you can indeed call the overloaded method and provide an Entity of your choice.
    The following would damage your Damageable with a LightiningStrike. Your DamageEntityByEntityEvent would then be fired with cause LIGHTNING.

    Code (Java):

    LightningStrike strike = world.spawnEntity(location, EntityType.LIGHTNING);
    damageable.damage(amount, strike);
     
     
    • Useful Useful x 2
  3. Why not just setting the last damage cause (and call the corresponding event)?

    You can easily construct an EntityDamageEvent and set it with Entity#setLastDamageCause
     
  4. Thats useful only for a very tiny amount of use cases.