From 7af13286ebb1289104bb737e3120a7fab02c6a3f Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Tue, 16 Dec 2025 18:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E8=AF=AD=E8=A8=80=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=9C=89=E5=BA=8F=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common-files/src/main/resources/config.yml | 3 +- .../core/pack/AbstractPackManager.java | 102 +----------------- .../pack/overlay/ResourcePackOverlay.java | 32 ++++++ .../core/plugin/locale/LangData.java | 4 +- 4 files changed, 39 insertions(+), 102 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/overlay/ResourcePackOverlay.java diff --git a/common-files/src/main/resources/config.yml b/common-files/src/main/resources/config.yml index 7b132f091..133632a86 100644 --- a/common-files/src/main/resources/config.yml +++ b/common-files/src/main/resources/config.yml @@ -93,7 +93,8 @@ resource-pack: path: "assets/minecraft/font/uniform.json" resolution: type: merge_font - # Validate if there is any error in the resource pack, such as missing textures or models + # Validate if there is any error in the resource pack, such as missing textures or models. + # Validation may not always be accurate due to the presence of overlays, and it is time-consuming for plugins to simulate multiple client versions for testing. # If your resource pack is compliant with the standard, you can disable validation to improve the resource pack generation speed. validation: enable: true 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 6cb3a8e0f..3288d670c 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 @@ -123,8 +123,8 @@ public abstract class AbstractPackManager implements PackManager { private final Map loadedPacks = new HashMap<>(); private final Map sectionParsers = new HashMap<>(); private final TreeSet sortedParsers = new TreeSet<>(); - private final JsonObject vanillaBlockAtlas; - private final JsonObject vanillaItemAtlas; + public final JsonObject vanillaBlockAtlas; + public final JsonObject vanillaItemAtlas; private Map cachedConfigFiles = Collections.emptyMap(); private Map cachedAssetFiles = Collections.emptyMap(); protected BiConsumer zipGenerator; @@ -886,61 +886,6 @@ public abstract class AbstractPackManager implements PackManager { } } - private void processAtlas(JsonObject atlasJsonObject, BiConsumer directory, Consumer existing, Consumer included) { - JsonArray sources = atlasJsonObject.getAsJsonArray("sources"); - if (sources != null) { - for (JsonElement source : sources) { - if (!(source instanceof JsonObject sourceJson)) continue; - String type = Optional.ofNullable(sourceJson.get("type")).map(JsonElement::getAsString).orElse(null); - if (type == null) continue; - switch (type) { - case "directory", "minecraft:directory" -> { - JsonElement source0 = sourceJson.get("source"); - JsonElement prefix = sourceJson.get("prefix"); - if (prefix == null || source0 == null) continue; - directory.accept(prefix.getAsString(), source0.getAsString() + "/"); - } - case "single", "minecraft:single" -> { - JsonElement resource = sourceJson.get("resource"); - if (resource == null) continue; - included.accept(Key.of(resource.getAsString())); - } - case "unstitch", "minecraft:unstitch" -> { - JsonElement resource = sourceJson.get("resource"); - if (resource == null) continue; - included.accept(Key.of(resource.getAsString())); - JsonArray regions = sourceJson.getAsJsonArray("regions"); - if (regions != null) { - for (JsonElement region : regions) { - if (!(region instanceof JsonObject regionJson)) continue; - JsonElement sprite = regionJson.get("sprite"); - if (sprite == null) continue; - existing.accept(Key.of(sprite.getAsString())); - } - } - } - case "paletted_permutations", "minecraft:paletted_permutations" -> { - JsonArray textures = sourceJson.getAsJsonArray("textures"); - if (textures == null) continue; - JsonObject permutationsJson = sourceJson.getAsJsonObject("permutations"); - if (permutationsJson == null) continue; - String separator = sourceJson.has("separator") ? sourceJson.get("separator").getAsString() : "_"; - List permutations = new ArrayList<>(permutationsJson.keySet()); - for (JsonElement texture : textures) { - if (!(texture instanceof JsonPrimitive texturePath)) continue; - for (String permutation : permutations) { - existing.accept(Key.of(texturePath.getAsString() + separator + permutation)); - } - } - } - case "filter", "minecraft:filter" -> { - // todo filter - } - } - } - } - } - @SuppressWarnings("DuplicatedCode") private void optimizeResourcePack(Path path) { // 收集全部overlay @@ -1903,7 +1848,7 @@ public abstract class AbstractPackManager implements PackManager { } // 经过这一步拿到的模型为包含全部父贴图的模型 - private TexturedModel getTexturedModel(Key path, JsonObject modelJson, Path[] rootPaths, Map models) { + public TexturedModel getTexturedModel(Key path, JsonObject modelJson, Path[] rootPaths, Map models) { TexturedModel texturedModel = new TexturedModel(modelJson); if (modelJson.has("parent")) { Key parentModelPath = Key.from(modelJson.get("parent").getAsString()); @@ -1949,47 +1894,6 @@ public abstract class AbstractPackManager implements PackManager { return null; } - private void verifyParentModelAndCollectTextures(Key rl, - JsonObject modelJson, - Path[] rootPaths, - Multimap imageToModels, - Set checkedModels) { - // 如果有父模型 - if (modelJson.has("parent")) { - Key parentRL = Key.from(modelJson.get("parent").getAsString()); - if (checkedModels.add(parentRL) && !VANILLA_MODELS.contains(parentRL)) { - String parentModelPath = "assets/" + parentRL.namespace() + "/models/" + parentRL.value() + ".json"; - label: { - for (Path rootPath : rootPaths) { - Path modelJsonPath = rootPath.resolve(parentModelPath); - if (Files.exists(modelJsonPath)) { - JsonObject jsonObject; - try { - jsonObject = GsonHelper.readJsonFile(modelJsonPath).getAsJsonObject(); - } catch (IOException | JsonParseException e) { - TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", modelJsonPath.toAbsolutePath().toString()); - break label; - } - verifyParentModelAndCollectTextures(parentRL, jsonObject, rootPaths, imageToModels, checkedModels); - break label; - } - } - TranslationManager.instance().log("warning.config.resource_pack.generation.missing_parent_model", rl.asString(), parentModelPath); - } - } - } - if (modelJson.has("textures")) { - JsonObject textures = modelJson.get("textures").getAsJsonObject(); - for (Map.Entry entry : textures.entrySet()) { - String value = entry.getValue().getAsString(); - // fixme 应该报错,这个影响资源包加载 - if (value.isEmpty() || value.charAt(0) == '#') continue; - Key textureResourceLocation = Key.from(value); - imageToModels.put(textureResourceLocation, rl); - } - } - } - private static void collectMultipart(JsonArray jsonArray, Consumer callback) { for (JsonElement element : jsonArray) { if (element instanceof JsonObject jo) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/overlay/ResourcePackOverlay.java b/core/src/main/java/net/momirealms/craftengine/core/pack/overlay/ResourcePackOverlay.java new file mode 100644 index 000000000..960c7da75 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/overlay/ResourcePackOverlay.java @@ -0,0 +1,32 @@ +package net.momirealms.craftengine.core.pack.overlay; + +import net.momirealms.craftengine.core.util.MinecraftVersion; + +import java.nio.file.Path; + +public class ResourcePackOverlay { + private final MinecraftVersion minVersion; + private final MinecraftVersion maxVersion; + private final Path folder; + + public ResourcePackOverlay(MinecraftVersion minVersion, + MinecraftVersion maxVersion, + Path folder + ) { + this.minVersion = minVersion; + this.maxVersion = maxVersion; + this.folder = folder; + } + + public MinecraftVersion minVersion() { + return minVersion; + } + + public MinecraftVersion maxVersion() { + return maxVersion; + } + + public Path folder() { + return folder; + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LangData.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LangData.java index b677d18a5..fa6689ecd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LangData.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LangData.java @@ -12,7 +12,7 @@ import java.util.function.Function; public class LangData { private static final Map>> LANG_KEY_PROCESSORS = new HashMap<>(); - public Map translations = new HashMap<>(); + public Map translations = new LinkedHashMap<>(); static { LANG_KEY_PROCESSORS.put("block_name", (id) -> { @@ -42,7 +42,7 @@ public class LangData { } public void processTranslations() { - Map temp = new HashMap<>(Math.max(10, this.translations.size())); + Map temp = new LinkedHashMap<>(Math.max(10, this.translations.size())); for (Map.Entry entry : this.translations.entrySet()) { String key = entry.getKey(); String[] split = key.split(":", 2);