9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-25 09:59:20 +00:00

improve vanilla crop interactions

This commit is contained in:
XiaoMoMi
2024-09-05 02:07:27 +08:00
parent 1a6a59a616
commit 577cd7cb10
10 changed files with 82 additions and 18 deletions

View File

@@ -38,9 +38,11 @@ import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
import net.momirealms.customcrops.api.core.mechanic.wateringcan.WateringCanConfig;
import net.momirealms.customcrops.common.helper.AdventureHelper;
import net.momirealms.customcrops.common.helper.VersionHelper;
import net.momirealms.customcrops.common.locale.TranslationManager;
import net.momirealms.customcrops.common.plugin.CustomCropsProperties;
import net.momirealms.customcrops.common.util.ListUtils;
import org.bukkit.Material;
import java.io.File;
import java.io.FileInputStream;
@@ -50,14 +52,23 @@ import java.util.*;
public class BukkitConfigManager extends ConfigManager {
private static final Set<Material> VANILLA_CROPS = new HashSet<>(
List.of(Material.WHEAT, Material.CARROTS, Material.POTATOES, Material.BEETROOTS, Material.SWEET_BERRY_BUSH,
Material.MELON_STEM, Material.PUMPKIN_STEM)
);
private static YamlDocument MAIN_CONFIG;
public static YamlDocument getMainConfig() {
return MAIN_CONFIG;
}
public BukkitConfigManager(BukkitCustomCropsPlugin plugin) {
super(plugin);
if (VersionHelper.isVersionNewerThan1_19_4()) {
VANILLA_CROPS.add(Material.TORCHFLOWER_CROP);
}
if (VersionHelper.isVersionNewerThan1_20()) {
VANILLA_CROPS.add(Material.PITCHER_CROP);
}
}
@Override
@@ -155,6 +166,27 @@ public class BukkitConfigManager extends ConfigManager {
for (String id : greenhouse) {
Registries.BLOCKS.register(id, BuiltInBlockMechanics.GREENHOUSE.mechanic());
}
overriddenCrops.clear();
overriddenCrops.addAll(config.getStringList("mechanics.override-vanilla-crops")
.stream()
.map(it -> {
try {
return Material.valueOf(it.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
plugin.getPluginLogger().warn("No enum constant exists", e);
return Material.AIR;
}
})
.filter(it -> {
if (it == Material.AIR) return false;
boolean allow = VANILLA_CROPS.contains(it);
if (!allow) {
plugin.getPluginLogger().warn(it.name() + " is not a supported vanilla crop type");
}
return allow;
})
.toList());
}
@Override
@@ -193,8 +225,12 @@ public class BukkitConfigManager extends ConfigManager {
boolean save = false;
for (Map.Entry<String, Object> entry : document.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof Section section) {
if (type.parse(this, entry.getKey(), section)) {
save = true;
try {
if (type.parse(this, entry.getKey(), section)) {
save = true;
}
} catch (Exception e) {
plugin.getPluginLogger().warn("Error occurs during parsing configs", e);
}
}
}

View File

@@ -37,7 +37,6 @@ import net.momirealms.customcrops.api.integration.ItemProvider;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.api.util.PluginUtils;
import net.momirealms.customcrops.api.util.StringUtils;
import net.momirealms.customcrops.common.item.Item;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -250,7 +249,7 @@ public class BukkitItemManager extends AbstractItemManager {
public String blockID(@NotNull Block block) {
String id = this.provider.blockID(block);
if (id == null) {
id = block.getType().toString();
id = block.getBlockData().getAsString();
}
return id;
}

View File

@@ -125,6 +125,8 @@ mechanics:
# Set hologram offset correction for other blocks
hologram-offset-correction:
"{0}crop_stage_death": 0
# Set the crop types that would be overridden
override-vanilla-crops: []
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