mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEnginePackGenerator-extension.git
synced 2025-12-19 14:59:16 +00:00
zip support
This commit is contained in:
@@ -6,14 +6,15 @@ import com.google.gson.JsonParser;
|
|||||||
import re.imc.geysermodelenginepackgenerator.generator.*;
|
import re.imc.geysermodelenginepackgenerator.generator.*;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class GeneratorMain {
|
public class GeneratorMain {
|
||||||
public static final Map<String, Entity> entityMap = new HashMap<>();
|
public static final Map<String, Entity> entityMap = new HashMap<>();
|
||||||
@@ -32,6 +33,84 @@ public class GeneratorMain {
|
|||||||
startGenerate(source, output);
|
startGenerate(source, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void generateFromZip(String currentPath, String modelId, ZipFile zip) {
|
||||||
|
Entity entity = new Entity(modelId);
|
||||||
|
ModelConfig modelConfig = new ModelConfig();
|
||||||
|
ZipEntry textureConfigFile = null;
|
||||||
|
for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) {
|
||||||
|
ZipEntry entry = it.next();
|
||||||
|
if (entry.getName().endsWith("config.json")) {
|
||||||
|
textureConfigFile = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textureConfigFile != null) {
|
||||||
|
try {
|
||||||
|
modelConfig = GSON.fromJson(new InputStreamReader(zip.getInputStream(textureConfigFile)), ModelConfig.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean canAdd = false;
|
||||||
|
for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) {
|
||||||
|
ZipEntry e = it.next();
|
||||||
|
if (e.getName().endsWith(".png")) {
|
||||||
|
String textureName = e.getName().replace(".png", "");
|
||||||
|
Set<String> bindingBones = new HashSet<>();
|
||||||
|
bindingBones.add("*");
|
||||||
|
if (modelConfig.getBingingBones().containsKey(textureName)) {
|
||||||
|
bindingBones = modelConfig.getBingingBones().get(textureName);
|
||||||
|
}
|
||||||
|
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
|
||||||
|
try {
|
||||||
|
map.put(textureName, new Texture(modelId, currentPath, bindingBones, ImageIO.read(zip.getInputStream(e))));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
entity.setTextureMap(map);
|
||||||
|
if (modelConfig.getBingingBones().isEmpty()) {
|
||||||
|
modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (e.getName().endsWith(".json")) {
|
||||||
|
try {
|
||||||
|
InputStream stream = zip.getInputStream(e);
|
||||||
|
String json = new String(stream.readAllBytes());
|
||||||
|
if (isAnimationFile(json)) {
|
||||||
|
Animation animation = new Animation();
|
||||||
|
animation.setPath(currentPath);
|
||||||
|
animation.setModelId(modelId);
|
||||||
|
|
||||||
|
animation.load(json);
|
||||||
|
animationMap.put(modelId, animation);
|
||||||
|
entity.setAnimation(animation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isGeometryFile(json)) {
|
||||||
|
Geometry geometry = new Geometry();
|
||||||
|
geometry.load(json);
|
||||||
|
geometry.setPath(currentPath);
|
||||||
|
geometry.setModelId(modelId);
|
||||||
|
geometryMap.put(modelId, geometry);
|
||||||
|
entity.setGeometry(geometry);
|
||||||
|
canAdd = true;
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (canAdd) {
|
||||||
|
entity.setModelConfig(modelConfig);
|
||||||
|
entity.setPath(currentPath);
|
||||||
|
entityMap.put(modelId, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void generateFromFolder(String currentPath, File folder) {
|
public static void generateFromFolder(String currentPath, File folder) {
|
||||||
if (folder.listFiles() == null) {
|
if (folder.listFiles() == null) {
|
||||||
return;
|
return;
|
||||||
@@ -54,6 +133,13 @@ public class GeneratorMain {
|
|||||||
if (e.isDirectory()) {
|
if (e.isDirectory()) {
|
||||||
generateFromFolder(currentPath + folder.getName() + "/", e);
|
generateFromFolder(currentPath + folder.getName() + "/", e);
|
||||||
}
|
}
|
||||||
|
if (e.getName().endsWith(".zip")) {
|
||||||
|
try {
|
||||||
|
generateFromZip(currentPath, e.getName().replace(".zip", "").toLowerCase(Locale.ROOT), new ZipFile(e));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (e.getName().endsWith(".png")) {
|
if (e.getName().endsWith(".png")) {
|
||||||
String textureName = e.getName().replace(".png", "");
|
String textureName = e.getName().replace(".png", "");
|
||||||
Set<String> bindingBones = new HashSet<>();
|
Set<String> bindingBones = new HashSet<>();
|
||||||
@@ -62,7 +148,11 @@ public class GeneratorMain {
|
|||||||
bindingBones = modelConfig.getBingingBones().get(textureName);
|
bindingBones = modelConfig.getBingingBones().get(textureName);
|
||||||
}
|
}
|
||||||
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
|
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
|
||||||
map.put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
|
try {
|
||||||
|
map.put(textureName, new Texture(modelId, currentPath, bindingBones, ImageIO.read(e)));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
entity.setTextureMap(map);
|
entity.setTextureMap(map);
|
||||||
if (modelConfig.getBingingBones().isEmpty()) {
|
if (modelConfig.getBingingBones().isEmpty()) {
|
||||||
modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||||
@@ -126,17 +216,9 @@ public class GeneratorMain {
|
|||||||
entityMap.put(modelId, entity);
|
entityMap.put(modelId, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startGenerate(File source, File output) {
|
public static void startGenerate(File source, File output) {
|
||||||
|
generateFromFolder("", source);
|
||||||
|
|
||||||
for (File file1 : source.listFiles()) {
|
|
||||||
if (file1.isDirectory()) {
|
|
||||||
if (file1.listFiles() == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
generateFromFolder("", file1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File animationsFolder = new File(output, "animations");
|
File animationsFolder = new File(output, "animations");
|
||||||
File entityFolder = new File(output, "entity");
|
File entityFolder = new File(output, "entity");
|
||||||
@@ -262,7 +344,7 @@ public class GeneratorMain {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Files.copy(entry.getValue().getOriginalPath(), path, StandardCopyOption.REPLACE_EXISTING);
|
ImageIO.write(entry.getValue().getImage(), "png", path.toFile());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package re.imc.geysermodelenginepackgenerator.generator;
|
package re.imc.geysermodelenginepackgenerator.generator;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -14,6 +11,7 @@ import java.util.Set;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ToString
|
||||||
public class ModelConfig {
|
public class ModelConfig {
|
||||||
|
|
||||||
@SerializedName("head_rotation")
|
@SerializedName("head_rotation")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -16,6 +17,6 @@ public class Texture {
|
|||||||
String modelId;
|
String modelId;
|
||||||
String path;
|
String path;
|
||||||
Set<String> bindingBones;
|
Set<String> bindingBones;
|
||||||
Path originalPath;
|
BufferedImage image;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user