From f3981c53af4b2841b016c7fd1054a4a0cacb9e40 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 30 May 2020 19:24:53 -0700 Subject: [PATCH] Added option to spawn broken block on block. Made it default. Fixes https://github.com/BentoBoxWorld/AOneBlock/issues/38 --- src/main/java/world/bentobox/aoneblock/Settings.java | 12 ++++++++++++ .../bentobox/aoneblock/listeners/BlockListener.java | 9 ++++++++- src/main/resources/config.yml | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/aoneblock/Settings.java b/src/main/java/world/bentobox/aoneblock/Settings.java index 3155fed1..a85278a0 100644 --- a/src/main/java/world/bentobox/aoneblock/Settings.java +++ b/src/main/java/world/bentobox/aoneblock/Settings.java @@ -221,6 +221,10 @@ public class Settings implements WorldSettings { // --------------------------------------------- /* ISLAND */ + @ConfigComment("Drop broken blocks on top of magic block") + @ConfigEntry(path = "island.drop-on-top", since = "1.3.0") + private boolean dropOnTop = true; + @ConfigComment("Magic block mob warning") @ConfigComment("Players might be able to hear hostile mobs up to this many blocks away") @ConfigComment("Minimum is 0 (no warning), max is 5") @@ -1691,4 +1695,12 @@ public List getMobLimitSettings() { public void setMobLimitSettings(List mobLimitSettings) { this.mobLimitSettings = mobLimitSettings; } + + public boolean isDropOnTop() { + return dropOnTop; + } + + public void setDropOnTop(boolean dropOnTop) { + this.dropOnTop = dropOnTop; + } } diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index 767dfa45..fa311765 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -272,7 +272,14 @@ private void process(Cancellable e, Island i, @Nullable Player player, @NonNull if (e instanceof BlockBreakEvent) { e.setCancelled(true); ItemStack tool = Objects.requireNonNull(player).getInventory().getItemInMainHand(); - block.breakNaturally(tool); + if (addon.getSettings().isDropOnTop()) { + // Drop the drops + block.getDrops(tool, player).forEach(item -> world.dropItem(block.getRelative(BlockFace.UP).getLocation().add(new Vector(0.5, 0, 0.5)), item)); + // Set the air + block.setType(Material.AIR); + } else { + block.breakNaturally(tool); + } // Give exp Objects.requireNonNull(player).giveExp(((BlockBreakEvent)e).getExpToDrop()); // Damage tool diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2308ef58..f7865c5e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -233,6 +233,8 @@ endGenerate: false endIslands: false dragonSpawn: false island: + # Drop broken blocks on top of magic block + drop-on-top: true # Magic block mob warning # Players might be able to hear hostile mobs up to this many blocks away # Minimum is 0 (no warning), max is 5