9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-30 12:29:12 +00:00

Implement logic for dead crops

This commit is contained in:
XiaoMoMi
2024-09-03 01:28:01 +08:00
parent 32a4ab166f
commit a21af25570
18 changed files with 137 additions and 106 deletions

View File

@@ -232,6 +232,7 @@ public class BukkitCustomCropsPluginImpl extends BukkitCustomCropsPlugin {
registryAccess.registerBlockMechanic(new ScarecrowBlock());
registryAccess.registerBlockMechanic(new SprinklerBlock());
registryAccess.registerBlockMechanic(new GreenhouseBlock());
registryAccess.registerBlockMechanic(new DeadCrop());
registryAccess.registerItemMechanic(new SeedItem());
registryAccess.registerItemMechanic(new WateringCanItem());

View File

@@ -27,7 +27,6 @@ import net.momirealms.customcrops.common.command.CustomCropsCommandManager;
import net.momirealms.customcrops.common.locale.MessageConstants;
import net.momirealms.customcrops.common.util.Key;
import net.momirealms.customcrops.common.util.QuadConsumer;
import net.momirealms.customcrops.common.util.TriConsumer;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
@@ -39,7 +38,6 @@ import org.incendo.cloud.bukkit.parser.WorldParser;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.parser.standard.EnumParser;
import org.incendo.cloud.parser.standard.StringParser;
import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider;

View File

@@ -19,7 +19,6 @@ package net.momirealms.customcrops.bukkit.command.feature;
import net.kyori.adventure.text.Component;
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.core.world.Season;
import net.momirealms.customcrops.api.integration.SeasonProvider;
import net.momirealms.customcrops.bukkit.command.BukkitCommandFeature;
import net.momirealms.customcrops.common.command.CustomCropsCommandManager;

View File

@@ -21,7 +21,6 @@ import net.kyori.adventure.text.Component;
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.core.ConfigManager;
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
import net.momirealms.customcrops.api.core.world.Season;
import net.momirealms.customcrops.api.integration.SeasonProvider;
import net.momirealms.customcrops.bukkit.command.BukkitCommandFeature;
import net.momirealms.customcrops.common.command.CustomCropsCommandManager;
@@ -32,11 +31,7 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.bukkit.parser.WorldParser;
import org.incendo.cloud.parser.standard.IntegerParser;
import org.incendo.cloud.parser.standard.StringParser;
import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider;
import java.util.Locale;
import java.util.Optional;
public class SetDateCommand extends BukkitCommandFeature<CommandSender> {

View File

@@ -28,19 +28,15 @@ import net.momirealms.customcrops.common.command.CustomCropsCommandManager;
import net.momirealms.customcrops.common.locale.MessageConstants;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.bukkit.parser.WorldParser;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.parser.standard.StringParser;
import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
public class SetSeasonCommand extends BukkitCommandFeature<CommandSender> {

View File

@@ -30,10 +30,7 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.core.*;
import net.momirealms.customcrops.api.core.block.CropConfig;
import net.momirealms.customcrops.api.core.block.CropStageConfig;
import net.momirealms.customcrops.api.core.block.PotConfig;
import net.momirealms.customcrops.api.core.block.SprinklerConfig;
import net.momirealms.customcrops.api.core.block.*;
import net.momirealms.customcrops.api.core.item.FertilizerConfig;
import net.momirealms.customcrops.api.core.item.WateringCanConfig;
import net.momirealms.customcrops.common.helper.AdventureHelper;
@@ -132,6 +129,16 @@ public class BukkitConfigManager extends ConfigManager {
preventTrampling = config.getBoolean("mechanics.vanilla-farmland.prevent-trampling", false);
disableMoistureMechanic = config.getBoolean("mechanics.vanilla-farmland.disable-moisture-mechanic", false);
offsets.clear();
Section section = config.getSection("mechanics.hologram-offset-correction");
if (section != null) {
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof Number n) {
offsets.put(entry.getKey(), n.doubleValue());
}
}
}
}
@Override
@@ -228,9 +235,21 @@ public class BukkitConfigManager extends ConfigManager {
Registries.CROP.register(config.id(), config);
Registries.SEED_TO_CROP.register(config.seed(), config);
Registries.ITEMS.register(config.seed(), BuiltInItemMechanics.SEED.mechanic());
for (DeathCondition condition : config.deathConditions()) {
String deadStage = condition.deathStage();
if (deadStage != null) {
if (!Registries.BLOCKS.containsKey(deadStage)) {
Registries.BLOCKS.register(deadStage, BuiltInBlockMechanics.DEAD_CROP.mechanic());
}
if (!Registries.ITEM_TO_DEAD_CROP.containsKey(deadStage)) {
Registries.ITEM_TO_DEAD_CROP.register(deadStage, 0);
}
}
}
for (CropStageConfig stageConfig : config.stages()) {
String stageID = stageConfig.stageID();
if (stageID != null) {
offsets.put(stageID, stageConfig.displayInfoOffset());
List<CropConfig> list = Registries.STAGE_TO_CROP_UNSAFE.get(stageID);
if (list != null) {
list.add(config);

View File

@@ -117,6 +117,9 @@ mechanics:
disable-moisture-mechanic: false
# Prevent entities from trampling the farmland
prevent-trampling: false
# Set hologram offset correction for other blocks
hologram-offset-correction:
"{0}crop_stage_death": 0
other-settings:
# It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below.
# Disable this would improve performance