3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-28 00:50:08 +01:00
Paper/nms-patches/Explosion.patch

154 Zeilen
7.7 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/Explosion.java
+++ b/net/minecraft/server/Explosion.java
2020-06-25 02:00:00 +02:00
@@ -15,6 +15,13 @@
2018-12-25 22:00:00 +01:00
import java.util.Set;
2016-11-17 02:41:03 +01:00
import javax.annotation.Nullable;
2015-02-26 23:41:06 +01:00
+// CraftBukkit start
+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;
+// CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public class Explosion {
2015-02-26 23:41:06 +01:00
private final boolean a;
2020-06-25 02:00:00 +02:00
@@ -31,11 +38,12 @@
private final ExplosionDamageCalculator k;
2015-02-26 23:41:06 +01:00
private final List<BlockPosition> blocks = Lists.newArrayList();
2020-06-25 02:00:00 +02:00
private final Map<EntityHuman, Vec3D> m = Maps.newHashMap();
+ public boolean wasCanceled = false; // CraftBukkit - add field
2020-06-25 02:00:00 +02:00
public Explosion(World world, @Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, 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;
2020-06-25 02:00:00 +02:00
@@ -85,6 +93,11 @@
}
public void a() {
+ // CraftBukkit start
+ if (this.size < 0.1F) {
+ return;
+ }
+ // CraftBukkit end
2018-12-25 22:00:00 +01:00
Set<BlockPosition> set = Sets.newHashSet();
boolean flag = true;
2020-06-25 02:00:00 +02:00
@@ -118,7 +131,7 @@
f -= ((Float) optional.get() + 0.3F) * 0.3F;
}
2020-06-25 02:00:00 +02:00
- if (f > 0.0F && this.k.a(this, this.world, blockposition, iblockdata, f)) {
+ if (f > 0.0F && this.k.a(this, this.world, blockposition, iblockdata, f) && blockposition.getY() < 256 && blockposition.getY() >= 0) { // CraftBukkit - don't wrap explosions
2018-12-25 22:00:00 +01:00
set.add(blockposition);
}
2020-06-25 02:00:00 +02:00
@@ -162,7 +175,16 @@
2019-04-23 04:00:00 +02:00
double d12 = (double) a(vec3d, entity);
double d13 = (1.0D - d7) * d12;
2020-06-25 02:00:00 +02:00
- entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ // entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
+ CraftEventFactory.entityDamage = source;
+ entity.forceExplosionKnockback = false;
2020-06-25 02:00:00 +02:00
+ boolean wasDamaged = entity.damageEntity(this.b(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
+ CraftEventFactory.entityDamage = null;
+ if (!wasDamaged && !(entity instanceof EntityTNTPrimed || entity instanceof EntityFallingBlock) && !entity.forceExplosionKnockback) {
+ continue;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
double d14 = d13;
2016-02-29 22:32:46 +01:00
if (entity instanceof EntityLiving) {
2020-06-25 02:00:00 +02:00
@@ -204,6 +226,51 @@
2019-12-10 23:00:00 +01:00
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().isAir()) {
+ blockList.add(bblock);
+ }
+ }
+
2015-03-22 20:42:46 +01:00
+ 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);
2015-03-22 20:42:46 +01:00
+ 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);
2015-03-22 20:42:46 +01:00
+ this.world.getServer().getPluginManager().callEvent(event);
+ cancelled = event.isCancelled();
+ bukkitBlocks = event.blockList();
+ yield = event.getYield();
+ }
+
+ this.blocks.clear();
+
2015-03-22 20:42:46 +01:00
+ for (org.bukkit.block.Block bblock : bukkitBlocks) {
+ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ());
+ blocks.add(coords);
+ }
+
2015-03-22 20:42:46 +01:00
+ if (cancelled) {
+ this.wasCanceled = true;
+ return;
+ }
+ // CraftBukkit end
2019-12-10 23:00:00 +01:00
+ iterator = this.blocks.iterator();
while (iterator.hasNext()) {
2019-12-10 23:00:00 +01:00
BlockPosition blockposition = (BlockPosition) iterator.next();
2020-06-25 02:00:00 +02:00
@@ -218,8 +285,8 @@
TileEntity tileentity = block.isTileEntity() ? this.world.getTileEntity(blockposition) : null;
2020-06-25 02:00:00 +02:00
LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer) this.world)).a(this.world.random).set(LootContextParameters.POSITION, blockposition).set(LootContextParameters.TOOL, ItemStack.b).setOptional(LootContextParameters.BLOCK_ENTITY, tileentity).setOptional(LootContextParameters.THIS_ENTITY, this.source);
- if (this.b == Explosion.Effect.DESTROY) {
2019-04-23 04:00:00 +02:00
- loottableinfo_builder.set(LootContextParameters.EXPLOSION_RADIUS, this.size);
+ if (this.b == Explosion.Effect.DESTROY || yield < 1.0F) { // CraftBukkit - add yield
2019-04-23 04:00:00 +02:00
+ loottableinfo_builder.set(LootContextParameters.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
}
2019-12-10 23:00:00 +01:00
iblockdata.a(loottableinfo_builder).forEach((itemstack) -> {
2020-06-25 02:00:00 +02:00
@@ -249,7 +316,11 @@
2019-12-10 23:00:00 +01:00
BlockPosition blockposition2 = (BlockPosition) iterator1.next();
2020-06-25 02:00:00 +02:00
if (this.c.nextInt(3) == 0 && this.world.getType(blockposition2).isAir() && this.world.getType(blockposition2.down()).i(this.world, blockposition2.down())) {
- this.world.setTypeUpdate(blockposition2, BlockFireAbstract.a((IBlockAccess) this.world, blockposition2));
+ // CraftBukkit start - Ignition by explosion
2019-12-10 23:00:00 +01:00
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.world, blockposition2.getX(), blockposition2.getY(), blockposition2.getZ(), this).isCancelled()) {
2020-06-25 02:00:00 +02:00
+ this.world.setTypeUpdate(blockposition2, BlockFireAbstract.a((IBlockAccess) this.world, blockposition2));
+ }
+ // CraftBukkit end
}
}
}
2020-06-25 02:00:00 +02:00
@@ -257,6 +328,7 @@
}
private static void a(ObjectArrayList<Pair<ItemStack, BlockPosition>> objectarraylist, ItemStack itemstack, BlockPosition blockposition) {
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425
int i = objectarraylist.size();
for (int j = 0; j < i; ++j) {