9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 04:46:37 +00:00

差不多了

This commit is contained in:
XiaoMoMi
2025-04-29 19:37:20 +08:00
parent 1f50f7dcb4
commit 65c5cece93
4 changed files with 44 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.EnumUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
@@ -110,9 +111,14 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
String type = (String) section.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.missing_type", path, id);
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.missing_type");
}
VanillaLoot.Type typeEnum;
try {
typeEnum = VanillaLoot.Type.valueOf(type.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.invalid_type", type, EnumUtils.toString(VanillaLoot.Type.values()));
}
VanillaLoot.Type typeEnum = VanillaLoot.Type.valueOf(type.toUpperCase(Locale.ENGLISH));
boolean override = (boolean) section.getOrDefault("override", false);
List<String> targets = MiscUtils.getAsStringList(section.getOrDefault("target", List.of()));
LootTable<?> lootTable = LootTable.fromMap(MiscUtils.castToMap(section.get("loot"), false));
@@ -122,14 +128,14 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
if (target.endsWith("]") && target.contains("[")) {
java.lang.Object blockState = BlockStateUtils.blockDataToBlockState(Bukkit.createBlockData(target));
if (blockState == Reflections.instance$Blocks$AIR$defaultState) {
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", path, id, target);
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", target);
}
VanillaLoot vanillaLoot = blockLoots.computeIfAbsent(BlockStateUtils.blockStateToId(blockState), k -> new VanillaLoot(VanillaLoot.Type.BLOCK));
vanillaLoot.addLootTable(lootTable);
} else {
for (Object blockState : BlockStateUtils.getAllVanillaBlockStates(Key.of(target))) {
if (blockState == Reflections.instance$Blocks$AIR$defaultState) {
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", path, id, target);
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", target);
}
VanillaLoot vanillaLoot = blockLoots.computeIfAbsent(BlockStateUtils.blockStateToId(blockState), k -> new VanillaLoot(VanillaLoot.Type.BLOCK));
if (override) vanillaLoot.override(true);