From 1e68a81498fe1130048a8c587f1d0e5e75d6f4f6 Mon Sep 17 00:00:00 2001 From: Torm <5649457+Torm@users.noreply.github.com> Date: Sun, 28 Nov 2021 03:45:58 +0100 Subject: [PATCH] Empty farmland trampling and replant delay and particles. --- build.gradle | 2 +- .../farmingupgrade/FarmingUpgradePlugin.java | 43 +++++++++++++++++-- src/main/resources/config.yml | 9 +++- src/main/resources/plugin.yml | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 7ae29e0..9aa1d30 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'no.hyp' -version '1.3.2' +version '1.3.3' sourceCompatibility = 1.16 targetCompatibility = 1.16 diff --git a/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java b/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java index e438431..9bbe651 100644 --- a/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java +++ b/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java @@ -159,6 +159,12 @@ final record FarmingUpgradeConfiguration ( boolean harvestReplant, + int harvestReplantDelayMinimum, + + int harvestReplantDelayMaximum, + + boolean harvestReplantParticles, + boolean harvestCollect, ImmutableList harvestCrops, @@ -179,7 +185,9 @@ final record FarmingUpgradeConfiguration ( boolean trampleUpgrade, - boolean trampleWalk + boolean trampleWalk, + + boolean revertEmpty ) { @@ -192,6 +200,9 @@ final record FarmingUpgradeConfiguration ( configuration.getBoolean("harvest.applyUnbreaking"), configuration.getBoolean("harvest.onlyMature"), configuration.getBoolean("harvest.replant"), + configuration.getInt("harvest.replantDelayMinimum"), + configuration.getInt("harvest.replantDelayMaximum"), + configuration.getBoolean("harvest.replantParticles"), configuration.getBoolean("harvest.collect"), readCrops(configuration, "harvest.crops"), configuration.getBoolean("hydrate.upgrade"), @@ -202,7 +213,8 @@ final record FarmingUpgradeConfiguration ( configuration.getBoolean("fertilise.upgrade"), readPlants(configuration, "fertilise.plants"), configuration.getBoolean("trample.upgrade"), - configuration.getBoolean("trample.walk") + configuration.getBoolean("trample.walk"), + configuration.getBoolean("trample.revertEmpty") ); } @@ -461,7 +473,27 @@ boolean harvestCrop(Player player, Block block, ItemStack tool, boolean replant, } } if (mode == GameMode.CREATIVE && replant) seedFound = true; // A crop is always replanted in creative mode. - if (seedFound) block.setType(state.getType()); // Replant the crop if the conditions are satisfied. + // Replant the crop if a seed was found or the player is in creative mode. + if (seedFound) { + var range = configuration().harvestReplantDelayMaximum() - configuration.harvestReplantDelayMinimum(); + int delay; + if (range == 0) { + delay = configuration().harvestReplantDelayMinimum(); + } else { + delay = configuration().harvestReplantDelayMinimum() + random.nextInt(range); + } + if (delay == 0) { + block.setType(state.getType()); + if (configuration().harvestReplantParticles()) fertiliseEffect(block); + } else { + getServer().getScheduler().runTaskLater(this, () -> { + if (block.isEmpty()) { + block.setType(state.getType()); + if (configuration().harvestReplantParticles()) fertiliseEffect(block); + } + }, delay); + } + } return true; } @@ -752,6 +784,11 @@ public void onFarmlandTrample(PlayerInteractEvent event) { var farmland = event.getClickedBlock(); var trample = farmland != null && farmland.getType() == Material.FARMLAND && event.getAction() == Action.PHYSICAL; if (!trample) return; + // If there is no crop above and trample.revertEmpty is enabled, let the farmland be trampled like in Vanilla. + var crop = farmland.getRelative(0, 1, 0); + if (crop.isEmpty() && configuration().revertEmpty()) { + return; + } // Cancel to handle manually. event.setUseInteractedBlock(Event.Result.DENY); // Trample the crop above the farmland. diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b89dc60..f15c395 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,7 @@ # FarmingUpgrade configuration # Default configuration: https://github.com/Torm/FarmingUpgrade/blob/master/src/main/resources/config.yml -# Configuration version. Do not change. +# Configuration version. Do not modify. version: 4 # The server requires the plugin. If the plugin fails, shut down the server. @@ -77,6 +77,11 @@ harvest: onlyMature: true # Crops are automatically replanted after being broken by a hoe if a seed is dropped. replant: true + # Minimum and maximum number of ticks to wait between harvesting and replanting. A random number in the range is sampled. + replantDelayMinimum: 10 + replantDelayMaximum: 20 + # Create particles when replanting. + replantParticles: true # Dropped items from crops broken by a hoe are collected in the player's inventory if there is space. collect: false # A list of crops and their seeds. @@ -131,3 +136,5 @@ trample: upgrade: true # Crops are trampled by walking or running over them. walk: false + # Farmland is trampled back to dirt if there is nothing growing on it. + revertEmpty: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a6263fa..082bb73 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: FarmingUpgrade author: Torm description: Upgraded farming mechanics. -version: 1.3.2 +version: 1.3.3 main: no.hyp.farmingupgrade.FarmingUpgradePlugin api-version: 1.16 permissions: