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
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.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DamageContainer
private float
private boolean
private final boolean
private final float
private int
-
Constructor Summary
ConstructorsConstructorDescriptionLivingShieldBlockEvent
(net.minecraft.world.entity.LivingEntity blocker, DamageContainer container, float blockedDamage, boolean originalBlockedState) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Used inEntity.hurt(DamageSource, float)
to signify that a blocking action has occurred.float
net.minecraft.world.damagesource.DamageSource
boolean
float
void
setBlocked
(boolean isBlocked) Sets the blocking state of the entity.void
setBlockedDamage
(float blocked) Set how much damage is blocked by this action.
Note that initially the blocked amount depends on theBlocksAttacks.damageReductions()
.void
setShieldDamage
(int damage) Set how much durability the shield will lose ifgetBlocked()
is true.int
If 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
getEntity
-
Field Details
-
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
-
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 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 depends on theBlocksAttacks.damageReductions()
. -
setShieldDamage
public void setShieldDamage(int damage) Set how much durability the shield will lose ifgetBlocked()
is true. Setting this to a value lower than0
will apply the vanillaBlocksAttacks.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 inEntity.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
-