From b6740b9de346d01da15bd4b7bf63eefb0af64cf8 Mon Sep 17 00:00:00 2001 From: dragontamerfred Date: Fri, 4 Oct 2019 19:01:03 +0200 Subject: [PATCH] Add hoe harvesting. --- README.md | 5 ++ .../HoeHarvesting/HoeHarvestingHandler.java | 64 +++++++++++++++++++ .../vanillatweaks/VanillaTweaks.java | 5 ++ .../nl/kallestruik/vanillatweaks/config.java | 16 +++++ src/main/resources/config.yml | 11 +++- 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/main/java/nl/kallestruik/vanillatweaks/HoeHarvesting/HoeHarvestingHandler.java diff --git a/README.md b/README.md index 58c3ad0..699ca75 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Currently included: - 2 paper + 1 iron ingot -> 1 name tag - 1 wool (any color) -> 4 string - 3 leather + 2 string + 2 iron ingot -> 1 saddle +- 1 blue ice -> 9 packed ice +- 1 packed ice -> 9 ice ### Dropped seed planting Automatically plants seed dropped on tilled soil. @@ -32,6 +34,9 @@ Allow players to shift right-click on any armor stand to swap armor with it. ### Nether sponge drying Instantly dry wet sponges when they are placed in the nether. +### Hoe harvesting +When breaking crops with a hoe you break a range around them. This drastically speeds up manual harvesting of crop farms. + ## Planned tweaks - Dynamite - Sign editing diff --git a/src/main/java/nl/kallestruik/vanillatweaks/HoeHarvesting/HoeHarvestingHandler.java b/src/main/java/nl/kallestruik/vanillatweaks/HoeHarvesting/HoeHarvestingHandler.java new file mode 100644 index 0000000..515a7b6 --- /dev/null +++ b/src/main/java/nl/kallestruik/vanillatweaks/HoeHarvesting/HoeHarvestingHandler.java @@ -0,0 +1,64 @@ +package nl.kallestruik.vanillatweaks.HoeHarvesting; + +import nl.kallestruik.vanillatweaks.config; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +public class HoeHarvestingHandler implements Listener { + + @EventHandler + public void onHoeBreaksBlock(BlockBreakEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + World world = block.getWorld(); + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + int range; + + if (itemInHand.getType() == Material.WOODEN_HOE) + range = config.HOE_HARVESTING_RANGE_WOOD; + else if (itemInHand.getType() == Material.STONE_HOE) + range = config.HOE_HARVESTING_RANGE_STONE; + else if (itemInHand.getType() == Material.IRON_HOE) + range = config.HOE_HARVESTING_RANGE_IRON; + else if (itemInHand.getType() == Material.GOLDEN_HOE) + range = config.HOE_HARVESTING_RANGE_GOLD; + else if (itemInHand.getType() == Material.DIAMOND_HOE) + range = config.HOE_HARVESTING_RANGE_DIAMOND; + else + return; + + + if (!isCrop(block.getType())) + return; + + Location startLocation = block.getLocation(); + + for (int x = -range; x <= range; x++) { + for (int z = -range; z <= range; z++) { + Block b = world.getBlockAt(startLocation.clone().add(x, 0, z)); + if (isCrop(b.getType())) { + Ageable ageable = (Ageable) b.getBlockData(); + if (ageable.getAge() == ageable.getMaximumAge()) { + b.breakNaturally(); + } + } + } + } + + } + + + private static boolean isCrop(Material material) { + return material == Material.WHEAT || + material == Material.BEETROOTS || + material == Material.CARROTS || + material == Material.POTATOES; + + } +} \ No newline at end of file diff --git a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java index 48d71a0..3a330be 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java @@ -2,6 +2,7 @@ package nl.kallestruik.vanillatweaks; import nl.kallestruik.vanillatweaks.ArmorStandSwapping.ArmorStandSwappingHandler; import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks; +import nl.kallestruik.vanillatweaks.HoeHarvesting.HoeHarvestingHandler; import nl.kallestruik.vanillatweaks.NetherSpongeDrying.NetherSpongeHandler; import nl.kallestruik.vanillatweaks.SeedDropPlanting.SeedDropPlanting; import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample; @@ -47,6 +48,10 @@ public final class VanillaTweaks extends JavaPlugin { getServer().getPluginManager().registerEvents(new NetherSpongeHandler(), this); } + if (config.HOE_HARVESTING_ENABLED) { + getServer().getPluginManager().registerEvents(new HoeHarvestingHandler(), this); + } + } catch (IOException | InvalidConfigurationException | NullPointerException e) { util.printException(e); } diff --git a/src/main/java/nl/kallestruik/vanillatweaks/config.java b/src/main/java/nl/kallestruik/vanillatweaks/config.java index af16ebd..c05e8fd 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/config.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/config.java @@ -24,6 +24,13 @@ public class config { public static boolean NETHER_SPONGE_DRYING_ENABLED; + public static boolean HOE_HARVESTING_ENABLED; + public static int HOE_HARVESTING_RANGE_WOOD; + public static int HOE_HARVESTING_RANGE_STONE; + public static int HOE_HARVESTING_RANGE_IRON; + public static int HOE_HARVESTING_RANGE_GOLD; + public static int HOE_HARVESTING_RANGE_DIAMOND; + public static void load(File file) throws IOException, InvalidConfigurationException { if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); @@ -47,5 +54,14 @@ public class config { ARMOR_STAND_SWAPPING_ENABLED = config.getBoolean("armor-stand-swapping.enabled"); NETHER_SPONGE_DRYING_ENABLED = config.getBoolean("nether-sponge-drying.enabled"); + + HOE_HARVESTING_ENABLED = config.getBoolean("hoe-harvesting.enabled"); + HOE_HARVESTING_RANGE_WOOD = config.getInt("hoe-harvesting.ranges.wood"); + HOE_HARVESTING_RANGE_STONE = config.getInt("hoe-harvesting.ranges.stone"); + HOE_HARVESTING_RANGE_IRON = config.getInt("hoe-harvesting.ranges.iron"); + HOE_HARVESTING_RANGE_GOLD = config.getInt("hoe-harvesting.ranges.gold"); + HOE_HARVESTING_RANGE_DIAMOND = config.getInt("hoe-harvesting.ranges.diamond"); + + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17fa9b4..07011dd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -17,4 +17,13 @@ armor-stand-swapping: enabled: true nether-sponge-drying: - enabled: true \ No newline at end of file + enabled: true + +hoe-harvesting: + enabled: true + ranges: + wood: 1 + stone: 1 + iron: 1 + gold: 1 + diamond: 2 \ No newline at end of file