geforkt von Mirrors/Paper
Add API for explosions to damage the explosion cause (#11180)
This intends to give plugin developers more control over explosions created using the World#createExplosion method, specifically by adding the option for explosions to damage the explosion cause (not the default behavior, and previously impossible to do, as far as I know). This is done by overloading existing methods with an extra `excludeSourceFromDamage` parameter. Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Dieser Commit ist enthalten in:
Ursprung
afe5fc14c8
Commit
96dde2d730
@ -5,6 +5,9 @@ Subject: [PATCH] Expand Explosions API
|
||||
|
||||
Add Entity as a Source capability, and add more API choices, and on Location.
|
||||
|
||||
Co-authored-by: Slqmy <90862990+Slqmy@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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/Location.java
|
||||
@ -125,9 +128,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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
|
||||
|
@ -5,6 +5,96 @@ Subject: [PATCH] Expand Explosions API
|
||||
|
||||
Add Entity as a Source capability, and add more API choices, and on Location.
|
||||
|
||||
Co-authored-by: Slqmy <90862990+Slqmy@users.noreply.github.com>
|
||||
Co-authored-by: Bjarne Koll <git@lynxplay.dev>
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||||
}
|
||||
|
||||
@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 - Allow explosions to damage source
|
||||
+ 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 - Allow explosions to damage source
|
||||
// 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -0,0 +0,0 @@ public class Explosion {
|
||||
public boolean wasCanceled = false;
|
||||
public float yield;
|
||||
// CraftBukkit end
|
||||
+ public boolean excludeSourceFromDamage = true; // Paper - Allow explosions to damage source
|
||||
|
||||
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
|
||||
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
|
||||
@@ -0,0 +0,0 @@ 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(excludeSourceFromDamage ? this.source : null, 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, Allow explosions to damage source
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||
}
|
||||
|
||||
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 - Allow explosions to damage source
|
||||
+ 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 - Allow explosions to damage source
|
||||
}
|
||||
|
||||
public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, Vec3 pos, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType) {
|
||||
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||
}
|
||||
|
||||
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 - Allow explosions to damage source
|
||||
+ 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 - Allow explosions to damage source
|
||||
}
|
||||
|
||||
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 - Allow explosions to damage source
|
||||
+ 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 - Allow explosions to damage source
|
||||
Explosion.BlockInteraction explosion_effect;
|
||||
|
||||
switch (explosionSourceType.ordinal()) {
|
||||
@@ -0,0 +0,0 @@ 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);
|
||||
+ if (configurator != null) configurator.accept(explosion); // Paper - Allow explosions to damage source
|
||||
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@ -15,8 +105,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
}
|
||||
+ // 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
|
||||
|
||||
|
@ -27719,8 +27719,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -0,0 +0,0 @@ public class Explosion {
|
||||
public float yield;
|
||||
// CraftBukkit end
|
||||
public boolean excludeSourceFromDamage = true; // Paper - Allow explosions to damage source
|
||||
|
||||
+ // Paper start - optimise collisions
|
||||
+ private static final double[] CACHED_RAYS;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren