mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 04:32:11 -07:00
Allow forcing break effects when using breakNaturally (#12734)
This commit is contained in:
@@ -499,6 +499,11 @@ public class CraftBlock implements Block {
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) {
|
||||
return this.breakNaturally(item, triggerEffect, dropExperience, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience, boolean forceEffect) {
|
||||
// Paper end
|
||||
// Order matters here, need to drop before setting to air so skulls can get their data
|
||||
net.minecraft.world.level.block.state.BlockState state = this.getNMS();
|
||||
@@ -510,18 +515,19 @@ public class CraftBlock implements Block {
|
||||
if (block != Blocks.AIR && (item == null || !state.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(state))) {
|
||||
net.minecraft.world.level.block.Block.dropResources(state, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); // Paper - Properly handle xp dropping
|
||||
// Paper start - improve Block#breakNaturally
|
||||
if (triggerEffect) {
|
||||
if (state.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {
|
||||
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.SOUND_EXTINGUISH_FIRE, this.position, 0);
|
||||
} else {
|
||||
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK, this.position, net.minecraft.world.level.block.Block.getId(state));
|
||||
}
|
||||
}
|
||||
if (dropExperience) block.popExperience(this.world.getMinecraftWorld(), this.position, block.getExpDrop(state, this.world.getMinecraftWorld(), this.position, nmsItem, true));
|
||||
// Paper end
|
||||
result = true;
|
||||
}
|
||||
|
||||
if ((result && triggerEffect) || (forceEffect && block != Blocks.AIR)) {
|
||||
if (state.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {
|
||||
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.SOUND_EXTINGUISH_FIRE, this.position, 0);
|
||||
} else {
|
||||
this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK, this.position, net.minecraft.world.level.block.Block.getId(state));
|
||||
}
|
||||
}
|
||||
|
||||
// SPIGOT-6778: Directly call setBlock instead of setBlockState, so that the block entity is not removed and custom remove logic is run.
|
||||
// Paper start - improve breakNaturally
|
||||
boolean destroyed = this.world.removeBlock(this.position, false);
|
||||
|
Reference in New Issue
Block a user