mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEnginePackGenerator-extension.git
synced 2025-12-20 15:29:24 +00:00
more cleanup
This commit is contained in:
@@ -50,8 +50,8 @@ public class GeneratorMain {
|
|||||||
if (textureConfigFile != null) {
|
if (textureConfigFile != null) {
|
||||||
try {
|
try {
|
||||||
modelConfig = GSON.fromJson(new InputStreamReader(zip.getInputStream(textureConfigFile)), ModelConfig.class);
|
modelConfig = GSON.fromJson(new InputStreamReader(zip.getInputStream(textureConfigFile)), ModelConfig.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException err) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean canAdd = false;
|
boolean canAdd = false;
|
||||||
@@ -72,11 +72,9 @@ public class GeneratorMain {
|
|||||||
throw new RuntimeException(err);
|
throw new RuntimeException(err);
|
||||||
}
|
}
|
||||||
entity.setTextureMap(map);
|
entity.setTextureMap(map);
|
||||||
if (modelConfig.getBingingBones().isEmpty()) {
|
if (modelConfig.getBingingBones().isEmpty()) modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||||
modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
if (e.getName().endsWith(".json")) {
|
if (e.getName().endsWith(".json")) {
|
||||||
try {
|
try {
|
||||||
InputStream stream = zip.getInputStream(e);
|
InputStream stream = zip.getInputStream(e);
|
||||||
@@ -100,8 +98,8 @@ public class GeneratorMain {
|
|||||||
entity.setGeometry(geometry);
|
entity.setGeometry(geometry);
|
||||||
canAdd = true;
|
canAdd = true;
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException err) {
|
||||||
ex.printStackTrace();
|
throw new RuntimeException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +206,6 @@ public class GeneratorMain {
|
|||||||
shouldOverrideConfig = true;
|
shouldOverrideConfig = true;
|
||||||
oldConfig.delete();
|
oldConfig.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException err) {
|
} catch (IOException err) {
|
||||||
throw new RuntimeException(err);
|
throw new RuntimeException(err);
|
||||||
}
|
}
|
||||||
@@ -316,9 +313,7 @@ public class GeneratorMain {
|
|||||||
|
|
||||||
entry.getValue().setId(id + "_" + suffix);
|
entry.getValue().setId(id + "_" + suffix);
|
||||||
|
|
||||||
if (path.toFile().exists()) {
|
if (path.toFile().exists()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
|
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
|
||||||
@@ -345,13 +340,10 @@ public class GeneratorMain {
|
|||||||
Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + textures.getKey() + "/" + entry.getKey() + ".png");
|
Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + textures.getKey() + "/" + entry.getKey() + ".png");
|
||||||
path.toFile().getParentFile().mkdirs();
|
path.toFile().getParentFile().mkdirs();
|
||||||
|
|
||||||
if (path.toFile().exists()) {
|
if (path.toFile().exists()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (entry.getValue().getImage() != null) {
|
if (entry.getValue().getImage() != null) Files.write(path, entry.getValue().getImage());
|
||||||
Files.write(path, entry.getValue().getImage());
|
|
||||||
}
|
|
||||||
} catch (IOException err) {
|
} catch (IOException err) {
|
||||||
throw new RuntimeException(err);
|
throw new RuntimeException(err);
|
||||||
}
|
}
|
||||||
@@ -380,9 +372,8 @@ public class GeneratorMain {
|
|||||||
RenderController controller = new RenderController(id, geometryMap.get(id).getBones(), entity);
|
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()) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8);
|
Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8);
|
||||||
} catch (IOException err) {
|
} catch (IOException err) {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class GeyserModelEnginePackGenerator implements Extension {
|
|||||||
public void onPackLoad(GeyserDefineResourcePacksEvent event) {
|
public void onPackLoad(GeyserDefineResourcePacksEvent event) {
|
||||||
if (!configManager.getConfig().getBoolean("options.resource-pack.auto-load")) return;
|
if (!configManager.getConfig().getBoolean("options.resource-pack.auto-load")) return;
|
||||||
|
|
||||||
ResourcePack resourcePack = ResourcePack.builder(PackCodec.path(generatedPackZip)).build();
|
ResourcePack resourcePack = ResourcePack.create(PackCodec.path(generatedPackZip));
|
||||||
event.register(resourcePack);
|
event.register(resourcePack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class Animation {
|
public class Animation {
|
||||||
|
|
||||||
|
private String modelId;
|
||||||
|
private JsonObject json;
|
||||||
|
private Set<String> animationIds = new HashSet<>();
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
public static final String HEAD_TEMPLATE = """
|
public static final String HEAD_TEMPLATE = """
|
||||||
{
|
{
|
||||||
"relative_to" : {
|
"relative_to" : {
|
||||||
@@ -21,12 +27,6 @@ public class Animation {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
private String modelId;
|
|
||||||
private JsonObject json;
|
|
||||||
private Set<String> animationIds = new HashSet<>();
|
|
||||||
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
public void load(String string) {
|
public void load(String string) {
|
||||||
this.json = JsonParser.parseString(string).getAsJsonObject();
|
this.json = JsonParser.parseString(string).getAsJsonObject();
|
||||||
JsonObject newAnimations = new JsonObject();
|
JsonObject newAnimations = new JsonObject();
|
||||||
@@ -42,6 +42,7 @@ public class Animation {
|
|||||||
// play once but override must use this to avoid strange anim
|
// play once but override must use this to avoid strange anim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
animation.remove("override_previous_animation");
|
animation.remove("override_previous_animation");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +82,8 @@ public class Animation {
|
|||||||
|
|
||||||
newAnimations.add("animation." + modelId + "." + element.getKey().replace(" ", "_"), element.getValue());
|
newAnimations.add("animation." + modelId + "." + element.getKey().replace(" ", "_"), element.getValue());
|
||||||
}
|
}
|
||||||
json.add("animations", newAnimations);
|
|
||||||
|
|
||||||
|
json.add("animations", newAnimations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHeadBind(Geometry geometry) {
|
public void addHeadBind(Geometry geometry) {
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class AnimationController {
|
public class AnimationController {
|
||||||
|
|
||||||
|
private JsonObject json;
|
||||||
|
private Entity entity;
|
||||||
|
|
||||||
public static final String CONTROLLER_TEMPLATE =
|
public static final String CONTROLLER_TEMPLATE =
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
@@ -33,9 +36,6 @@ public class AnimationController {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
private JsonObject json;
|
|
||||||
private Entity entity;
|
|
||||||
|
|
||||||
public void load(Animation animation, Entity entity) {
|
public void load(Animation animation, Entity entity) {
|
||||||
JsonObject root = new JsonObject();
|
JsonObject root = new JsonObject();
|
||||||
json = root;
|
json = root;
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ public class Geometry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getInternal() {
|
public JsonObject getInternal() {
|
||||||
return json.get("minecraft:geometry").getAsJsonArray().get(0)
|
return json.get("minecraft:geometry").getAsJsonArray().get(0).getAsJsonObject();
|
||||||
.getAsJsonObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modify() {
|
public void modify() {
|
||||||
|
|||||||
@@ -57,10 +57,10 @@ public class RenderController {
|
|||||||
} else {
|
} else {
|
||||||
controller.addProperty("geometry", "Geometry.default");
|
controller.addProperty("geometry", "Geometry.default");
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray materials = new JsonArray();
|
JsonArray materials = new JsonArray();
|
||||||
String material = entity.getModelConfig().getTextureMaterials().get(key);
|
String material = entity.getModelConfig().getTextureMaterials().get(key);
|
||||||
|
|
||||||
|
|
||||||
JsonObject materialItem = new JsonObject();
|
JsonObject materialItem = new JsonObject();
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
materialItem.addProperty("*", "Material." + material);
|
materialItem.addProperty("*", "Material." + material);
|
||||||
@@ -88,6 +88,7 @@ public class RenderController {
|
|||||||
} else {
|
} else {
|
||||||
textures.add("Texture." + key);
|
textures.add("Texture." + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.add("textures", textures);
|
controller.add("textures", textures);
|
||||||
|
|
||||||
// if (enable) {
|
// if (enable) {
|
||||||
@@ -115,9 +116,9 @@ public class RenderController {
|
|||||||
if (uvBone.equals("*")) {
|
if (uvBone.equals("*")) {
|
||||||
uvAllBones.addAll(bones.keySet());
|
uvAllBones.addAll(bones.keySet());
|
||||||
}
|
}
|
||||||
if (!bones.containsKey(uvBone.toLowerCase())) {
|
|
||||||
continue;
|
if (!bones.containsKey(uvBone.toLowerCase())) continue;
|
||||||
}
|
|
||||||
uvAllBones.add(uvBone.toLowerCase());
|
uvAllBones.add(uvBone.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,9 +138,8 @@ public class RenderController {
|
|||||||
|
|
||||||
|
|
||||||
for (Map.Entry<String, Set<String>> entry : entity.getModelConfig().bingingBones.entrySet()) {
|
for (Map.Entry<String, Set<String>> entry : entity.getModelConfig().bingingBones.entrySet()) {
|
||||||
if (entry.getKey().equals(key)) {
|
if (entry.getKey().equals(key)) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (entry.getValue().stream().anyMatch(boneName::equalsIgnoreCase)) {
|
if (entry.getValue().stream().anyMatch(boneName::equalsIgnoreCase)) {
|
||||||
uvParent = false;
|
uvParent = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user