PaperMC/nms-patches/Explosion.patch
2019-12-11 09:00:00 +11:00

145 lines
7.2 KiB
Diff

--- a/net/minecraft/server/Explosion.java
+++ b/net/minecraft/server/Explosion.java
@@ -14,6 +14,13 @@
import java.util.Set;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.Location;
+import org.bukkit.event.block.BlockExplodeEvent;
+// CraftBukkit end
+
public class Explosion {
private final boolean a;
@@ -29,11 +36,12 @@
private DamageSource j;
private final List<BlockPosition> blocks = Lists.newArrayList();
private final Map<EntityHuman, Vec3D> l = Maps.newHashMap();
+ public boolean wasCanceled = false; // CraftBukkit - add field
public Explosion(World world, @Nullable Entity entity, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
this.world = world;
this.source = entity;
- this.size = f;
+ this.size = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values
this.posX = d0;
this.posY = d1;
this.posZ = d2;
@@ -78,6 +86,11 @@
}
public void a() {
+ // CraftBukkit start
+ if (this.size < 0.1F) {
+ return;
+ }
+ // CraftBukkit end
Set<BlockPosition> set = Sets.newHashSet();
boolean flag = true;
@@ -116,7 +129,7 @@
f -= (f2 + 0.3F) * 0.3F;
}
- if (f > 0.0F && (this.source == null || this.source.a(this, this.world, blockposition, iblockdata, f))) {
+ if (f > 0.0F && (this.source == null || this.source.a(this, this.world, blockposition, iblockdata, f)) && blockposition.getY() < 256 && blockposition.getY() >= 0) { // CraftBukkit - don't wrap explosions
set.add(blockposition);
}
@@ -160,7 +173,16 @@
double d12 = (double) a(vec3d, entity);
double d13 = (1.0D - d7) * d12;
- entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f3 + 1.0D)));
+ // CraftBukkit start
+ // entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f3 + 1.0D)));
+ CraftEventFactory.entityDamage = source;
+ entity.forceExplosionKnockback = false;
+ boolean wasDamaged = entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f3 + 1.0D)));
+ CraftEventFactory.entityDamage = null;
+ if (!wasDamaged && !(entity instanceof EntityTNTPrimed || entity instanceof EntityFallingBlock) && !entity.forceExplosionKnockback) {
+ continue;
+ }
+ // CraftBukkit end
double d14 = d13;
if (entity instanceof EntityLiving) {
@@ -202,6 +224,51 @@
Collections.shuffle(this.blocks, this.world.random);
Iterator iterator = this.blocks.iterator();
+ // CraftBukkit start
+ org.bukkit.World bworld = this.world.getWorld();
+ org.bukkit.entity.Entity explode = this.source == null ? null : this.source.getBukkitEntity();
+ Location location = new Location(bworld, this.posX, this.posY, this.posZ);
+
+ List<org.bukkit.block.Block> blockList = Lists.newArrayList();
+ for (int i1 = this.blocks.size() - 1; i1 >= 0; i1--) {
+ BlockPosition cpos = (BlockPosition) this.blocks.get(i1);
+ org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ());
+ if (bblock.getType() != org.bukkit.Material.AIR) {
+ blockList.add(bblock);
+ }
+ }
+
+ boolean cancelled;
+ List<org.bukkit.block.Block> bukkitBlocks;
+ float yield;
+
+ if (explode != null) {
+ EntityExplodeEvent event = new EntityExplodeEvent(explode, location, blockList, this.b == Explosion.Effect.DESTROY ? 1.0F / this.size : 1.0F);
+ this.world.getServer().getPluginManager().callEvent(event);
+ cancelled = event.isCancelled();
+ bukkitBlocks = event.blockList();
+ yield = event.getYield();
+ } else {
+ BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.b == Explosion.Effect.DESTROY ? 1.0F / this.size : 1.0F);
+ this.world.getServer().getPluginManager().callEvent(event);
+ cancelled = event.isCancelled();
+ bukkitBlocks = event.blockList();
+ yield = event.getYield();
+ }
+
+ this.blocks.clear();
+
+ for (org.bukkit.block.Block bblock : bukkitBlocks) {
+ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ());
+ blocks.add(coords);
+ }
+
+ if (cancelled) {
+ this.wasCanceled = true;
+ return;
+ }
+ // CraftBukkit end
+ iterator = this.blocks.iterator();
while (iterator.hasNext()) {
BlockPosition blockposition = (BlockPosition) iterator.next();
@@ -216,8 +283,8 @@
TileEntity tileentity = block.isTileEntity() ? this.world.getTileEntity(blockposition) : null;
LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer) this.world)).a(this.world.random).set(LootContextParameters.POSITION, blockposition).set(LootContextParameters.TOOL, ItemStack.a).setOptional(LootContextParameters.BLOCK_ENTITY, tileentity).setOptional(LootContextParameters.THIS_ENTITY, this.source);
- if (this.b == Explosion.Effect.DESTROY) {
- loottableinfo_builder.set(LootContextParameters.EXPLOSION_RADIUS, this.size);
+ if (this.b == Explosion.Effect.DESTROY || yield < 1.0F) { // CraftBukkit - add yield
+ loottableinfo_builder.set(LootContextParameters.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
}
iblockdata.a(loottableinfo_builder).forEach((itemstack) -> {
@@ -247,7 +314,11 @@
BlockPosition blockposition2 = (BlockPosition) iterator1.next();
if (this.c.nextInt(3) == 0 && this.world.getType(blockposition2).isAir() && this.world.getType(blockposition2.down()).g(this.world, blockposition2.down())) {
- this.world.setTypeUpdate(blockposition2, Blocks.FIRE.getBlockData());
+ // CraftBukkit start - Ignition by explosion
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.world, blockposition2.getX(), blockposition2.getY(), blockposition2.getZ(), this).isCancelled()) {
+ this.world.setTypeUpdate(blockposition2, Blocks.FIRE.getBlockData());
+ }
+ // CraftBukkit end
}
}
}