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-28 03:53:14 +08:00
parent 99bc0b3117
commit 6e5b923059
31 changed files with 396 additions and 215 deletions

View File

@@ -26,6 +26,7 @@ import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
@@ -331,13 +332,28 @@ public class BukkitBlockManager extends AbstractBlockManager {
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
// check duplicated config
if (byId.containsKey(id)) {
TranslationManager.instance().log("warning.config.block.duplicated", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.duplicated", path, id);
}
// read block settings
BlockSettings settings = BlockSettings.fromMap(MiscUtils.castToMap(section.getOrDefault("settings", Map.of()), false));
BlockSettings settings;
try {
settings = BlockSettings.fromMap(MiscUtils.castToMap(section.getOrDefault("settings", Map.of()), false));
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
// read loot table
LootTable<ItemStack> lootTable = LootTable.fromMap(MiscUtils.castToMap(section.getOrDefault("loot", Map.of()), false));
LootTable<ItemStack> lootTable;
try {
lootTable = LootTable.fromMap(MiscUtils.castToMap(section.getOrDefault("loot", Map.of()), false));
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
// read states
Map<String, Property<?>> properties;
Map<String, Integer> appearances;
@@ -347,8 +363,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
properties = Map.of();
int internalId = MiscUtils.getAsInt(stateSection.getOrDefault("id", -1));
if (internalId < 0) {
TranslationManager.instance().log("warning.config.block.state.lack_real_id", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.state.lack_real_id", path, id);
}
Pair<Key, Integer> pair = parseAppearanceSection(pack, path, id, stateSection);
@@ -358,34 +373,27 @@ public class BukkitBlockManager extends AbstractBlockManager {
Key internalBlockId = Key.of(CraftEngine.NAMESPACE, pair.left().value() + "_" + internalId);
int internalBlockRegistryId = MiscUtils.getAsInt(internalId2StateId.getOrDefault(internalBlockId, -1));
if (internalBlockRegistryId == -1) {
TranslationManager.instance().log("warning.config.block.state.invalid_real_state_id",
path.toString(),
id.toString(),
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_state_id", path, id,
pair.left().value() + "_" + internalId,
String.valueOf(MiscUtils.getAsInt(registeredRealBlockSlots.get(pair.left()))-1)
);
return;
String.valueOf(MiscUtils.getAsInt(registeredRealBlockSlots.get(pair.left()))-1));
}
variants = Map.of("", new VariantState("default", settings, internalBlockRegistryId));
} else {
// states
Map<String, Object> statesSection = MiscUtils.castToMap(section.get("states"), true);
if (statesSection == null) {
TranslationManager.instance().log("warning.config.block.lack_state", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.lack_state", path, id);
}
// properties
Map<String, Object> propertySection = MiscUtils.castToMap(statesSection.get("properties"), true);
if (propertySection == null) {
TranslationManager.instance().log("warning.config.block.state.lack_properties", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.state.lack_properties", path, id);
}
properties = parseProperties(path, id, propertySection);
// appearance
Map<String, Object> appearancesSection = MiscUtils.castToMap(statesSection.get("appearances"), true);
if (appearancesSection == null) {
TranslationManager.instance().log("warning.config.block.state.lack_appearances", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.state.lack_appearances", path, id);
}
appearances = new HashMap<>();
Map<String, Key> tempTypeMap = new HashMap<>();
@@ -400,8 +408,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
// variants
Map<String, Object> variantsSection = MiscUtils.castToMap(statesSection.get("variants"), true);
if (variantsSection == null) {
TranslationManager.instance().log("warning.config.block.state.lack_variants", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.block.state.lack_variants", path, id);
}
variants = new HashMap<>();
for (Map.Entry<String, Object> variantEntry : variantsSection.entrySet()) {
@@ -410,25 +417,19 @@ public class BukkitBlockManager extends AbstractBlockManager {
String variantName = variantEntry.getKey();
String appearance = (String) variantSection.get("appearance");
if (appearance == null) {
TranslationManager.instance().log("warning.config.block.state.variant.lack_appearance", path.toString(), id.toString(), variantName);
return;
throw new LocalizedResourceConfigException("warning.config.block.state.variant.lack_appearance", path, id, variantName);
}
if (!appearances.containsKey(appearance)) {
TranslationManager.instance().log("warning.config.block.state.variant.invalid_appearance", path.toString(), id.toString(), variantName, appearance);
return;
throw new LocalizedResourceConfigException("warning.config.block.state.variant.invalid_appearance", path, id, variantName, appearance);
}
int internalId = MiscUtils.getAsInt(variantSection.getOrDefault("id", -1));
Key baseBlock = tempTypeMap.get(appearance);
Key internalBlockId = Key.of(CraftEngine.NAMESPACE, baseBlock.value() + "_" + internalId);
int internalBlockRegistryId = MiscUtils.getAsInt(internalId2StateId.getOrDefault(internalBlockId, -1));
if (internalBlockRegistryId == -1) {
TranslationManager.instance().log("warning.config.block.state.invalid_real_state_id",
path.toString(),
id.toString(),
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_state_id", path, id,
internalBlockId.toString(),
String.valueOf(MiscUtils.getAsInt(registeredRealBlockSlots.getOrDefault(baseBlock, 1)) - 1)
);
return;
String.valueOf(MiscUtils.getAsInt(registeredRealBlockSlots.getOrDefault(baseBlock, 1)) - 1));
}
Map<String, Object> anotherSetting = MiscUtils.castToMap(variantSection.get("settings"), true);
variants.put(variantName, new VariantState(appearance, anotherSetting == null ? settings : BlockSettings.ofFullCopy(settings, anotherSetting), internalBlockRegistryId));
@@ -436,12 +437,23 @@ public class BukkitBlockManager extends AbstractBlockManager {
}
}
// create or get block holder
Holder.Reference<CustomBlock> holder = BuiltInRegistries.BLOCK.get(id).orElseGet(() ->
((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), id)));
// create block
Map<String, Object> behaviorSection = MiscUtils.castToMap(section.getOrDefault("behavior", Map.of()), false);
BukkitCustomBlock block = new BukkitCustomBlock(id, holder, properties, appearances, variants, settings, behaviorSection, lootTable);
Map<String, Object> behaviors = MiscUtils.castToMap(section.getOrDefault("behavior", Map.of()), false);
CustomBlock block;
try {
block = BukkitCustomBlock.builder(id)
.appearances(appearances)
.variantMapper(variants)
.lootTable(lootTable)
.properties(properties)
.settings(settings)
.behavior(behaviors)
.build();
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
// bind appearance and real state
for (ImmutableBlockState state : block.variantProvider().states()) {

View File

@@ -9,8 +9,11 @@ import net.momirealms.craftengine.core.block.*;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.loot.LootTable;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceKey;
import net.momirealms.craftengine.core.util.Tristate;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.shared.ObjectHolder;
@@ -25,17 +28,17 @@ import java.util.Set;
public class BukkitCustomBlock extends CustomBlock {
public BukkitCustomBlock(
protected BukkitCustomBlock(
Key id,
Holder.Reference<CustomBlock> holder,
Map<String, Property<?>> properties,
Map<String, Integer> appearances,
Map<String, VariantState> variantMapper,
BlockSettings settings,
Map<String, Object> behaviorSettings,
Map<String, Object> behavior,
@Nullable LootTable<?> lootTable
) {
super(id, holder, properties, appearances, variantMapper, settings, behaviorSettings, lootTable);
super(id, holder, properties, appearances, variantMapper, settings, behavior, lootTable);
}
@SuppressWarnings("unchecked")
@@ -139,4 +142,23 @@ public class BukkitCustomBlock extends CustomBlock {
CraftEngine.instance().logger().warn("Failed to init block settings", e);
}
}
public static Builder builder(Key id) {
return new Builder(id);
}
public static class Builder extends CustomBlock.Builder {
protected Builder(Key id) {
super(id);
}
@Override
public CustomBlock build() {
// create or get block holder
Holder.Reference<CustomBlock> holder = BuiltInRegistries.BLOCK.get(id).orElseGet(() ->
((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), id)));
return new BukkitCustomBlock(id, holder, properties, appearances, variantMapper, settings, behavior, lootTable);
}
}
}

View File

@@ -13,6 +13,7 @@ import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -159,7 +160,7 @@ public class ConcretePowderBlockBehavior extends FallingBlockBehavior {
int hurtMax = MiscUtils.getAsInt(arguments.getOrDefault("max-hurt", -1));
String solidBlock = (String) arguments.get("solid-block");
if (solidBlock == null) {
throw new IllegalArgumentException("No `solid-block` specified for concrete powder block behavior");
throw new LocalizedResourceConfigException("warning.config.block.behavior.concrete.lack_solid_block", new NullPointerException("No `solid-block` specified for concrete powder block behavior"));
}
return new ConcretePowderBlockBehavior(block, hurtAmount, hurtMax, Key.of(solidBlock));
}

View File

@@ -16,6 +16,7 @@ import net.momirealms.craftengine.core.loot.LootContext;
import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.Tuple;
@@ -170,7 +171,7 @@ public class CropBlockBehavior extends BushBlockBehavior {
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
Property<Integer> ageProperty = (Property<Integer>) block.getProperty("age");
if (ageProperty == null) {
throw new IllegalArgumentException("age property not set for crop");
throw new LocalizedResourceConfigException("warning.config.block.behavior.crop.lack_age", new IllegalArgumentException("age property not set for crop"));
}
int minGrowLight = MiscUtils.getAsInt(arguments.getOrDefault("light-requirement", 9));
float growSpeed = MiscUtils.getAsFloat(arguments.getOrDefault("grow-speed", 0.125f));

View File

@@ -14,6 +14,7 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.VersionHelper;
@@ -174,11 +175,11 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior {
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Property<Boolean> persistent = (Property<Boolean>) block.getProperty("persistent");
if (persistent == null) {
throw new NullPointerException("persistent property not set for block " + block.id());
throw new LocalizedResourceConfigException("warning.config.block.behavior.leaves.lack_persistent", new NullPointerException("persistent property not set for block " + block.id()));
}
Property<Integer> distance = (Property<Integer>) block.getProperty("distance");
if (distance == null) {
throw new NullPointerException("distance not set for block " + block.id());
throw new LocalizedResourceConfigException("warning.config.block.behavior.leaves.lack_distance", new NullPointerException("distance property not set for block " + block.id()));
}
Property<Boolean> waterlogged = (Property<Boolean>) block.getProperty("waterlogged");
int actual = distance.possibleValues().get(distance.possibleValues().size() - 1);

View File

@@ -10,6 +10,7 @@ import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.RandomUtils;
@@ -142,11 +143,11 @@ public class SaplingBlockBehavior extends BushBlockBehavior {
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String feature = (String) arguments.get("feature");
if (feature == null) {
throw new IllegalArgumentException("feature is null");
throw new LocalizedResourceConfigException("warning.config.block.behavior.sapling.lack_feature", new IllegalArgumentException("'feature' is required for sapling block behavior"));
}
Property<Integer> stageProperty = (Property<Integer>) block.getProperty("stage");
if (stageProperty == null) {
throw new IllegalArgumentException("stage property not set for sapling");
throw new LocalizedResourceConfigException("warning.config.block.behavior.sapling.lack_stage", new IllegalArgumentException("stage property not set for sapling"));
}
double boneMealSuccessChance = MiscUtils.getAsDouble(arguments.getOrDefault("bone-meal-success-chance", 0.45));
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.shared.block.BlockBehavior;
@@ -26,7 +27,7 @@ public class StrippableBlockBehavior extends BukkitBlockBehavior {
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String stripped = (String) arguments.get("stripped");
if (stripped == null) {
throw new IllegalArgumentException("stripped is null");
throw new LocalizedResourceConfigException("warning.config.block.behavior.strippable.lack_stripped", new IllegalArgumentException("'stripped' is required for strippable block behavior"));
}
return new StrippableBlockBehavior(block, Key.of(stripped));
}

View File

@@ -14,6 +14,7 @@ import net.momirealms.craftengine.core.block.properties.IntegerProperty;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.Tuple;
@@ -203,7 +204,7 @@ public class SugarCaneBlockBehavior extends BushBlockBehavior {
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
Property<Integer> ageProperty = (Property<Integer>) block.getProperty("age");
if (ageProperty == null) {
throw new IllegalArgumentException("age property not set for sugar cane");
throw new LocalizedResourceConfigException("warning.config.block.behavior.sugar_cane.lack_age", new IllegalArgumentException("'age' property not set for sugar cane block behavior"));
}
int maxHeight = MiscUtils.getAsInt(arguments.getOrDefault("max-height", 3));
List<String> nearbyLiquids = MiscUtils.getAsStringList(arguments.getOrDefault("required-adjacent-liquids", List.of()));

View File

@@ -28,7 +28,7 @@ import net.momirealms.craftengine.core.pack.model.select.ChargeTypeSelectPropert
import net.momirealms.craftengine.core.pack.model.select.TrimMaterialSelectProperty;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.WritableRegistry;
@@ -240,11 +240,10 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
@Override
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
if (customItems.containsKey(id)) {
TranslationManager.instance().log("warning.config.item.duplicated", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.item.duplicated", path, id);
}
// just register for recipes
// register for recipes
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
@@ -254,14 +253,12 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
if (isVanillaItem)
materialStringId = id.value();
if (materialStringId == null) {
TranslationManager.instance().log("warning.config.item.lack_material", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.item.lack_material", path, id);
}
Material material = MaterialUtils.getMaterial(materialStringId);
if (material == null) {
TranslationManager.instance().log("warning.config.item.invalid_material", path.toString(), id.toString(), materialStringId);
return;
throw new LocalizedResourceConfigException("warning.config.item.invalid_material", path, id);
}
Key materialId = Key.of(material.getKey().namespace(), material.getKey().value());
@@ -399,12 +396,11 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
// check conflict
Map<Integer, Key> conflict = cmdConflictChecker.computeIfAbsent(materialId, k -> new HashMap<>());
if (conflict.containsKey(customModelData)) {
TranslationManager.instance().log("warning.config.item.custom_model_data_conflict", path.toString(), id.toString(), String.valueOf(customModelData), conflict.get(customModelData).toString());
return;
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", path, id, String.valueOf(customModelData), conflict.get(customModelData).toString());
}
if (customModelData > 16_777_216) {
TranslationManager.instance().log("warning.config.item.bad_custom_model_data_value", path.toString(), id.toString(), String.valueOf(customModelData));
throw new LocalizedResourceConfigException("warning.config.item.bad_custom_model_data_value", path, id, String.valueOf(customModelData));
}
conflict.put(customModelData, id);
@@ -451,7 +447,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
}
}
if (!hasModel) {
TranslationManager.instance().log("warning.config.item.lack_model_id", path.toString(), id.toString());
throw new LocalizedResourceConfigException("warning.config.item.lack_model_id", path, id);
}
}
}

View File

@@ -20,6 +20,7 @@ import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.world.BlockPos;
@@ -187,7 +188,7 @@ public class BlockItemBehavior extends ItemBehavior {
public ItemBehavior create(Pack pack, Path path, Key key, Map<String, Object> arguments) {
Object id = arguments.get("block");
if (id == null) {
throw new IllegalArgumentException("Missing required parameter 'block' for block_item behavior");
throw new LocalizedResourceConfigException("warning.config.item.behavior.block.lack_block", new IllegalArgumentException("Missing required parameter 'block' for block_item behavior"));
}
if (id instanceof Map<?, ?> map) {
if (map.containsKey(key.toString())) {

View File

@@ -19,6 +19,7 @@ import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.collision.AABB;
@@ -154,7 +155,7 @@ public class FurnitureItemBehavior extends ItemBehavior {
public ItemBehavior create(Pack pack, Path path, Key key, Map<String, Object> arguments) {
Object id = arguments.get("furniture");
if (id == null) {
throw new IllegalArgumentException("Missing required parameter 'furniture' for furniture_item behavior");
throw new LocalizedResourceConfigException("warning.config.item.behavior.furniture.lack_furniture", new IllegalArgumentException("Missing required parameter 'furniture' for furniture_item behavior"));
}
if (id instanceof Map<?,?> map) {
if (map.containsKey(key.toString())) {

View File

@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -63,7 +64,7 @@ public class LiquidCollisionBlockItemBehavior extends BlockItemBehavior {
public ItemBehavior create(Pack pack, Path path, Key key, Map<String, Object> arguments) {
Object id = arguments.get("block");
if (id == null) {
throw new IllegalArgumentException("Missing required parameter 'block' for liquid_collision_block_item behavior");
throw new LocalizedResourceConfigException("warning.config.item.behavior.liquid_collision_block.lack_block", new IllegalArgumentException("Missing required parameter 'block' for liquid_collision_block_item behavior"));
}
int offset = MiscUtils.getAsInt(arguments.getOrDefault("y-offset", 1));
if (id instanceof Map<?, ?> map) {

View File

@@ -15,7 +15,7 @@ import net.momirealms.craftengine.core.loot.parameter.LootParameters;
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.TranslationManager;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
@@ -110,8 +110,7 @@ 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) {
TranslationManager.instance().log("warning.config.vanilla_loot.type_not_exist", path.toString(), id.toString());
return;
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.type_not_exist", path, id);
}
VanillaLoot.Type typeEnum = VanillaLoot.Type.valueOf(type.toUpperCase(Locale.ENGLISH));
boolean override = (boolean) section.getOrDefault("override", false);
@@ -123,16 +122,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) {
TranslationManager.instance().log("warning.config.vanilla_loot.block.invalid_target", path.toString(), id.toString(), target);
return;
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", path, id, 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) {
TranslationManager.instance().log("warning.config.vanilla_loot.block.invalid_target", path.toString(), id.toString(), target);
return;
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.block.invalid_target", path, id, target);
}
VanillaLoot vanillaLoot = blockLoots.computeIfAbsent(BlockStateUtils.blockStateToId(blockState), k -> new VanillaLoot(VanillaLoot.Type.BLOCK));
if (override) vanillaLoot.override(true);