Class LivingShieldBlockEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent

public class LivingShieldBlockEvent extends LivingEvent
LivingShieldBlockEvent is fired when an entity is hurt and vanilla checks if the entity is attempting to block with a shield.
Cancelling this event will have the same impact as if the shield was not eligible to block.
The damage blocked cannot be set lower than zero or greater than the original value.

Note: This event fires whether the player is actively using a shield or not. Vanilla shield blocking logic is captured and passed into the event via getOriginalBlock(). If this is true, The shield item stack "should" be available from LivingEntity.getUseItem() at least for players.

See Also:
  • Field Details

    • container

      private final DamageContainer container
    • dmgBlocked

      private float dmgBlocked
    • originalDmgBlocked

      private final float originalDmgBlocked
    • shieldDamage

      private int shieldDamage
    • originalBlocked

      private final boolean originalBlocked
    • newBlocked

      private boolean newBlocked
  • Constructor Details

    • LivingShieldBlockEvent

      public LivingShieldBlockEvent(net.minecraft.world.entity.LivingEntity blocker, DamageContainer container, float blockedDamage, boolean originalBlockedState)
  • Method Details

    • getDamageContainer

      public DamageContainer getDamageContainer()
    • getDamageSource

      public net.minecraft.world.damagesource.DamageSource getDamageSource()
      Returns:
      The damage source.
    • getOriginalBlockedDamage

      public float getOriginalBlockedDamage()
      Returns:
      The original amount of damage blocked.
    • getBlockedDamage

      public float getBlockedDamage()
      Returns:
      The current amount of damage blocked, as a result of this event.
    • shieldDamage

      public int shieldDamage()
      If the event is getBlocked() and the user is holding a shield, the returned amount will be taken from the item's durability.
      Returns:
      The amount of shield durability damage to take.
    • setBlockedDamage

      public void setBlockedDamage(float blocked)
      Set how much damage is blocked by this action.
      Note that initially the blocked amount depends on the BlocksAttacks.damageReductions().
    • setShieldDamage

      public void setShieldDamage(int damage)
      Set how much durability the shield will lose if getBlocked() is true. Setting this to a value lower than 0 will apply the vanilla BlocksAttacks.itemDamage().
      Parameters:
      damage - the new durability value taken from the shield on successful block
    • getOriginalBlock

      public boolean getOriginalBlock()
      Returns:
      whether the damage would have been blocked by vanilla logic
    • getBlocked

      public boolean getBlocked()
      Used in Entity.hurt(DamageSource, float) to signify that a blocking action has occurred. If returning false, damage to the shield will not occur.
      Returns:
      true if the entity should be considered "blocking"
    • setBlocked

      public void setBlocked(boolean isBlocked)
      Sets the blocking state of the entity. By default, entities raising a shield, facing the damage source, and not being hit by a source that bypasses shields will be considered blocking. An entity can be considered blocking regardless by supplying true to this.
      Parameters:
      isBlocked - should the entity be treated as if it is blocking