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
- All Implemented Interfaces:
 net.neoforged.bus.api.ICancellableEvent
public class LivingShieldBlockEvent
extends LivingEvent
implements net.neoforged.bus.api.ICancellableEvent
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 
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:
 
- 
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEventNested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size - 
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DamageContainerprivate floatprivate booleanprivate final booleanprivate float - 
Constructor Summary
ConstructorsConstructorDescriptionLivingShieldBlockEvent(LivingEntity blocker, DamageContainer container, boolean originalBlockedState)  - 
Method Summary
Modifier and TypeMethodDescriptionbooleanUsed inLivingEntity.hurt(DamageSource, float)to signify that a blocking action has occurred.floatbooleanfloatvoidsetBlocked(boolean isBlocked) Sets the blocking state of the entity.voidsetBlockedDamage(float blocked) Set how much damage is blocked by this action.
Note that initially the blocked amount is the entire attack.voidsetShieldDamage(float damage) Set how much durability the shield will lose ifgetBlocked()is true.floatIf the event isgetBlocked()and the user is holding a shield, the returned amount will be taken from the item's durability.Methods inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
getEntityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled 
- 
Field Details
- 
container
 - 
dmgBlocked
private float dmgBlocked - 
shieldDamage
private float shieldDamage - 
originalBlocked
private final boolean originalBlocked - 
newBlocked
private boolean newBlocked 
 - 
 - 
Constructor Details
- 
LivingShieldBlockEvent
public LivingShieldBlockEvent(LivingEntity blocker, DamageContainer container, boolean originalBlockedState)  
 - 
 - 
Method Details
- 
getDamageContainer
 - 
getDamageSource
- Returns:
 - The damage source.
 
 - 
getOriginalBlockedDamage
public float getOriginalBlockedDamage()- Returns:
 - The original amount of damage blocked, which is the same as the original incoming damage value.
 
 - 
getBlockedDamage
public float getBlockedDamage()- Returns:
 - The current amount of damage blocked, as a result of this event.
 
 - 
shieldDamage
public float shieldDamage()If the event isgetBlocked()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 is the entire attack. - 
setShieldDamage
public void setShieldDamage(float damage) Set how much durability the shield will lose ifgetBlocked()is true.- 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 inLivingEntity.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
 
 -