diff --git a/common-files/src/main/resources/config.yml b/common-files/src/main/resources/config.yml index 4f14758e1..3203ee842 100644 --- a/common-files/src/main/resources/config.yml +++ b/common-files/src/main/resources/config.yml @@ -23,6 +23,7 @@ resource-pack: method-1: false method-2: false method-3: false # Enable this would increase the resource pack size by 0.67MB + # [Premium Exclusive] # Obfuscate your resource pack obfuscation: enable: false @@ -50,9 +51,13 @@ resource-pack: - "@vanilla_models" bypass-sounds: [] bypass-equipments: [] - # Validate if there are any errors in the resource pack, such as missing textures or models - validate: + # Validate if there is any error in the resource pack, such as missing textures or models + # If your resource pack is compliant with the standard, you can disable validation to improve the resource pack generation speed. + validation: enable: true + # [Premium Exclusive] + # Fix images that are not within the texture atlas. + fix-atlas: true # Define the name of the overlay folders overlay-format: "ce_overlay_{version}" # Allowed values: @@ -138,6 +143,7 @@ resource-pack: type: merge_atlas item: + # [Premium Exclusive] # Make custom-model-data and item-model clientside by default client-bound-model: true # Add a tag on custom name and lore 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 268e9bdc9..f74448582 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 @@ -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 existingTextures = new HashSet<>(VANILLA_TEXTURES); Map directoryMapper = new HashMap<>(); processAtlas(this.vanillaAtlas, directoryMapper::put, existingTextures::add, texturesInAtlas::add); + Map 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 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 texturesToFix = new HashSet<>(); + // 验证贴图是否存在 boolean enableObf = Config.enableObfuscation() && Config.enableRandomResourceLocation(); label: for (Map.Entry> 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 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 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); + } } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java index 1cb3d542b..8f36b8752 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java @@ -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() { diff --git a/gradle.properties b/gradle.properties index c3f2fe021..94725baf0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] project_version=0.0.63.7 -config_version=46 +config_version=47 lang_version=31 project_group=net.momirealms latest_supported_version=1.21.8