mirror of
https://github.com/GeyserExtensionists/GeyserModelEnginePackGenerator.git
synced 2025-12-19 23:19:20 +00:00
animation controller
This commit is contained in:
@@ -101,6 +101,7 @@ public class GeneratorMain {
|
|||||||
File entityFolder = new File(output, "entity");
|
File entityFolder = new File(output, "entity");
|
||||||
File modelsFolder = new File(output, "models/entity");
|
File modelsFolder = new File(output, "models/entity");
|
||||||
File texturesFolder = new File(output, "textures/entity");
|
File texturesFolder = new File(output, "textures/entity");
|
||||||
|
File animationControllersFolder = new File(output, "animation_controllers");
|
||||||
|
|
||||||
|
|
||||||
File manifestFile = new File(output, "manifest.json");
|
File manifestFile = new File(output, "manifest.json");
|
||||||
@@ -138,6 +139,7 @@ public class GeneratorMain {
|
|||||||
entityFolder.mkdirs();
|
entityFolder.mkdirs();
|
||||||
modelsFolder.mkdirs();
|
modelsFolder.mkdirs();
|
||||||
texturesFolder.mkdirs();
|
texturesFolder.mkdirs();
|
||||||
|
animationControllersFolder.mkdirs();
|
||||||
|
|
||||||
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
|
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
|
||||||
entry.getValue().modify();
|
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) {
|
private static boolean isGeometryFile(String json) {
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ public class Animation {
|
|||||||
public void modify() {
|
public void modify() {
|
||||||
JsonObject newAnimations = new JsonObject();
|
JsonObject newAnimations = new JsonObject();
|
||||||
for (Map.Entry<String, JsonElement> element : json.get("animations").getAsJsonObject().entrySet()) {
|
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());
|
newAnimations.add("animation." + modelId + "." + element.getKey(), element.getValue());
|
||||||
}
|
}
|
||||||
json.add("animations", newAnimations);
|
json.add("animations", newAnimations);
|
||||||
|
|||||||
@@ -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')"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}""";
|
||||||
|
}
|
||||||
@@ -28,15 +28,17 @@ public class Entity {
|
|||||||
"default": "%geometry%"
|
"default": "%geometry%"
|
||||||
},
|
},
|
||||||
"animations": {
|
"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": {
|
"scripts": {
|
||||||
"animate": [
|
"animate": [
|
||||||
"default",
|
"modelengine_controller",
|
||||||
"look_at_target",
|
"look_at_target"
|
||||||
"spawn"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"render_controllers": [
|
"render_controllers": [
|
||||||
@@ -51,7 +53,8 @@ public class Entity {
|
|||||||
String modelId;
|
String modelId;
|
||||||
String json;
|
String json;
|
||||||
boolean hasHeadAnimation = false;
|
boolean hasHeadAnimation = false;
|
||||||
|
boolean hasWalkAnimation = false;
|
||||||
|
boolean hasSpawnAnimation = false;
|
||||||
String path;
|
String path;
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
@@ -61,15 +64,26 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void modify() {
|
public void modify() {
|
||||||
|
|
||||||
|
String walk;
|
||||||
|
String spawn;
|
||||||
|
walk = spawn = "idle";
|
||||||
|
if (hasWalkAnimation) {
|
||||||
|
walk = "walk";
|
||||||
|
}
|
||||||
|
if (hasSpawnAnimation) {
|
||||||
|
spawn = "spawn";
|
||||||
|
}
|
||||||
json = TEMPLATE.replace("%entity_id%", modelId)
|
json = TEMPLATE.replace("%entity_id%", modelId)
|
||||||
.replace("%geometry%", "geometry.modelengine_" + modelId)
|
.replace("%geometry%", "geometry.modelengine_" + modelId)
|
||||||
.replace("%texture%", "textures/entity/" + path + modelId)
|
.replace("%texture%", "textures/entity/" + path + modelId)
|
||||||
.replace("%look_at_target%", "animation." + modelId + ".look_at_target")
|
.replace("%look_at_target%", "animation." + modelId + ".look_at_target")
|
||||||
|
.replace("%walk%", walk)
|
||||||
|
.replace("%spawn%", spawn)
|
||||||
.replace("%material%", properties.getProperty("material", "entity_alphatest"))
|
.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"));
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user