diff --git a/README.md b/README.md index 5f7cf4b..671a390 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,18 @@ Currently included: - 1 wool (any color) -> 4 string - 3 leather + 2 string + 2 iron ingot -> 1 saddle +### Dropped seed planting +Automatically plants seed dropped on tilled soil. +Works for: +- Wheat +- Beetroot +- Carrot +- Potato +- Melon +- Pumpkin + ## Planned tweaks - Dynamite -- Seed drop planting - Sign editing - Armor stand swapping - Nether sponge drying diff --git a/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java b/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java new file mode 100644 index 0000000..e912be7 --- /dev/null +++ b/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java @@ -0,0 +1,54 @@ +package nl.kallestruik.vanillatweaks.SeedDropPlanting; + +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.plugin.java.JavaPlugin; + + +public class SeedDropPlanting { + + public static void init(JavaPlugin plugin) { + Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> { + for (World world : plugin.getServer().getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity instanceof Item) { + Item item = ((Item) entity); + Block b = world.getBlockAt(item.getLocation()); + Block below = world.getBlockAt(item.getLocation().add(0, -1, 0)); + if (b.getType() == Material.AIR && below.getType() == Material.FARMLAND) { + switch (item.getItemStack().getType()) { + case WHEAT_SEEDS: + b.setType(Material.WHEAT); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + case BEETROOT_SEEDS: + b.setType(Material.BEETROOT); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + case MELON_SEEDS: + b.setType(Material.MELON_STEM); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + case PUMPKIN_SEEDS: + b.setType(Material.PUMPKIN_STEM); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + case POTATO: + b.setType(Material.POTATOES); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + case CARROT: + b.setType(Material.CARROTS); + world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + break; + } + } + + } + } + } + }, 20 * 10, 20 * 10); + } +} diff --git a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java index 711c62f..49169e3 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java @@ -1,6 +1,7 @@ package nl.kallestruik.vanillatweaks; import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks; +import nl.kallestruik.vanillatweaks.SeedDropPlanting.SeedDropPlanting; import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample; import nl.kallestruik.vanillatweaks.ToggleTrample.TrampleHandler; import org.bukkit.configuration.InvalidConfigurationException; @@ -32,11 +33,9 @@ public final class VanillaTweaks extends JavaPlugin { * Throwable tnt with a smaller explosion. */ - /** - * Seed drop planting - * - * Seeds dropped on tilled soil will plant themselves after a random amount of time. - */ + if (config.SEED_DROP_PLANTING_ENABLED) { + SeedDropPlanting.init(this); + } /** * Sign editing diff --git a/src/main/java/nl/kallestruik/vanillatweaks/config.java b/src/main/java/nl/kallestruik/vanillatweaks/config.java index c5e73c7..d28e7c4 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/config.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/config.java @@ -9,12 +9,15 @@ import java.io.IOException; public class config { public static boolean TOGGLE_TRAMPLE_ENABLED; + public static boolean CRAFTING_TWEAKS_ENABLED; public static boolean CRAFTING_TWEAKS_BETTER_CHEST; public static boolean CRAFTING_TWEAKS_NAME_TAG; public static boolean CRAFTING_TWEAKS_WOOL_TO_STRING; public static boolean CRAFTING_TWEAKS_SADDLE; + public static boolean SEED_DROP_PLANTING_ENABLED; + public static void load(File file) throws IOException, InvalidConfigurationException { if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e93ebea..149b254 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,3 +8,5 @@ crafting-tweaks: wool-to-string: true saddle: true +seed-drop-planting: + enabled: true \ No newline at end of file