Interface CombatService


public interface CombatService
The combat rules: hits, damage, blocking, knockback and death, registered as a service so plugins can replace them.
Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    attack(LivingEntity attacker, Entity target)
    Makes an entity hit another with the item in its main hand, as a player does when they click an entity, or a mob when it strikes its target.
    int
    Returns the ticks a swing of this player takes to recharge, from their attack speed.
    float
    Returns the damage a fully charged melee hit of this entity deals, before enchantments.
    double
    Returns the extra knockback a melee hit of this entity deals.
    float
    Returns the charge of the next hit of a player, between 0 and 1.
    boolean
    damage(LivingEntity target, DamageSource source, float amount)
    Hurts an entity, running the full pipeline: invulnerability frames, shield, armor, Resistance, enchantments, absorption, events, client packets and death.
    void
    disableBlocking(LivingEntity entity, float seconds)
    Lowers the shield of an entity and keeps it from raising it again for a while, as an axe does.
    boolean
    Returns true if this entity holds a raised shield, past its raising delay, that is not disabled.
    void
    kill(LivingEntity target, @Nullable Entity killer)
    Kills an entity outright, bypassing armor, shields, totems and invulnerability.
    void
    knockback(LivingEntity target, double strength, double fromX, double fromZ)
    Pushes an entity away from a point, the way a hit does.
    boolean
     
    Returns the factory of the damage sources this service understands.
  • Method Details

    • sources

      Returns the factory of the damage sources this service understands.
      Returns:
      the factory of the damage sources this service understands
      Since:
      0.1.0
    • attack

      boolean attack(LivingEntity attacker, Entity target)
      Makes an entity hit another with the item in its main hand, as a player does when they click an entity, or a mob when it strikes its target.
      Parameters:
      attacker - the entity swinging
      target - the entity being hit
      Returns:
      true if damage was actually dealt
      Since:
      0.1.0
    • damage

      boolean damage(LivingEntity target, DamageSource source, float amount)
      Hurts an entity, running the full pipeline: invulnerability frames, shield, armor, Resistance, enchantments, absorption, events, client packets and death.
      Parameters:
      target - the entity taking the hit
      source - the origin of the damage
      amount - damage in half-hearts before reduction; values <= 0 are ignored
      Returns:
      true if the hit hurt the entity, even when armor took all of it; false when it was refused or cancelled, absorbed by the invulnerability left by the last hit, or blocked by a shield
      Since:
      0.1.0
    • knockback

      void knockback(LivingEntity target, double strength, double fromX, double fromZ)
      Pushes an entity away from a point, the way a hit does.
      Parameters:
      target - the entity to push
      strength - the horizontal knockback strength; <= 0 does nothing
      fromX - the x coordinate the push originates from
      fromZ - the z coordinate the push originates from
      Since:
      0.1.0
    • kill

      void kill(LivingEntity target, @Nullable Entity killer)
      Kills an entity outright, bypassing armor, shields, totems and invulnerability.
      Parameters:
      target - the entity to kill
      killer - the entity credited with the kill, or null
      Since:
      0.1.0
    • attackDamage

      float attackDamage(LivingEntity attacker)
      Returns the damage a fully charged melee hit of this entity deals, before enchantments.: its minecraft:attack_damage attribute, the weapon in its main hand and its effects included
      Parameters:
      attacker - the attacking entity
      Returns:
      the damage a fully charged melee hit of this entity deals, before enchantments
      Since:
      0.1.0
    • attackKnockback

      double attackKnockback(LivingEntity attacker)
      Returns the extra knockback a melee hit of this entity deals.: its minecraft:attack_knockback attribute, plus one for a sprinting player
      Parameters:
      attacker - the attacking entity
      Returns:
      the extra knockback a melee hit of this entity deals
      Since:
      0.1.0
    • attackStrengthScale

      float attackStrengthScale(Player attacker)
      Returns the charge of the next hit of a player, between 0 and 1.
      Parameters:
      attacker - the attacking player
      Returns:
      the charge of the next hit of a player, between 0 and 1
      Since:
      0.1.0
    • attackCooldownTicks

      int attackCooldownTicks(Player attacker)
      Returns the ticks a swing of this player takes to recharge, from their attack speed.
      Parameters:
      attacker - the attacking player
      Returns:
      the ticks a swing of this player takes to recharge, from their attack speed
      Since:
      0.1.0
    • isBlocking

      boolean isBlocking(LivingEntity entity)
      Returns true if this entity holds a raised shield, past its raising delay, that is not disabled.
      Parameters:
      entity - the entity
      Returns:
      true if this entity holds a raised shield, past its raising delay, that is not disabled
      Since:
      0.1.0
    • disableBlocking

      void disableBlocking(LivingEntity entity, float seconds)
      Lowers the shield of an entity and keeps it from raising it again for a while, as an axe does.
      Parameters:
      entity - the entity
      seconds - how long the shield stays disabled; <= 0 does nothing
      Since:
      0.1.0
    • pvpEnabled

      boolean pvpEnabled(World world)
      Parameters:
      world - the world
      Returns:
      true when players are allowed to damage each other in this world
      Since:
      0.1.0