Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
e3c8a8eef1
* Add PlayerInsertLecternBookEvent * Rebase Additionally, moves the event call higher up and removes the lectern block state clone from the event. * jSpecify * Shrink correctly * style fixups * move methods * rename param to cancel * fix javadocs * more javadoc fixes * fix co-author on patch from yesterday * last fix --------- Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: Bjarne Koll <lynxplay101@gmail.com>
117 Zeilen
9.9 KiB
Diff
117 Zeilen
9.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 20 Jun 2018 23:17:24 -0400
|
|
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 <lynxplay101@gmail.com>
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 1fac100819e59d00f50e530d3a4157b56d966dba..f2e75b36cbceb9cfa0755bd045f23073712d0e8a 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1424,8 +1424,10 @@ 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 b216140a8be65e210250358af8daf49344850f20..ce8ac06b47e81161ad5ff6cc865ad6d3d59807c1 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 - Allow explosions to damage source
|
|
|
|
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
|
|
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
|
|
@@ -227,7 +228,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(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 6944c0b0cfcde9fa4dd78742aee3e3b87d679abf..7138fb36062eceaf92ae8513f9b8aef3d1238656 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -782,7 +782,12 @@ 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) {
|
|
@@ -794,10 +799,21 @@ 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()) {
|
|
@@ -827,6 +843,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);
|
|
+ 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 3c00eaf52ab04d1396f226cc074d9dd013c57027..2c13ece6592700126365a155f104d6971aab4ede 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -789,6 +789,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
return !this.world.explode(source == null ? null : ((CraftEntity) source).getHandle(), x, y, z, power, setFire, explosionType).wasCanceled;
|
|
}
|
|
+ // Paper start
|
|
+ @Override
|
|
+ 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
|
|
|
|
@Override
|
|
public boolean createExplosion(Location loc, float power) {
|