Skip to content

Commit

Permalink
Fixed #114
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Aug 13, 2023
1 parent fec175c commit e3cb49f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ protected MixinMinecartTNT(EntityType<?> entityType, Level level) {
ci.cancel();
return null;
}
return level.explode((MinecartTNT) (Object) this, x, y, z, event.getRadius(), event.getFire(), interaction);
return level.explode(entity, source, calculator, x, y, z, event.getRadius(), event.getFire(), interaction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,49 @@ public void finalizeExplosion(boolean spawnParticles) {
boolean flag2 = this.getIndirectSourceEntity() instanceof Player;
Util.shuffle(this.toBlow, this.level.random);

float yield = this.callBlockExplodeEvent();
// CraftBukkit start
org.bukkit.World bworld = this.level.getWorld();
org.bukkit.entity.Entity explode = this.source == null ? null : this.source.getBukkitEntity();
Location location = new Location(bworld, this.x, this.y, this.z);

List<org.bukkit.block.Block> blockList = new ObjectArrayList<>();
for (int i1 = this.toBlow.size() - 1; i1 >= 0; i1--) {
BlockPos cpos = this.toBlow.get(i1);
org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ());
if (!bblock.getType().isAir()) {
blockList.add(bblock);
}
}

boolean cancelled;
List<org.bukkit.block.Block> bukkitBlocks;
float yield;

if (explode != null) {
EntityExplodeEvent event = new EntityExplodeEvent(explode, location, blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
this.level.getCraftServer().getPluginManager().callEvent(event);
cancelled = event.isCancelled();
bukkitBlocks = event.blockList();
yield = event.getYield();
} else {
BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
this.level.getCraftServer().getPluginManager().callEvent(event);
cancelled = event.isCancelled();
bukkitBlocks = event.blockList();
yield = event.getYield();
}

if (Float.isNaN(yield)) {
this.toBlow.clear();
for (org.bukkit.block.Block bblock : bukkitBlocks) {
BlockPos coords = new BlockPos(bblock.getX(), bblock.getY(), bblock.getZ());
toBlow.add(coords);
}

if (cancelled) {
this.wasCanceled = true;
return;
}
// CraftBukkit end

for (BlockPos blockpos : this.toBlow) {
BlockState blockstate = this.level.getBlockState(blockpos);
Expand All @@ -270,23 +307,20 @@ public void finalizeExplosion(boolean spawnParticles) {
if (!blockstate.isAir()) {
BlockPos blockpos1 = blockpos.immutable();
this.level.getProfiler().push("explosion_blocks");
if (block.dropFromExplosion(((Explosion) (Object) this))) {
Level var11 = this.level;
if (var11 instanceof ServerLevel serverLevel) {
BlockEntity blockEntity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder builder = (new LootParams.Builder(serverLevel)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (yield < 1.0F) { // CraftBukkit - add yield
builder.withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
}

blockstate.spawnAfterBreak(serverLevel, blockpos, ItemStack.EMPTY, flag2);
blockstate.getDrops(builder).forEach((itemStack) -> {
addBlockDrops(objectarraylist, itemStack, blockpos1);
});
if (block.dropFromExplosion(((Explosion) (Object) this))&& this.level instanceof ServerLevel serverLevel) {
BlockEntity blockEntity = blockstate.hasBlockEntity() ? this.level.getBlockEntity(blockpos) : null;
LootParams.Builder builder = (new LootParams.Builder(serverLevel)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source);
if (yield < 1.0F) { // CraftBukkit - add yield
builder.withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0F / yield); // CraftBukkit - add yield
}

blockstate.spawnAfterBreak(serverLevel, blockpos, ItemStack.EMPTY, flag2);
blockstate.getDrops(builder).forEach((itemStack) -> {
addBlockDrops(objectarraylist, itemStack, blockpos1);
});

}

this.level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
block.wasExploded(this.level, blockpos, ((Explosion) (Object) this));
this.level.getProfiler().pop();
}
Expand All @@ -309,46 +343,6 @@ public void finalizeExplosion(boolean spawnParticles) {
}
}

private float callBlockExplodeEvent() {
org.bukkit.World world = this.level.getWorld();
org.bukkit.entity.Entity exploder = this.source == null ? null : this.source.getBukkitEntity();
Location location = new Location(world, this.x, this.y, this.z);
List<org.bukkit.block.Block> blockList = Lists.newArrayList();
for (int i = this.toBlow.size() - 1; i >= 0; i--) {
BlockPos blockPos = this.toBlow.get(i);
org.bukkit.block.Block block = world.getBlockAt(blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (!block.getType().isAir()) {
blockList.add(block);
}
}

boolean cancelled;
List<org.bukkit.block.Block> bukkitBlocks;
float bukkitYield;

if (exploder != null) {
EntityExplodeEvent event = new EntityExplodeEvent(exploder, location, blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
Bukkit.getPluginManager().callEvent(event);
cancelled = event.isCancelled();
bukkitBlocks = event.blockList();
bukkitYield = event.getYield();
} else {
BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F);
Bukkit.getPluginManager().callEvent(event);
cancelled = event.isCancelled();
bukkitBlocks = event.blockList();
bukkitYield = event.getYield();
}

this.toBlow.clear();

for (org.bukkit.block.Block block : bukkitBlocks) {
BlockPos blockPos = new BlockPos(block.getX(), block.getY(), block.getZ());
this.toBlow.add(blockPos);
}
return cancelled ? Float.NaN : bukkitYield;
}

@Override
public boolean bridge$wasCanceled() {
return wasCanceled;
Expand Down

0 comments on commit e3cb49f

Please sign in to comment.