This commit is contained in:
zimzaza4
2024-10-13 11:16:44 +08:00
parent 02017dd8c2
commit f587c6e900
7 changed files with 115 additions and 21 deletions

19
pom.xml
View File

@@ -35,6 +35,10 @@
<enabled>true</enabled> <enabled>true</enabled>
</snapshots> </snapshots>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@@ -62,5 +66,20 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/libs/geyserutils-geyser-1.0-SNAPSHOT.jar</systemPath> <systemPath>${project.basedir}/libs/geyserutils-geyser-1.0-SNAPSHOT.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>me.rochblondiaux</groupId>
<artifactId>blockbenchmodelreader</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.github.GeyserMC.PackConverter</groupId>
<artifactId>bedrock-pack-schema</artifactId>
<version>3d8150474d</version>
</dependency>
<dependency>
<groupId>com.github.GeyserMC.PackConverter</groupId>
<artifactId>pack-schema-api</artifactId>
<version>3d8150474d</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -14,13 +14,15 @@ 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.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
public class GeneratorMain { public class GeneratorMain {
public static final Map<String, Entity> entityMap = new HashMap<>(); public static final Map<String, Entity> entityMap = new HashMap<>();
public static final Map<String, Animation> animationMap = new HashMap<>(); public static final Map<String, Animation> animationMap = new HashMap<>();
public static final Map<String, Geometry> geometryMap = new HashMap<>(); public static final Map<String, Geometry> geometryMap = new HashMap<>();
public static final Map<String, Texture> textureMap = new HashMap<>(); public static final Map<String, Map<String, Texture>> textureMap = new HashMap<>();
public static final Gson GSON = new GsonBuilder().setPrettyPrinting() public static final Gson GSON = new GsonBuilder().setPrettyPrinting()
.create(); .create();
@@ -40,13 +42,23 @@ public class GeneratorMain {
String modelId = folder.getName().toLowerCase(); String modelId = folder.getName().toLowerCase();
Entity entity = new Entity(modelId); Entity entity = new Entity(modelId);
TextureConfig textureConfig = new TextureConfig();
boolean canAdd = false; boolean canAdd = false;
for (File e : folder.listFiles()) { for (File e : folder.listFiles()) {
if (e.isDirectory()) { if (e.isDirectory()) {
generateFromFolder(currentPath + folder.getName() + "/", e); generateFromFolder(currentPath + folder.getName() + "/", e);
} }
if (e.getName().endsWith(".png")) { if (e.getName().endsWith(".png")) {
textureMap.put(modelId, new Texture(modelId, currentPath, e.toPath())); String textureName = e.getName().replace(".png", "");
Set<String> bindingBones = new HashSet<>();
bindingBones.add("*");
if (!textureConfig.getBingingBones().containsKey(textureName)) {
bindingBones = textureConfig.getBingingBones().get(textureName);
}
textureMap.computeIfAbsent(modelId, s -> new HashMap<>()).put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
if (!textureConfig.getBingingBones().isEmpty()) {
textureConfig.getBingingBones().put(textureName, Set.of("*"));
}
} }
if (e.getName().endsWith(".json")) { if (e.getName().endsWith(".json")) {
try { try {
@@ -136,6 +148,15 @@ public class GeneratorMain {
materialsFolder.mkdirs(); materialsFolder.mkdirs();
File materialFile = new File(materialsFolder, "entity.material"); File materialFile = new File(materialsFolder, "entity.material");
if (!materialFile.exists()) {
try {
Files.writeString(materialFile.toPath(),
Material.TEMPLATE, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) { for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
Entity entity = entityMap.get(entry.getKey()); Entity entity = entityMap.get(entry.getKey());
@@ -179,7 +200,7 @@ public class GeneratorMain {
} }
} }
for (Map.Entry<String, Texture> entry : textureMap.entrySet()) { for (Map.Entry<String, Map<String, Texture>> entry : textureMap.entrySet()) {
Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + entry.getKey() + ".png"); Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + entry.getKey() + ".png");
path.toFile().getParentFile().mkdirs(); path.toFile().getParentFile().mkdirs();
@@ -213,7 +234,7 @@ public class GeneratorMain {
String id = entity.getModelId(); String id = entity.getModelId();
if (!geometryMap.containsKey(id)) continue; if (!geometryMap.containsKey(id)) continue;
RenderController controller = new RenderController(id, geometryMap.get(id).getBones()); RenderController controller = new RenderController(id, geometryMap.get(id).getBones(), entity);
entity.setRenderController(controller); entity.setRenderController(controller);
Path renderPath = new File(renderControllersFolder, "controller.render." + id + ".json").toPath(); Path renderPath = new File(renderControllersFolder, "controller.render." + id + ".json").toPath();
if (renderPath.toFile().exists()) { if (renderPath.toFile().exists()) {

View File

@@ -11,6 +11,7 @@ import me.zimzaza4.geyserutils.geyser.GeyserUtils;
import re.imc.geysermodelenginepackgenerator.GeneratorMain; import re.imc.geysermodelenginepackgenerator.GeneratorMain;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
@@ -26,13 +27,12 @@ public class Entity {
"description": { "description": {
"identifier": "modelengine:%entity_id%", "identifier": "modelengine:%entity_id%",
"materials": { "materials": {
"default": "%material%" "default": "%material%",
"anim": "entity_alphatest_anim_change_color"
}, },
"textures": { "textures": {
"default": "%texture%"
}, },
"geometry": { "geometry": {
"default": "%geometry%"
}, },
"animations": { "animations": {
"look_at_target": "%look_at_target%" "look_at_target": "%look_at_target%"
@@ -54,19 +54,13 @@ public class Entity {
String modelId; String modelId;
JsonObject json; JsonObject json;
boolean hasHeadAnimation = false; boolean hasHeadAnimation = false;
@Setter
@Getter
Animation animation; Animation animation;
@Setter
@Getter
Geometry geometry; Geometry geometry;
@Setter
@Getter
RenderController renderController; RenderController renderController;
String path; String path;
Map<String, Texture> textureMap;
TextureConfig textureConfig;
Properties config = new Properties(); Properties config = new Properties();
@@ -87,6 +81,14 @@ public class Entity {
JsonObject description = json.get("minecraft:client_entity").getAsJsonObject().get("description").getAsJsonObject(); JsonObject description = json.get("minecraft:client_entity").getAsJsonObject().get("description").getAsJsonObject();
JsonObject jsonAnimations = description.get("animations").getAsJsonObject(); JsonObject jsonAnimations = description.get("animations").getAsJsonObject();
JsonObject jsonTextures = description.get("textures").getAsJsonObject();
JsonObject jsonGeometry = description.get("geometry").getAsJsonObject();
for (String name : textureMap.keySet()) {
jsonTextures.addProperty(name,"textures/entity/" + path + modelId + "/" + name);
jsonGeometry.addProperty(name, "geometry.modelengine_" + modelId);
}
JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray(); JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray();
if (animation != null) { if (animation != null) {

View File

@@ -0,0 +1,17 @@
package re.imc.geysermodelenginepackgenerator.generator;
public class Material {
public static final String TEMPLATE = """
{
"materials":{
"version":"1.0.0",
"entity_alphatest_anim_change_color:entity_alphatest_change_color":{
"+defines":[
"USE_UV_ANIM"
]
}
}
}
""";
}

View File

@@ -11,10 +11,12 @@ public class RenderController {
public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_"); public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_");
String modelId; String modelId;
Set<String> bones; Set<String> bones;
Entity entity;
public RenderController(String modelId, Set<String> bones) { public RenderController(String modelId, Set<String> bones, Entity entity) {
this.modelId = modelId; this.modelId = modelId;
this.bones = bones; this.bones = bones;
this.entity = entity;
} }
// look, I'm fine with your other code and stuff, but I ain't using templates for JSON lmao // look, I'm fine with your other code and stuff, but I ain't using templates for JSON lmao

View File

@@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Set;
@Getter @Getter
@Setter @Setter
@@ -12,8 +13,7 @@ import java.nio.file.Path;
public class Texture { public class Texture {
String modelId; String modelId;
String path; String path;
Set<String> bindingBones;
Path originalPath; Path originalPath;
} }

View File

@@ -0,0 +1,33 @@
package re.imc.geysermodelenginepackgenerator.generator;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class TextureConfig {
@SerializedName("binding_bones")
Map<String, Set<String>> bingingBones = new HashMap<>();
@SerializedName("anim_textures")
Map<String, AnimTextureOptions> animTextures = new HashMap<>();
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public static class AnimTextureOptions {
boolean animUv;
float fps;
int frames;
}
}