more cleanup

This commit is contained in:
xSquishyLiam
2025-08-22 21:15:18 +01:00
parent e79c4a36ab
commit 6129e16f45
6 changed files with 32 additions and 41 deletions

View File

@@ -50,8 +50,8 @@ public class GeneratorMain {
if (textureConfigFile != null) {
try {
modelConfig = GSON.fromJson(new InputStreamReader(zip.getInputStream(textureConfigFile)), ModelConfig.class);
} catch (IOException e) {
e.printStackTrace();
} catch (IOException err) {
throw new RuntimeException(err);
}
}
boolean canAdd = false;
@@ -72,11 +72,9 @@ public class GeneratorMain {
throw new RuntimeException(err);
}
entity.setTextureMap(map);
if (modelConfig.getBingingBones().isEmpty()) {
modelConfig.getBingingBones().put(textureName, Set.of("*"));
}
if (modelConfig.getBingingBones().isEmpty()) modelConfig.getBingingBones().put(textureName, Set.of("*"));
}
if (e.getName().endsWith(".json")) {
try {
InputStream stream = zip.getInputStream(e);
@@ -100,8 +98,8 @@ public class GeneratorMain {
entity.setGeometry(geometry);
canAdd = true;
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (IOException err) {
throw new RuntimeException(err);
}
}
}
@@ -208,7 +206,6 @@ public class GeneratorMain {
shouldOverrideConfig = true;
oldConfig.delete();
}
} catch (IOException err) {
throw new RuntimeException(err);
}
@@ -316,9 +313,7 @@ public class GeneratorMain {
entry.getValue().setId(id + "_" + suffix);
if (path.toFile().exists()) {
continue;
}
if (path.toFile().exists()) continue;
try {
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.toFile().getParentFile().mkdirs();
if (path.toFile().exists()) {
continue;
}
if (path.toFile().exists()) continue;
try {
if (entry.getValue().getImage() != null) {
Files.write(path, entry.getValue().getImage());
}
if (entry.getValue().getImage() != null) Files.write(path, entry.getValue().getImage());
} catch (IOException err) {
throw new RuntimeException(err);
}
@@ -380,9 +372,8 @@ public class GeneratorMain {
RenderController controller = new RenderController(id, geometryMap.get(id).getBones(), entity);
entity.setRenderController(controller);
Path renderPath = new File(renderControllersFolder, "controller.render." + id + ".json").toPath();
if (renderPath.toFile().exists()) {
continue;
}
if (renderPath.toFile().exists()) continue;
try {
Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8);
} catch (IOException err) {

View File

@@ -81,7 +81,7 @@ public class GeyserModelEnginePackGenerator implements Extension {
public void onPackLoad(GeyserDefineResourcePacksEvent event) {
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);
}

View File

@@ -12,6 +12,12 @@ import java.util.Set;
public class Animation {
private String modelId;
private JsonObject json;
private Set<String> animationIds = new HashSet<>();
private String path;
public static final String HEAD_TEMPLATE = """
{
"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) {
this.json = JsonParser.parseString(string).getAsJsonObject();
JsonObject newAnimations = new JsonObject();
@@ -42,6 +42,7 @@ public class Animation {
// play once but override must use this to avoid strange anim
}
}
animation.remove("override_previous_animation");
}
@@ -81,8 +82,8 @@ public class Animation {
newAnimations.add("animation." + modelId + "." + element.getKey().replace(" ", "_"), element.getValue());
}
json.add("animations", newAnimations);
json.add("animations", newAnimations);
}
public void addHeadBind(Geometry geometry) {

View File

@@ -13,6 +13,9 @@ import java.util.Map;
public class AnimationController {
private JsonObject json;
private Entity entity;
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) {
JsonObject root = new JsonObject();
json = root;

View File

@@ -34,8 +34,7 @@ public class Geometry {
}
public JsonObject getInternal() {
return json.get("minecraft:geometry").getAsJsonArray().get(0)
.getAsJsonObject();
return json.get("minecraft:geometry").getAsJsonArray().get(0).getAsJsonObject();
}
public void modify() {

View File

@@ -57,10 +57,10 @@ public class RenderController {
} else {
controller.addProperty("geometry", "Geometry.default");
}
JsonArray materials = new JsonArray();
String material = entity.getModelConfig().getTextureMaterials().get(key);
JsonObject materialItem = new JsonObject();
if (material != null) {
materialItem.addProperty("*", "Material." + material);
@@ -88,6 +88,7 @@ public class RenderController {
} else {
textures.add("Texture." + key);
}
controller.add("textures", textures);
// if (enable) {
@@ -115,9 +116,9 @@ public class RenderController {
if (uvBone.equals("*")) {
uvAllBones.addAll(bones.keySet());
}
if (!bones.containsKey(uvBone.toLowerCase())) {
continue;
}
if (!bones.containsKey(uvBone.toLowerCase())) continue;
uvAllBones.add(uvBone.toLowerCase());
}
@@ -137,9 +138,8 @@ public class RenderController {
for (Map.Entry<String, Set<String>> entry : entity.getModelConfig().bingingBones.entrySet()) {
if (entry.getKey().equals(key)) {
continue;
}
if (entry.getKey().equals(key)) continue;
if (entry.getValue().stream().anyMatch(boneName::equalsIgnoreCase)) {
uvParent = false;
break;