Class CriticalHitEvent
Player.attack(Entity)
.
It can be used to change the critical hit status and the critical damage multiplier. Additionally, this event allows controlling if the critical hit will impact sweep conditions.
This event is fired on both the logical client and logical server.
-
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
FieldsModifier and TypeFieldDescriptionprivate boolean
private float
private boolean
private final boolean
private final net.minecraft.world.entity.Entity
private final float
-
Constructor Summary
ConstructorsConstructorDescriptionCriticalHitEvent
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, float dmgMultiplier, boolean isCriticalHit) -
Method Summary
Modifier and TypeMethodDescriptionboolean
If this attack is a critical hit, returns if a sweep should be prevented.float
The damage multiplier is applied to the base attack's damage if the attack critically hits.net.minecraft.world.entity.Entity
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.void
setDisableSweep
(boolean disableSweep) Sets if this attack should prevent a sweep from occurring.Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
getEntity
-
Field Details
-
target
private final net.minecraft.world.entity.Entity target -
vanillaDmgMultiplier
private final float vanillaDmgMultiplier -
isVanillaCritical
private final boolean isVanillaCritical -
dmgMultiplier
private float dmgMultiplier -
isCriticalHit
private boolean isCriticalHit -
disableSweep
private boolean disableSweep
-
-
Constructor Details
-
CriticalHitEvent
public CriticalHitEvent(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, float dmgMultiplier, boolean isCriticalHit)
-
-
Method Details
-
getTarget
public net.minecraft.world.entity.Entity 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.
-
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:
dmgMultiplier
- 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
-
setDisableSweep
public void setDisableSweep(boolean disableSweep) Sets if this attack should prevent a sweep from occurring.In vanilla, a critical hit always prevents a sweep from occurring. This method can allow an attack to both critically hit and sweep without having to validate the other sweep conditions.
-
disableSweep
public boolean disableSweep()If this attack is a critical hit, returns if a sweep should be prevented.If this attack is not a critical hit, the return value of this method is meaningless.
-