Paper/patches/api/0112-Expand-Explosions-API.patch
Bjarne Koll d0dcd7d251
Fix incorrect invulnerability damage reduction (#11599)
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.
2024-11-19 11:54:58 +01:00

222 lines
9.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 19 Dec 2017 16:24:42 -0500
Subject: [PATCH] Expand Explosions API
Add Entity as a Source capability, and add more API choices, and on Location.
Co-authored-by: Esoteric Enderman <90862990+EsotericEnderman@users.noreply.github.com>
Co-authored-by: Bjarne Koll <git@lynxplay.dev>
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index df88bc77a3fa2506adf17eddc6300ac65774df6f..fe2e0939df61b1f59d12adf3f760f1d619bb3de3 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
+import org.bukkit.entity.Entity; // Paper
import org.bukkit.util.NumberConversions;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -569,6 +570,89 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
}
// Paper end - expand Location API
+ // Paper start - Expand Explosions API
+ /**
+ * Creates explosion at this location with given power
+ * <p>
+ * Will break blocks and ignite blocks on fire.
+ *
+ * @param power The power of explosion, where 4F is TNT
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(float power) {
+ return this.getWorld().createExplosion(this, power);
+ }
+
+ /**
+ * Creates explosion at this location with given power and optionally
+ * setting blocks on fire.
+ * <p>
+ * Will break blocks.
+ *
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether to set blocks on fire
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(float power, boolean setFire) {
+ return this.getWorld().createExplosion(this, power, setFire);
+ }
+
+ /**
+ * Creates explosion at this location with given power and optionally
+ * setting blocks on fire.
+ *
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether to set blocks on fire
+ * @param breakBlocks Whether to have blocks be destroyed
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(float power, boolean setFire, boolean breakBlocks) {
+ return this.getWorld().createExplosion(this, power, setFire, breakBlocks);
+ }
+
+ /**
+ * Creates explosion at this location with given power, with the specified entity as the source.
+ * <p>
+ * Will break blocks and ignite blocks on fire.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(@Nullable Entity source, float power) {
+ return this.getWorld().createExplosion(source, this, power, true, true);
+ }
+
+ /**
+ * Creates explosion at this location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ * <p>
+ * Will break blocks.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether to set blocks on fire
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(@Nullable Entity source, float power, boolean setFire) {
+ return this.getWorld().createExplosion(source, this, power, setFire, true);
+ }
+
+ /**
+ * Creates explosion at this location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether to set blocks on fire
+ * @param breakBlocks Whether to have blocks be destroyed
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(@Nullable Entity source, float power, boolean setFire, boolean breakBlocks) {
+ return this.getWorld().createExplosion(source, this, power, setFire, breakBlocks);
+ }
+ // Paper end - Expand Explosions API
+
// Paper start - additional getNearbyEntities API
/**
* Returns a list of entities within a bounding box centered around a Location.
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 44a74f15bea60ecd8380520e8faaea41a6c261c5..c2b5fdaace13c8bd46c073ac6d427fe411d96367 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -1424,6 +1424,104 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
*/
public boolean createExplosion(@NotNull Location loc, float power, boolean setFire);
+ // Paper start
+ /**
+ * Creates explosion at given location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * @param source The source entity of the explosion
+ * @param loc Location to blow up
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether or not to set blocks on fire
+ * @param breakBlocks Whether or not to have blocks be destroyed
+ * @param excludeSourceFromDamage whether the explosion should exclude the passed source from taking damage like vanilla explosions do.
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(@Nullable Entity source, @NotNull Location loc, float power, boolean setFire, boolean breakBlocks, boolean excludeSourceFromDamage);
+
+ /**
+ * Creates explosion at given location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * @param source The source entity of the explosion
+ * @param loc Location to blow up
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether or not to set blocks on fire
+ * @param breakBlocks Whether or not to have blocks be destroyed
+ * @return false if explosion was canceled, otherwise true
+ */
+ default boolean createExplosion(@Nullable Entity source, @NotNull Location loc, float power, boolean setFire, boolean breakBlocks) {
+ return createExplosion(source, loc, power, setFire, breakBlocks, true);
+ }
+
+ /**
+ * Creates explosion at given location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * Will destroy other blocks
+ *
+ * @param source The source entity of the explosion
+ * @param loc Location to blow up
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether or not to set blocks on fire
+ * @return false if explosion was canceled, otherwise true
+ */
+ public default boolean createExplosion(@Nullable Entity source, @NotNull Location loc, float power, boolean setFire) {
+ return createExplosion(source, loc, power, setFire, true);
+ }
+ /**
+ * Creates explosion at given location with given power, with the specified entity as the source.
+ * Will set blocks on fire and destroy blocks.
+ *
+ * @param source The source entity of the explosion
+ * @param loc Location to blow up
+ * @param power The power of explosion, where 4F is TNT
+ * @return false if explosion was canceled, otherwise true
+ */
+ public default boolean createExplosion(@Nullable Entity source, @NotNull Location loc, float power) {
+ return createExplosion(source, loc, power, true, true);
+ }
+ /**
+ * Creates explosion at given entities location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether or not to set blocks on fire
+ * @param breakBlocks Whether or not to have blocks be destroyed
+ * @return false if explosion was canceled, otherwise true
+ */
+ public default boolean createExplosion(@NotNull Entity source, float power, boolean setFire, boolean breakBlocks) {
+ return createExplosion(source, source.getLocation(), power, setFire, breakBlocks);
+ }
+ /**
+ * Creates explosion at given entities location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * Will destroy blocks.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @param setFire Whether or not to set blocks on fire
+ * @return false if explosion was canceled, otherwise true
+ */
+ public default boolean createExplosion(@NotNull Entity source, float power, boolean setFire) {
+ return createExplosion(source, source.getLocation(), power, setFire, true);
+ }
+
+ /**
+ * Creates explosion at given entities location with given power and optionally
+ * setting blocks on fire, with the specified entity as the source.
+ *
+ * @param source The source entity of the explosion
+ * @param power The power of explosion, where 4F is TNT
+ * @return false if explosion was canceled, otherwise true
+ */
+ public default boolean createExplosion(@NotNull Entity source, float power) {
+ return createExplosion(source, source.getLocation(), power, true, true);
+ }
+ // Paper end
+
/**
* Creates explosion at given coordinates with given power and optionally
* setting blocks on fire or breaking blocks.