From 051c51915e26de4f01961bfc180c5e37c40cda7d Mon Sep 17 00:00:00 2001 From: iTwins Date: Thu, 7 Sep 2023 05:33:42 +0200 Subject: [PATCH 01/13] fix sensitive blocks attached to sf blocks not dropping (1.19+) --- .../listeners/BlockListener.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) 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 30593427ee..75a9cdba8c 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 @@ -14,6 +14,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -25,6 +26,7 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.bakedlibs.dough.protection.Interaction; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent; @@ -53,6 +55,8 @@ */ public class BlockListener implements Listener { + private static final BlockFace[] CARDINAL_BLOCKFACES = new BlockFace[]{BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP}; + public BlockListener(@Nonnull Slimefun plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } @@ -152,6 +156,9 @@ public void onBlockBreak(BlockBreakEvent e) { } callBlockHandler(e, item, drops, sfItem); + + checkForSensitiveBlocks(e.getBlock(), 0); + dropItems(e, drops); } } @@ -222,6 +229,52 @@ private void dropItems(BlockBreakEvent e, List drops) { } } + /** + * This method checks recursively for any sensitive blocks + * that are no longer supported due to this block breaking + * + * @param block + * The {@link Block} in question + * @param c + * The amount of times this has been recursively called + */ + @ParametersAreNonnullByDefault + private void checkForSensitiveBlocks(Block block, Integer c) { + if (c >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { + return; + } + for (BlockFace face : CARDINAL_BLOCKFACES) { + block.setType(Material.AIR, false); + if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) { + Block relative = block.getRelative(face); + for (ItemStack drop : relative.getDrops()) { + block.getWorld().dropItemNaturally(relative.getLocation(), drop); + } + checkForSensitiveBlocks(relative, ++c); + } + } + } + + /** + * This method checks if the {@link BlockData} would be + * supported at the given {@link Block}. + * + * @param blockData + * The {@link BlockData} to check + * @param block + * The {@link Block} the {@link BlockData} would be at + * @return + * Whether the {@link BlockData} would be supported at the given {@link Block} + */ + private boolean isSupported(BlockData blockData, Block block) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { + return blockData.isSupported(block); + } else { + // TODO: Make 1.16-1.18 version. BlockData::isSupported is 1.19+. + return true; + } + } + /** * This method checks for a sensitive {@link Block}. * Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken From 9c5114f9c274899923807b946a34f402895cfc45 Mon Sep 17 00:00:00 2001 From: iTwins Date: Thu, 7 Sep 2023 05:41:25 +0200 Subject: [PATCH 02/13] annotation --- .../slimefun4/implementation/listeners/BlockListener.java | 1 + 1 file changed, 1 insertion(+) 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 75a9cdba8c..b919ac0980 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 @@ -266,6 +266,7 @@ private void checkForSensitiveBlocks(Block block, Integer c) { * @return * Whether the {@link BlockData} would be supported at the given {@link Block} */ + @ParametersAreNonnullByDefault private boolean isSupported(BlockData blockData, Block block) { if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { return blockData.isSupported(block); From d4b6c0aac8d510fcc1bab2f19f877ce95c371822 Mon Sep 17 00:00:00 2001 From: iTwins Date: Sat, 9 Sep 2023 16:46:14 +0200 Subject: [PATCH 03/13] renamed c to count --- .../slimefun4/implementation/listeners/BlockListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 b919ac0980..46152d988e 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 @@ -235,12 +235,12 @@ private void dropItems(BlockBreakEvent e, List drops) { * * @param block * The {@link Block} in question - * @param c + * @param count * The amount of times this has been recursively called */ @ParametersAreNonnullByDefault - private void checkForSensitiveBlocks(Block block, Integer c) { - if (c >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { + private void checkForSensitiveBlocks(Block block, Integer count) { + if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { return; } for (BlockFace face : CARDINAL_BLOCKFACES) { @@ -250,7 +250,7 @@ private void checkForSensitiveBlocks(Block block, Integer c) { for (ItemStack drop : relative.getDrops()) { block.getWorld().dropItemNaturally(relative.getLocation(), drop); } - checkForSensitiveBlocks(relative, ++c); + checkForSensitiveBlocks(relative, ++count); } } } From e261bbebe9e9e2f6b1cad358698b2e5df2eced46 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:39:49 -0600 Subject: [PATCH 04/13] Strip search term --- .../slimefun4/implementation/guide/SurvivalSlimefunGuide.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index 2e86296008..b9d0b70b9a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -350,7 +350,7 @@ public void openSearch(PlayerProfile profile, String input, boolean addToHistory } ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.search.inventory").replace("%item%", ChatUtils.crop(ChatColor.WHITE, input))); - String searchTerm = input.toLowerCase(Locale.ROOT); + String searchTerm = ChatColor.strip(input.toLowerCase(Locale.ROOT)); if (addToHistory) { profile.getGuideHistory().add(searchTerm); From d0963697ca682f58411ffecbd0ab787834dcf85c Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:48:45 -0600 Subject: [PATCH 05/13] use proper method name --- .../slimefun4/implementation/guide/SurvivalSlimefunGuide.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index b9d0b70b9a..621431efc1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -350,7 +350,7 @@ public void openSearch(PlayerProfile profile, String input, boolean addToHistory } ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.search.inventory").replace("%item%", ChatUtils.crop(ChatColor.WHITE, input))); - String searchTerm = ChatColor.strip(input.toLowerCase(Locale.ROOT)); + String searchTerm = ChatColor.stripColor(input.toLowerCase(Locale.ROOT)); if (addToHistory) { profile.getGuideHistory().add(searchTerm); From e83c9f704e8ca78756aa0ef1bb32457ef0dbc54e Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:48:57 -0600 Subject: [PATCH 06/13] Add test for both normal and colored seearches --- .../core/guide/TestGuideOpening.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java index 8ed5d838b9..586800bec4 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java @@ -5,11 +5,14 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -90,8 +93,28 @@ void testOpenItemStack() throws InterruptedException { } @Test - @DisplayName("Test if the Slimefun Search can be opened from the History") + @DisplayName("Test if the Slimefun Search works with normal and colored querys") void testOpenSearch() throws InterruptedException { + String normalQuery = "iron"; + String coloredQuery = ChatColor.DARK_PURPLE + "iron"; + + SlimefunItem testItem = TestUtilities.mockSlimefunItem(plugin, "IRON_ITEM", new CustomItemStack(Material.IRON_INGOT, "iron item")); + testItem.register(plugin); + + Player player = server.addPlayer(); + PlayerProfile profile = TestUtilities.awaitProfile(player); + SlimefunGuideImplementation guide = new SurvivalSlimefunGuide(false, false); + + guide.openSearch(profile, normalQuery, false); + Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on normal query"); + + guide.openSearch(profile, coloredQuery, false); + Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on colored query"); + } + + @Test + @DisplayName("Test if the Slimefun Search can be opened from the History") + void testOpenSearchHistory() throws InterruptedException { String query = "electric"; SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class); From 82c8c91451306158a6211d7ce3375fe2cfc566ce Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:28:39 -0600 Subject: [PATCH 07/13] Suggestions and consistency --- .../core/guide/TestGuideOpening.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java index 586800bec4..a8685b9736 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/guide/TestGuideOpening.java @@ -93,10 +93,10 @@ void testOpenItemStack() throws InterruptedException { } @Test - @DisplayName("Test if the Slimefun Search works with normal and colored querys") - void testOpenSearch() throws InterruptedException { - String normalQuery = "iron"; - String coloredQuery = ChatColor.DARK_PURPLE + "iron"; + @DisplayName("Test if the Slimefun Search works with normal and colored terms") + void testOpenSearch_withColoredSearchTerm() throws InterruptedException { + String normalTerm = "iron"; + String coloredTerm = ChatColor.DARK_PURPLE + "iron"; SlimefunItem testItem = TestUtilities.mockSlimefunItem(plugin, "IRON_ITEM", new CustomItemStack(Material.IRON_INGOT, "iron item")); testItem.register(plugin); @@ -105,21 +105,23 @@ void testOpenSearch() throws InterruptedException { PlayerProfile profile = TestUtilities.awaitProfile(player); SlimefunGuideImplementation guide = new SurvivalSlimefunGuide(false, false); - guide.openSearch(profile, normalQuery, false); + guide.openSearch(profile, normalTerm, false); + // Assert we can open with a non-coloured search term Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on normal query"); - guide.openSearch(profile, coloredQuery, false); + guide.openSearch(profile, coloredTerm, false); + // Assert we can open with a coloured search term Assertions.assertTrue(player.getOpenInventory().getTopInventory().contains(testItem.getItem()), "Failed on colored query"); } @Test @DisplayName("Test if the Slimefun Search can be opened from the History") void testOpenSearchHistory() throws InterruptedException { - String query = "electric"; + String term = "electric"; SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class); - PlayerProfile profile = prepare(guide, history -> history.add(query)); - Mockito.verify(guide).openSearch(profile, query, false); + PlayerProfile profile = prepare(guide, history -> history.add(term)); + Mockito.verify(guide).openSearch(profile, term, false); } @Test From e1d230dcb6c799bc2060f0d70d9d1135f5d37d64 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:47:22 -0600 Subject: [PATCH 08/13] Patch hopefully --- .../slimefun4/implementation/listeners/BlockListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 967a6ad6d6..beb241f7ad 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 @@ -257,8 +257,9 @@ private void checkForSensitiveBlocks(Block block, Integer count) { if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { return; } + BlockData blockData = block.getBlockData(); + block.setType(Material.AIR, false); for (BlockFace face : CARDINAL_BLOCKFACES) { - block.setType(Material.AIR, false); if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) { Block relative = block.getRelative(face); for (ItemStack drop : relative.getDrops()) { @@ -267,6 +268,7 @@ private void checkForSensitiveBlocks(Block block, Integer count) { checkForSensitiveBlocks(relative, ++count); } } + block.setBlockData(blockData, false); } /** From d6516613700cdfe928087f7270367e27b895ac84 Mon Sep 17 00:00:00 2001 From: J3fftw <44972470+J3fftw1@users.noreply.github.com> Date: Sat, 9 Dec 2023 04:39:27 +0100 Subject: [PATCH 09/13] 1.19.3 support (#4039) --- .../resources/tags/block_placer_ignored_materials.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/resources/tags/block_placer_ignored_materials.json b/src/main/resources/tags/block_placer_ignored_materials.json index 3f9417b711..bc32030c7f 100644 --- a/src/main/resources/tags/block_placer_ignored_materials.json +++ b/src/main/resources/tags/block_placer_ignored_materials.json @@ -27,7 +27,6 @@ "minecraft:lily_pad", "minecraft:dead_bush", "minecraft:fern", - "minecraft:grass", "minecraft:sea_pickle", "minecraft:nether_wart", "minecraft:seagrass", @@ -35,6 +34,10 @@ "minecraft:kelp", "minecraft:bell", "minecraft:lantern", + { + "id" : "minecraft:grass", + "required" : false + }, { "id" : "minecraft:soul_lantern", "required" : false @@ -58,6 +61,10 @@ { "id" : "minecraft:weeping_vines", "required" : false + }, + { + "id" : "minecraft:short_grass", + "required" : false } ] } From d35798040cc5c3758e897c9d8a3e03c6dd1ab111 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Sat, 9 Dec 2023 09:03:54 -0600 Subject: [PATCH 10/13] Revert Sensitive Block Changes --- .../listeners/BlockListener.java | 53 ------------------- 1 file changed, 53 deletions(-) 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 beb241f7ad..f66140c3e7 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 @@ -14,7 +14,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -26,7 +25,6 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.bakedlibs.dough.protection.Interaction; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent; @@ -171,8 +169,6 @@ public void onBlockBreak(BlockBreakEvent e) { callBlockHandler(e, item, drops, sfItem); - checkForSensitiveBlocks(e.getBlock(), 0); - dropItems(e, drops); } } @@ -243,55 +239,6 @@ private void dropItems(BlockBreakEvent e, List drops) { } } - /** - * This method checks recursively for any sensitive blocks - * that are no longer supported due to this block breaking - * - * @param block - * The {@link Block} in question - * @param count - * The amount of times this has been recursively called - */ - @ParametersAreNonnullByDefault - private void checkForSensitiveBlocks(Block block, Integer count) { - if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { - return; - } - BlockData blockData = block.getBlockData(); - block.setType(Material.AIR, false); - for (BlockFace face : CARDINAL_BLOCKFACES) { - if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) { - Block relative = block.getRelative(face); - for (ItemStack drop : relative.getDrops()) { - block.getWorld().dropItemNaturally(relative.getLocation(), drop); - } - checkForSensitiveBlocks(relative, ++count); - } - } - block.setBlockData(blockData, false); - } - - /** - * This method checks if the {@link BlockData} would be - * supported at the given {@link Block}. - * - * @param blockData - * The {@link BlockData} to check - * @param block - * The {@link Block} the {@link BlockData} would be at - * @return - * Whether the {@link BlockData} would be supported at the given {@link Block} - */ - @ParametersAreNonnullByDefault - private boolean isSupported(BlockData blockData, Block block) { - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { - return blockData.isSupported(block); - } else { - // TODO: Make 1.16-1.18 version. BlockData::isSupported is 1.19+. - return true; - } - } - /** * This method checks for a sensitive {@link Block}. * Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken From 6a4b1fe794c8857433fae7f1cfa97a88734ee8f3 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sat, 9 Dec 2023 18:16:34 +0100 Subject: [PATCH 11/13] Fixed vanilla sensitive blocks --- .../listeners/BlockListener.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) 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 f66140c3e7..3526b4d11a 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 @@ -10,10 +10,13 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -170,6 +173,8 @@ public void onBlockBreak(BlockBreakEvent e) { callBlockHandler(e, item, drops, sfItem); dropItems(e, drops); + + checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); } } @@ -283,6 +288,59 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i } } + /** + * This method checks recursively for any sensitive blocks + * that are no longer supported due to this block breaking + * + * @param block + * The {@link Block} in question + * @param count + * The amount of times this has been recursively called + */ + @ParametersAreNonnullByDefault + private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropItems) { + if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) { + return; + } + + BlockState state = block.getState(); + block.setType(Material.AIR, false); + for (BlockFace face : CARDINAL_BLOCKFACES) { + if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) { + Block relative = block.getRelative(face); + if (!isDropItems) { + for (ItemStack drop : relative.getDrops()) { + block.getWorld().dropItemNaturally(relative.getLocation(), drop); + } + } + checkForSensitiveBlocks(relative, ++count, isDropItems); + } + } + block.setBlockData(state.getBlockData(), false); + state.update(true, false); + } + + /** + * This method checks if the {@link BlockData} would be + * supported at the given {@link Block}. + * + * @param blockData + * The {@link BlockData} to check + * @param block + * The {@link Block} the {@link BlockData} would be at + * @return + * Whether the {@link BlockData} would be supported at the given {@link Block} + */ + @ParametersAreNonnullByDefault + private boolean isSupported(BlockData blockData, Block block) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { + return blockData.isSupported(block); + } else { + // TODO: Make 1.16-1.18 version. BlockData::isSupported is 1.19+. + return true; + } + } + private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) { int amount = 1; From b3ff154f241612abd973d7affd33105ec41874e7 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sat, 9 Dec 2023 18:30:56 +0100 Subject: [PATCH 12/13] Import order, comments --- .../slimefun4/implementation/listeners/BlockListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 3526b4d11a..60b44b3ab0 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 @@ -10,7 +10,6 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -32,6 +31,7 @@ import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; @@ -168,12 +168,15 @@ public void onBlockBreak(BlockBreakEvent e) { } if (!e.isCancelled()) { + // Checks for Slimefun sensitive blocks above, using Slimefun Tags + // 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); dropItems(e, drops); + // Checks for vanilla sensitive blocks everywhere checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); } } From b38743d713a8d972d0c996c2545166940e49fa5d Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sat, 9 Dec 2023 18:36:00 +0100 Subject: [PATCH 13/13] More comments --- .../slimefun4/implementation/listeners/BlockListener.java | 2 ++ 1 file changed, 2 insertions(+) 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 60b44b3ab0..91fb9eb291 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 @@ -307,6 +307,7 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI } BlockState state = block.getState(); + // We set the block to air to make use of BlockData#isSupported. block.setType(Material.AIR, false); for (BlockFace face : CARDINAL_BLOCKFACES) { if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) { @@ -319,6 +320,7 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI checkForSensitiveBlocks(relative, ++count, isDropItems); } } + // Set the BlockData back: this makes it so containers and spawners drop correctly. This is a hacky fix. block.setBlockData(state.getBlockData(), false); state.update(true, false); }