mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEnginePackGenerator-extension.git
synced 2025-12-19 14:59:16 +00:00
anim and more config
This commit is contained in:
@@ -21,7 +21,7 @@ public class GeneratorMain {
|
||||
public static final Map<String, Animation> animationMap = new HashMap<>();
|
||||
public static final Map<String, Geometry> geometryMap = new HashMap<>();
|
||||
public static final Map<String, Texture> textureMap = new HashMap<>();
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
|
||||
@@ -81,8 +81,10 @@ public class GeneratorMain {
|
||||
if (config.exists()) {
|
||||
entity.getConfig().load(new FileReader(config));
|
||||
} else {
|
||||
entity.getConfig().setProperty("enable-part-visibility", "false");
|
||||
entity.getConfig().store(new FileWriter(config), "For some reasons, the part visibility render controller may cause client crash");
|
||||
entity.getConfig().setProperty("head-rotation", "true");
|
||||
entity.getConfig().setProperty("material", "entity_alphatest_change_color");
|
||||
entity.getConfig().setProperty("blend-transition", "true");
|
||||
entity.getConfig().store(new FileWriter(config), "");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -136,6 +138,7 @@ public class GeneratorMain {
|
||||
File materialFile = new File(materialsFolder, "entity.material");
|
||||
|
||||
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
|
||||
Entity entity = entityMap.get(entry.getKey());
|
||||
Geometry geo = geometryMap.get(entry.getKey());
|
||||
if (geo != null) {
|
||||
entry.getValue().addHeadBind(geo);
|
||||
@@ -151,9 +154,10 @@ public class GeneratorMain {
|
||||
}
|
||||
|
||||
AnimationController controller = new AnimationController();
|
||||
controller.load(entry.getValue());
|
||||
controller.load(entry.getValue(), entity);
|
||||
|
||||
try {
|
||||
Files.writeString(path, entry.getValue().getJson().toString(), StandardCharsets.UTF_8);
|
||||
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
|
||||
Files.writeString(pathController, controller.getJson().toString(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -54,6 +54,7 @@ public class Animation {
|
||||
// play once but override must use this to avoid strange anim
|
||||
}
|
||||
}
|
||||
animation.remove("override_previous_animation");
|
||||
}
|
||||
|
||||
if (animation.has("loop")) {
|
||||
@@ -81,7 +82,7 @@ public class Animation {
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {}
|
||||
if (end != null && end.get("lerp_mode").getAsString().equals("catmullrom")) {
|
||||
if (end != null && end.has("lerp_mode") && end.get("lerp_mode").getAsString().equals("catmullrom")) {
|
||||
end.addProperty("lerp_mode", "linear");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package re.imc.geysermodelenginepackgenerator.generator;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnimationController {
|
||||
|
||||
@@ -28,82 +31,14 @@ 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.variant == 1"
|
||||
}
|
||||
],
|
||||
"blend_transition": 0.2
|
||||
},
|
||||
"idle": {
|
||||
"animations": [
|
||||
"idle"
|
||||
],
|
||||
"transitions": [
|
||||
{
|
||||
"spawn": "q.variant == 0"
|
||||
},
|
||||
{
|
||||
"walk": "q.variant == 2"
|
||||
},
|
||||
{
|
||||
"stop": "q.variant == 3"
|
||||
}
|
||||
],
|
||||
"blend_transition": 0.2
|
||||
},
|
||||
"walk": {
|
||||
"animations": [
|
||||
"walk"
|
||||
],
|
||||
"transitions": [
|
||||
{
|
||||
"spawn": "q.variant == 0"
|
||||
},
|
||||
{
|
||||
"stop": "q.variant == 3"
|
||||
},
|
||||
{
|
||||
"idle": "q.variant == 1"
|
||||
}
|
||||
],
|
||||
"blend_transition": 0.2
|
||||
},
|
||||
"stop": {
|
||||
"transitions": [
|
||||
{
|
||||
"idle": "q.variant == 1"
|
||||
},
|
||||
{
|
||||
"spawn": "q.variant == 0"
|
||||
},
|
||||
{
|
||||
"walk": "q.variant == 2"
|
||||
}
|
||||
],
|
||||
"blend_transition": 0.2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}""";
|
||||
|
||||
@Getter
|
||||
JsonObject json;
|
||||
@Setter
|
||||
@Getter
|
||||
Entity entity;
|
||||
|
||||
public void load(Animation animation) {
|
||||
public void load(Animation animation, Entity entity) {
|
||||
JsonObject root = new JsonObject();
|
||||
json = root;
|
||||
root.addProperty("format_version", "1.10.0");
|
||||
@@ -121,6 +56,14 @@ public class AnimationController {
|
||||
JsonObject controller = new JsonParser().parse(CONTROLLER_TEMPLATE.replace("%anim%", id).replace("%query%", "math.mod(math.floor(query.property('modelengine:anim" + i / 24 + "') / " + n + "), 2)")).getAsJsonObject();
|
||||
animationControllers.add("controller.animation." + animation.modelId + "." + id, controller);
|
||||
i++;
|
||||
if (entity != null) {
|
||||
boolean blend = Boolean.parseBoolean(entity.getConfig().getProperty("blend-transition", "true"));
|
||||
if (!blend) {
|
||||
for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) {
|
||||
states.getValue().getAsJsonObject().remove("blend_transition");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Entity {
|
||||
json = new JsonParser().parse(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("%look_at_target%", Boolean.parseBoolean(config.getProperty("head-rotation", "true".toLowerCase())) ? "animation." + modelId + ".look_at_target" : "animation.none")
|
||||
.replace("%material%", config.getProperty("material", "entity_alphatest_change_color"))
|
||||
.replace("%render_controller%", config.getProperty("render_controller", "controller.render.default"))).getAsJsonObject();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user