From 753ce7e05ae2be411c416f2614868b583fa38e67 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 18 May 2025 19:44:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=8B=E5=8A=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=A7=E7=89=88=E6=A8=A1=E5=9E=8B=E8=A6=86=E5=86=99?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/translations/en.yml | 2 + .../src/main/resources/translations/zh_cn.yml | 29 ++++++-- .../bukkit/block/BukkitBlockManager.java | 30 +++++---- .../bukkit/item/BukkitItemManager.java | 1 - .../core/item/AbstractItemManager.java | 66 ++++++++----------- .../core/pack/AbstractPackManager.java | 4 +- .../core/pack/model/LegacyItemModel.java | 36 ++++++++-- .../core/pack/model/LegacyOverridesModel.java | 6 +- .../core/util/IntIdentityList.java | 4 +- gradle.properties | 6 +- 10 files changed, 111 insertions(+), 73 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index c33a67965..ba193d14e 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -156,6 +156,8 @@ warning.config.item.behavior.block.missing_block: "Issue found in file < warning.config.item.behavior.furniture.missing_furniture: "Issue found in file - The item '' is missing the required 'furniture' argument for 'furniture_item' behavior." warning.config.item.behavior.liquid_collision.missing_block: "Issue found in file - The item '' is missing the required 'block' argument for 'liquid_collision_block_item' behavior." warning.config.item.legacy_model.missing_path: "Issue found in file - The item '' is missing the require 'path' argument for legacy-model." +warning.config.item.legacy_model.overrides.missing_path: "Issue found in file - The item '' is missing the require 'path' argument for legacy-model overrides." +warning.config.item.legacy_model.overrides.missing_predicate: "Issue found in file - The item '' is missing the require 'predicate' argument for legacy-model overrides." warning.config.item.legacy_model.cannot_convert: "Issue found in file - Cannot convert 1.21.4+ items to legacy format for item ''. Please manually create 'legacy-model' section for this item." warning.config.item.model.invalid_type: "Issue found in file - The item '' is using an invalid model type ''." warning.config.item.model.tint.missing_type: "Issue found in file - The item '' is missing the required 'type' argument for tint." diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index ea6b6e9b8..9b35e58a3 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -90,8 +90,10 @@ warning.config.condition.match_block_property.missing_properties: "在 warning.config.condition.match_item.missing_id: "在文件 发现问题 - 配置项 '' 缺少 'match_item' 条件所需的 'id' 参数" warning.config.condition.table_bonus.missing_enchantment: "在文件 发现问题 - 配置项 '' 缺少 'table_bonus' 条件所需的 'enchantment' 参数" warning.config.condition.table_bonus.missing_chances: "在文件 发现问题 - 配置项 '' 缺少 'table_bonus' 条件所需的 'chances' 参数" - - +warning.config.condition.permission.missing_permission: "在文件 中发现问题 - 配置项 '' 缺少 'permission' 条件必需的 'permission' 参数" +warning.config.condition.equals.missing_value1: "在文件 中发现问题 - 配置项 '' 缺少 'equals' 条件必需的 'value1' 参数" +warning.config.condition.equals.missing_value2: "在文件 中发现问题 - 配置项 '' 缺少 'equals' 条件必需的 'value2' 参数" +warning.config.condition.expression.missing_expression: "在文件 中发现问题 - 配置项 '' 缺少 'expression' 条件必需的 'expression' 参数" warning.config.structure.not_section: "在文件 发现问题 - 配置项 '' 应为配置段落 但实际类型为 ''" warning.config.image.duplicate: "在文件 发现问题 - 重复的图片配置 '' 请检查其他文件中是否存在相同配置" warning.config.image.missing_height: "在文件 发现问题 - 图片 '' 缺少必需的 'height' 参数" @@ -147,11 +149,16 @@ warning.config.item.invalid_custom_model_data: "在文件 发现 warning.config.item.bad_custom_model_data: "在文件 发现问题 - 物品 '' 使用的自定义模型数据 '' 数值过大 建议使用小于 16,777,216 的值" warning.config.item.custom_model_data_conflict: "在文件 发现问题 - 物品 '' 使用的自定义模型数据 '' 已被物品 '' 占用" warning.config.item.missing_model_id: "在文件 发现问题 - 物品 '' 缺少必需的 'custom-model-data' 或 'item-model' 参数" +warning.config.item.missing_model: "在文件 中发现问题 - 物品 '' 缺少支持 1.21.4+ 资源包必需的 'model' 配置项" warning.config.item.behavior.missing_type: "在文件 发现问题 - 物品 '' 的行为配置缺少必需的 'type' 参数" warning.config.item.behavior.invalid_type: "在文件 发现问题 - 物品 '' 使用了无效的行为类型 ''" warning.config.item.behavior.block.missing_block: "在文件 发现问题 - 物品 '' 的 'block_item' 行为缺少必需的 'block' 参数" warning.config.item.behavior.furniture.missing_furniture: "在文件 发现问题 - 物品 '' 的 'furniture_item' 行为缺少必需的 'furniture' 参数" warning.config.item.behavior.liquid_collision.missing_block: "在文件 发现问题 - 物品 '' 的 'liquid_collision_block_item' 行为缺少必需的 'block' 参数" +warning.config.item.legacy_model.missing_path: "在文件 中发现问题 - 物品 '' 的旧版模型(legacy-model)缺少必需的 'path' 参数" +warning.config.item.legacy_model.overrides.missing_path: "在文件 中发现问题 - 物品 '' 的旧版模型覆写规则(overrides)缺少必需的 'path' 参数" +warning.config.item.legacy_model.overrides.missing_predicate: "在文件 中发现问题 - 物品 '' 的旧版模型覆写规则(overrides)缺少必需的 'predicate' 参数" +warning.config.item.legacy_model.cannot_convert: "在文件 中发现问题 - 无法将物品 '' 自动转换为旧版格式,请手动为此物品创建 'legacy-model' 配置项" warning.config.item.model.invalid_type: "在文件 发现问题 - 物品 '' 使用了无效的模型类型 ''" warning.config.item.model.tint.missing_type: "在文件 发现问题 - 物品 '' 的染色配置缺少必需的 'type' 参数" warning.config.item.model.tint.invalid_type: "在文件 发现问题 - 物品 '' 使用了无效的染色类型 ''" @@ -298,10 +305,18 @@ warning.config.conflict_matcher.all_of.missing_terms: "在 config.yml warning.config.conflict_matcher.any_of.missing_terms: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 任一匹配器缺少必需的 'terms' 参数" warning.config.conflict_resolution.missing_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案缺少必需的 'type' 参数" warning.config.conflict_resolution.invalid_type: "在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 ''" -warning.config.event.missing_trigger: "Issue found in file - The config '' is missing the required 'on' argument for event triggers." -warning.config.event.invalid_trigger: "Issue found in file - The config '' is using an invalid event trigger ''." +warning.config.event.missing_trigger: "在文件 中发现问题 - 配置项 '' 缺少事件触发器必需的 'on' 参数" +warning.config.event.invalid_trigger: "在文件 中发现问题 - 配置项 '' 使用了无效的事件触发器 ''" warning.config.event.condition.missing_type: "在文件 - 配置项 '' 的事件条件缺少 'type' 参数" warning.config.event.condition.invalid_type: "在文件 - 配置项 '' 使用了无效的事件条件类型 ''" -warning.config.function.missing_type: "Issue found in file - The config '' is missing the required 'type' argument for function." -warning.config.function.invalid_type: "Issue found in file - The config '' is using an invalid function type ''." -warning.config.function.command.missing_command: "Issue found in file - The config '' is missing the required 'command' argument for 'command' function." \ No newline at end of file +warning.config.function.missing_type: "在文件 中发现问题 - 配置项 '' 缺少函数必需的 'type' 参数" +warning.config.function.invalid_type: "在文件 中发现问题 - 配置项 '' 使用了无效的函数类型 ''" +warning.config.function.command.missing_command: "在文件 中发现问题 - 配置项 '' 缺少 'command' 函数必需的 'command' 参数" +warning.config.function.actionbar.missing_actionbar: "在文件 中发现问题 - 配置项 '' 缺少 'actionbar' 函数必需的 'actionbar' 参数" +warning.config.function.message.missing_message: "在文件 中发现问题 - 配置项 '' 缺少 'message' 函数必需的 'message' 参数" +warning.config.selector.missing_type: "在文件 中发现问题 - 配置项 '' 缺少选择器必需的 'type' 参数" +warning.config.selector.invalid_type: "在文件 中发现问题 - 配置项 '' 使用了无效的选择器类型 ''" +warning.config.selector.invalid_target: "在文件 中发现问题 - 配置项 '' 使用了无效的选择器目标 ''" +warning.config.resource_pack.item_model.conflict.vanilla: "无法为 '' 生成物品模型,因为该物品模型已被原版物品占用" +warning.config.resource_pack.item_model.already_exist: "无法为 '' 生成物品模型,因为文件 '' 已存在" +warning.config.resource_pack.model.generation.already_exist: "无法生成模型,因为模型文件 '' 已存在" \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java index 7d77e45fe..7a039f9b2 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java @@ -7,6 +7,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.dejvokep.boostedyaml.YamlDocument; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine; import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector; @@ -55,11 +59,11 @@ public class BukkitBlockManager extends AbstractBlockManager { private final BlockParser blockParser; // A temporary map used to detect whether the same block state corresponds to multiple models. - private final Map tempRegistryIdConflictMap = new HashMap<>(); + private final Map tempRegistryIdConflictMap = new Int2ObjectOpenHashMap<>(); // A temporary map that converts the custom block registered on the server to the vanilla block ID. - private final Map tempBlockAppearanceConvertor = new HashMap<>(); + private final Map tempBlockAppearanceConvertor = new Int2IntOpenHashMap(); // A temporary map that stores the model path of a certain vanilla block state - private final Map tempVanillaBlockStateModels = new HashMap<>(); + private final Map tempVanillaBlockStateModels = new Int2ObjectOpenHashMap<>(); // The total amount of blocks registered private int customBlockCount; @@ -79,10 +83,10 @@ public class BukkitBlockManager extends AbstractBlockManager { private ImmutableSet affectedSoundBlocks; private ImmutableMap soundMapper; // A list to record the order of registration - private List blockRegisterOrder = new ArrayList<>(); + private List blockRegisterOrder = new ObjectArrayList<>(); // a reverted mapper - private final Map> appearanceToRealState = new HashMap<>(); + private final Map> appearanceToRealState = new Int2ObjectOpenHashMap<>(); // Used to store override information of json files private final Map> blockStateOverrides = new HashMap<>(); // for mod, real block id -> state models @@ -232,11 +236,11 @@ public class BukkitBlockManager extends AbstractBlockManager { } public ImmutableMap> blockAppearanceArranger() { - return blockAppearanceArranger; + return this.blockAppearanceArranger; } public ImmutableMap> realBlockArranger() { - return realBlockArranger; + return this.realBlockArranger; } @Nullable @@ -275,7 +279,7 @@ public class BukkitBlockManager extends AbstractBlockManager { try { Class modClass = ReflectionUtils.getClazz(CraftEngine.MOD_CLASS); Field amountField = ReflectionUtils.getDeclaredField(modClass, "vanillaRegistrySize"); - vanillaStateCount = (int) amountField.get(null); + vanillaStateCount = amountField.getInt(null); } catch (Exception e) { vanillaStateCount = RegistryUtils.currentBlockRegistrySize(); plugin.logger().severe("Fatal error", e); @@ -481,7 +485,7 @@ public class BukkitBlockManager extends AbstractBlockManager { } stateId2ImmutableBlockStates[state.customBlockState().registryId() - BlockStateUtils.vanillaStateSize()] = state; tempBlockAppearanceConvertor.put(state.customBlockState().registryId(), state.vanillaBlockState().registryId()); - appearanceToRealState.computeIfAbsent(state.vanillaBlockState().registryId(), k -> new ArrayList<>()).add(state.customBlockState().registryId()); + appearanceToRealState.computeIfAbsent(state.vanillaBlockState().registryId(), k -> new IntArrayList()).add(state.customBlockState().registryId()); } BukkitBlockManager.this.byId.put(id, block); @@ -649,9 +653,9 @@ public class BukkitBlockManager extends AbstractBlockManager { YamlDocument mappings = Config.instance().loadOrCreateYamlData("mappings.yml"); Map blockStateMappings = loadBlockStateMappings(mappings); this.validateBlockStateMappings(mappingFile, blockStateMappings); - Map stateMap = new HashMap<>(); + Map stateMap = new Int2ObjectOpenHashMap<>(); Map blockTypeCounter = new LinkedHashMap<>(); - Map appearanceMapper = new HashMap<>(); + Map appearanceMapper = new Int2IntOpenHashMap(); Map> appearanceArranger = new HashMap<>(); for (Map.Entry entry : blockStateMappings.entrySet()) { this.processBlockStateMapping(mappingFile, entry, stateMap, blockTypeCounter, appearanceMapper, appearanceArranger); @@ -727,7 +731,7 @@ public class BukkitBlockManager extends AbstractBlockManager { counter.compute(key, (k, count) -> count == null ? 1 : count + 1); stateMap.put(beforeId, entry.getKey()); stateMap.put(afterId, entry.getValue()); - arranger.computeIfAbsent(key, (k) -> new ArrayList<>()).add(beforeId); + arranger.computeIfAbsent(key, (k) -> new IntArrayList()).add(beforeId); } else { String previousState = stateMap.get(previous); plugin.logger().warn(mappingFile, "Duplicate entry: '" + previousState + "' equals '" + entry.getKey() + "'"); @@ -776,7 +780,7 @@ public class BukkitBlockManager extends AbstractBlockManager { Object clientSideBlock = getBlockFromRegistry(createResourceLocation(clientSideBlockType)); int amount = blockWithCount.getValue(); - List stateIds = new ArrayList<>(); + List stateIds = new IntArrayList(); for (int i = 0; i < amount; i++) { Key realBlockKey = createRealBlockKey(clientSideBlockType, i); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java index 175a35013..b961ac758 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java @@ -36,7 +36,6 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java index d0dd2f51c..ce2e61986 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java @@ -258,6 +258,16 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl public class ItemParser implements ConfigParser { public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"}; + private static final float VERSION_1_21_2 = 21.2f; + private static final float VERSION_1_21_4 = 21.4f; + + private boolean isModernFormatRequired() { + return Config.packMaxVersion() >= VERSION_1_21_4; + } + + private boolean needsLegacyCompatibility() { + return Config.packMinVersion() < VERSION_1_21_4; + } @Override public String[] sectionId() { @@ -338,7 +348,7 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl // add it to category if (section.containsKey("category")) { - plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList()); + AbstractItemManager.this.plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList()); } // model part, can be null @@ -353,7 +363,7 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl throw new LocalizedResourceConfigException("warning.config.item.missing_model_id"); } // 1.21.4+必须要配置model区域 - if (Config.packMaxVersion() >= 21.4f && modelSection == null) { + if (isModernFormatRequired() && modelSection == null) { throw new LocalizedResourceConfigException("warning.config.item.missing_model"); } @@ -362,47 +372,22 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl // 旧版格式 TreeSet legacyOverridesModels = null; - if (Config.packMaxVersion() >= 21.4f) { + if (isModernFormatRequired() || (needsLegacyCompatibility() && legacyModelSection == null)) { modernModel = ItemModels.fromMap(modelSection); for (ModelGeneration generation : modernModel.modelsToGenerate()) { prepareModelGeneration(generation); } - // 如果最低支持版本低于1.21.4,则需要准备旧版overrides模型 - if (Config.packMinVersion() < 21.4f) { - // 如果有旧版格式,就用旧版 - if (legacyModelSection != null) { - LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection); - for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) { - prepareModelGeneration(generation); - } - legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides()); - } else { - // 否则把新版格式并转换为旧版 - legacyOverridesModels = new TreeSet<>(); - processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData); - if (legacyOverridesModels.isEmpty()) { - TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString()); - } - } - } } - // 最高支持版本不超过1.21.4,所以新版model格式为非必需 - else { - // 如果有旧版格式,就用旧版 + if (needsLegacyCompatibility()) { if (legacyModelSection != null) { - LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection); + LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection, customModelData); for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) { prepareModelGeneration(generation); } legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides()); } else { - // 否则读新版格式并转换为旧版 - ItemModel model = ItemModels.fromMap(modelSection); - for (ModelGeneration generation : model.modelsToGenerate()) { - prepareModelGeneration(generation); - } legacyOverridesModels = new TreeSet<>(); - processModelRecursively(model, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData); + processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData); if (legacyOverridesModels.isEmpty()) { TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString()); } @@ -413,29 +398,30 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl if (customModelData != 0) { // use custom model data // check conflict - Map conflict = cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>()); + Map conflict = AbstractItemManager.this.cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>()); if (conflict.containsKey(customModelData)) { throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", String.valueOf(customModelData), conflict.get(customModelData).toString()); } conflict.put(customModelData, id); // Parse models - if (Config.packMaxVersion() >= 21.4f && modernModel != null) { - TreeMap map = modernOverrides.computeIfAbsent(material, k -> new TreeMap<>()); + if (isModernFormatRequired() && modernModel != null) { + TreeMap map = AbstractItemManager.this.modernOverrides.computeIfAbsent(material, k -> new TreeMap<>()); map.put(customModelData, modernModel); } - if (Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) { - TreeSet lom = legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>()); + if (needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) { + TreeSet lom = AbstractItemManager.this.legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>()); lom.addAll(legacyOverridesModels); } } // use item model if (itemModelKey != null) { - if (Config.packMaxVersion() >= 21.4f && modernModel != null) { - modernItemModels1_21_4.put(itemModelKey, modernModel); + if (isModernFormatRequired() && modernModel != null) { + AbstractItemManager.this.modernItemModels1_21_4.put(itemModelKey, modernModel); } - if (Config.packMaxVersion() >= 21.2f && Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) { - modernItemModels1_21_2.put(itemModelKey, legacyOverridesModels); + if (Config.packMaxVersion() >= VERSION_1_21_2 && needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) { + TreeSet lom = AbstractItemManager.this.modernItemModels1_21_2.computeIfAbsent(itemModelKey, k -> new TreeSet<>()); + lom.addAll(legacyOverridesModels); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java index 4cd03a29b..a91f3b95d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java @@ -428,8 +428,10 @@ public abstract class AbstractPackManager implements PackManager { Yaml yaml = new Yaml(new StringKeyConstructor(new LoaderOptions())); for (Pack pack : loadedPacks()) { if (!pack.enabled()) continue; + Path configurationFolderPath = pack.configurationFolder(); + if (!Files.isDirectory(configurationFolderPath)) continue; try { - Files.walkFileTree(pack.configurationFolder(), new SimpleFileVisitor<>() { + Files.walkFileTree(configurationFolderPath, new SimpleFileVisitor<>() { @Override public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) { if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(".yml")) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyItemModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyItemModel.java index 81db56d2e..925b2bb87 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyItemModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyItemModel.java @@ -1,10 +1,13 @@ package net.momirealms.craftengine.core.pack.model; import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration; +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.ResourceConfigUtils; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,13 +34,38 @@ public class LegacyItemModel { return path; } - public static LegacyItemModel fromMap(Map legacyModel) { + @SuppressWarnings("unchecked") + public static LegacyItemModel fromMap(Map legacyModel, int customModelData) { String legacyModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(legacyModel.get("path"), "warning.config.item.legacy_model.missing_path"); Map generation = MiscUtils.castToMap(legacyModel.get("generation"), true); - ModelGeneration modelGeneration = null; + ModelGeneration baseModelGeneration = null; if (generation != null) { - modelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation); + baseModelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation); + } + List> overrides = (List>) legacyModel.get("overrides"); + if (overrides != null) { + List modelGenerations = new ArrayList<>(); + List legacyOverridesModels = new ArrayList<>(); + if (baseModelGeneration != null) modelGenerations.add(baseModelGeneration); + legacyOverridesModels.add(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData)); + for (Map override : overrides) { + String overrideModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(override.get("path"), () -> new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_path")); + Map predicate = MiscUtils.castToMap(ResourceConfigUtils.requireNonNullOrThrow(override.get("predicate"), "warning.config.item.legacy_model.overrides.missing_predicate"), false); + if (predicate.isEmpty()) { + throw new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_predicate"); + } + Map overrideGeneration = MiscUtils.castToMap(override.get("generation"), true); + if (overrideGeneration != null) { + modelGenerations.add(ModelGeneration.of(Key.of(overrideModelPath), overrideGeneration)); + } + legacyOverridesModels.add(new LegacyOverridesModel(predicate, overrideModelPath, customModelData)); + } + return new LegacyItemModel(legacyModelPath, legacyOverridesModels, modelGenerations); + } else { + return new LegacyItemModel(legacyModelPath, + List.of(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData)), + baseModelGeneration == null ? List.of() : List.of(baseModelGeneration) + ); } - LegacyOverridesModel legacyOverridesModel = new LegacyOverridesModel(); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyOverridesModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyOverridesModel.java index 07d6d1e7f..6d63b08f2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyOverridesModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/LegacyOverridesModel.java @@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.pack.model; import com.google.gson.JsonObject; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -11,8 +13,8 @@ public class LegacyOverridesModel implements Comparable { private final String model; private final int customModelData; - public LegacyOverridesModel(Map predicate, String model, int customModelData) { - this.predicate = predicate; + public LegacyOverridesModel(@Nullable Map predicate, @NotNull String model, int customModelData) { + this.predicate = predicate == null ? new HashMap<>() : predicate; this.model = model; this.customModelData = customModelData; if (customModelData > 0) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/IntIdentityList.java b/core/src/main/java/net/momirealms/craftengine/core/util/IntIdentityList.java index c6f539f05..a60be053e 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/IntIdentityList.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/IntIdentityList.java @@ -1,9 +1,9 @@ package net.momirealms.craftengine.core.util; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -13,7 +13,7 @@ public class IntIdentityList implements IndexedIterable { public IntIdentityList(int size) { this.size = size; - list = new ArrayList<>(size); + list = new IntArrayList(size); for (int i = 0; i < size; i++) { list.add(i); } diff --git a/gradle.properties b/gradle.properties index 1fabb99a5..a350543e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.54.1 -config_version=32 -lang_version=12 +project_version=0.0.54.2 +config_version=33 +lang_version=13 project_group=net.momirealms latest_supported_version=1.21.5