2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/level/Explosion.java
|
|
|
|
+++ b/net/minecraft/world/level/Explosion.java
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -42,6 +42,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-01-03 18:07:01 +01:00
|
|
|
@@ -60,6 +69,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
private final ExplosionDamageCalculator damageCalculator;
|
|
|
|
private final List<BlockPosition> toBlow;
|
|
|
|
private final Map<EntityHuman, Vec3D> hitPlayers;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public boolean wasCanceled = false; // CraftBukkit - add field
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
public Explosion(World world, @Nullable Entity entity, double d0, double d1, double d2, float f) {
|
|
|
|
this(world, entity, d0, d1, d2, f, false, Explosion.Effect.DESTROY);
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -84,7 +94,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-01-03 18:07:01 +01:00
|
|
|
@@ -134,6 +144,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
|
2021-11-21 23:00:00 +01:00
|
|
|
this.level.gameEvent(this.source, GameEvent.EXPLODE, new BlockPosition(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;
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -217,7 +232,35 @@
|
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
|
2014-11-25 22:32:16 +01:00
|
|
|
+ CraftEventFactory.entityDamage = source;
|
2022-01-03 18:07:01 +01:00
|
|
|
+ entity.lastDamageCancelled = false;
|
|
|
|
+
|
|
|
|
+ // 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (entity instanceof EntityEnderDragon) {
|
|
|
|
+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) {
|
|
|
|
+ if (list.contains(entityComplexPart)) {
|
|
|
|
+ entityComplexPart.hurt(this.getDamageSource(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } 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
|
2016-11-17 02:41:03 +01:00
|
|
|
double d14 = d13;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
if (entity instanceof EntityLiving) {
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -259,6 +302,51 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
Collections.shuffle(this.toBlow, this.level.random);
|
|
|
|
Iterator iterator = 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
|
|
|
+
|
|
|
|
+ List<org.bukkit.block.Block> blockList = Lists.newArrayList();
|
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) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ EntityExplodeEvent event = new EntityExplodeEvent(explode, location, blockList, this.blockInteraction == Explosion.Effect.DESTROY ? 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 {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.blockInteraction == Explosion.Effect.DESTROY ? 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
|
2021-06-11 07:00:00 +02:00
|
|
|
+ iterator = this.toBlow.iterator();
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
2019-12-10 23:00:00 +01:00
|
|
|
BlockPosition blockposition = (BlockPosition) iterator.next();
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -273,8 +361,8 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
TileEntity tileentity = iblockdata.hasBlockEntity() ? this.level.getBlockEntity(blockposition) : null;
|
|
|
|
LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer) this.level)).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
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
- if (this.blockInteraction == Explosion.Effect.DESTROY) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- loottableinfo_builder.withParameter(LootContextParameters.EXPLOSION_RADIUS, this.radius);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.blockInteraction == Explosion.Effect.DESTROY || yield < 1.0F) { // CraftBukkit - add yield
|
2021-11-21 23:00:00 +01:00
|
|
|
+ loottableinfo_builder.withParameter(LootContextParameters.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
iblockdata.getDrops(loottableinfo_builder).forEach((itemstack) -> {
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -304,7 +392,11 @@
|
2019-12-10 23:00:00 +01:00
|
|
|
BlockPosition blockposition2 = (BlockPosition) iterator1.next();
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 18:07:01 +01:00
|
|
|
@@ -312,6 +404,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) {
|