mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 20:09:13 +00:00
添加atlas修复功能
This commit is contained in:
@@ -866,9 +866,6 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "filter", "minecraft:filter" -> {
|
||||
// todo filter
|
||||
}
|
||||
case "paletted_permutations", "minecraft:paletted_permutations" -> {
|
||||
JsonArray textures = sourceJson.getAsJsonArray("textures");
|
||||
if (textures == null) continue;
|
||||
@@ -883,6 +880,9 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "filter", "minecraft:filter" -> {
|
||||
// todo filter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -908,28 +908,32 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
Set<Key> existingTextures = new HashSet<>(VANILLA_TEXTURES);
|
||||
Map<String, String> directoryMapper = new HashMap<>();
|
||||
processAtlas(this.vanillaAtlas, directoryMapper::put, existingTextures::add, texturesInAtlas::add);
|
||||
Map<Path, JsonObject> allAtlas = new HashMap<>();
|
||||
|
||||
for (Path rootPath : rootPaths) {
|
||||
Path assetsPath = rootPath.resolve("assets");
|
||||
if (!Files.isDirectory(assetsPath)) continue;
|
||||
|
||||
Path atlasesFile = assetsPath.resolve("minecraft").resolve("atlases").resolve("blocks.json");
|
||||
if (Files.exists(atlasesFile)) {
|
||||
try {
|
||||
JsonObject atlasJsonObject = GsonHelper.readJsonFile(atlasesFile).getAsJsonObject();
|
||||
processAtlas(atlasJsonObject, directoryMapper::put, existingTextures::add, texturesInAtlas::add);
|
||||
allAtlas.put(atlasesFile, atlasJsonObject);
|
||||
} catch (IOException | JsonParseException e) {
|
||||
TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", atlasesFile.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
List<Path> namespaces;
|
||||
try {
|
||||
namespaces = FileUtils.collectNamespaces(assetsPath);
|
||||
} catch (IOException e) {
|
||||
plugin.logger().warn("Failed to collect namespaces for " + assetsPath.toAbsolutePath(), e);
|
||||
this.plugin.logger().warn("Failed to collect namespaces for " + assetsPath.toAbsolutePath(), e);
|
||||
return;
|
||||
}
|
||||
for (Path namespacePath : namespaces) {
|
||||
Path atlasesFile = namespacePath.resolve("atlases").resolve("blocks.json");
|
||||
if (Files.exists(atlasesFile)) {
|
||||
try {
|
||||
JsonObject atlasJsonObject = GsonHelper.readJsonFile(atlasesFile).getAsJsonObject();
|
||||
processAtlas(atlasJsonObject, directoryMapper::put, existingTextures::add, texturesInAtlas::add);
|
||||
} catch (IOException | JsonParseException e) {
|
||||
TranslationManager.instance().log("warning.config.resource_pack.generation.malformatted_json", atlasesFile.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (Path namespacePath : namespaces) {
|
||||
Path fontPath = namespacePath.resolve("font");
|
||||
if (Files.isDirectory(fontPath)) {
|
||||
try {
|
||||
@@ -1079,6 +1083,8 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
TranslationManager.instance().log("warning.config.resource_pack.generation.missing_block_model", entry.getValue().stream().distinct().toList().toString(), modelPath);
|
||||
}
|
||||
|
||||
Set<Key> texturesToFix = new HashSet<>();
|
||||
|
||||
// 验证贴图是否存在
|
||||
boolean enableObf = Config.enableObfuscation() && Config.enableRandomResourceLocation();
|
||||
label: for (Map.Entry<Key, Collection<Key>> entry : imageToModels.asMap().entrySet()) {
|
||||
@@ -1108,7 +1114,48 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
continue label;
|
||||
}
|
||||
}
|
||||
TranslationManager.instance().log("warning.config.resource_pack.generation.texture_not_in_atlas", key.toString());
|
||||
if (Config.fixTextureAtlas()) {
|
||||
texturesToFix.add(key);
|
||||
} else {
|
||||
TranslationManager.instance().log("warning.config.resource_pack.generation.texture_not_in_atlas", key.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.fixTextureAtlas() && !texturesToFix.isEmpty()) {
|
||||
List<JsonObject> sourcesToAdd = new ArrayList<>();
|
||||
for (Key toFix : texturesToFix) {
|
||||
JsonObject source = new JsonObject();
|
||||
source.addProperty("type", "single");
|
||||
source.addProperty("resource", toFix.asString());
|
||||
sourcesToAdd.add(source);
|
||||
}
|
||||
|
||||
Path defaultAtlas = path.resolve("assets").resolve("minecraft").resolve("atlases").resolve("blocks.json");
|
||||
if (!allAtlas.containsKey(defaultAtlas)) {
|
||||
allAtlas.put(defaultAtlas, new JsonObject());
|
||||
try {
|
||||
Files.createDirectories(defaultAtlas.getParent());
|
||||
} catch (IOException e) {
|
||||
this.plugin.logger().warn("could not create default atlas directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Path, JsonObject> atlas : allAtlas.entrySet()) {
|
||||
JsonObject right = atlas.getValue();
|
||||
JsonArray sources = right.getAsJsonArray("sources");
|
||||
if (sources == null) {
|
||||
sources = new JsonArray();
|
||||
right.add("sources", sources);
|
||||
}
|
||||
for (JsonObject source : sourcesToAdd) {
|
||||
sources.add(source);
|
||||
}
|
||||
try {
|
||||
GsonHelper.writeJsonFile(right, atlas.getKey());
|
||||
} catch (IOException e) {
|
||||
this.plugin.logger().warn("Failed to write atlas to json file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ public class Config {
|
||||
protected boolean resource_pack$protection$crash_tools$method_2;
|
||||
protected boolean resource_pack$protection$crash_tools$method_3;
|
||||
|
||||
protected boolean resource_pack$validate$enable;
|
||||
protected boolean resource_pack$validation$enable;
|
||||
protected boolean resource_pack$validation$fix_atlas;
|
||||
protected boolean resource_pack$exclude_core_shaders;
|
||||
|
||||
protected boolean resource_pack$protection$obfuscation$enable;
|
||||
@@ -296,7 +297,7 @@ public class Config {
|
||||
resource_pack$protection$crash_tools$method_1 = config.getBoolean("resource-pack.protection.crash-tools.method-1", false);
|
||||
resource_pack$protection$crash_tools$method_2 = config.getBoolean("resource-pack.protection.crash-tools.method-2", false);
|
||||
resource_pack$protection$crash_tools$method_3 = config.getBoolean("resource-pack.protection.crash-tools.method-3", false);
|
||||
resource_pack$protection$obfuscation$enable = config.getBoolean("resource-pack.protection.obfuscation.enable", false);
|
||||
resource_pack$protection$obfuscation$enable = VersionHelper.PREMIUM && config.getBoolean("resource-pack.protection.obfuscation.enable", false);
|
||||
resource_pack$protection$obfuscation$seed = config.getLong("resource-pack.protection.obfuscation.seed", 0L);
|
||||
resource_pack$protection$obfuscation$fake_directory = config.getBoolean("resource-pack.protection.obfuscation.fake-directory", false);
|
||||
resource_pack$protection$obfuscation$escape_unicode = config.getBoolean("resource-pack.protection.obfuscation.escape-unicode", false);
|
||||
@@ -313,7 +314,8 @@ public class Config {
|
||||
resource_pack$protection$obfuscation$resource_location$bypass_models = config.getStringList("resource-pack.protection.obfuscation.resource-location.bypass-models");
|
||||
resource_pack$protection$obfuscation$resource_location$bypass_sounds = config.getStringList("resource-pack.protection.obfuscation.resource-location.bypass-sounds");
|
||||
resource_pack$protection$obfuscation$resource_location$bypass_equipments = config.getStringList("resource-pack.protection.obfuscation.resource-location.bypass-equipments");
|
||||
resource_pack$validate$enable = config.getBoolean("resource-pack.validate.enable", true);
|
||||
resource_pack$validation$enable = config.getBoolean("resource-pack.validation.enable", true);
|
||||
resource_pack$validation$fix_atlas = VersionHelper.PREMIUM && config.getBoolean("resource-pack.validation.fix-atlas", true);
|
||||
resource_pack$exclude_core_shaders = config.getBoolean("resource-pack.exclude-core-shaders", false);
|
||||
resource_pack$overlay_format = config.getString("resource-pack.overlay-format", "overlay_{version}");
|
||||
if (!resource_pack$overlay_format.contains("{version}")) {
|
||||
@@ -895,7 +897,11 @@ public class Config {
|
||||
}
|
||||
|
||||
public static boolean validateResourcePack() {
|
||||
return instance.resource_pack$validate$enable;
|
||||
return instance.resource_pack$validation$enable;
|
||||
}
|
||||
|
||||
public static boolean fixTextureAtlas() {
|
||||
return instance.resource_pack$validation$fix_atlas;
|
||||
}
|
||||
|
||||
public static boolean excludeShaders() {
|
||||
|
||||
Reference in New Issue
Block a user