9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

打倒了atlas恶魔

This commit is contained in:
XiaoMoMi
2025-12-18 04:41:32 +08:00
parent 4262015da5
commit 37b8b06a58
5 changed files with 39 additions and 29 deletions

View File

@@ -203,10 +203,9 @@ fun registerPaperTask(
version: String,
dirName: String = version,
javaVersion : Int = 21,
serverJar: File? = null,
downloadPlugins: Action<DownloadPluginsSpec>? = null
serverJar: File? = null
) {
listOf(version, "${version}-with-viaversion").forEach { taskName ->
listOf(version).forEach { taskName ->
tasks.register(taskName, RunServer::class) {
group = "run dev server"
minecraftVersion(version)
@@ -224,18 +223,6 @@ fun registerPaperTask(
jvmArgs("-Ddisable.watchdog=true")
jvmArgs("-Xlog:redefine+class*=info")
jvmArgs("-XX:+AllowEnhancedClassRedefinition")
if (taskName.contains("viaversion")) {
downloadPlugins {
url("https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/${getJenkinsArtifactFileName("https://ci.viaversion.com/job/ViaVersion/lastSuccessfulBuild/api/json?tree=artifacts[*]")}")
url("https://ci.viaversion.com/view/ViaBackwards/job/ViaBackwards/662/artifact/build/libs/${getJenkinsArtifactFileName("https://ci.viaversion.com/job/ViaBackwards/lastSuccessfulBuild/api/json?tree=artifacts[*]")}")
}
}
}
}
}
fun getJenkinsArtifactFileName(url: String): String {
val response = URI.create(url).toURL().readText()
val regex = """"fileName":"([^"]+)"""".toRegex()
return regex.find(response)?.groupValues?.get(1) ?: throw Exception("fileName not found")
}

View File

@@ -16,8 +16,9 @@ resource-pack:
# This option determines the location of the generated resource pack
# You can use either an absolute path or a relative path here
path: "./generated/resource_pack.zip"
# The minimum client version supported by CraftEngine is 1.20. If you need to provide support for lower client versions, please modify the resource pack yourself.
# Allowed values:
# - 1.20.1, 1.21, 1.21.8, etc.
# - 1.20.2, 1.21, 1.21.8, etc.
# - latest: the latest client version
# - server: the current server version
supported-version:

View File

@@ -865,9 +865,8 @@ public abstract class AbstractPackManager implements PackManager {
}
for (Revision revision : revisions) {
JsonObject entry = new JsonObject();
JsonObject formats = new JsonObject();
entry.add("formats", formats);
JsonArray formatsArray = new JsonArray();
entry.add("formats", formatsArray);
formatsArray.add(revision.minPackVersion().major());
formatsArray.add(revision.maxPackVersion().major());
entry.add("min_format", revision.minPackVersion().getAsJsonArray());
@@ -1188,8 +1187,10 @@ public abstract class AbstractPackManager implements PackManager {
private void validateResourcePack(Path path) {
Path packMcMetaPath = path.resolve("pack.mcmeta");
PackMcMeta packMeta;
JsonObject packMetaJson;
try {
packMeta = new PackMcMeta(GsonHelper.readJsonFile(packMcMetaPath).getAsJsonObject());
packMetaJson = GsonHelper.readJsonFile(packMcMetaPath).getAsJsonObject();
packMeta = new PackMcMeta(packMetaJson);
} catch (IOException e) {
this.plugin.logger().warn("Failed to read pack.mcmeta " + packMcMetaPath.toAbsolutePath(), e);
return;
@@ -1256,7 +1257,7 @@ public abstract class AbstractPackManager implements PackManager {
this.plugin.logger().info(TranslationManager.instance().translateLog("info.resource_pack.validate.start",
String.valueOf(i + 1), String.valueOf(size), String.valueOf(segment.min()), String.valueOf(segment.max()), overlayInOrder.stream().map(Overlay::directory).toList().toString()));
ValidationResult result = validateOverlayedResourcePack(rootPathList.toArray(new Path[0]), segment.max() >= MinecraftVersion.V1_21_11.packFormat().major());
if (Config.fixTextureAtlas()) {
if (Config.fixTextureAtlas() && !Config.enableObfuscation()) {
// 有修复物品
if (result.fixedItemAtlas != null) {
itemFixer.addEntry(segment.min(), segment.max(), result.fixedItemAtlas);
@@ -1272,7 +1273,7 @@ public abstract class AbstractPackManager implements PackManager {
}
// 尝试修复atlas
if (Config.fixTextureAtlas()) {
if (Config.fixTextureAtlas() && !Config.enableObfuscation()) {
Map<String, JsonObject> atlasToAdd = new LinkedHashMap<>();
// 物品
for (AtlasFixer.Entry entry : itemFixer.entries()) {
@@ -1296,7 +1297,7 @@ public abstract class AbstractPackManager implements PackManager {
}
}
// 方块
for (AtlasFixer.Entry entry : itemFixer.entries()) {
for (AtlasFixer.Entry entry : blockFixer.entries()) {
int min = entry.min();
int max = entry.max();
String directoryName = Config.createOverlayFolderName(min + "-" + max);
@@ -1330,6 +1331,25 @@ public abstract class AbstractPackManager implements PackManager {
}
}
}
JsonObject overlaysJson = packMetaJson.getAsJsonObject("overlays");
if (overlaysJson == null) {
overlaysJson = new JsonObject();
packMetaJson.add("overlays", overlaysJson);
}
JsonArray overlayEntries = overlaysJson.getAsJsonArray("entries");
if (overlayEntries == null) {
overlayEntries = new JsonArray();
overlaysJson.add("entries", overlayEntries);
}
for (JsonElement entry : atlasToAdd.values()) {
overlayEntries.add(entry);
}
try {
GsonHelper.writeJsonFile(packMetaJson, packMcMetaPath);
} catch (IOException e) {
this.plugin.logger().warn("Failed to write pack.mcmeta", e);
}
}
}

View File

@@ -8,6 +8,7 @@ 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.AdventureHelper;
import net.momirealms.craftengine.core.util.GsonHelper;
import net.momirealms.craftengine.core.util.Key;
@@ -162,12 +163,12 @@ public class ResolutionMergePackMcMeta implements Resolution {
JsonObject entryJson = entry.getAsJsonObject();
if (entryJson == null) continue;
Pair<PackVersion, PackVersion> supportedVersions = getSupportedVersions(entryJson);
PackVersion min = supportedVersions.left();
PackVersion max = supportedVersions.right();
PackVersion min = PackVersion.getHigher(supportedVersions.left(), PackVersion.MIN_OVERLAY_VERSION);
PackVersion max = PackVersion.getHigher(supportedVersions.right(), PackVersion.MIN_OVERLAY_VERSION);
// 旧版格式支持
JsonObject supportedFormats = new JsonObject();
supportedFormats.addProperty("min_inclusive", min.major());
supportedFormats.addProperty("max_inclusive", max.major());
JsonArray supportedFormats = new JsonArray();
supportedFormats.add(min.major());
supportedFormats.add(max.major());
entryJson.add("formats", supportedFormats);
// 新版格式支持
JsonArray minFormat = new JsonArray();
@@ -186,8 +187,8 @@ public class ResolutionMergePackMcMeta implements Resolution {
public static void mergePack(JsonObject merged, JsonObject pack1, JsonObject pack2) {
Pair<PackVersion, PackVersion> pack1Version = getSupportedVersions(pack1);
Pair<PackVersion, PackVersion> pack2Version = getSupportedVersions(pack2);
PackVersion min = PackVersion.getLower(pack1Version.left(), pack2Version.left());
PackVersion max = PackVersion.getHigher(pack1Version.right(), pack2Version.right());
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());

View File

@@ -7,6 +7,7 @@ import java.util.List;
public record PackVersion(int major, int minor) implements Comparable<PackVersion> {
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 MAX_PACK_VERSION = new PackVersion(1000, 0); // future
public PackVersion(int major) {