diff options
16 files changed, 169 insertions, 14 deletions
diff --git a/LICENSE.md b/LICENSE.md index 704c1863a1..687fd815fe 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -43,7 +43,7 @@ ysl3000 <[email protected]> Machine_Maker <[email protected]> Ivan Pekov <[email protected]> Camotoy <[email protected]> -Bjarne Koll <[email protected]> +Bjarne Koll <[email protected]> MeFisto94 <[email protected]> Owen1212055 <[email protected]> LemonCaramel <[email protected]> diff --git a/patches/api/0112-Expand-Explosions-API.patch b/patches/api/0112-Expand-Explosions-API.patch index 42f8422bee..bc6d875f8f 100644 --- a/patches/api/0112-Expand-Explosions-API.patch +++ b/patches/api/0112-Expand-Explosions-API.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Expand Explosions API Add Entity as a Source capability, and add more API choices, and on Location. Co-authored-by: Esoteric Enderman <[email protected]> -Co-authored-by: Bjarne Koll <[email protected]> +Co-authored-by: Bjarne Koll <[email protected]> diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java index df88bc77a3fa2506adf17eddc6300ac65774df6f..fe2e0939df61b1f59d12adf3f760f1d619bb3de3 100644 diff --git a/patches/api/0472-Introduce-registry-entry-and-builders.patch b/patches/api/0472-Introduce-registry-entry-and-builders.patch index 56e6efc80a..0a25fd735e 100644 --- a/patches/api/0472-Introduce-registry-entry-and-builders.patch +++ b/patches/api/0472-Introduce-registry-entry-and-builders.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Thu, 13 Jun 2024 22:35:05 +0200 Subject: [PATCH] Introduce registry entry and builders diff --git a/patches/api/0497-Fix-incorrect-invulnerability-damage-reduction.patch b/patches/api/0497-Fix-incorrect-invulnerability-damage-reduction.patch new file mode 100644 index 0000000000..63a5ca94e0 --- /dev/null +++ b/patches/api/0497-Fix-incorrect-invulnerability-damage-reduction.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll <[email protected]> +Date: Mon, 11 Nov 2024 21:35:22 +0100 +Subject: [PATCH] Fix incorrect invulnerability damage reduction + +Fixes incorrect spigot handling of the invulnerability damage +reduction applied when an already invulnerable entity is damaged with a +larger damage amount than the initial damage. +Vanilla still damages entities even if invulnerable if the damage to be +applied is larger than the previous damage taken. In that case, vanilla +applies the difference between the previous damage taken and the +proposed damage. + +Spigot's damage modifier API takes over the computation of damage +reducing effects, however spigot invokes this handling with the initial +damage before computing the difference to the previous damage amount. +This leads to the reduction values to generally be larger than expected, +as they are computed on the not-yet-reduced value. +Spigot applies these reductions after calling the EntityDamageEvent and +*then* subtracts the previous damage point, leading to the final damage +amount being smaller than expected. + +This patch cannot simply call the EntityDamageEvent with the reduced +damage, as that would lead to EntityDamageEvent#getDamage() returning +the already reduced damage, which breaks its method contract. +Instead, this patch makes use of the DamageModifier API, implementing +the last-damage-reduction as a DamageModifier. + +diff --git a/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java +index ef5b2a0f18c1c126db0b0c4a4d2a57483680665a..73aa5dc079ecb1c38c55ae1916b12edf81b723f5 100644 +--- a/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java ++++ b/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java +@@ -247,6 +247,7 @@ public class EntityDamageEvent extends EntityEvent implements Cancellable { + * raw {@link EntityDamageEvent#getDamage()}. + */ + BASE, ++ INVULNERABILITY_REDUCTION, // Paper - fix invulnerability reduction in EntityDamageEvent - needs to be right under BASE as its the first reduction all others are based on + /** + * This represents the damage increased by freezing status. + */ diff --git a/patches/server/0202-Expand-Explosions-API.patch b/patches/server/0202-Expand-Explosions-API.patch index 1dd84c44a5..7bf62df21c 100644 --- a/patches/server/0202-Expand-Explosions-API.patch +++ b/patches/server/0202-Expand-Explosions-API.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Expand Explosions API Add Entity as a Source capability, and add more API choices, and on Location. Co-authored-by: Esoteric Enderman <[email protected]> -Co-authored-by: Bjarne Koll <[email protected]> +Co-authored-by: Bjarne Koll <[email protected]> diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index 03161ef12960cab3b9c81c190dd808a9c5c476e1..f0fc08bcc2988277b6a5e3107e6fc5c89bb67b93 100644 diff --git a/patches/server/0607-Fix-setPatternColor-on-tropical-fish-bucket-meta.patch b/patches/server/0607-Fix-setPatternColor-on-tropical-fish-bucket-meta.patch index c313451894..f5c3a81df3 100644 --- a/patches/server/0607-Fix-setPatternColor-on-tropical-fish-bucket-meta.patch +++ b/patches/server/0607-Fix-setPatternColor-on-tropical-fish-bucket-meta.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Sat, 6 Nov 2021 23:15:20 +0100 Subject: [PATCH] Fix setPatternColor on tropical fish bucket meta diff --git a/patches/server/0781-Correctly-shrink-items-during-EntityResurrectEvent.patch b/patches/server/0781-Correctly-shrink-items-during-EntityResurrectEvent.patch index 58fdf1c475..d2f07ac306 100644 --- a/patches/server/0781-Correctly-shrink-items-during-EntityResurrectEvent.patch +++ b/patches/server/0781-Correctly-shrink-items-during-EntityResurrectEvent.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Tue, 10 Jan 2023 21:06:42 +0100 Subject: [PATCH] Correctly shrink items during EntityResurrectEvent diff --git a/patches/server/0835-Only-erase-allay-memory-on-non-item-targets.patch b/patches/server/0835-Only-erase-allay-memory-on-non-item-targets.patch index b26cfd040b..581af491b6 100644 --- a/patches/server/0835-Only-erase-allay-memory-on-non-item-targets.patch +++ b/patches/server/0835-Only-erase-allay-memory-on-non-item-targets.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Fri, 4 Aug 2023 15:53:36 +0200 Subject: [PATCH] Only erase allay memory on non-item targets diff --git a/patches/server/0965-Adopt-MaterialRerouting.patch b/patches/server/0965-Adopt-MaterialRerouting.patch index 648057e1dd..e66973fb9d 100644 --- a/patches/server/0965-Adopt-MaterialRerouting.patch +++ b/patches/server/0965-Adopt-MaterialRerouting.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Thu, 13 Jun 2024 11:02:36 +0200 Subject: [PATCH] Adopt MaterialRerouting diff --git a/patches/server/0969-Configurable-damage-tick-when-blocking-with-shield.patch b/patches/server/0969-Configurable-damage-tick-when-blocking-with-shield.patch index 7946c9fb9e..0c5196e832 100644 --- a/patches/server/0969-Configurable-damage-tick-when-blocking-with-shield.patch +++ b/patches/server/0969-Configurable-damage-tick-when-blocking-with-shield.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Thu, 13 Jun 2024 17:16:01 +0200 Subject: [PATCH] Configurable damage tick when blocking with shield diff --git a/patches/server/0985-Remove-streams-from-hot-code.patch b/patches/server/0985-Remove-streams-from-hot-code.patch index bab16c74ad..f1585163e2 100644 --- a/patches/server/0985-Remove-streams-from-hot-code.patch +++ b/patches/server/0985-Remove-streams-from-hot-code.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Remove streams from hot code Feature patch -Co-authored-by: Bjarne Koll <[email protected]> +Co-authored-by: Bjarne Koll <[email protected]> Co-authored-by: Spottedleaf <[email protected]> diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java b/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java diff --git a/patches/server/0993-Add-registry-entry-and-builders.patch b/patches/server/0993-Add-registry-entry-and-builders.patch index be3eccb69a..37f4a6a8c0 100644 --- a/patches/server/0993-Add-registry-entry-and-builders.patch +++ b/patches/server/0993-Add-registry-entry-and-builders.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Thu, 13 Jun 2024 23:45:32 +0200 Subject: [PATCH] Add registry entry and builders diff --git a/patches/server/1000-Only-call-EntityDamageEvents-before-actuallyHurt.patch b/patches/server/1000-Only-call-EntityDamageEvents-before-actuallyHurt.patch index 80cac108bc..b607b89045 100644 --- a/patches/server/1000-Only-call-EntityDamageEvents-before-actuallyHurt.patch +++ b/patches/server/1000-Only-call-EntityDamageEvents-before-actuallyHurt.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Mon, 8 Jul 2024 22:01:08 +0200 Subject: [PATCH] Only call EntityDamageEvents before actuallyHurt diff --git a/patches/server/1023-Remove-wall-time-unused-skip-tick-protection.patch b/patches/server/1023-Remove-wall-time-unused-skip-tick-protection.patch index deaf422ec7..c25e6680dc 100644 --- a/patches/server/1023-Remove-wall-time-unused-skip-tick-protection.patch +++ b/patches/server/1023-Remove-wall-time-unused-skip-tick-protection.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Mon, 16 Sep 2024 23:07:29 +0200 Subject: [PATCH] Remove wall-time / unused skip tick protection diff --git a/patches/server/1059-Correct-update-cursor.patch b/patches/server/1059-Correct-update-cursor.patch index 9d4e655ebb..77c0c52550 100644 --- a/patches/server/1059-Correct-update-cursor.patch +++ b/patches/server/1059-Correct-update-cursor.patch @@ -1,5 +1,5 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll <[email protected]> +From: Bjarne Koll <[email protected]> Date: Fri, 1 Nov 2024 14:58:57 +0100 Subject: [PATCH] Correct update cursor diff --git a/patches/server/1066-Fix-incorrect-invulnerability-damage-reduction.patch b/patches/server/1066-Fix-incorrect-invulnerability-damage-reduction.patch new file mode 100644 index 0000000000..3b3dd3d144 --- /dev/null +++ b/patches/server/1066-Fix-incorrect-invulnerability-damage-reduction.patch @@ -0,0 +1,115 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll <[email protected]> +Date: Mon, 11 Nov 2024 21:35:27 +0100 +Subject: [PATCH] Fix incorrect invulnerability damage reduction + +Fixes incorrect spigot handling of the invulnerability damage +reduction applied when an already invulnerable entity is damaged with a +larger damage amount than the initial damage. +Vanilla still damages entities even if invulnerable if the damage to be +applied is larger than the previous damage taken. In that case, vanilla +applies the difference between the previous damage taken and the +proposed damage. + +Spigot's damage modifier API takes over the computation of damage +reducing effects, however spigot invokes this handling with the initial +damage before computing the difference to the previous damage amount. +This leads to the reduction values to generally be larger than expected, +as they are computed on the not-yet-reduced value. +Spigot applies these reductions after calling the EntityDamageEvent and +*then* subtracts the previous damage point, leading to the final damage +amount being smaller than expected. + +This patch cannot simply call the EntityDamageEvent with the reduced +damage, as that would lead to EntityDamageEvent#getDamage() returning +the already reduced damage, which breaks its method contract. +Instead, this patch makes use of the DamageModifier API, implementing +the last-damage-reduction as a DamageModifier. + +diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java +index 6a3a8f0466998409a01223bc0c16d92b96e50118..51f913a495e7fda7e0e72439c6d7cc9607bd4af8 100644 +--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java ++++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -1505,12 +1505,12 @@ public abstract class LivingEntity extends Entity implements Attackable { + } + + // Paper start - only call damage event when actuallyHurt will be called - move call logic down +- event = this.handleEntityDamage(source, amount); ++ event = this.handleEntityDamage(source, amount, this.lastHurt); // Paper - fix invulnerability reduction in EntityDamageEvent - pass lastDamage reduction + amount = computeAmountFromEntityDamageEvent(event); + // Paper end - only call damage event when actuallyHurt will be called - move call logic down + + // CraftBukkit start +- if (!this.actuallyHurt(world, source, (float) event.getFinalDamage() - this.lastHurt, event)) { ++ if (!this.actuallyHurt(world, source, (float) event.getFinalDamage(), event)) { // Paper - fix invulnerability reduction in EntityDamageEvent - no longer subtract lastHurt, that is part of the damage event calc now + return false; + } + if (this instanceof ServerPlayer && event.getDamage() == 0 && originalAmount == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - skip damage if the vanilla damage is 0 and was not modified by plugins in the event. +@@ -1519,7 +1519,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + flag1 = false; + } else { + // Paper start - only call damage event when actuallyHurt will be called - move call logic down +- event = this.handleEntityDamage(source, amount); ++ event = this.handleEntityDamage(source, amount, 0); // Paper - fix invulnerability reduction in EntityDamageEvent - pass lastDamage reduction (none in this branch) + amount = computeAmountFromEntityDamageEvent(event); + // Paper end - only call damage event when actuallyHurt will be called - move call logic down + // CraftBukkit start +@@ -2322,8 +2322,19 @@ public abstract class LivingEntity extends Entity implements Attackable { + } + + // CraftBukkit start +- private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f) { ++ private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f, final float invulnerabilityRelatedLastDamage) { // Paper - fix invulnerability reduction in EntityDamageEvent + float originalDamage = f; ++ // Paper start - fix invulnerability reduction in EntityDamageEvent ++ final com.google.common.base.Function<Double, Double> invulnerabilityReductionEquation = d -> { ++ if (invulnerabilityRelatedLastDamage == 0) return 0D; // no last damage, no reduction ++ // last damage existed, this means the reduction *technically* is (new damage - last damage). ++ // If the event damage was changed to something less than invul damage, hard lock it at 0. ++ if (d < invulnerabilityRelatedLastDamage) return 0D; ++ return (double) -invulnerabilityRelatedLastDamage; ++ }; ++ final float originalInvulnerabilityReduction = invulnerabilityReductionEquation.apply((double) f).floatValue(); ++ f += originalInvulnerabilityReduction; ++ // Paper end - fix invulnerability reduction in EntityDamageEvent + + com.google.common.base.Function<Double, Double> freezing = new com.google.common.base.Function<Double, Double>() { + @Override +@@ -2400,7 +2411,12 @@ public abstract class LivingEntity extends Entity implements Attackable { + }; + float absorptionModifier = absorption.apply((double) f).floatValue(); + +- return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption); ++ // Paper start - fix invulnerability reduction in EntityDamageEvent ++ return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption, (damageModifierDoubleMap, damageModifierFunctionMap) -> { ++ damageModifierFunctionMap.put(DamageModifier.INVULNERABILITY_REDUCTION, invulnerabilityReductionEquation); ++ damageModifierDoubleMap.put(DamageModifier.INVULNERABILITY_REDUCTION, (double) originalInvulnerabilityReduction); ++ }); ++ // Paper end - fix invulnerability reduction in EntityDamageEvent + } + + protected boolean actuallyHurt(ServerLevel worldserver, final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final +diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +index deba03eb37012c638e08e20cd1c98e9db190c790..e37aaf77f94b97b736cc20ef070cefdff0400188 100644 +--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +@@ -1218,6 +1218,11 @@ public class CraftEventFactory { + private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0); + + public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double freezingModifier, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> freezing, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) { ++ // Paper start - fix invulnerability reduction in EntityDamageEvent ++ return handleLivingEntityDamageEvent(damagee, source, rawDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption, null); ++ } ++ public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double freezingModifier, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> freezing, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption, java.util.function.BiConsumer<Map<DamageModifier, Double>, Map<DamageModifier, Function<? super Double, Double>>> callback) { ++ // Paper end - fix invulnerability reduction in EntityDamageEvent + Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class); + Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class); + modifiers.put(DamageModifier.BASE, rawDamage); +@@ -1242,6 +1247,7 @@ public class CraftEventFactory { + modifierFunctions.put(DamageModifier.MAGIC, magic); + modifiers.put(DamageModifier.ABSORPTION, absorptionModifier); + modifierFunctions.put(DamageModifier.ABSORPTION, absorption); ++ if (callback != null) callback.accept(modifiers, modifierFunctions); // Paper - fix invulnerability reduction in EntityDamageEvent + return CraftEventFactory.handleEntityDamageEvent(damagee, source, modifiers, modifierFunctions); + } + |