animation controller

This commit is contained in:
zimzaza4
2024-05-25 14:53:27 +08:00
parent 9dc8c9c386
commit eb599cadce
4 changed files with 113 additions and 9 deletions

View File

@@ -101,6 +101,7 @@ public class GeneratorMain {
File entityFolder = new File(output, "entity");
File modelsFolder = new File(output, "models/entity");
File texturesFolder = new File(output, "textures/entity");
File animationControllersFolder = new File(output, "animation_controllers");
File manifestFile = new File(output, "manifest.json");
@@ -138,6 +139,7 @@ public class GeneratorMain {
entityFolder.mkdirs();
modelsFolder.mkdirs();
texturesFolder.mkdirs();
animationControllersFolder.mkdirs();
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
entry.getValue().modify();
@@ -201,6 +203,15 @@ public class GeneratorMain {
}
}
File controller = new File(animationControllersFolder, "modelengine.animation_controller.json");
if (!controller.exists()) {
try {
Files.writeString(controller.toPath(), AnimationController.TEMPLATE);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static boolean isGeometryFile(String json) {

View File

@@ -43,6 +43,14 @@ public class Animation {
public void modify() {
JsonObject newAnimations = new JsonObject();
for (Map.Entry<String, JsonElement> element : json.get("animations").getAsJsonObject().entrySet()) {
if (element.getKey().equals("spawn")) {
GeneratorMain.entityMap
.get(modelId).setHasSpawnAnimation(true);
}
if (element.getKey().equals("walk")) {
GeneratorMain.entityMap
.get(modelId).setHasWalkAnimation(true);
}
newAnimations.add("animation." + modelId + "." + element.getKey(), element.getValue());
}
json.add("animations", newAnimations);

View File

@@ -0,0 +1,71 @@
package re.imc.geysermodelenginepackgenerator.generator;
public class AnimationController {
public static final String TEMPLATE =
"""
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.modelengine": {
"initial_state": "spawn",
"states": {
"spawn": {
"animations": [
"spawn"
],
"transitions": [
{
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
}
]
},
"idle": {
"animations": [
"idle"
],
"transitions": [
{
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
},
{
"walk": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:redstone')"
},
{
"stop": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:air')"
}
]
},
"walk": {
"animations": [
"walk"
],
"transitions": [
{
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
},
{
"stop": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:air')"
},
{
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
}
]
},
"stop": {
"transitions": [
{
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
},
{
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
},
{
"walk": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:redstone')"
}
]
}
}
}
}
}""";
}

View File

@@ -28,15 +28,17 @@ public class Entity {
"default": "%geometry%"
},
"animations": {
"default": "animation.%entity_id%",
"look_at_target": "%look_at_target%"
"idle": "animation.%entity_id%.idle",
"spawn": "animation.%entity_id%.%spawn%",
"walk": "animation.%entity_id%.%walk%",
"look_at_target": "%look_at_target%",
"modelengine_controller": "controller.animation.modelengine"
},
"scripts": {
"animate": [
"default",
"look_at_target",
"spawn"
"modelengine_controller",
"look_at_target"
]
},
"render_controllers": [
@@ -51,7 +53,8 @@ public class Entity {
String modelId;
String json;
boolean hasHeadAnimation = false;
boolean hasWalkAnimation = false;
boolean hasSpawnAnimation = false;
String path;
Properties properties = new Properties();
@@ -61,15 +64,26 @@ public class Entity {
}
public void modify() {
String walk;
String spawn;
walk = spawn = "idle";
if (hasWalkAnimation) {
walk = "walk";
}
if (hasSpawnAnimation) {
spawn = "spawn";
}
json = TEMPLATE.replace("%entity_id%", modelId)
.replace("%geometry%", "geometry.modelengine_" + modelId)
.replace("%texture%", "textures/entity/" + path + modelId)
.replace("%look_at_target%", "animation." + modelId + ".look_at_target")
.replace("%walk%", walk)
.replace("%spawn%", spawn)
.replace("%material%", properties.getProperty("material", "entity_alphatest"))
.replace("%render_controller%", properties.getProperty("render_controller", "controller.render.default"))
.replace("%render_controller%", properties.getProperty("render_controller", "controller.render.default"));
;
}