Skip to content

Commit

Permalink
Add Bjarne's patches
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Sep 26, 2024
1 parent a4c0b9b commit 0d86679
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
38 changes: 38 additions & 0 deletions patches/api/0490-More-more-explosion-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <[email protected]>
Date: Fri, 20 Sep 2024 13:53:59 +0200
Subject: [PATCH] More MORE explosion API


diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index d8a23aa0d898ca3360757721e38ddb97387f7d21..adcd8161846b06fd1a7895750f98b629204a8406 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -2139,9 +2139,25 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @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);
+ 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

102 changes: 102 additions & 0 deletions patches/server/1059-More-more-explosion-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <[email protected]>
Date: Fri, 20 Sep 2024 13:53:49 +0200
Subject: [PATCH] More MORE explosion API


diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index c96f3dcd365bc140b1f4680ef6bd770c80f8eda1..8f73e28e6a529296c9eed530e62c1fa846ab1447 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1774,8 +1774,10 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
}

@Override
- 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, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent) {
- Explosion explosion = this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, false, particle, emitterParticle, soundEvent);
+ // Paper start - expand explosion API
+ 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, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent, java.util.function.Consumer<Explosion> configurator) {
+ Explosion explosion = this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, false, particle, emitterParticle, soundEvent, configurator);
+ // Paper end - expand explosion API
// CraftBukkit start
if (explosion.wasCanceled) {
return explosion;
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index ad57bf49476192dea6a7367cbd0ad3f11e142e1b..ebe95187130c2ed32b9c0c2de3f9ec11e269ec5e 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -74,6 +74,7 @@ public class Explosion {
public boolean wasCanceled = false;
public float yield;
// CraftBukkit end
+ public boolean excludeSourceFromDamage = true; // Paper - expand explosion API

// Paper start - optimise collisions
private static final double[] CACHED_RAYS;
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index e2a0487089eb5a7bdc1433e4c75f69d8e9f9d5f9..73f00d0a98c155540fac662423d84cf4112948c8 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1461,7 +1461,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
}

public Explosion explode(@Nullable Entity entity, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType) {
- return this.explode(entity, Explosion.getDefaultDamageSource(this, entity), (ExplosionDamageCalculator) null, x, y, z, power, createFire, explosionSourceType, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE);
+ // Paper start - expand explosion API
+ return this.explode(entity, x, y, z, power, createFire, explosionSourceType, null);
+ }
+ public Explosion explode(@Nullable Entity entity, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, @Nullable Consumer<Explosion> configurator) {
+ return this.explode(entity, Explosion.getDefaultDamageSource(this, entity), (ExplosionDamageCalculator) null, x, y, z, power, createFire, explosionSourceType, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE, configurator);
+ // Paper end - expand explosion API
}

public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, Vec3 pos, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType) {
@@ -1473,10 +1478,21 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
}

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, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent) {
- return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, true, particle, emitterParticle, soundEvent);
+ // Paper start - expand explosion API
+ return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, particle, emitterParticle, soundEvent, null);
+ }
+
+ 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, ParticleOptions particle, ParticleOptions emitterParticle, Holder<SoundEvent> soundEvent, @Nullable Consumer<Explosion> configurator) {
+ return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, true, particle, emitterParticle, soundEvent, configurator);
+ // Paper end - expand explosion API
}

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) {
+ // Paper start - expand explosion API
+ return this.explode(entity, damageSource, behavior, x, y, z, power, createFire, explosionSourceType, particle, emitterParticle, soundEvent, null);
+ }
+ 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, @Nullable Consumer<Explosion> configurator) {
+ // Paper end - expand explosion API
Explosion.BlockInteraction explosion_effect;

switch (explosionSourceType.ordinal()) {
@@ -1506,6 +1522,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl

Explosion.BlockInteraction explosion_effect1 = explosion_effect;
Explosion explosion = new Explosion(this, entity, damageSource, behavior, x, y, z, power, createFire, explosion_effect1, particle, emitterParticle, soundEvent);
+ if (configurator != null) configurator.accept(explosion); // Paper - expand explosion API

explosion.explode();
explosion.finalizeExplosion(particles);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index cd3381d8225e0322b3e285b3c4aa0a1265a91cc0..38b046da5acac8633db8618a2957187d291f5e73 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -910,8 +910,10 @@ public class CraftWorld extends CraftRegionAccessor implements World {
}
// Paper start
@Override
- public boolean createExplosion(Entity source, Location loc, float power, boolean setFire, boolean breakBlocks) {
- return !world.explode(source != null ? ((org.bukkit.craftbukkit.entity.CraftEntity) source).getHandle() : null, loc.getX(), loc.getY(), loc.getZ(), power, setFire, breakBlocks ? net.minecraft.world.level.Level.ExplosionInteraction.MOB : net.minecraft.world.level.Level.ExplosionInteraction.NONE).wasCanceled;
+ public boolean createExplosion(Entity source, Location loc, float power, boolean setFire, boolean breakBlocks, boolean excludeSourceFromDamage) {
+ return !world.explode(source != null ? ((org.bukkit.craftbukkit.entity.CraftEntity) source).getHandle() : null, loc.getX(), loc.getY(), loc.getZ(), power, setFire, breakBlocks ? net.minecraft.world.level.Level.ExplosionInteraction.MOB : net.minecraft.world.level.Level.ExplosionInteraction.NONE, explosion -> {
+ explosion.excludeSourceFromDamage = excludeSourceFromDamage;
+ }).wasCanceled;
}
// Paper end


0 comments on commit 0d86679

Please sign in to comment.