Skip to content

Commit

Permalink
fix: sugarcane placement on top of each other
Browse files Browse the repository at this point in the history
feat: add kelp and seagrass to multiblock crops
  • Loading branch information
Wertik committed Nov 24, 2024
1 parent 3dfeef8 commit ecc6097
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions blockregen-ancient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion blockregen-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions blockregen-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -14,7 +14,7 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
10 changes: 5 additions & 5 deletions blockregen-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -112,25 +112,25 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-common</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-legacy</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-ancient</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Spigot API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
import com.cryptomorin.xseries.XBlock;
import com.cryptomorin.xseries.XMaterial;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.TownBlock;
import lombok.extern.java.Log;
Expand Down Expand Up @@ -284,8 +285,10 @@ private void handleMultiblockCrop(BlockBreakEvent event, Block block, Player pla
boolean regenerateWhole = preset.isRegenerateWhole();

handleMultiblockAbove(block, player, above -> BlockUtil.isMultiblockCrop(plugin, above), (b) -> {
if (regenerateWhole) {
RegenerationProcess process = plugin.getRegenerationManager().createProcess(b, preset, region);
BlockPreset abovePreset = plugin.getPresetManager().getPreset(b);

if (regenerateWhole && abovePreset != null && abovePreset.isHandleCrops()) {
RegenerationProcess process = plugin.getRegenerationManager().createProcess(b, abovePreset, region);
process.start();
} else {
// Just destroy...
Expand All @@ -307,9 +310,23 @@ private void handleMultiblockCrop(BlockBreakEvent event, Block block, Player pla

private Block findBase(Block block) {
Block below = block.getRelative(BlockFace.DOWN);
if (below.getType() != block.getType()) {

XMaterial belowType = plugin.getVersionManager().getMethods().getType(below);
XMaterial type = plugin.getVersionManager().getMethods().getType(block);

// After kelp/kelp_plant is broken, the block below gets converted from kelp_plant to kelp
if (BlockUtil.isKelp(type)) {
if (!BlockUtil.isKelp(belowType)) {
return block;
} else {
return findBase(below);
}
}

if (type != belowType) {
return block;
}

return findBase(below);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import nl.aurorion.blockregen.api.BlockRegenBlockRegenerationEvent;
import nl.aurorion.blockregen.system.preset.struct.BlockPreset;
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial;
import nl.aurorion.blockregen.util.BlockUtil;
import nl.aurorion.blockregen.util.LocationUtil;
import nl.aurorion.blockregen.version.api.NodeData;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -149,10 +150,12 @@ public void regenerate() {

if (regenerateInto.requiresSolidGround() && preset.isCheckSolidGround()) {
Block below = this.block.getRelative(BlockFace.DOWN);
XMaterial belowType = plugin.getVersionManager().getMethods().getType(below);
RegenerationProcess processBelow = plugin.getRegenerationManager().getProcess(below);

// Sugarcane on sugarcane (aka not solid, still can be placed)
if (!below.getType().isSolid() && below.getType() != block.getType()) {
// + kelp on kelp
if (!below.getType().isSolid() && belowType != XMaterial.SUGAR_CANE && !BlockUtil.isKelp(belowType) && !BlockUtil.isSeagrass(belowType)) {
if (processBelow != null) {
long delay = processBelow.getRegenerationTime() >= this.getRegenerationTime() ? processBelow.getRegenerationTime() - this.getRegenerationTime() + 100 : 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ public static boolean isMultiblockCrop(BlockRegen plugin, Block block) {
return isMultiblockCrop(type);
}

public static boolean isKelp(XMaterial material) {
return material == XMaterial.KELP || material == XMaterial.KELP_PLANT;
}

public static boolean isSeagrass(XMaterial material) {
return material == XMaterial.SEAGRASS || material == XMaterial.TALL_SEAGRASS;
}

public static boolean isMultiblockCrop(XMaterial type) {
return type == XMaterial.CACTUS ||
type == XMaterial.SUGAR_CANE ||
type == XMaterial.BAMBOO;
type == XMaterial.BAMBOO ||
type == XMaterial.KELP_PLANT ||
type == XMaterial.KELP ||
type == XMaterial.TALL_SEAGRASS;
}
}
4 changes: 2 additions & 2 deletions blockregen-version/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
</parent>

<artifactId>blockregen-version</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-common</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Spigot API -->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>nl.aurorion.blockregen</groupId>
<artifactId>BlockRegen</artifactId>
<version>3.16.3</version>
<version>3.16.4-SNAPSHOT</version>
<modules>
<module>blockregen-version</module>
<module>blockregen-common</module>
Expand Down

0 comments on commit ecc6097

Please sign in to comment.