Search in sources :

Example 1 with ItemTransformVec3f

use of net.minecraft.client.renderer.model.ItemTransformVec3f in project Magma-1.16.x by magmafoundation.

the class ModelBuilder method toJson.

@VisibleForTesting
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    if (this.parent != null) {
        root.addProperty("parent", this.parent.getLocation().toString());
    }
    if (!this.ambientOcclusion) {
        root.addProperty("ambientocclusion", this.ambientOcclusion);
    }
    if (this.guiLight != null) {
        root.addProperty("gui_light", this.guiLight.getSerializedName());
    }
    Map<Perspective, ItemTransformVec3f> transforms = this.transforms.build();
    if (!transforms.isEmpty()) {
        JsonObject display = new JsonObject();
        for (Entry<Perspective, ItemTransformVec3f> e : transforms.entrySet()) {
            JsonObject transform = new JsonObject();
            ItemTransformVec3f vec = e.getValue();
            if (vec.equals(ItemTransformVec3f.NO_TRANSFORM))
                continue;
            if (!vec.rotation.equals(ItemTransformVec3f.Deserializer.DEFAULT_ROTATION)) {
                transform.add("rotation", serializeVector3f(vec.rotation));
            }
            if (!vec.translation.equals(ItemTransformVec3f.Deserializer.DEFAULT_TRANSLATION)) {
                transform.add("translation", serializeVector3f(e.getValue().translation));
            }
            if (!vec.scale.equals(ItemTransformVec3f.Deserializer.DEFAULT_SCALE)) {
                transform.add("scale", serializeVector3f(e.getValue().scale));
            }
            display.add(e.getKey().name, transform);
        }
        root.add("display", display);
    }
    if (!this.textures.isEmpty()) {
        JsonObject textures = new JsonObject();
        for (Entry<String, String> e : this.textures.entrySet()) {
            textures.addProperty(e.getKey(), serializeLocOrKey(e.getValue()));
        }
        root.add("textures", textures);
    }
    if (!this.elements.isEmpty()) {
        JsonArray elements = new JsonArray();
        this.elements.stream().map(ElementBuilder::build).forEach(part -> {
            JsonObject partObj = new JsonObject();
            partObj.add("from", serializeVector3f(part.from));
            partObj.add("to", serializeVector3f(part.to));
            if (part.rotation != null) {
                JsonObject rotation = new JsonObject();
                rotation.add("origin", serializeVector3f(part.rotation.origin));
                rotation.addProperty("axis", part.rotation.axis.getSerializedName());
                rotation.addProperty("angle", part.rotation.angle);
                if (part.rotation.rescale) {
                    rotation.addProperty("rescale", part.rotation.rescale);
                }
                partObj.add("rotation", rotation);
            }
            if (!part.shade) {
                partObj.addProperty("shade", part.shade);
            }
            JsonObject faces = new JsonObject();
            for (Direction dir : Direction.values()) {
                BlockPartFace face = part.faces.get(dir);
                if (face == null)
                    continue;
                JsonObject faceObj = new JsonObject();
                faceObj.addProperty("texture", serializeLocOrKey(face.texture));
                if (!Arrays.equals(face.uv.uvs, part.uvsByFace(dir))) {
                    faceObj.add("uv", new Gson().toJsonTree(face.uv.uvs));
                }
                if (face.cullForDirection != null) {
                    faceObj.addProperty("cullface", face.cullForDirection.getSerializedName());
                }
                if (face.uv.rotation != 0) {
                    faceObj.addProperty("rotation", face.uv.rotation);
                }
                if (face.tintIndex != -1) {
                    faceObj.addProperty("tintindex", face.tintIndex);
                }
                faces.add(dir.getSerializedName(), faceObj);
            }
            if (!part.faces.isEmpty()) {
                partObj.add("faces", faces);
            }
            elements.add(partObj);
        });
        root.add("elements", elements);
    }
    if (customLoader != null)
        return customLoader.toJson(root);
    return root;
}
Also used : JsonArray(com.google.gson.JsonArray) BlockPartFace(net.minecraft.client.renderer.model.BlockPartFace) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ItemTransformVec3f(net.minecraft.client.renderer.model.ItemTransformVec3f) Direction(net.minecraft.util.Direction) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ItemTransformVec3f

use of net.minecraft.client.renderer.model.ItemTransformVec3f in project LoliServer by Loli-Server.

the class ModelBuilder method toJson.

@VisibleForTesting
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    if (this.parent != null) {
        root.addProperty("parent", this.parent.getLocation().toString());
    }
    if (!this.ambientOcclusion) {
        root.addProperty("ambientocclusion", this.ambientOcclusion);
    }
    if (this.guiLight != null) {
        root.addProperty("gui_light", this.guiLight.getSerializedName());
    }
    Map<Perspective, ItemTransformVec3f> transforms = this.transforms.build();
    if (!transforms.isEmpty()) {
        JsonObject display = new JsonObject();
        for (Entry<Perspective, ItemTransformVec3f> e : transforms.entrySet()) {
            JsonObject transform = new JsonObject();
            ItemTransformVec3f vec = e.getValue();
            if (vec.equals(ItemTransformVec3f.NO_TRANSFORM))
                continue;
            if (!vec.rotation.equals(ItemTransformVec3f.Deserializer.DEFAULT_ROTATION)) {
                transform.add("rotation", serializeVector3f(vec.rotation));
            }
            if (!vec.translation.equals(ItemTransformVec3f.Deserializer.DEFAULT_TRANSLATION)) {
                transform.add("translation", serializeVector3f(e.getValue().translation));
            }
            if (!vec.scale.equals(ItemTransformVec3f.Deserializer.DEFAULT_SCALE)) {
                transform.add("scale", serializeVector3f(e.getValue().scale));
            }
            display.add(e.getKey().name, transform);
        }
        root.add("display", display);
    }
    if (!this.textures.isEmpty()) {
        JsonObject textures = new JsonObject();
        for (Entry<String, String> e : this.textures.entrySet()) {
            textures.addProperty(e.getKey(), serializeLocOrKey(e.getValue()));
        }
        root.add("textures", textures);
    }
    if (!this.elements.isEmpty()) {
        JsonArray elements = new JsonArray();
        this.elements.stream().map(ElementBuilder::build).forEach(part -> {
            JsonObject partObj = new JsonObject();
            partObj.add("from", serializeVector3f(part.from));
            partObj.add("to", serializeVector3f(part.to));
            if (part.rotation != null) {
                JsonObject rotation = new JsonObject();
                rotation.add("origin", serializeVector3f(part.rotation.origin));
                rotation.addProperty("axis", part.rotation.axis.getSerializedName());
                rotation.addProperty("angle", part.rotation.angle);
                if (part.rotation.rescale) {
                    rotation.addProperty("rescale", part.rotation.rescale);
                }
                partObj.add("rotation", rotation);
            }
            if (!part.shade) {
                partObj.addProperty("shade", part.shade);
            }
            JsonObject faces = new JsonObject();
            for (Direction dir : Direction.values()) {
                BlockPartFace face = part.faces.get(dir);
                if (face == null)
                    continue;
                JsonObject faceObj = new JsonObject();
                faceObj.addProperty("texture", serializeLocOrKey(face.texture));
                if (!Arrays.equals(face.uv.uvs, part.uvsByFace(dir))) {
                    faceObj.add("uv", new Gson().toJsonTree(face.uv.uvs));
                }
                if (face.cullForDirection != null) {
                    faceObj.addProperty("cullface", face.cullForDirection.getSerializedName());
                }
                if (face.uv.rotation != 0) {
                    faceObj.addProperty("rotation", face.uv.rotation);
                }
                if (face.tintIndex != -1) {
                    faceObj.addProperty("tintindex", face.tintIndex);
                }
                faces.add(dir.getSerializedName(), faceObj);
            }
            if (!part.faces.isEmpty()) {
                partObj.add("faces", faces);
            }
            elements.add(partObj);
        });
        root.add("elements", elements);
    }
    if (customLoader != null)
        return customLoader.toJson(root);
    return root;
}
Also used : JsonArray(com.google.gson.JsonArray) BlockPartFace(net.minecraft.client.renderer.model.BlockPartFace) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ItemTransformVec3f(net.minecraft.client.renderer.model.ItemTransformVec3f) Direction(net.minecraft.util.Direction) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Gson (com.google.gson.Gson)2 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 BlockPartFace (net.minecraft.client.renderer.model.BlockPartFace)2 ItemTransformVec3f (net.minecraft.client.renderer.model.ItemTransformVec3f)2 Direction (net.minecraft.util.Direction)2