Class CriticalHitEvent
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.player.PlayerEvent
net.neoforged.neoforge.event.entity.player.CriticalHitEvent
This event is fired when a player attacks an entity in
Player.attack(Entity)
.
It can be used to change the critical hit status and damage modifier
In the event the attack was not a critical hit, the event will still be fired, but it will be preemptively cancelled.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemSmeltedEvent, PlayerEvent.LoadFromFile, PlayerEvent.NameFormat, PlayerEvent.PlayerChangedDimensionEvent, PlayerEvent.PlayerChangeGameModeEvent, PlayerEvent.PlayerLoggedInEvent, PlayerEvent.PlayerLoggedOutEvent, PlayerEvent.PlayerRespawnEvent, PlayerEvent.SaveToFile, PlayerEvent.StartTracking, PlayerEvent.StopTracking, PlayerEvent.TabListNameFormat
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
Modifier and TypeFieldDescriptionprivate float
private boolean
private final boolean
private final Entity
private final float
-
Constructor Summary
ConstructorDescriptionCriticalHitEvent
(Player player, Entity target, float dmgMultiplier, boolean isCriticalHit) -
Method Summary
Modifier and TypeMethodDescriptionfloat
The damage multiplier is applied to the base attack's damage if the attack critically hits.Returns the entity that was attacked by the player.float
Gets the original damage multiplier set by vanilla.boolean
Returns if the attack will critically hit.boolean
Returns true if the attack was considered a critical hit by vanilla.void
setCriticalHit
(boolean isCriticalHit) Changes the critical hit state.void
setDamageMultiplier
(float dmgMultiplier) Sets the damage multiplier for the critical hit.Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
getEntity
-
Field Details
-
target
-
vanillaDmgMultiplier
private final float vanillaDmgMultiplier -
isVanillaCritical
private final boolean isVanillaCritical -
dmgMultiplier
private float dmgMultiplier -
isCriticalHit
private boolean isCriticalHit
-
-
Constructor Details
-
CriticalHitEvent
-
-
Method Details
-
getTarget
Returns the entity that was attacked by the player.- Returns:
- the entity that was attacked by the player
-
getDamageMultiplier
public float getDamageMultiplier()The damage multiplier is applied to the base attack's damage if the attack critically hits.A damage multiplier of 1.0 will not change the damage, a value of 1.5 will increase the damage by 50%, and so on.
- Parameters:
modifier
- The new damage modifier.
-
setDamageMultiplier
public void setDamageMultiplier(float dmgMultiplier) Sets the damage multiplier for the critical hit. Not used ifisCriticalHit()
is false.Changing the damage modifier to zero does not guarantee that the attack does zero damage.
- Parameters:
modifier
- The new damage modifier. Must not be negative.- See Also:
-
isCriticalHit
public boolean isCriticalHit()Returns if the attack will critically hit.- Returns:
- if the attack will critically hit
-
setCriticalHit
public void setCriticalHit(boolean isCriticalHit) Changes the critical hit state.- Parameters:
isCriticalHit
- true if the attack should critically hit
-
getVanillaMultiplier
public float getVanillaMultiplier()Gets the original damage multiplier set by vanilla.If the event
isVanillaCritical()
, the damage multiplier will be 1.5, otherwise it will be 1.0- See Also:
-
isVanillaCritical
public boolean isVanillaCritical()Returns true if the attack was considered a critical hit by vanilla.- Returns:
- true if the attack was considered a critical hit by vanilla
-