mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEnginePackGenerator-extension.git
synced 2025-12-20 07:19:19 +00:00
Binary file not shown.
@@ -6,6 +6,7 @@ import org.geysermc.geyser.api.event.lifecycle.GeyserLoadResourcePacksEvent;
|
|||||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
||||||
import org.geysermc.geyser.api.extension.Extension;
|
import org.geysermc.geyser.api.extension.Extension;
|
||||||
import re.imc.geysermodelenginepackgenerator.generator.Entity;
|
import re.imc.geysermodelenginepackgenerator.generator.Entity;
|
||||||
|
import re.imc.geysermodelenginepackgenerator.generator.Geometry;
|
||||||
import re.imc.geysermodelenginepackgenerator.util.ZipUtil;
|
import re.imc.geysermodelenginepackgenerator.util.ZipUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -35,7 +36,7 @@ public class ExtensionMain implements Extension {
|
|||||||
|
|
||||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) {
|
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) {
|
||||||
// 压缩文件夹
|
// 压缩文件夹
|
||||||
ZipUtil.compressFolder(generatedPack, generatedPack.getName(), zipOutputStream);
|
ZipUtil.compressFolder(generatedPack, null, zipOutputStream);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -44,6 +45,18 @@ public class ExtensionMain implements Extension {
|
|||||||
for (String entity : GeneratorMain.entityMap.keySet()) {
|
for (String entity : GeneratorMain.entityMap.keySet()) {
|
||||||
String id = "modelengine:" + entity;
|
String id = "modelengine:" + entity;
|
||||||
GeyserUtils.addCustomEntity(id);
|
GeyserUtils.addCustomEntity(id);
|
||||||
|
|
||||||
|
Geometry geometry = GeneratorMain.geometryMap.get(entity);
|
||||||
|
geometry.getBones().forEach(bone -> {
|
||||||
|
GeyserUtils.addProperty(id, entity + ":" + bone, Boolean.class);
|
||||||
|
});
|
||||||
|
|
||||||
|
GeyserUtils.addProperty(id, "modelengine:anim_idle", Boolean.class);
|
||||||
|
GeyserUtils.addProperty(id, "modelengine:anim_spawn", Boolean.class);
|
||||||
|
GeyserUtils.addProperty(id, "modelengine:anim_walk", Boolean.class);
|
||||||
|
GeyserUtils.addProperty(id, "modelengine:anim_stop", Boolean.class);
|
||||||
|
|
||||||
|
GeyserUtils.registerProperties(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ public class GeneratorMain {
|
|||||||
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 animationControllersFolder = new File(output, "animation_controllers");
|
||||||
|
File renderControllersFolder = new File(output, "render_controllers");
|
||||||
|
|
||||||
|
|
||||||
File manifestFile = new File(output, "manifest.json");
|
File manifestFile = new File(output, "manifest.json");
|
||||||
@@ -140,6 +141,7 @@ public class GeneratorMain {
|
|||||||
modelsFolder.mkdirs();
|
modelsFolder.mkdirs();
|
||||||
texturesFolder.mkdirs();
|
texturesFolder.mkdirs();
|
||||||
animationControllersFolder.mkdirs();
|
animationControllersFolder.mkdirs();
|
||||||
|
renderControllersFolder.mkdirs();
|
||||||
|
|
||||||
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
|
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
|
||||||
entry.getValue().modify();
|
entry.getValue().modify();
|
||||||
@@ -190,14 +192,33 @@ public class GeneratorMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, Entity> entry : entityMap.entrySet()) {
|
for (Map.Entry<String, Entity> entry : entityMap.entrySet()) {
|
||||||
entry.getValue().modify();
|
Entity entity = entry.getValue();
|
||||||
Path path = entityFolder.toPath().resolve(entry.getValue().getPath() + entry.getKey() + ".entity.json");
|
entity.getProperties().setProperty("render_controller", "controller.render." + entry.getKey());
|
||||||
path.toFile().getParentFile().mkdirs();
|
entity.modify();
|
||||||
if (path.toFile().exists()) {
|
|
||||||
|
Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json");
|
||||||
|
entityPath.toFile().getParentFile().mkdirs();
|
||||||
|
if (entityPath.toFile().exists()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Files.writeString(path, entry.getValue().getJson(), StandardCharsets.UTF_8);
|
Files.writeString(entityPath, entity.getJson(), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// render controller part
|
||||||
|
|
||||||
|
String id = entity.getModelId();
|
||||||
|
if (!geometryMap.containsKey(id)) continue;
|
||||||
|
RenderController controller = new RenderController(id, geometryMap.get(id).getBones());
|
||||||
|
|
||||||
|
Path renderPath = new File(renderControllersFolder, "controller.render." + id + ".json").toPath();
|
||||||
|
if (renderPath.toFile().exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class AnimationController {
|
|||||||
],
|
],
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{
|
{
|
||||||
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
|
"idle": "query.property('modelengine:anim_idle')"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -25,13 +25,13 @@ public class AnimationController {
|
|||||||
],
|
],
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{
|
{
|
||||||
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
|
"spawn": "query.property('modelengine:anim_spawn')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"walk": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:redstone')"
|
"walk": "query.property('modelengine:anim_walk')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"stop": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:air')"
|
"stop": "query.property('modelengine:anim_stop')"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -41,26 +41,26 @@ public class AnimationController {
|
|||||||
],
|
],
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{
|
{
|
||||||
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
|
"spawn": "query.property('modelengine:anim_spawn')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"stop": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:air')"
|
"stop": "query.property('modelengine:anim_stop')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
|
"idle": "query.property('modelengine:anim_idle')"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"stop": {
|
"stop": {
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{
|
{
|
||||||
"idle": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:stone')"
|
"idle": "query.property('modelengine:anim_idle')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"spawn": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:iron_block')"
|
"spawn": "query.property('modelengine:anim_spawn')"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"walk": "q.is_item_name_any('slot.armor.head', 0, 'minecraft:redstone')"
|
"walk": "query.property('modelengine:anim_walk')"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class Entity {
|
|||||||
.replace("%look_at_target%", "animation." + modelId + ".look_at_target")
|
.replace("%look_at_target%", "animation." + modelId + ".look_at_target")
|
||||||
.replace("%walk%", walk)
|
.replace("%walk%", walk)
|
||||||
.replace("%spawn%", spawn)
|
.replace("%spawn%", spawn)
|
||||||
.replace("%material%", properties.getProperty("material", "entity_alphatest"))
|
.replace("%material%", properties.getProperty("material", "entity_alphatest_change_color"))
|
||||||
.replace("%render_controller%", properties.getProperty("render_controller", "controller.render.default"));
|
.replace("%render_controller%", properties.getProperty("render_controller", "controller.render.default"));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package re.imc.geysermodelenginepackgenerator.generator;
|
package re.imc.geysermodelenginepackgenerator.generator;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -19,6 +19,7 @@ public class Geometry {
|
|||||||
|
|
||||||
String modelId;
|
String modelId;
|
||||||
JsonObject json;
|
JsonObject json;
|
||||||
|
List<String> bones = new ArrayList<>();
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
public void load(String json) {
|
public void load(String json) {
|
||||||
@@ -40,15 +41,21 @@ public class Geometry {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
JsonElement element = iterator.next();
|
JsonElement element = iterator.next();
|
||||||
if (element.isJsonObject()) {
|
if (element.isJsonObject()) {
|
||||||
String name = element.getAsJsonObject().get("name").getAsString();
|
String name = element.getAsJsonObject().get("name").getAsString().toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
|
element.getAsJsonObject().remove("name");
|
||||||
|
element.getAsJsonObject().addProperty("name", name);
|
||||||
|
|
||||||
if (name.equals("hitbox") ||
|
if (name.equals("hitbox") ||
|
||||||
|
name.equals("mount") ||
|
||||||
name.startsWith("p_") ||
|
name.startsWith("p_") ||
|
||||||
name.startsWith("b_") ||
|
name.startsWith("b_") ||
|
||||||
name.startsWith("ob_")) {
|
name.startsWith("ob_")) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
} else bones.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setId("geometry.modelengine_" + modelId);
|
setId("geometry.modelengine_" + modelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package re.imc.geysermodelenginepackgenerator.generator;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RenderController {
|
||||||
|
|
||||||
|
String modelId;
|
||||||
|
List<String> bones;
|
||||||
|
|
||||||
|
public RenderController(String modelId, List<String> bones) {
|
||||||
|
this.modelId = modelId;
|
||||||
|
this.bones = bones;
|
||||||
|
}
|
||||||
|
|
||||||
|
// look, I'm fine with your other code and stuff, but I ain't using templates for JSON lmao
|
||||||
|
public String generate() {
|
||||||
|
JsonObject root = new JsonObject();
|
||||||
|
root.addProperty("format_version", "1.8.0");
|
||||||
|
|
||||||
|
JsonObject renderControllers = new JsonObject();
|
||||||
|
root.add("render_controllers", renderControllers);
|
||||||
|
|
||||||
|
JsonObject controller = new JsonObject();
|
||||||
|
renderControllers.add("controller.render." + modelId, controller);
|
||||||
|
|
||||||
|
controller.addProperty("geometry", "Geometry.default");
|
||||||
|
|
||||||
|
JsonArray materials = new JsonArray();
|
||||||
|
JsonObject materialItem = new JsonObject();
|
||||||
|
materialItem.addProperty("*", "Material.default");
|
||||||
|
materials.add(materialItem);
|
||||||
|
controller.add("materials", materials);
|
||||||
|
|
||||||
|
JsonArray textures = new JsonArray();
|
||||||
|
textures.add("Texture.default");
|
||||||
|
controller.add("textures", textures);
|
||||||
|
|
||||||
|
JsonArray partVisibility = new JsonArray();
|
||||||
|
JsonObject visibilityDefault = new JsonObject();
|
||||||
|
visibilityDefault.addProperty("*", true);
|
||||||
|
partVisibility.add(visibilityDefault);
|
||||||
|
|
||||||
|
for (String bone : bones) {
|
||||||
|
JsonObject visibilityItem = new JsonObject();
|
||||||
|
visibilityItem.addProperty(bone, "query.property('" + modelId + ":" + bone + "')");
|
||||||
|
partVisibility.add(visibilityItem);
|
||||||
|
}
|
||||||
|
controller.add("part_visibility", partVisibility);
|
||||||
|
|
||||||
|
return root.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,8 +13,16 @@ public class ZipUtil {
|
|||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
|
if (folderName == null) {
|
||||||
|
compressFolder(file, file.getName(), zipOutputStream);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
compressFolder(file, folderName + "/" + file.getName(), zipOutputStream);
|
compressFolder(file, folderName + "/" + file.getName(), zipOutputStream);
|
||||||
} else {
|
} else {
|
||||||
|
if (folderName == null) {
|
||||||
|
addToZipFile(file.getName(), file, zipOutputStream);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
addToZipFile(folderName + "/" + file.getName(), file, zipOutputStream);
|
addToZipFile(folderName + "/" + file.getName(), file, zipOutputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user