Search in sources :

Example 1 with ModelState

use of com.builtbroken.mc.client.json.render.state.ModelState in project Engine by VoltzEngine-Project.

the class ModelStateJsonProcessor method process.

@Override
public IRenderState process(JsonObject renderStateObject, String stateID, String globalRenderType, String subRenderType) {
    ModelState renderState;
    //Data
    String modelID = null;
    Pos offset = null;
    Pos scale = null;
    EulerAngle rotation = null;
    //Load model ID, child objects may or may not contain this
    if (renderStateObject.has("modelID")) {
        modelID = renderStateObject.get("modelID").getAsString();
    }
    //Loads position offset
    if (renderStateObject.has("offset")) {
        offset = JsonConverterPos.fromJson(renderStateObject.get("offset"));
        if (offset == null) {
            throw new IllegalArgumentException("Unknown value type for offset " + renderStateObject.get("offset"));
        }
    }
    //Loads scale value
    if (renderStateObject.has("scale")) {
        scale = JsonConverterPos.fromJson(renderStateObject.get("scale"));
        if (scale == null) {
            throw new IllegalArgumentException("Unknown value type for scale " + renderStateObject.get("scale"));
        }
    }
    //Loads rotations
    if (renderStateObject.has("rotation")) {
        JsonObject rotationObject = renderStateObject.get("rotation").getAsJsonObject();
        double yaw = 0;
        double pitch = 0;
        double roll = 0;
        if (rotationObject.has("yaw")) {
            yaw = rotationObject.getAsJsonPrimitive("yaw").getAsDouble();
        }
        if (rotationObject.has("pitch")) {
            pitch = rotationObject.getAsJsonPrimitive("pitch").getAsDouble();
        }
        if (rotationObject.has("roll")) {
            roll = rotationObject.getAsJsonPrimitive("roll").getAsDouble();
        }
        rotation = new EulerAngle(yaw, pitch, roll);
    }
    //Creates state object
    if (globalRenderType.equalsIgnoreCase("tile")) {
        renderState = new TileState(stateID, modelID, offset, scale, rotation);
    } else {
        renderState = new ModelState(stateID, modelID, offset, scale, rotation);
    }
    if (renderStateObject.has("renderOnlyParts")) {
        renderState.renderOnlyParts = renderStateObject.get("renderOnlyParts").getAsBoolean();
    }
    if (renderStateObject.has("renderParent")) {
        renderState.renderParent = renderStateObject.get("renderParent").getAsBoolean();
    }
    //Loads parts to render if all is not selected
    if (renderStateObject.has("parts")) {
        String parts = renderStateObject.get("parts").getAsString();
        if (!parts.equals("all")) {
            renderState.parts = parts.split(",");
        }
    }
    return renderState;
}
Also used : TileState(com.builtbroken.mc.client.json.render.tile.TileState) JsonConverterPos(com.builtbroken.mc.lib.json.conversion.JsonConverterPos) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ModelState(com.builtbroken.mc.client.json.render.state.ModelState) JsonObject(com.google.gson.JsonObject) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle)

Aggregations

ModelState (com.builtbroken.mc.client.json.render.state.ModelState)1 TileState (com.builtbroken.mc.client.json.render.tile.TileState)1 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 JsonConverterPos (com.builtbroken.mc.lib.json.conversion.JsonConverterPos)1 JsonObject (com.google.gson.JsonObject)1