papermc/patches/api/0318-Add-critical-damage-API.patch

52 lines
2.7 KiB
Diff
Raw Normal View History

2021-10-20 22:15:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: dodison <kacpik@mapik.eu>
Date: Mon, 26 Jul 2021 17:35:20 +0200
Subject: [PATCH] Add critical damage API
diff --git a/src/main/java/org/bukkit/event/entity/EntityDamageByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamageByEntityEvent.java
2023-09-24 23:02:46 +00:00
index 869bad7405ec7fa67728e90d8b9f2e11b542611f..aec5a0c2882cf69e8802b9e754b14d0acc34b162 100644
2021-10-20 22:15:28 +00:00
--- a/src/main/java/org/bukkit/event/entity/EntityDamageByEntityEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityDamageByEntityEvent.java
2023-03-23 21:57:03 +00:00
@@ -11,15 +11,40 @@ import org.jetbrains.annotations.NotNull;
2021-10-20 22:15:28 +00:00
public class EntityDamageByEntityEvent extends EntityDamageEvent {
private final Entity damager;
+ @Deprecated // Paper - add critical damage API
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
super(damagee, cause, damage);
this.damager = damager;
+ this.critical = false; // Paper - add critical damage API
}
+ @Deprecated // Paper - add critical damage API
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
+ // Paper start - add critical damage API
+ this(damager, damagee, cause, modifiers, modifierFunctions, false);
+ }
+
+ private final boolean critical;
+ public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions, boolean critical) {
+ // Paper end
super(damagee, cause, modifiers, modifierFunctions);
this.damager = damager;
+ // Paper start - add critical damage API
+ this.critical = critical;
2023-03-23 21:57:03 +00:00
+ }
+
2021-10-20 22:15:28 +00:00
+ /**
+ * Shows this damage instance was critical.
+ * The damage instance can be critical if the attacking player met the respective conditions.
+ * Furthermore arrows may also cause a critical damage event if the arrow {@link org.bukkit.entity.AbstractArrow#isCritical()}.
+ *
+ * @return if the hit was critical.
2023-09-24 23:02:46 +00:00
+ * @see <a href="https://minecraft.wiki/wiki/Damage#Critical_hit">https://minecraft.wiki/wiki/Damage#Critical_hit</a>
2021-10-20 22:15:28 +00:00
+ */
+ public boolean isCritical() {
+ return this.critical;
2023-03-23 21:57:03 +00:00
}
2021-10-20 22:15:28 +00:00
+ // Paper end
2023-03-23 21:57:03 +00:00
2021-10-20 22:15:28 +00:00
/**
* Returns the entity that damaged the defender.