接口 DamageSource


public interface DamageSource
代表一个伤害来源.
  • 方法详细资料

    • getDamageType

      @NotNull @NotNull DamageType getDamageType()
      获取DamageType.

      原文: Get the DamageType.

      返回:
      伤害类型
    • getCausingEntity

      @Nullable @Nullable Entity getCausingEntity()
      获取造成伤害的Entity.

      不要与getDirectEntity()混淆, 造成伤害的实体是当受伤害者死亡时最终归因的实体. 例如, 如果受伤害者被弹射物击中, 将返回射击者/投掷者.

      原文: Get the Entity that caused the damage to occur.

      Not to be confused with getDirectEntity(), the causing entity is the entity to which the damage is ultimately attributed if the receiver is killed. If, for example, the receiver was damaged by a projectile, the shooter/thrower would be returned.

      返回:
      一个Entity或null
    • getDirectEntity

      @Nullable @Nullable Entity getDirectEntity()
      获取直接造成伤害的Entity.

      不要与getCausingEntity()混淆, 直接实体是实际造成伤害的实体. 例如, 如果受伤害者被弹射物击中, 将返回弹射物.

      原文: Get the Entity that directly caused the damage.

      Not to be confused with getCausingEntity(), the direct entity is the entity that actually inflicted the damage. If, for example, the receiver was damaged by a projectile, the projectile would be returned.

      返回:
      一个Entity或null
    • getDamageLocation

      @Nullable @Nullable Location getDamageLocation()
      获取伤害来源的Location. 仅在伤害不是由实体造成时存在.

      原文: Get the Location from where the damage originated. This will only be present if an entity did not cause the damage.

      返回:
      位置, 如果没有则返回null
    • getSourceLocation

      @Nullable @Nullable Location getSourceLocation()
      获取伤害来源的Location.

      这是一个便捷方法来获取伤害的最终位置. 此方法将尝试返回伤害位置. 如果为null, 将返回造成伤害实体的位置. 最后如果既没有伤害位置也没有造成伤害的实体, 将返回null.

      原文: Get the Location from where the damage originated.

      This is a convenience method to get the final location of the damage. This method will attempt to return the damage location. If this is null, the causing entity location will be returned. Finally if there is no damage location nor a causing entity, null will be returned.

      返回:
      位置来源或null.
    • isIndirect

      boolean isIndirect()
      获取此伤害是否为间接伤害.

      如果getCausingEntity()不等于getDirectEntity(), 则伤害被视为间接的. 例如, 如果骷髅射箭或玩家投掷药水, 就是这种情况.

      原文: Get if this damage is indirect.

      Damage is considered indirect if getCausingEntity() is not equal to getDirectEntity(). This will be the case, for example, if a skeleton shot an arrow or a player threw a potion.

      返回:
      true 如果是间接伤害, false 否则.
    • getFoodExhaustion

      float getFoodExhaustion()
      获取此伤害造成的饥饿消耗量.

      原文: Get the amount of hunger exhaustion caused by this damage.

      返回:
      造成的饥饿消耗量.
    • scalesWithDifficulty

      boolean scalesWithDifficulty()
      获取此伤害来源是否随难度缩放.

      原文: Gets if this source of damage scales with difficulty.

      返回:
      True 如果缩放.
    • builder

      创建一个新的DamageSource.Builder.

      原文: Create a new DamageSource.Builder.

      参数:
      damageType - 要使用的DamageType
      返回:
      一个DamageSource.Builder