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-15 22:11:51 +08:00
parent 898ab0a979
commit c17455c547
2 changed files with 29 additions and 21 deletions

View File

@@ -1248,8 +1248,8 @@ public abstract class AbstractPackManager implements PackManager {
Multimap<Key, Key> textureToEquipments = ArrayListMultimap.create(); // 纹理到盔甲的映射 Multimap<Key, Key> textureToEquipments = ArrayListMultimap.create(); // 纹理到盔甲的映射
Multimap<Key, Key> oggToSoundEvents = ArrayListMultimap.create(); // 音频到声音的映射 Multimap<Key, Key> oggToSoundEvents = ArrayListMultimap.create(); // 音频到声音的映射
Map<Path, JsonObject> blockAtlasJsons = new HashMap<>(); Map<Path, JsonObject> blockAtlasJsons = new LinkedHashMap<>();
Map<Path, JsonObject> itemAtlasJsons = new HashMap<>(); Map<Path, JsonObject> itemAtlasJsons = new LinkedHashMap<>();
// 如果需要验证资源包则需要先读取所有atlas // 如果需要验证资源包则需要先读取所有atlas
for (Path rootPath : rootPaths) { for (Path rootPath : rootPaths) {
@@ -1291,6 +1291,24 @@ public abstract class AbstractPackManager implements PackManager {
itemAtlasJsons.put(defaultItemAtlas, new JsonObject()); itemAtlasJsons.put(defaultItemAtlas, new JsonObject());
} }
/*
构建Atlas文件
*/
Atlas blockAtlas = new Atlas(MiscUtils.make(new ArrayList<>(), k -> {
k.add(blockAtlasJsons.get(defaultBlockAtlas));
k.add(this.vanillaBlockAtlas);
return k;
}));
Atlas itemAtlas = new Atlas(MiscUtils.make(new ArrayList<>(), k -> {
k.add(itemAtlasJsons.get(defaultItemAtlas));
k.add(this.vanillaItemAtlas);
return k;
}));
for (Path rootPath : rootPaths) { for (Path rootPath : rootPaths) {
Path assetsPath = rootPath.resolve("assets"); Path assetsPath = rootPath.resolve("assets");
if (!Files.isDirectory(assetsPath)) continue; if (!Files.isDirectory(assetsPath)) continue;
@@ -1512,24 +1530,6 @@ public abstract class AbstractPackManager implements PackManager {
/* /*
构建Atlas文件
*/
Atlas blockAtlas = new Atlas(MiscUtils.make(new ArrayList<>(), k -> {
k.addAll(blockAtlasJsons.values());
k.add(this.vanillaBlockAtlas);
return k;
}));
Atlas itemAtlas = new Atlas(MiscUtils.make(new ArrayList<>(), k -> {
k.addAll(itemAtlasJsons.values());
k.add(this.vanillaItemAtlas);
return k;
}));
/*
收集全部 含有贴图的有效模型阶段 收集全部 含有贴图的有效模型阶段
有效指的是被实际使用的模型 有效指的是被实际使用的模型
@@ -1753,7 +1753,7 @@ public abstract class AbstractPackManager implements PackManager {
} }
} }
if (Config.fixTextureAtlas()) { if (Config.fixTextureAtlas() && !Config.enableObfuscation()) {
// 获取两个 Multimap 的所有 key // 获取两个 Multimap 的所有 key
// 找出相同的 key // 找出相同的 key
Set<Key> commonKeys = new LinkedHashSet<>(blockAtlasesToFix.keySet()); Set<Key> commonKeys = new LinkedHashSet<>(blockAtlasesToFix.keySet());
@@ -1792,6 +1792,13 @@ public abstract class AbstractPackManager implements PackManager {
后续我们先对剩余的正常模型进行贴图路径验证此阶段不验证那些存在atlas问题的模型理论已被全部移除 后续我们先对剩余的正常模型进行贴图路径验证此阶段不验证那些存在atlas问题的模型理论已被全部移除
*/ */
// 如果最低支持版本太低了那么全部塞blocks.json里
if (!Config.packMinVersion().isAtOrAbove(MinecraftVersions.V1_21_11)) {
blockAtlasesToFix.putAll(itemAtlasesToFix);
itemAtlasesToFix.clear();
}
if (!itemAtlasesToFix.isEmpty()) { if (!itemAtlasesToFix.isEmpty()) {
List<JsonObject> sourcesToAdd = new ArrayList<>(); List<JsonObject> sourcesToAdd = new ArrayList<>();
for (Key itemTexture : itemAtlasesToFix.keySet()) { for (Key itemTexture : itemAtlasesToFix.keySet()) {

View File

@@ -122,6 +122,7 @@ public final class Atlas {
JsonArray newSources = new JsonArray(); JsonArray newSources = new JsonArray();
atlasJson.add("sources", newSources); atlasJson.add("sources", newSources);
for (JsonObject other : atlasJsons) { for (JsonObject other : atlasJsons) {
if (other == null) continue;
JsonArray sources = other.getAsJsonArray("sources"); JsonArray sources = other.getAsJsonArray("sources");
if (sources != null) { if (sources != null) {
newSources.addAll(sources); newSources.addAll(sources);