Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Explosive pickaxe not properly dropping blocks #4062

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ public void onBlockBreak(BlockBreakEvent e) {
}

ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
SlimefunItem sfItem = BlockStorage.check(e.getBlock());
Block block = e.getBlock();
SlimefunItem sfBlock = BlockStorage.check(block);

// If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event and return
if (sfItem != null) {
SlimefunBlockBreakEvent breakEvent = new SlimefunBlockBreakEvent(e.getPlayer(), item, e.getBlock(), sfItem);
if (sfBlock != null) {
SlimefunBlockBreakEvent breakEvent = new SlimefunBlockBreakEvent(e.getPlayer(), item, e.getBlock(), sfBlock);
Bukkit.getPluginManager().callEvent(breakEvent);

if (breakEvent.isCancelled()) {
Expand All @@ -175,9 +176,9 @@ public void onBlockBreak(BlockBreakEvent e) {
// TODO: merge this with the vanilla sensitive block check (when 1.18- is dropped)
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), item);

callBlockHandler(e, item, drops, sfItem);
callBlockHandler(e, item, drops, sfBlock);

dropItems(e, drops);
dropItems(e, item, block, sfBlock, drops);

// Checks for vanilla sensitive blocks everywhere
// checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
Expand Down Expand Up @@ -237,24 +238,30 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack>
}

@ParametersAreNonnullByDefault
private void dropItems(BlockBreakEvent e, List<ItemStack> drops) {
private void dropItems(BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List<ItemStack> drops) {
if (!drops.isEmpty()) {
// TODO: properly support loading inventories within unit tests
if (!Slimefun.instance().isUnitTest()) {
// Notify plugins like CoreProtect
Slimefun.getProtectionManager().logAction(e.getPlayer(), e.getBlock(), Interaction.BREAK_BLOCK);
Slimefun.getProtectionManager().logAction(e.getPlayer(), block, Interaction.BREAK_BLOCK);
}

// Fixes #2560
if (e.isDropItems()) {
// Disable normal block drops
e.setDropItems(false);

// Fixes #4051
if (sfBlock == null) {
block.breakNaturally(item);
Comment on lines +254 to +256
Copy link

@mcchampions mcchampions Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call Block#breakNaturally will drop drops, it will cause many bugs(double drops,drops that should disappear fall normally)

}

// The list only contains other drops, not those from the block itself, so we still need to handle those
for (ItemStack drop : drops) {
// Prevent null or air from being dropped
if (drop != null && drop.getType() != Material.AIR) {
if (e.getPlayer().getGameMode() != GameMode.CREATIVE || Slimefun.getCfg().getBoolean("options.drop-block-creative")) {
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
block.getWorld().dropItemNaturally(block.getLocation(), drop);
}
}
}
Expand Down
Loading