2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/level/Explosion.java
|
|
|
|
+++ b/net/minecraft/world/level/Explosion.java
|
2022-06-07 18:00:00 +02:00
|
|
|
@@ -40,6 +40,15 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit start
|
2022-01-03 18:07:01 +01:00
|
|
|
+import net.minecraft.world.entity.boss.EntityComplexPart;
|
|
|
|
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
+import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
+import org.bukkit.Location;
|
2015-03-22 20:42:46 +01:00
|
|
|
+import org.bukkit.event.block.BlockExplodeEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
public class Explosion {
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
|
2022-06-07 18:00:00 +02:00
|
|
|
@@ -58,6 +67,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
private final ExplosionDamageCalculator damageCalculator;
|
2022-06-07 18:00:00 +02:00
|
|
|
private final ObjectArrayList<BlockPosition> toBlow;
|
2021-06-11 07:00:00 +02:00
|
|
|
private final Map<EntityHuman, Vec3D> hitPlayers;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public boolean wasCanceled = false; // CraftBukkit - add field
|
|
|
|
|
2022-12-07 17:00:00 +01:00
|
|
|
public Explosion(World world, @Nullable Entity entity, double d0, double d1, double d2, float f, List<BlockPosition> list) {
|
|
|
|
this(world, entity, d0, d1, d2, f, false, Explosion.Effect.DESTROY_WITH_DECAY, list);
|
|
|
|
@@ -78,7 +88,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
this.hitPlayers = Maps.newHashMap();
|
|
|
|
this.level = world;
|
2014-11-25 22:32:16 +01:00
|
|
|
this.source = entity;
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.radius = f;
|
|
|
|
+ this.radius = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values
|
|
|
|
this.x = d0;
|
|
|
|
this.y = d1;
|
|
|
|
this.z = d2;
|
2022-12-07 17:00:00 +01:00
|
|
|
@@ -128,6 +138,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
public void explode() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.radius < 0.1F) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2022-06-07 18:00:00 +02:00
|
|
|
this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z));
|
2018-12-25 22:00:00 +01:00
|
|
|
Set<BlockPosition> set = Sets.newHashSet();
|
2014-11-25 22:32:16 +01:00
|
|
|
boolean flag = true;
|
2023-02-27 10:34:19 +01:00
|
|
|
@@ -211,7 +226,39 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
double d12 = (double) getSeenPercent(vec3d, entity);
|
2014-11-25 22:32:16 +01:00
|
|
|
double d13 = (1.0D - d7) * d12;
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- entity.hurt(this.getDamageSource(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit start
|
2022-01-03 18:07:01 +01:00
|
|
|
+
|
|
|
|
+ // 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;
|
|
|
|
+ }
|
|
|
|
+
|
2022-12-29 04:06:51 +01:00
|
|
|
+ CraftEventFactory.entityDamage = source;
|
|
|
|
+ entity.lastDamageCancelled = false;
|
|
|
|
+
|
2022-01-03 18:07:01 +01:00
|
|
|
+ if (entity instanceof EntityEnderDragon) {
|
|
|
|
+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) {
|
2023-02-27 10:34:19 +01:00
|
|
|
+ // Calculate damage separately for each EntityComplexPart
|
|
|
|
+ double d7part;
|
|
|
|
+ if (list.contains(entityComplexPart) && (d7part = Math.sqrt(entityComplexPart.distanceToSqr(vec3d)) / f2) <= 1.0D) {
|
|
|
|
+ double d13part = (1.0D - d7part) * getSeenPercent(vec3d, entityComplexPart);
|
|
|
|
+ entityComplexPart.hurt(this.getDamageSource(), (float) ((int) ((d13part * d13part + d13part) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
2022-01-03 18:07:01 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ entity.hurt(this.getDamageSource(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ CraftEventFactory.entityDamage = null;
|
2022-01-03 18:07:01 +01:00
|
|
|
+ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
|
2015-01-25 00:45:02 +01:00
|
|
|
+ continue;
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2023-03-14 17:30:00 +01:00
|
|
|
double d14;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
if (entity instanceof EntityLiving) {
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -263,6 +310,51 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-06-07 18:00:00 +02:00
|
|
|
SystemUtils.shuffle(this.toBlow, this.level.random);
|
|
|
|
ObjectListIterator objectlistiterator = this.toBlow.iterator();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2021-06-11 07:00:00 +02:00
|
|
|
+ org.bukkit.World bworld = this.level.getWorld();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ org.bukkit.entity.Entity explode = this.source == null ? null : this.source.getBukkitEntity();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ Location location = new Location(bworld, this.x, this.y, this.z);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2022-06-07 18:00:00 +02:00
|
|
|
+ List<org.bukkit.block.Block> blockList = new ObjectArrayList<>();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ for (int i1 = this.toBlow.size() - 1; i1 >= 0; i1--) {
|
|
|
|
+ BlockPosition cpos = (BlockPosition) this.toBlow.get(i1);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ());
|
2020-01-27 00:09:46 +01:00
|
|
|
+ if (!bblock.getType().isAir()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ blockList.add(bblock);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2015-03-22 20:42:46 +01:00
|
|
|
+ boolean cancelled;
|
|
|
|
+ List<org.bukkit.block.Block> bukkitBlocks;
|
|
|
|
+ float yield;
|
|
|
|
+
|
|
|
|
+ if (explode != null) {
|
2023-03-04 01:47:05 +01:00
|
|
|
+ EntityExplodeEvent event = new EntityExplodeEvent(explode, location, blockList, this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(event);
|
2015-03-22 20:42:46 +01:00
|
|
|
+ cancelled = event.isCancelled();
|
|
|
|
+ bukkitBlocks = event.blockList();
|
|
|
|
+ yield = event.getYield();
|
|
|
|
+ } else {
|
2023-03-04 01:47:05 +01:00
|
|
|
+ BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(event);
|
2015-03-22 20:42:46 +01:00
|
|
|
+ cancelled = event.isCancelled();
|
|
|
|
+ bukkitBlocks = event.blockList();
|
|
|
|
+ yield = event.getYield();
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.toBlow.clear();
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2015-03-22 20:42:46 +01:00
|
|
|
+ for (org.bukkit.block.Block bblock : bukkitBlocks) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ());
|
2021-06-11 07:00:00 +02:00
|
|
|
+ toBlow.add(coords);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2015-03-22 20:42:46 +01:00
|
|
|
+ if (cancelled) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.wasCanceled = true;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2022-06-07 18:00:00 +02:00
|
|
|
+ objectlistiterator = this.toBlow.iterator();
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-06-07 18:00:00 +02:00
|
|
|
while (objectlistiterator.hasNext()) {
|
|
|
|
BlockPosition blockposition = (BlockPosition) objectlistiterator.next();
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -281,8 +373,8 @@
|
2022-06-07 18:00:00 +02:00
|
|
|
TileEntity tileentity = iblockdata.hasBlockEntity() ? this.level.getBlockEntity(blockposition) : null;
|
|
|
|
LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder(worldserver)).withRandom(this.level.random).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParameters.THIS_ENTITY, this.source);
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-12-07 17:00:00 +01:00
|
|
|
- if (this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY) {
|
2022-06-07 18:00:00 +02:00
|
|
|
- loottableinfo_builder.withParameter(LootContextParameters.EXPLOSION_RADIUS, this.radius);
|
2023-03-04 01:47:05 +01:00
|
|
|
+ if (yield < 1.0F) { // CraftBukkit - add yield
|
2022-06-07 18:00:00 +02:00
|
|
|
+ loottableinfo_builder.withParameter(LootContextParameters.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
|
|
|
|
}
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-06-07 18:00:00 +02:00
|
|
|
iblockdata.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, flag2);
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -314,7 +406,11 @@
|
2022-06-07 18:00:00 +02:00
|
|
|
BlockPosition blockposition2 = (BlockPosition) objectlistiterator1.next();
|
2019-12-10 23:00:00 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition2).isAir() && this.level.getBlockState(blockposition2.below()).isSolidRender(this.level, blockposition2.below())) {
|
|
|
|
- this.level.setBlockAndUpdate(blockposition2, BlockFireAbstract.getState(this.level, blockposition2));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Ignition by explosion
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.level, blockposition2.getX(), blockposition2.getY(), blockposition2.getZ(), this).isCancelled()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.setBlockAndUpdate(blockposition2, BlockFireAbstract.getState(this.level, blockposition2));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -326,6 +422,7 @@
|
2019-12-13 04:06:25 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPosition>> objectarraylist, ItemStack itemstack, BlockPosition blockposition) {
|
2019-12-13 04:06:25 +01:00
|
|
|
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425
|
|
|
|
int i = objectarraylist.size();
|
|
|
|
|
|
|
|
for (int j = 0; j < i; ++j) {
|