From 4cb2825b46ba6e65ec1d30e1ed1822157f91e2c4 Mon Sep 17 00:00:00 2001 From: zimzaza4 <3625282098@qq.com> Date: Sun, 21 Apr 2024 19:30:53 +0800 Subject: [PATCH] dont rewrite all files --- .../ExtensionMain.java | 1 - .../GeneratorMain.java | 50 +++++++++++++++---- .../generator/Entity.java | 15 ++++-- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/main/java/re/imc/geysermodelenginepackgenerator/ExtensionMain.java b/src/main/java/re/imc/geysermodelenginepackgenerator/ExtensionMain.java index c561629..1401708 100644 --- a/src/main/java/re/imc/geysermodelenginepackgenerator/ExtensionMain.java +++ b/src/main/java/re/imc/geysermodelenginepackgenerator/ExtensionMain.java @@ -39,7 +39,6 @@ public class ExtensionMain implements Extension { GeneratorMain.startGenerate(source, generatedPack); - Path generatedPackZip = dataFolder().resolve("generated_pack.zip"); try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) { diff --git a/src/main/java/re/imc/geysermodelenginepackgenerator/GeneratorMain.java b/src/main/java/re/imc/geysermodelenginepackgenerator/GeneratorMain.java index ee63a65..c764568 100644 --- a/src/main/java/re/imc/geysermodelenginepackgenerator/GeneratorMain.java +++ b/src/main/java/re/imc/geysermodelenginepackgenerator/GeneratorMain.java @@ -2,10 +2,12 @@ package re.imc.geysermodelenginepackgenerator; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import com.google.gson.JsonParser; import re.imc.geysermodelenginepackgenerator.generator.*; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -13,6 +15,7 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; +import java.util.UUID; public class GeneratorMain { public static final Map entityMap = new HashMap<>(); @@ -42,12 +45,20 @@ public class GeneratorMain { } String modelId = file1.getName().toLowerCase(); - entityMap.put(modelId, new Entity(modelId)); + Entity entity = new Entity(modelId); + entityMap.put(modelId, entity); + for (File e : file1.listFiles()) { if (e.getName().endsWith(".png")) { textureMap.put(modelId, new Texture(modelId, e.toPath())); } - + if (e.getName().equals("config.properties")) { + try { + entity.getProperties().load(new FileReader(e)); + } catch (IOException ex) { + ex.printStackTrace(); + } + } if (e.getName().endsWith(".json")) { try { String json = Files.readString(e.toPath()); @@ -83,18 +94,28 @@ public class GeneratorMain { generateManifest = true; } File[] files = entityFolder.listFiles(); - if (files == null || files.length < entityMap.size()) { + if (files == null || files.length != entityMap.size()) { generateManifest = true; } if (generateManifest) { output.mkdirs(); Path path = new File(output, "manifest.json").toPath(); - try { - Files.writeString(path, - PackManifest.generate(), StandardCharsets.UTF_8); - } catch (IOException e) { - e.printStackTrace(); + if (path.toFile().exists()) { + try { + JsonObject manifest = new JsonParser().parse(Files.readString(path)).getAsJsonObject(); + manifest.get("header").getAsJsonObject().addProperty("uuid", UUID.randomUUID().toString()); + Files.writeString(path, GSON.toJson(manifest)); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + try { + Files.writeString(path, + PackManifest.generate(), StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } } } @@ -110,6 +131,9 @@ public class GeneratorMain { stringAnimationEntry.getValue().addHeadBind(geo); } Path path = animationsFolder.toPath().resolve(stringAnimationEntry.getKey() + ".animation.json"); + if (path.toFile().exists()) { + continue; + } try { Files.writeString(path, GSON.toJson(stringAnimationEntry.getValue().getJson()), StandardCharsets.UTF_8); } catch (IOException e) { @@ -120,6 +144,9 @@ public class GeneratorMain { for (Map.Entry stringGeometryEntry : geometryMap.entrySet()) { stringGeometryEntry.getValue().modify(); Path path = modelsFolder.toPath().resolve(stringGeometryEntry.getKey() + ".geo.json"); + if (path.toFile().exists()) { + continue; + } try { Files.writeString(path, GSON.toJson(stringGeometryEntry.getValue().getJson()), StandardCharsets.UTF_8); } catch (IOException e) { @@ -129,6 +156,9 @@ public class GeneratorMain { for (Map.Entry stringTextureEntry : textureMap.entrySet()) { Path path = texturesFolder.toPath().resolve(stringTextureEntry.getKey() + ".png"); + if (path.toFile().exists()) { + continue; + } try { Files.copy(stringTextureEntry.getValue().getPath(), path, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { @@ -139,7 +169,9 @@ public class GeneratorMain { for (Map.Entry stringEntityEntry : entityMap.entrySet()) { stringEntityEntry.getValue().modify(); Path path = entityFolder.toPath().resolve(stringEntityEntry.getKey() + ".entity.json"); - + if (path.toFile().exists()) { + continue; + } try { Files.writeString(path, stringEntityEntry.getValue().getJson(), StandardCharsets.UTF_8); } catch (IOException e) { diff --git a/src/main/java/re/imc/geysermodelenginepackgenerator/generator/Entity.java b/src/main/java/re/imc/geysermodelenginepackgenerator/generator/Entity.java index 4d0d621..b6c7a4a 100644 --- a/src/main/java/re/imc/geysermodelenginepackgenerator/generator/Entity.java +++ b/src/main/java/re/imc/geysermodelenginepackgenerator/generator/Entity.java @@ -5,6 +5,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import java.util.Properties; + @Getter @Setter @AllArgsConstructor @@ -17,7 +19,7 @@ public class Entity { "description": { "identifier": "modelengine:%entity_id%", "materials": { - "default": "entity_alphatest" + "default": "%material%" }, "textures": { "default": "%texture%" @@ -37,7 +39,7 @@ public class Entity { ] }, "render_controllers": [ - "controller.render.default" + "%render_controller%" ] } } @@ -48,6 +50,9 @@ public class Entity { String modelId; String json; boolean hasHeadAnimation = false; + + Properties properties = new Properties(); + public Entity(String modelId) { this.modelId = modelId; } @@ -56,7 +61,11 @@ public class Entity { json = TEMPLATE.replace("%entity_id%", modelId) .replace("%geometry%", "geometry.modelengine_" + modelId) .replace("%texture%", "textures/entity/" + modelId) - .replace("%look_at_target%", hasHeadAnimation ? "animation." + modelId + ".look_at_target" : "animation.common.look_at_target") + .replace("%look_at_target%", "animation." + modelId + ".look_at_target") + .replace("%material%", properties.getProperty("material", "entity_alphatest")) + .replace("%render_controller%", properties.getProperty("render_controller", "controller.render.default")) + + ; }