1.15.2 Damage an entity without knockback

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

  1. I have two questions related to damage & health system in spigot.

    1) Is it possible to damage entity without the knockback?

    2) Platforms like sponge and forge allow modders to create new types of, what spigot calls, DamageCause. DamageCause is is implemented in spigot as an enum. May plugin developers create new damagecause types without shady practices as forge's EnumHelper?
  2. Of course. Use the entity damage event, check if the item used has the knockback enchantment, if so cancel the knockback effect. (setKnockback(0.0))

    From what I know, no, but there's always a work around depending on what you're trying to achieve.
  3. With the knockback i meant the default behavior of method Livingentity#damage(damage, DamageCause), not the knockback enchantment :)
  4. I think you can use the entity damage event, get the entity being hit, change it's heart variable by taking of the amount of damage it took and then cancel the event which will cancel the knockback I believe.
    • Like Like x 1
  5. isnt it just call the entitydamagebyentity event and than entity.setVelocity(0)?
  6. @wailord2 is correct. When listening to the EntityDamageEvent you can use event.setCancelled(true) to cancel the event, including the knockback. You can then get the player from the event by using event.getPlayer() and the final damage by using event.getFinalDamage(), and then you can manually damage the player by doing player.damage(damage).

    Assuming that by "call the entitydamagebyentity event" you mean listening to the event, and by "entity.setVelocity(0)", you mean entity.setVelocity(new Velocity(0, 0, 0)); This will work, but probably not the way you want it to work. When you set a velocity of (0, 0, 0), the player will be set to not move at all, so being stopped in place, until the player moves again.