186 lines
10 KiB
Diff
186 lines
10 KiB
Diff
--- a/net/minecraft/world/level/ServerExplosion.java
|
|
+++ b/net/minecraft/world/level/ServerExplosion.java
|
|
@@ -34,6 +34,13 @@
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
|
import net.minecraft.world.phys.Vec3D;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.world.entity.boss.EntityComplexPart;
|
|
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
|
|
+import net.minecraft.world.level.block.Blocks;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+// CraftBukkit end
|
|
+
|
|
public class ServerExplosion implements Explosion {
|
|
|
|
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
|
|
@@ -49,16 +56,21 @@
|
|
private final DamageSource damageSource;
|
|
private final ExplosionDamageCalculator damageCalculator;
|
|
private final Map<EntityHuman, Vec3D> hitPlayers = new HashMap();
|
|
+ // CraftBukkit - add field
|
|
+ public boolean wasCanceled = false;
|
|
+ public float yield;
|
|
+ // CraftBukkit end
|
|
|
|
public ServerExplosion(WorldServer worldserver, @Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, Vec3D vec3d, float f, boolean flag, Explosion.Effect explosion_effect) {
|
|
this.level = worldserver;
|
|
this.source = entity;
|
|
- this.radius = f;
|
|
+ this.radius = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values
|
|
this.center = vec3d;
|
|
this.fire = flag;
|
|
this.blockInteraction = explosion_effect;
|
|
this.damageSource = damagesource == null ? worldserver.damageSources().explosion(this) : damagesource;
|
|
this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator;
|
|
+ this.yield = this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit
|
|
}
|
|
|
|
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity entity) {
|
|
@@ -171,7 +183,10 @@
|
|
int i1 = MathHelper.floor(this.center.z - (double) f - 1.0D);
|
|
int j1 = MathHelper.floor(this.center.z + (double) f + 1.0D);
|
|
|
|
- for (Entity entity : this.level.getEntities(this.source, new AxisAlignedBB((double) i, (double) k, (double) i1, (double) j, (double) l, (double) j1))) {
|
|
+ // CraftBukkit start
|
|
+ List<Entity> list = this.level.getEntities(this.source, new AxisAlignedBB((double) i, (double) k, (double) i1, (double) j, (double) l, (double) j1));
|
|
+ for (Entity entity :list) {
|
|
+ // CraftBukkit end
|
|
if (!entity.ignoreExplosion(this)) {
|
|
double d0 = Math.sqrt(entity.distanceToSqr(this.center)) / (double) f;
|
|
|
|
@@ -190,7 +205,35 @@
|
|
float f2 = !flag && f1 == 0.0F ? 0.0F : getSeenPercent(this.center, entity);
|
|
|
|
if (flag) {
|
|
- entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
|
|
+ // CraftBukkit start
|
|
+
|
|
+ // Special case ender dragon only give knockback if no damage is cancelled
|
|
+ // Thinks to note:
|
|
+ // - Setting a velocity to a ComplexEntityPart is ignored (and therefore not needed)
|
|
+ // - Damaging ComplexEntityPart while forward the damage to EntityEnderDragon
|
|
+ // - Damaging EntityEnderDragon does nothing
|
|
+ // - EntityEnderDragon hitbock always covers the other parts and is therefore always present
|
|
+ if (entity instanceof EntityComplexPart) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ entity.lastDamageCancelled = false;
|
|
+
|
|
+ if (entity instanceof EntityEnderDragon) {
|
|
+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) {
|
|
+ // Calculate damage separately for each EntityComplexPart
|
|
+ if (list.contains(entityComplexPart)) {
|
|
+ entityComplexPart.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
|
|
+ }
|
|
+
|
|
+ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
|
|
+ continue;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
double d5 = (1.0D - d0) * (double) f2 * (double) f1;
|
|
@@ -209,6 +252,17 @@
|
|
d3 *= d6;
|
|
Vec3D vec3d = new Vec3D(d1, d2, d3);
|
|
|
|
+ // CraftBukkit start - Call EntityKnockbackEvent
|
|
+ if (entity instanceof EntityLiving) {
|
|
+ Vec3D result = entity.getDeltaMovement().add(vec3d);
|
|
+ org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d6, vec3d, result.x, result.y, result.z);
|
|
+
|
|
+ // SPIGOT-7640: Need to subtract entity movement from the event result,
|
|
+ // since the code below (the setDeltaMovement call as well as the hitPlayers map)
|
|
+ // want the vector to be the relative velocity will the event provides the absolute velocity
|
|
+ vec3d = (event.isCancelled()) ? Vec3D.ZERO : new Vec3D(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()).subtract(entity.getDeltaMovement());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
entity.push(vec3d);
|
|
if (entity instanceof EntityHuman) {
|
|
EntityHuman entityhuman = (EntityHuman) entity;
|
|
@@ -230,8 +284,30 @@
|
|
List<ServerExplosion.a> list1 = new ArrayList();
|
|
|
|
SystemUtils.shuffle(list, this.level.random);
|
|
+ // CraftBukkit start
|
|
+ List<org.bukkit.block.Block> bukkitBlocks = CraftEventFactory.handleExplodeEvent(this, list);
|
|
+
|
|
+ list.clear();
|
|
+ list.addAll(bukkitBlocks.stream().map(bblock -> new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ())).toList());
|
|
+
|
|
+ if (this.wasCanceled) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
for (BlockPosition blockposition : list) {
|
|
+ // CraftBukkit start - TNTPrimeEvent
|
|
+ IBlockData iblockdata = this.level.getBlockState(blockposition);
|
|
+ Block block = iblockdata.getBlock();
|
|
+ if (block instanceof net.minecraft.world.level.block.BlockTNT) {
|
|
+ BlockPosition sourceBlock = source == null ? BlockPosition.containing(this.center) : null;
|
|
+ if (!CraftEventFactory.callTNTPrimeEvent(this.level, blockposition, org.bukkit.event.block.TNTPrimeEvent.PrimeCause.EXPLOSION, source, sourceBlock)) {
|
|
+ this.level.sendBlockUpdated(blockposition, Blocks.AIR.defaultBlockState(), iblockdata, 3); // Update the block on the client
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> {
|
|
addOrAppendStack(list1, itemstack, blockposition1);
|
|
});
|
|
@@ -246,13 +322,22 @@
|
|
private void createFire(List<BlockPosition> list) {
|
|
for (BlockPosition blockposition : list) {
|
|
if (this.level.random.nextInt(3) == 0 && this.level.getBlockState(blockposition).isAir() && this.level.getBlockState(blockposition.below()).isSolidRender()) {
|
|
- this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition));
|
|
+ // CraftBukkit start - Ignition by explosion
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.level, blockposition, this).isCancelled()) {
|
|
+ this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void explode() {
|
|
+ // CraftBukkit start
|
|
+ if (this.radius < 0.1F) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, this.center);
|
|
List<BlockPosition> list = this.calculateExplodedPositions();
|
|
|
|
@@ -263,7 +348,15 @@
|
|
gameprofilerfiller.push("explosion_blocks");
|
|
this.interactWithBlocks(list);
|
|
gameprofilerfiller.pop();
|
|
+ // CraftBukkit start - handle KEEP effect
|
|
+ } else {
|
|
+ SystemUtils.shuffle(list, this.level.random); // CraftBukkit - Copy from calculateExplodedPositions
|
|
+ List<org.bukkit.block.Block> bukkitBlocks = CraftEventFactory.handleExplodeEvent(this, list);
|
|
+
|
|
+ list.clear();
|
|
+ list.addAll(bukkitBlocks.stream().map(bblock -> new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ())).toList());
|
|
}
|
|
+ // CraftBukkit end
|
|
|
|
if (this.fire) {
|
|
this.createFire(list);
|
|
@@ -272,6 +365,7 @@
|
|
}
|
|
|
|
private static void addOrAppendStack(List<ServerExplosion.a> list, ItemStack itemstack, BlockPosition blockposition) {
|
|
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425
|
|
for (ServerExplosion.a serverexplosion_a : list) {
|
|
serverexplosion_a.tryMerge(itemstack);
|
|
if (itemstack.isEmpty()) {
|