9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-19 15:09:25 +00:00
This commit is contained in:
XiaoMoMi
2025-06-08 23:43:05 +08:00
parent 37a8f24263
commit a42b0fd15e
14 changed files with 123 additions and 23 deletions

View File

@@ -72,7 +72,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
plugin.getPluginLogger().warn("`plant` action is not executed due to crop[" + key + "] not exists");
return;
}
Location cropLocation = requireNonNull(context.arg(ContextKeys.LOCATION)).clone().add(0,y,0);
Location cropLocation = requireNonNull(context.arg(ContextKeys.LOCATION)).clone().add(0, y, 0);
Location potLocation = cropLocation.clone().subtract(0,1,0);
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(cropLocation.getWorld());
if (optionalWorld.isEmpty()) {
@@ -86,6 +86,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
CustomCropsBlockState potState = potBlock.fixOrGetState(world, potPos3, potConfig, potItemID);
if (potState == null) {
plugin.debug(() -> "Pot doesn't exist below the crop when executing `plant` action at location[" + world.worldName() + "," + potPos3 + "]");
return;
}
CropBlock cropBlock = (CropBlock) BuiltInBlockMechanics.CROP.mechanic();

View File

@@ -28,6 +28,7 @@ import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
import net.momirealms.customcrops.api.core.world.ExplosionIndicator;
import net.momirealms.customcrops.api.core.world.Pos3;
import net.momirealms.customcrops.api.event.BoneMealDispenseEvent;
import net.momirealms.customcrops.api.util.EventUtils;
@@ -54,11 +55,13 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Constructor;
import java.util.*;
public abstract class AbstractCustomEventListener implements Listener {
private final HashSet<EntityType> entities = new HashSet<>();
private final HashSet<Material> blocks = new HashSet<>();
private final ExplosionIndicator explosionIndicator;
protected Set<Material> ignoredMaterials() {
return blocks;
@@ -88,6 +91,17 @@ public abstract class AbstractCustomEventListener implements Listener {
if (VersionHelper.isVersionNewerThan1_20()) {
this.blocks.add(Material.CHERRY_LEAVES);
}
if (!VersionHelper.isVersionNewerThan1_21()) {
this.explosionIndicator = new ExplosionIndicator.AlwaysTrue();
} else {
try {
Class<?> clazz = Class.forName("net.momirealms.customcrops.bukkit.j21.ModernExplosionIndicator");
Constructor<?> constructor = clazz.getConstructor();
this.explosionIndicator = (ExplosionIndicator) constructor.newInstance();
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Failed to init ", e);
}
}
}
@EventHandler
@@ -315,6 +329,9 @@ public abstract class AbstractCustomEventListener implements Listener {
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onExplosion(EntityExplodeEvent event) {
if (!this.explosionIndicator.canDestroyBlocks(event)) {
return;
}
Entity entity = event.getEntity();
for (Block block : event.blockList()) {
this.itemManager.handleEntityExplode(entity, block.getLocation(), this.itemManager.blockID(block), event);

View File

@@ -24,6 +24,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -46,6 +47,8 @@ public interface CropConfig {
*/
String seed();
List<String> seeds();
/**
* Gets the maximum growth points for this crop.
*
@@ -247,7 +250,7 @@ public interface CropConfig {
* @param seed The seed item ID.
* @return The builder instance for chaining.
*/
Builder seed(String seed);
Builder seed(List<String> seed);
/**
* Sets the maximum growth points for this crop.

View File

@@ -29,7 +29,7 @@ import java.util.*;
public class CropConfigImpl implements CropConfig {
private final String id;
private final String seed;
private final List<String> seed;
private final int maxPoints;
private final Action<Player>[] wrongPotActions;
private final Action<Player>[] interactActions;
@@ -55,7 +55,7 @@ public class CropConfigImpl implements CropConfig {
public CropConfigImpl(
String id,
String seed,
List<String> seed,
int maxPoints,
Action<Player>[] wrongPotActions,
Action<Player>[] interactActions,
@@ -125,7 +125,12 @@ public class CropConfigImpl implements CropConfig {
@Override
public String seed() {
return seed;
return this.seed.get(0);
}
@Override
public List<String> seeds() {
return this.seed;
}
@Override
@@ -246,7 +251,7 @@ public class CropConfigImpl implements CropConfig {
public static class BuilderImpl implements Builder {
private String id;
private String seed;
private List<String> seed;
private ExistenceForm existenceForm;
private int maxPoints;
private Action<Player>[] wrongPotActions;
@@ -279,7 +284,7 @@ public class CropConfigImpl implements CropConfig {
}
@Override
public Builder seed(String seed) {
public Builder seed(List<String> seed) {
this.seed = seed;
return this;
}

View File

@@ -0,0 +1,15 @@
package net.momirealms.customcrops.api.core.world;
import org.bukkit.event.entity.EntityExplodeEvent;
public interface ExplosionIndicator {
boolean canDestroyBlocks(EntityExplodeEvent event);
class AlwaysTrue implements ExplosionIndicator {
@Override
public boolean canDestroyBlocks(EntityExplodeEvent event) {
return true;
}
}
}

View File

@@ -87,27 +87,31 @@ public class VersionHelper {
}
public static boolean isVersionNewerThan1_18() {
return version >= 18;
return version >= 18f;
}
public static boolean isVersionNewerThan1_19() {
return version >= 19;
return version >= 19f;
}
public static boolean isVersionNewerThan1_19_4() {
return version >= 19.39;
return version >= 19.39f;
}
public static boolean isVersionNewerThan1_20() {
return version >= 20;
return version >= 20f;
}
public static boolean isVersionNewerThan1_21_4() {
return version >= 21.39;
return version >= 21.39f;
}
public static boolean isVersionNewerThan1_21_2() {
return version >= 19;
return version >= 21.19f;
}
public static boolean isVersionNewerThan1_21() {
return version >= 21f;
}
public static boolean isFolia() {