diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 12937e45a4..a09cc7a72e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -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()) { @@ -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()); @@ -237,12 +238,12 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List } @ParametersAreNonnullByDefault - private void dropItems(BlockBreakEvent e, List drops) { + private void dropItems(BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List 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 @@ -250,11 +251,17 @@ private void dropItems(BlockBreakEvent e, List drops) { // Disable normal block drops e.setDropItems(false); + // Fixes #4051 + if (sfBlock == null) { + block.breakNaturally(item); + } + + // 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); } } }