diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java b/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java index e0a3dbf..c463d48 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java @@ -19,7 +19,9 @@ package net.momirealms.customcrops.api.core; import com.flowpowered.nbt.CompoundMap; import com.flowpowered.nbt.Tag; +import com.flowpowered.nbt.TagType; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.StringJoiner; @@ -78,25 +80,36 @@ public class SynchronizedCompoundMap { @Override public String toString() { - return compoundMapToString(compoundMap); + return compoundMapToString("BlockData", compoundMap); } - private String compoundMapToString(CompoundMap compoundMap) { + private String compoundMapToString(String key, CompoundMap compoundMap) { StringJoiner joiner = new StringJoiner(", "); for (Map.Entry> entry : compoundMap.entrySet()) { Tag tag = entry.getValue(); String tagValue; switch (tag.getType()) { - case TAG_STRING, TAG_BYTE, TAG_DOUBLE, TAG_FLOAT, TAG_INT, TAG_INT_ARRAY, TAG_LONG, TAG_SHORT, TAG_SHORT_ARRAY, TAG_LONG_ARRAY, TAG_BYTE_ARRAY, - TAG_LIST -> + case TAG_STRING, TAG_BYTE, TAG_DOUBLE, TAG_FLOAT, TAG_INT, TAG_INT_ARRAY, TAG_LONG, TAG_SHORT, TAG_SHORT_ARRAY, TAG_LONG_ARRAY, TAG_BYTE_ARRAY -> tagValue = tag.getValue().toString(); - case TAG_COMPOUND -> tagValue = compoundMapToString((CompoundMap) tag.getValue()); + case TAG_LIST -> { + List> list = (List>) tag.getValue(); + StringJoiner listJoiner = new StringJoiner(", "); + for (Tag tag2 : list) { + if (tag2.getType() == TagType.TAG_COMPOUND) { + listJoiner.add(compoundMapToString(tag2.getName(), (CompoundMap) tag2.getValue())); + } else { + listJoiner.add(tag2.getValue().toString()); + } + } + tagValue = tag.getName() + "[" + listJoiner + "]"; + } + case TAG_COMPOUND -> tagValue = compoundMapToString(tag.getName(), (CompoundMap) tag.getValue()); default -> { continue; } } joiner.add("\"" + entry.getKey() + "\":\"" + tagValue + "\""); } - return "BlockData{" + joiner + "}"; + return key + "{" + joiner + "}"; } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java index a7dbfd7..e29d8eb 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java @@ -437,7 +437,7 @@ public class PotBlock extends AbstractCustomCropsBlock { public Fertilizer[] fertilizers(CustomCropsBlockState state) { Tag fertilizerTag = state.get("fertilizers"); if (fertilizerTag == null) return new Fertilizer[0]; - List tags = ((ListTag) fertilizerTag.getValue()).getValue(); + List tags = ((List) fertilizerTag.getValue()); Fertilizer[] fertilizers = new Fertilizer[tags.size()]; for (int i = 0; i < tags.size(); i++) { CompoundTag tag = tags.get(i); @@ -480,10 +480,10 @@ public class PotBlock extends AbstractCustomCropsBlock { public boolean addFertilizer(CustomCropsBlockState state, Fertilizer fertilizer) { Tag fertilizerTag = state.get("fertilizers"); if (fertilizerTag == null) { - fertilizerTag = new ListTag("", TagType.TAG_COMPOUND, new ArrayList<>()); + fertilizerTag = new ListTag("fertilizers", TagType.TAG_COMPOUND, new ArrayList<>()); state.set("fertilizers", fertilizerTag); } - List tags = ((ListTag) fertilizerTag.getValue()).getValue(); + List tags = ((List) fertilizerTag.getValue()); for (CompoundTag tag : tags) { CompoundMap map = tag.getValue(); Fertilizer applied = tagToFertilizer(map); @@ -510,7 +510,7 @@ public class PotBlock extends AbstractCustomCropsBlock { if (fertilizerTag == null) { return false; } - List tags = ((ListTag) fertilizerTag.getValue()).getValue(); + List tags = ((List) fertilizerTag.getValue()); if (tags.isEmpty()) { return false; } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfig.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfig.java index 496491f..cc804f5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfig.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfig.java @@ -71,6 +71,8 @@ public interface PotConfig { Action[] fullWaterActions(); + Action[] maxFertilizerActions(); + static Builder builder() { return new PotConfigImpl.BuilderImpl(); } @@ -113,6 +115,8 @@ public interface PotConfig { Builder fullWaterActions(Action[] fullWaterActions); + Builder maxFertilizerActions(Action[] maxFertilizerActions); + Builder basicAppearance(Pair basicAppearance); Builder potAppearanceMap(HashMap> potAppearanceMap); diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfigImpl.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfigImpl.java index 68eb348..b203610 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfigImpl.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotConfigImpl.java @@ -54,6 +54,7 @@ public class PotConfigImpl implements PotConfig { private final Action[] breakActions; private final Action[] addWaterActions; private final Action[] fullWaterActions; + private final Action[] maxFertilizerActions; public PotConfigImpl( String id, @@ -74,7 +75,8 @@ public class PotConfigImpl implements PotConfig { Action[] placeActions, Action[] breakActions, Action[] addWaterActions, - Action[] fullWaterActions + Action[] fullWaterActions, + Action[] maxFertilizerActions ) { this.id = id; this.basicAppearance = basicAppearance; @@ -95,6 +97,7 @@ public class PotConfigImpl implements PotConfig { this.breakActions = breakActions; this.addWaterActions = addWaterActions; this.fullWaterActions = fullWaterActions; + this.maxFertilizerActions = maxFertilizerActions; this.blocks.add(basicAppearance.left()); this.blocks.add(basicAppearance.right()); this.wetBlocks.add(basicAppearance.right()); @@ -211,6 +214,11 @@ public class PotConfigImpl implements PotConfig { return fullWaterActions; } + @Override + public Action[] maxFertilizerActions() { + return maxFertilizerActions; + } + public static class BuilderImpl implements Builder { private String id; @@ -233,10 +241,11 @@ public class PotConfigImpl implements PotConfig { private Action[] breakActions; private Action[] addWaterActions; private Action[] fullWaterActions; + private Action[] maxFertilizerActions; @Override public PotConfig build() { - return new PotConfigImpl(id, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions); + return new PotConfigImpl(id, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions, maxFertilizerActions); } @Override @@ -341,6 +350,12 @@ public class PotConfigImpl implements PotConfig { return this; } + @Override + public Builder maxFertilizerActions(Action[] maxFertilizerActions) { + this.maxFertilizerActions = maxFertilizerActions; + return this; + } + @Override public Builder basicAppearance(Pair basicAppearance) { this.basicAppearance = basicAppearance; diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java index 87993f3..d50f8f8 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java @@ -53,7 +53,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { @Override public InteractionResult interactAt(WrappedInteractEvent event) { - FertilizerConfig fertilizerConfig = Registries.FERTILIZER.get(event.itemID()); + FertilizerConfig fertilizerConfig = Registries.ITEM_TO_FERTILIZER.get(event.itemID()); if (fertilizerConfig == null) { return InteractionResult.COMPLETE; } @@ -114,6 +114,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { .build(); CustomCropsBlockState potState = potBlock.fixOrGetState(world, Pos3.from(targetLocation), potConfig, event.relatedID()); if (!potBlock.canApplyFertilizer(potState,fertilizer)) { + ActionManager.trigger(context, potConfig.maxFertilizerActions()); return InteractionResult.COMPLETE; } // trigger event diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java index 6c8951e..df56e6d 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java @@ -125,6 +125,7 @@ public class ConfigType { .addWaterActions(pam.parseActions(section.getSection("events.add_water"))) .placeActions(pam.parseActions(section.getSection("events.place"))) .breakActions(pam.parseActions(section.getSection("events.break"))) + .maxFertilizerActions(pam.parseActions(section.getSection("events.max_fertilizers"))) .interactActions(pam.parseActions(section.getSection("events.interact"))) .reachLimitActions(pam.parseActions(section.getSection("events.reach_limit"))) .fullWaterActions(pam.parseActions(section.getSection("events.full"))) diff --git a/plugin/src/main/resources/contents/pots/default.yml b/plugin/src/main/resources/contents/pots/default.yml index 8b95198..0e2136d 100644 --- a/plugin/src/main/resources/contents/pots/default.yml +++ b/plugin/src/main/resources/contents/pots/default.yml @@ -11,6 +11,8 @@ default: absorb-rainwater: true # Does nearby water make the pot wet absorb-nearby-water: false + # The max amount of fertilizers + max-fertilizers: 1 # Set unique looks for pots with different fertilizer statuses fertilized-pots: quality: