Skip to content

Commit

Permalink
Add the ability for explosions to damage the explosion cause
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Aug 23, 2024
1 parent 2fdb2e9 commit ae12cce
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 86 deletions.
31 changes: 30 additions & 1 deletion patches/api/0112-Expand-Explosions-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ index 3161eae2fa5f03b7d3a5e9945ab659c15cf568c6..af737017ee397f80c44ee02c6cc60cef
/**
* 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..50c1e4957f66826feb0a2eb04293dbd6b5595700 100644
index 44a74f15bea60ecd8380520e8faaea41a6c261c5..8b35c3d7384103881b6c218de81f2ef015c448c1 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -1424,6 +1424,88 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
Expand Down Expand Up @@ -200,3 +200,32 @@ index 44a74f15bea60ecd8380520e8faaea41a6c261c5..50c1e4957f66826feb0a2eb04293dbd6
/**
* Creates explosion at given coordinates with given power and optionally
* setting blocks on fire or breaking blocks.
@@ -1455,6 +1537,28 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
*/
public boolean createExplosion(@NotNull Location loc, float power, boolean setFire, boolean breakBlocks, @Nullable Entity source);

+ // Paper start - Add the option for explosions to damage the explosion cause
+ /**
+ * Creates explosion at given coordinates with given power and optionally
+ * setting blocks on fire, breaking blocks, or damaging the {@code source} entity.
+ * <p>
+ * Note that if a non-null {@code source} Entity is provided and {@code
+ * breakBlocks} is {@code true}, the value of {@code breakBlocks} will be
+ * ignored if {@link GameRule#MOB_GRIEFING} is {@code false} in the world
+ * in which the explosion occurs. In other words, the mob griefing gamerule
+ * will take priority over {@code breakBlocks} if explosions are not allowed.
+ *
+ * @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 source the source entity, used for tracking damage
+ * @param shouldDamageSource Whether or not the explosion should damage the {@code source} entity
+ * @return false if explosion was canceled, otherwise true
+ */
+ public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks, Entity source, boolean shouldDamageSource);
+ // Paper end - Add the option for explosions to damage the explosion cause
+
/**
* Gets the current PVP setting for this world.
*
12 changes: 6 additions & 6 deletions patches/api/0166-Fix-Spigot-annotation-mistakes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ index e455eb21abf121dc6ff10ff8a13dd06f67096a8f..bbc01e7c192ae6689c301670047ff114
return origin;
}
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index fcdc5d83621acff5f9210585455be1ea50abb77c..216995288f6b8b407ef8240411b5ed4713379a7a 100644
index 6bd436a07b1ab0eefea9117fec5b98dbc9cbe0fa..ff95f65c2f58a333fad23383f29418185122c3d2 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -418,9 +418,8 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
Expand All @@ -632,15 +632,15 @@ index fcdc5d83621acff5f9210585455be1ea50abb77c..216995288f6b8b407ef8240411b5ed47
public boolean refreshChunk(int x, int z);

/**
@@ -3797,6 +3796,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3819,6 +3818,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);

// Spigot start
+ @Deprecated(forRemoval = true) // Paper
public class Spigot {

/**
@@ -3830,7 +3830,11 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3852,7 +3852,11 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
}
}

Expand All @@ -652,7 +652,7 @@ index fcdc5d83621acff5f9210585455be1ea50abb77c..216995288f6b8b407ef8240411b5ed47
Spigot spigot();
// Spigot end

@@ -4048,9 +4052,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -4070,9 +4074,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* Gets the dimension ID of this environment
*
* @return dimension ID
Expand All @@ -664,7 +664,7 @@ index fcdc5d83621acff5f9210585455be1ea50abb77c..216995288f6b8b407ef8240411b5ed47
public int getId() {
return id;
}
@@ -4060,9 +4064,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -4082,9 +4086,9 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
*
* @param id The ID of the environment
* @return The environment
Expand Down Expand Up @@ -890,7 +890,7 @@ index bafef53c1d449135f1300c8c8fbb06f482ba67e1..f50aaddf8582be55fd4860ad374d8f22
+@Deprecated(forRemoval = true) // Paper
public interface LingeringPotion extends ThrownPotion { }
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index b5ea7b60b47f056553a1cec766c57e0f75735633..ec35111df4b38fd55cc34f4baedebcf39c7fc92b 100644
index 3f1b74af137868e502792c65ccd7ca74f3c3cb8c..c89ffb0f98dccd015e80e299142252fed3ece4a8 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -716,7 +716,9 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
Expand Down
4 changes: 2 additions & 2 deletions patches/api/0260-More-World-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] More World API


diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 216995288f6b8b407ef8240411b5ed4713379a7a..d3fc033aba36c5fd99846e9200ed0071fddd6045 100644
index ff95f65c2f58a333fad23383f29418185122c3d2..4800cf82ce51840d3dc9572e4f33c66b04f9546c 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -3795,6 +3795,72 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3817,6 +3817,72 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@Nullable
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);

Expand Down
8 changes: 4 additions & 4 deletions patches/api/0348-Expand-FallingBlock-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Subject: [PATCH] Expand FallingBlock API
Co-authored-by: Lukas Planz <[email protected]>

diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 8e9ab00503167799c6c929d00e48c07cb328848c..907906e15c9250fea385e49f10d3c248236fd004 100644
index 778933623213f2929fdba2565d9d43113ea317df..061ed4ca85242a694a3c56411d7e1dc76b5716c8 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -2228,8 +2228,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -2250,8 +2250,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* MaterialData} are null or {@link Material} of the {@link MaterialData} is not a block
Expand All @@ -24,7 +24,7 @@ index 8e9ab00503167799c6c929d00e48c07cb328848c..907906e15c9250fea385e49f10d3c248
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull MaterialData data) throws IllegalArgumentException;

/**
@@ -2242,8 +2244,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -2264,8 +2266,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* BlockData} are null
Expand All @@ -35,7 +35,7 @@ index 8e9ab00503167799c6c929d00e48c07cb328848c..907906e15c9250fea385e49f10d3c248
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull BlockData data) throws IllegalArgumentException;

/**
@@ -2260,7 +2264,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -2282,7 +2286,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* Material} are null or {@link Material} is not a block
Expand Down
4 changes: 2 additions & 2 deletions patches/api/0458-More-Raid-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ index 983a8c20a06d2b509602b27f49c090598b8ecc42..fa98599e3eee37bf68f0e9813497c718
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index ecc2d486cfec79cce27a947dfeed4853575a594d..d8a23aa0d898ca3360757721e38ddb97387f7d21 100644
index 94c73439f0a0489187ccc12193ba1f4ef13a4687..7d0ea31ee8eadee0b321729dbfc424e07a81647f 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -4111,6 +4111,17 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -4133,6 +4133,17 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@Nullable
public Raid locateNearestRaid(@NotNull Location location, int radius);

Expand Down
79 changes: 76 additions & 3 deletions patches/server/0203-Expand-Explosions-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,86 @@ Subject: [PATCH] Expand Explosions API

Add Entity as a Source capability, and add more API choices, and on Location.

diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index b216140a8be65e210250358af8daf49344850f20..a92a2288836385e1821cbdda751e896136b1c49c 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -160,7 +160,13 @@ public class Explosion {
return new Vec3(this.x, this.y, this.z);
}

+ // Paper start - Add the option for explosions to damage the explosion cause
public void explode() {
+ this.explode(false);
+ }
+ // Paper end - Add the option for explosions to damage the explosion cause
+
+ public void explode(boolean shouldDamageSource) { // Paper - Add the option for explosions to damage the explosion cause
// CraftBukkit start
if (this.radius < 0.1F) {
return;
@@ -227,7 +233,7 @@ public class Explosion {
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
int j1 = Mth.floor(this.z - (double) f2 - 1.0D);
int k1 = Mth.floor(this.z + (double) f2 + 1.0D);
- List<Entity> list = this.level.getEntities(this.source, new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1), (com.google.common.base.Predicate<Entity>) entity -> entity.isAlive() && !entity.isSpectator()); // Paper - Fix lag from explosions processing dead entities
+ List<Entity> list = this.level.getEntities(shouldDamageSource ? null : this.source, new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1), (com.google.common.base.Predicate<Entity>) entity -> entity.isAlive() && !entity.isSpectator()); // Paper - Fix lag from explosions processing dead entities // Paper - Add the option for explosions to damage the explosion
Vec3 vec3d = new Vec3(this.x, this.y, this.z);
Iterator iterator = list.iterator();

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 6944c0b0cfcde9fa4dd78742aee3e3b87d679abf..84124c43a496a7ff77f8e10cb8ef096e172eb69b 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -797,7 +797,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, true, particle, emitterParticle, soundEvent);
}

+ // Paper start - Add the ability for explosions to damage the explosion cause
public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, boolean particles, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent) {
+ return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, particles, particle, emitterParticle, soundEvent, false);
+ }
+ // Paper end - Add the ability for explosions to damage the explosion cause
+
+ public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, boolean particles, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent, boolean shouldDamageSource) {
Explosion.BlockInteraction explosion_effect;

switch (explosionSourceType.ordinal()) {
@@ -828,7 +834,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
Explosion.BlockInteraction explosion_effect1 = explosion_effect;
Explosion explosion = new Explosion(this, entity, damageSource, behavior, x, y, z, power, createFire, explosion_effect1, particle, emitterParticle, soundEvent);

- explosion.explode();
+ explosion.explode(shouldDamageSource); // Paper - Add the ability for explosions to damage the explosion cause
explosion.finalizeExplosion(particles);
return explosion;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 3c00eaf52ab04d1396f226cc074d9dd013c57027..b2a1f7e6576757d02a0369c42d4526ca3ac3d775 100644
index 3c00eaf52ab04d1396f226cc074d9dd013c57027..46b68d31bbc9dde0f1ff2620fa968d3f02132c2f 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -789,6 +789,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@@ -776,8 +776,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return this.createExplosion(x, y, z, power, setFire, breakBlocks, null);
}

+ // Paper start - Add the option for explosions to damage the explosion cause
@Override
public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks, Entity source) {
+ return this.createExplosion(x, y, z, power, setFire, breakBlocks, source, false);
+ }
+ // Paper end - Add the option for explosions to damage the explosion cause
+
+ @Override
+ public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks, Entity source, boolean shouldDamageSource) { // Paper - Add the option for explosions to damage the explosion cause
net.minecraft.world.level.Level.ExplosionInteraction explosionType;
if (!breakBlocks) {
explosionType = net.minecraft.world.level.Level.ExplosionInteraction.NONE; // Don't break blocks
@@ -787,8 +794,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
explosionType = net.minecraft.world.level.Level.ExplosionInteraction.MOB; // Respect mobGriefing gamerule
}

return !this.world.explode(source == null ? null : ((CraftEntity) source).getHandle(), x, y, z, power, setFire, explosionType).wasCanceled;
- return !this.world.explode(source == null ? null : ((CraftEntity) source).getHandle(), x, y, z, power, setFire, explosionType).wasCanceled;
+ return !this.world.explode(source == null ? null : ((CraftEntity) source).getHandle(), net.minecraft.world.level.Explosion.getDefaultDamageSource(this.getHandle(), source == null ? null : ((CraftEntity) source).getHandle()), (net.minecraft.world.level.ExplosionDamageCalculator) null, x, y, z, power, setFire, explosionType, true, net.minecraft.core.particles.ParticleTypes.EXPLOSION, net.minecraft.core.particles.ParticleTypes.EXPLOSION_EMITTER, net.minecraft.sounds.SoundEvents.GENERIC_EXPLODE, shouldDamageSource).wasCanceled; // Paper - Add the option for explosions to damage the explosion cause
}
+ // Paper start
+ @Override
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0207-Implement-World.getEntity-UUID-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Implement World.getEntity(UUID) API


diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index b2a1f7e6576757d02a0369c42d4526ca3ac3d775..281fa67cb5c95e6016c7220c0ef912bbfd28cd9f 100644
index 46b68d31bbc9dde0f1ff2620fa968d3f02132c2f..a286cf12496c59c7d9b4170eea995c7a0008bab7 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1125,6 +1125,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@@ -1132,6 +1132,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Optimize to check if the captured list even has values in it, and also to
just do a get call since the value can never be null.

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 8e2acb3c6f815b5b1d3237a2f4e0b5f3683d2c60..5a3a89c568d42a2adbc2b6e2631fd4b70e54f0bf 100644
index f3530398466ada594f15c71478386e152e50453c..b1ff6f34bcc0842d055a8c8162349a2a95d6e1fe 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -912,9 +912,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -918,9 +918,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {

@Nullable
public BlockEntity getBlockEntity(BlockPos blockposition, boolean validate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Optimize call to getFluid for explosions


diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 512d79b66fed3d1bef645c3ecb59bda032c81d15..1350c8df69b4ffcf9daa73549e496627db8bc6f7 100644
index a92a2288836385e1821cbdda751e896136b1c49c..12a348c2ec5968f22bc77c038af63eb199bfe776 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -193,7 +193,7 @@ public class Explosion {
@@ -199,7 +199,7 @@ public class Explosion {
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockposition = BlockPos.containing(d4, d5, d6);
BlockState iblockdata = this.level.getBlockState(blockposition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ index 1b3f1b06155e114cd5ab76a406c1b4e745ef58c6..52e8664f8d0368daed43e349aa67e3b2
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 20bb365b188c7081123db87186f0e1a999758817..a381688de78f5a78980b660f9765f839413a6c65 100644
index 53d1f62db2a966c8dcebe1b5e087b013a72932a4..82c26b57a7464d3489cc1f3a7c5f5ddd6536d4bb 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1165,7 +1165,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@@ -1172,7 +1172,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {

@Override
public void setDifficulty(Difficulty difficulty) {
Expand Down
Loading

0 comments on commit ae12cce

Please sign in to comment.