From 92b310e5e297e9b45ec5659b63498d8b475b357e Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 3 Mar 2026 03:50:56 +0100 Subject: [PATCH] Working json for model --- .../cosmetics/hat/HatFeatureRenderer.java | 4 -- .../saturnclient/cosmetics/obj/ObjModel.java | 43 ++++++++++++++++--- .../models/cosmetic/horns/model.json | 4 ++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/assets/saturnclient/models/cosmetic/horns/model.json diff --git a/src/main/java/org/saturnclient/cosmetics/hat/HatFeatureRenderer.java b/src/main/java/org/saturnclient/cosmetics/hat/HatFeatureRenderer.java index ef06149..96daa52 100644 --- a/src/main/java/org/saturnclient/cosmetics/hat/HatFeatureRenderer.java +++ b/src/main/java/org/saturnclient/cosmetics/hat/HatFeatureRenderer.java @@ -44,11 +44,7 @@ public class HatFeatureRenderer extends FeatureRenderer loadedObjModels = new HashMap<>(); public record Config( - @JsonProperty("transform") Transform transform) { + @JsonProperty("transform") Vec3d transform, + @JsonProperty("scale") Vec3d scale) { @JsonFormat(shape = JsonFormat.Shape.ARRAY) - public record Transform(double x, double y, double z) { + public record Vec3d(float x, float y, float z) { } } @@ -37,21 +45,42 @@ public class ObjModel { } ObjModel(Identifier identifier) { - Identifier obj = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".obj"); - System.out.println(obj); - // Identifier json = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".json"); + Identifier objId = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".obj"); + Identifier jsonId = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".json"); try { - this.obj = ObjRenderer.loadObj(obj); + this.obj = ObjRenderer.loadObj(objId); } catch (IOException e) { e.printStackTrace(); } - Identifier.of(obj.toString()); + // Try loading JSON config if it exists + ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager(); + Optional resource = resourceManager.getResource(jsonId); + + if (resource.isPresent()) { + try (InputStream stream = resource.get().getInputStream()) { + this.config = MAPPER.readValue(stream, Config.class); + } catch (Exception e) { + e.printStackTrace(); + } + } } public void render(Map mtlMap, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + matrices.push(); + + matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(180.0f)); + matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_Y.rotationDegrees(180.0f)); + + if (this.config != null) { + matrices.scale(config.scale.x, config.scale.y, config.scale.z); + matrices.translate(config.transform.x, config.transform.y, config.transform.z); + } + ObjRenderer.renderObj(this.obj, mtlMap, matrices, vertexConsumers, light, overlay); + + matrices.pop(); } } diff --git a/src/main/resources/assets/saturnclient/models/cosmetic/horns/model.json b/src/main/resources/assets/saturnclient/models/cosmetic/horns/model.json new file mode 100644 index 0000000..2212050 --- /dev/null +++ b/src/main/resources/assets/saturnclient/models/cosmetic/horns/model.json @@ -0,0 +1,4 @@ +{ + "transform": [0.0, 1.0, 0.0], + "scale": [0.25, 0.25, 0.25] + } \ No newline at end of file