From f7ca82037de96dcebd7cc8d9ee1604c454858a72 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Thu, 19 Jun 2025 01:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=8C=96json=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/translations/en.yml | 3 +- .../src/main/resources/translations/zh_cn.yml | 3 +- .../core/pack/AbstractPackManager.java | 33 ++++++++++++------- gradle.properties | 2 +- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/common-files/src/main/resources/translations/en.yml b/common-files/src/main/resources/translations/en.yml index 9b5a09aa2..57db5e240 100644 --- a/common-files/src/main/resources/translations/en.yml +++ b/common-files/src/main/resources/translations/en.yml @@ -369,4 +369,5 @@ warning.config.resource_pack.generation.missing_font_texture: "Font 'Model '' is missing texture ''" warning.config.resource_pack.generation.missing_item_model: "Item '' is missing model file: ''" warning.config.resource_pack.generation.missing_block_model: "Block '' is missing model file: ''" -warning.config.resource_pack.generation.missing_parent_model: "Model '' cannot find parent model: ''" \ No newline at end of file +warning.config.resource_pack.generation.missing_parent_model: "Model '' cannot find parent model: ''" +warning.config.resource_pack.generation.malformatted_json: "Json file '' is malformatted." \ No newline at end of file diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml index 3be3e86b2..62be30309 100644 --- a/common-files/src/main/resources/translations/zh_cn.yml +++ b/common-files/src/main/resources/translations/zh_cn.yml @@ -369,4 +369,5 @@ warning.config.resource_pack.generation.missing_font_texture: "字体'模型''缺少纹理''" warning.config.resource_pack.generation.missing_item_model: "物品''缺少模型文件: ''" warning.config.resource_pack.generation.missing_block_model: "方块''缺少模型文件: ''" -warning.config.resource_pack.generation.missing_parent_model: "模型''找不到父级模型文件: ''" \ No newline at end of file +warning.config.resource_pack.generation.missing_parent_model: "模型''找不到父级模型文件: ''" +warning.config.resource_pack.generation.malformatted_json: "Json文件 '' 格式错误." \ No newline at end of file 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 bafeb5802..ace40069b 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 @@ -631,7 +631,7 @@ public abstract class AbstractPackManager implements PackManager { try { rootPaths = FileUtils.collectOverlays(path); } catch (IOException e) { - plugin.logger().warn("Failed to read overlays for " + path.toAbsolutePath(), e); + plugin.logger().warn("Failed to collect overlays for " + path.toAbsolutePath(), e); return; } Multimap imageToFonts = ArrayListMultimap.create(); // 图片到字体的映射 @@ -647,7 +647,7 @@ public abstract class AbstractPackManager implements PackManager { try { namespaces = FileUtils.collectNamespaces(assetsPath); } catch (IOException e) { - plugin.logger().warn("Failed to read namespaces for " + assetsPath.toAbsolutePath(), e); + plugin.logger().warn("Failed to collect namespaces for " + assetsPath.toAbsolutePath(), e); return; } for (Path namespacePath : namespaces) { @@ -662,7 +662,7 @@ public abstract class AbstractPackManager implements PackManager { try { fontJson = GsonHelper.readJsonFile(file).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read font json for " + file.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; } JsonArray providers = fontJson.getAsJsonArray("providers"); @@ -698,7 +698,7 @@ public abstract class AbstractPackManager implements PackManager { try { itemJson = GsonHelper.readJsonFile(file).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read items json for " + file.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; } Key item = Key.of(namespacePath.getFileName().toString(), FileUtils.pathWithoutExtension(file.getFileName().toString())); @@ -716,14 +716,14 @@ public abstract class AbstractPackManager implements PackManager { try { Files.walkFileTree(blockStatesPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { @Override - public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException { + public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) { if (!isJsonFile(file)) return FileVisitResult.CONTINUE; String blockId = FileUtils.pathWithoutExtension(file.getFileName().toString()); JsonObject blockStateJson; try { blockStateJson = GsonHelper.readJsonFile(file).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read blockstates json for " + file.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; } if (blockStateJson.has("multipart")) { @@ -760,11 +760,14 @@ public abstract class AbstractPackManager implements PackManager { for (Path rootPath : rootPaths) { Path modelJsonPath = rootPath.resolve(modelPath); if (Files.exists(rootPath.resolve(modelPath))) { + JsonObject jsonObject; try { - collectModels(key, GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(), rootPaths, imageToModels); + jsonObject = GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read model " + modelJsonPath.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", modelJsonPath.toAbsolutePath().toString()); + continue; } + collectModels(key, jsonObject, rootPaths, imageToModels); continue label; } } @@ -778,11 +781,14 @@ public abstract class AbstractPackManager implements PackManager { for (Path rootPath : rootPaths) { Path modelJsonPath = rootPath.resolve(modelPath); if (Files.exists(modelJsonPath)) { + JsonObject jsonObject; try { - collectModels(key, GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(), rootPaths, imageToModels); + jsonObject = GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read model " + modelJsonPath.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", modelJsonPath.toAbsolutePath().toString()); + continue; } + collectModels(key, jsonObject, rootPaths, imageToModels); continue label; } } @@ -811,11 +817,14 @@ public abstract class AbstractPackManager implements PackManager { for (Path rootPath : rootPaths) { Path modelJsonPath = rootPath.resolve(parentModelPath); if (Files.exists(modelJsonPath)) { + JsonObject jsonObject; try { - collectModels(parentResourceLocation, GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(), rootPaths, imageToModels); + jsonObject = GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(); } catch (IOException | JsonSyntaxException e) { - plugin.logger().warn("Failed to read model " + modelJsonPath.toAbsolutePath(), e); + TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", modelJsonPath.toAbsolutePath().toString()); + break label; } + collectModels(parentResourceLocation, jsonObject, rootPaths, imageToModels); break label; } } diff --git a/gradle.properties b/gradle.properties index 6b7770117..a9c37c7f5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # Rule: [major update].[feature update].[bug fix] project_version=0.0.57.4 config_version=37 -lang_version=16 +lang_version=17 project_group=net.momirealms latest_supported_version=1.21.6