Skip to content

Commit

Permalink
Version 1.5.0
Browse files Browse the repository at this point in the history
- Enable planting on any soil, not just farmland.
  • Loading branch information
Torm committed Sep 28, 2023
1 parent 37d3230 commit 3eba570
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 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.4.1'
version '1.5.0'

sourceCompatibility = 1.16
targetCompatibility = 1.16
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ void onPlant(BlockPlaceEvent event) {
var crop = event.getBlock(); // The block/blockState is updated before the event is called. If the event is cancelled, the blockState is reverted to the original. That is why the planting task is delayed by 1 tick.
var cropType = crop.getType();
if (!toolUpgrade.isCrop(cropType)) return;
var soilType = crop.getRelative(0, -1, 0).getType();
var player = event.getPlayer();
// Try to find a tool in the mainhand or offhand.
@Nullable HarvestToolType tool;
Expand Down Expand Up @@ -656,17 +657,17 @@ void onPlant(BlockPlaceEvent event) {
}
if (foundItem == null) return; // Cancel if the tool cannot be found.
var centre = crop.getRelative(0, -1, 0);
if (centre.getType() != Material.FARMLAND) return;
if (centre.getType() != soilType) return;
var radius = calculateRadius(tool, toolItem);
var farmlands = findAdjacentMaterials(List.of(Material.FARMLAND), centre, radius, false);
var soilBlocks = findAdjacentMaterials(List.of(soilType), centre, radius, false);
var particleMultiplier = toolUpgrade.plantParticleMultiplier;
var creative = player.getGameMode() == GameMode.CREATIVE;
for (var farmland : farmlands) {
var aboveFarmland = farmland.getRelative(0, 1, 0);
if (aboveFarmland.getType() != Material.AIR) continue;
var placeEvent = new BlockPlaceEvent(aboveFarmland, aboveFarmland.getState(), farmland, event.getItemInHand(), player, event.canBuild()); //TODO canBuild
var savedState = aboveFarmland.getState();
aboveFarmland.setType(cropType);
for (var soil : soilBlocks) {
var aboveSoil = soil.getRelative(0, 1, 0);
if (aboveSoil.getType() != Material.AIR) continue;
var placeEvent = new BlockPlaceEvent(aboveSoil, aboveSoil.getState(), soil, event.getItemInHand(), player, event.canBuild()); //TODO canBuild
var savedState = aboveSoil.getState();
aboveSoil.setType(cropType);
callingBlockPlaceEvent = true;
getServer().getPluginManager().callEvent(placeEvent);
callingBlockPlaceEvent = false;
Expand All @@ -675,7 +676,7 @@ void onPlant(BlockPlaceEvent event) {
continue;
}
if (!creative) inventory.removeItem(seedItem.clone()); // Remove the planted seed. Clone in case server implementation reduces amount.
FarmingUpgradePlugin.fertiliseEffect(aboveFarmland, particleMultiplier);
FarmingUpgradePlugin.fertiliseEffect(aboveSoil, particleMultiplier);
if (!creative && !inventory.containsAtLeast(seedItem, 1)) break; // Break if there are no more seeds left.
}
FarmingUpgradePlugin.fertiliseEffect(crop, particleMultiplier); // Particles for centre crop.
Expand Down
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.4.1
version: 1.5.0
main: no.hyp.farmingupgrade.FarmingUpgradePlugin
api-version: 1.16
permissions:
Expand Down

0 comments on commit 3eba570

Please sign in to comment.