From 89fc7639a596d347fedf8d8fe8f0be79145b2710 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Fri, 19 Dec 2025 03:30:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96overlay=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resolution/ResolutionMergePackMcMeta.java | 64 ++++++------------- .../craftengine/core/pack/mcmeta/Overlay.java | 6 ++ .../core/pack/mcmeta/PackVersion.java | 7 +- 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java index ef7057ec0..e0ff95b11 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java @@ -8,7 +8,6 @@ import com.google.gson.JsonPrimitive; import net.momirealms.craftengine.core.pack.conflict.PathContext; import net.momirealms.craftengine.core.pack.mcmeta.PackVersion; import net.momirealms.craftengine.core.plugin.CraftEngine; -import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.util.GsonHelper; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Pair; @@ -18,9 +17,6 @@ import java.nio.file.Path; import java.util.*; import java.util.function.Consumer; -import static net.momirealms.craftengine.core.pack.mcmeta.PackVersion.MAX_PACK_VERSION; -import static net.momirealms.craftengine.core.pack.mcmeta.PackVersion.MIN_PACK_VERSION; - public class ResolutionMergePackMcMeta implements Resolution { public static final Factory FACTORY = new Factory(); public static final Set STANDARD_PACK_KEYS = ImmutableSet.of("pack", "features", "filter", "overlays", "language"); @@ -157,7 +153,7 @@ public class ResolutionMergePackMcMeta implements Resolution { if (entry.isJsonObject()) { JsonObject entryJson = entry.getAsJsonObject(); if (entryJson == null) continue; - Pair supportedVersions = getSupportedVersions(entryJson); + Pair supportedVersions = getOverlayVersions(entryJson); PackVersion min = PackVersion.getHigher(supportedVersions.left(), PackVersion.MIN_OVERLAY_VERSION); PackVersion max = PackVersion.getHigher(supportedVersions.right(), PackVersion.MIN_OVERLAY_VERSION); // 旧版格式支持 @@ -179,51 +175,27 @@ public class ResolutionMergePackMcMeta implements Resolution { } } - public static void mergePack(JsonObject merged, JsonObject pack1, JsonObject pack2) { - Pair pack1Version = getSupportedVersions(pack1); - Pair pack2Version = getSupportedVersions(pack2); - PackVersion min = Config.packMinVersion().packFormat(); - PackVersion max = PackVersion.getHigher(PackVersion.getHigher(pack1Version.right(), pack2Version.right()), Config.packMaxVersion().packFormat()); - // 旧版格式支持 - JsonObject supportedFormats = new JsonObject(); - supportedFormats.addProperty("min_inclusive", min.major()); - supportedFormats.addProperty("max_inclusive", max.major()); - merged.add("supported_formats", supportedFormats); - merged.addProperty("pack_format", min.major()); - // 新版格式支持 - JsonArray minFormat = new JsonArray(); - minFormat.add(min.major()); - minFormat.add(min.minor()); - merged.add("min_format", minFormat); - JsonArray maxFormat = new JsonArray(); - maxFormat.add(max.major()); - maxFormat.add(max.minor()); - merged.add("max_format", maxFormat); - } - - private static Pair getSupportedVersions(JsonObject pack) { - if (pack == null) return Pair.of(MIN_PACK_VERSION, MAX_PACK_VERSION); + private static Pair getOverlayVersions(JsonObject pack) { + if (pack == null) return Pair.of(PackVersion.MIN_OVERLAY_VERSION, PackVersion.MAX_PACK_VERSION); List minVersions = new ArrayList<>(); List maxVersions = new ArrayList<>(); - if (pack.has("pack_format")) { - minVersions.add(new PackVersion(pack.get("pack_format").getAsInt(), 0)); - } if (pack.has("min_format")) { - minVersions.add(getFormatVersion(pack.get("min_format"), MIN_PACK_VERSION)); + minVersions.add(getFormatVersion(pack.get("min_format"), PackVersion.MIN_OVERLAY_VERSION)); } if (pack.has("max_format")) { - maxVersions.add(getFormatVersion(pack.get("max_format"), MAX_PACK_VERSION)); - } - if (pack.has("supported_formats")) { - Pair supportedFormats = parseSupportedFormats(pack.get("supported_formats")); - minVersions.add(supportedFormats.left()); - maxVersions.add(supportedFormats.right()); + maxVersions.add(getFormatVersion(pack.get("max_format"), PackVersion.MAX_PACK_VERSION)); } if (pack.has("formats")) { Pair supportedFormats = parseSupportedFormats(pack.get("formats")); minVersions.add(supportedFormats.left()); maxVersions.add(supportedFormats.right()); } + if (maxVersions.isEmpty()) { + maxVersions.add(PackVersion.MAX_PACK_VERSION); + } + if (minVersions.isEmpty()) { + minVersions.add(PackVersion.MIN_OVERLAY_VERSION); + } return Pair.of( PackVersion.getLowest(minVersions), PackVersion.getHighest(maxVersions) @@ -233,29 +205,29 @@ public class ResolutionMergePackMcMeta implements Resolution { private static Pair parseSupportedFormats(JsonElement formats) { switch (formats) { case null -> { - return Pair.of(MIN_PACK_VERSION, MAX_PACK_VERSION); + return Pair.of(PackVersion.MIN_OVERLAY_VERSION, PackVersion.MAX_PACK_VERSION); } case JsonPrimitive jsonPrimitive -> { return new Pair<>(new PackVersion(jsonPrimitive.getAsInt(), 0), new PackVersion(jsonPrimitive.getAsInt(), 0)); } case JsonArray array -> { - if (array.isEmpty()) return Pair.of(MIN_PACK_VERSION, MAX_PACK_VERSION); + if (array.isEmpty()) return Pair.of(PackVersion.MIN_OVERLAY_VERSION, PackVersion.MAX_PACK_VERSION); if (array.size() == 1) { - return new Pair<>(new PackVersion(GsonHelper.getAsInt(array.get(0), MIN_PACK_VERSION.major()), 0), MAX_PACK_VERSION); + return new Pair<>(new PackVersion(GsonHelper.getAsInt(array.get(0), PackVersion.MIN_OVERLAY_VERSION.major()), 0), PackVersion.MAX_PACK_VERSION); } if (array.size() == 2) { - return new Pair<>(new PackVersion(GsonHelper.getAsInt(array.get(0), MIN_PACK_VERSION.major()), 0), new PackVersion(GsonHelper.getAsInt(array.get(1), MAX_PACK_VERSION.major()), 0)); + return new Pair<>(new PackVersion(GsonHelper.getAsInt(array.get(0), PackVersion.MIN_OVERLAY_VERSION.major()), 0), new PackVersion(GsonHelper.getAsInt(array.get(1), PackVersion.MAX_PACK_VERSION.major()), 0)); } } case JsonObject object -> { - int min = GsonHelper.getAsInt(object.get("min_inclusive"), MIN_PACK_VERSION.major()); - int max = GsonHelper.getAsInt(object.get("max_inclusive"), MAX_PACK_VERSION.major()); + int min = GsonHelper.getAsInt(object.get("min_inclusive"), PackVersion.MIN_OVERLAY_VERSION.major()); + int max = GsonHelper.getAsInt(object.get("max_inclusive"), PackVersion.MAX_PACK_VERSION.major()); return new Pair<>(new PackVersion(min, 0), new PackVersion(max, 0)); } default -> { } } - return Pair.of(MIN_PACK_VERSION, MAX_PACK_VERSION); + return Pair.of(PackVersion.MIN_OVERLAY_VERSION, PackVersion.MAX_PACK_VERSION); } private static PackVersion getFormatVersion(JsonElement format, PackVersion defaultVersion) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/Overlay.java b/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/Overlay.java index a40b02acc..12709b893 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/Overlay.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/Overlay.java @@ -91,6 +91,12 @@ public class Overlay { minVersions.add(supportedFormats.left()); maxVersions.add(supportedFormats.right()); } + if (maxVersions.isEmpty()) { + maxVersions.add(PackVersion.MAX_PACK_VERSION); + } + if (minVersions.isEmpty()) { + minVersions.add(PackVersion.MIN_OVERLAY_VERSION); + } return Pair.of( PackVersion.getLowest(minVersions), PackVersion.getHighest(maxVersions) diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/PackVersion.java b/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/PackVersion.java index 4022e9bd5..79cc07d8f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/PackVersion.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/mcmeta/PackVersion.java @@ -6,8 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; public record PackVersion(int major, int minor) implements Comparable { - public static final PackVersion MIN_PACK_VERSION = new PackVersion(15, 0); // 1.20 - public static final PackVersion MIN_OVERLAY_VERSION = new PackVersion(18, 0); // 1.20 + public static final PackVersion MIN_OVERLAY_VERSION = new PackVersion(18, 0); // 1.20.2 public static final PackVersion PACK_FORMAT_CHANGE_VERSION = new PackVersion(65, 0); // 25w31a public static final PackVersion MAX_PACK_VERSION = new PackVersion(1000, 0); // future @@ -77,7 +76,7 @@ public record PackVersion(int major, int minor) implements Comparable versions) { if (versions == null || versions.isEmpty()) { - return MIN_PACK_VERSION; + return null; } PackVersion lowest = versions.getFirst(); @@ -89,7 +88,7 @@ public record PackVersion(int major, int minor) implements Comparable versions) { if (versions == null || versions.isEmpty()) { - return MAX_PACK_VERSION; + return null; } PackVersion highest = versions.getFirst();