Skip to content

Commit

Permalink
Empty farmland trampling and replant delay and particles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Torm committed Nov 28, 2021
1 parent ca82c3f commit 1e68a81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'no.hyp'
version '1.3.2'
version '1.3.3'

sourceCompatibility = 1.16
targetCompatibility = 1.16
Expand Down
43 changes: 40 additions & 3 deletions src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ final record FarmingUpgradeConfiguration (

boolean harvestReplant,

int harvestReplantDelayMinimum,

int harvestReplantDelayMaximum,

boolean harvestReplantParticles,

boolean harvestCollect,

ImmutableList<ReplantableCrop> harvestCrops,
Expand All @@ -179,7 +185,9 @@ final record FarmingUpgradeConfiguration (

boolean trampleUpgrade,

boolean trampleWalk
boolean trampleWalk,

boolean revertEmpty

) {

Expand All @@ -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"),
Expand All @@ -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")
);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 1e68a81

Please sign in to comment.