Class JsonHelper

java.lang.Object
net.thewinnt.cutscenes.util.JsonHelper

public class JsonHelper extends Object
A class containing some helpful functions for JSON parsing.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @org.jetbrains.annotations.Nullable float[]
    getColor(com.google.gson.JsonObject json, String name, float defaultAlpha)
    Gets a 4-long float array from a JSON object, if it's written in the form of [r, g, b, a] or "#RRGGBBAA"
    static @Nullable com.google.gson.JsonElement
    getFromArraySafe(com.google.gson.JsonArray array, int index)
    Returns a JSON element from an array, or null if the array is too short or the element is null
    static @Nullable com.google.gson.JsonObject
    getNullableObject(com.google.gson.JsonObject json, String name)
    Returns a JSON object from another object, or null if it's absent or null
    static @Nullable PointProvider
    pointFromJson(com.google.gson.JsonElement json)
    Returns a point provider from a JSON object.
    static @Nullable PointProvider
    pointFromJson(com.google.gson.JsonObject json, String name)
    Returns a point provider from a JSON object.
    static @Nullable net.minecraft.world.phys.Vec3
    vec3FromJson(com.google.gson.JsonElement json)
    Gets a Vec3 from a JSON element, if it's written in the form of [x, y, z]
    static @Nullable net.minecraft.world.phys.Vec3
    vec3FromJson(com.google.gson.JsonObject json, String name)
    Gets a Vec3 from a JSON object, if it's written in the form of [x, y, z]

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonHelper

      public JsonHelper()
  • Method Details

    • vec3FromJson

      @Nullable public static @Nullable net.minecraft.world.phys.Vec3 vec3FromJson(com.google.gson.JsonObject json, String name)
      Gets a Vec3 from a JSON object, if it's written in the form of [x, y, z]
      Parameters:
      json - The JSON object to look in
      name - The name of the field
      Returns:
      the Vec3, if it's there and written correctly, or null otherwise
      Throws:
      IndexOutOfBoundsException - if the vector array is shorter than 3 numbers
    • vec3FromJson

      @Nullable public static @Nullable net.minecraft.world.phys.Vec3 vec3FromJson(com.google.gson.JsonElement json)
      Gets a Vec3 from a JSON element, if it's written in the form of [x, y, z]
      Parameters:
      json - The JSON element to read from
      Returns:
      the Vec3, if it's written correctly, or null otherwise
      Throws:
      IndexOutOfBoundsException - if the vector array is shorter than 3 numbers
    • pointFromJson

      @Nullable public static @Nullable PointProvider pointFromJson(com.google.gson.JsonObject json, String name)
      Returns a point provider from a JSON object. If it's an inlined vector, like this: "point": [1, 2, 3], returns a static provider. Otherwise, looks for a type field and returns the PointProvider corresponding to that type.
      Parameters:
      json - The JSON object to look for
      name - The name of the field
      Returns:
      a point provider
    • pointFromJson

      @Nullable public static @Nullable PointProvider pointFromJson(com.google.gson.JsonElement json)
      Returns a point provider from a JSON object. If it's an inlined vector, like this: "point": [1, 2, 3], returns a static provider. Otherwise, looks for a type field and returns the PointProvider corresponding to that type.
      Parameters:
      json - The JSON object to look for
      Returns:
      a point provider
    • getColor

      @Nullable public static @org.jetbrains.annotations.Nullable float[] getColor(com.google.gson.JsonObject json, String name, float defaultAlpha)
      Gets a 4-long float array from a JSON object, if it's written in the form of [r, g, b, a] or "#RRGGBBAA"
      Parameters:
      json - The JSON object to look in
      name - The name of the field
      defaultAlpha - Value of output[3], if it's not specified
      Returns:
      the float array, if it's there and written correctly, or null otherwise
      Throws:
      IndexOutOfBoundsException - if the color array is shorter than 3 numbers
    • getNullableObject

      @Nullable public static @Nullable com.google.gson.JsonObject getNullableObject(com.google.gson.JsonObject json, String name)
      Returns a JSON object from another object, or null if it's absent or null
    • getFromArraySafe

      @Nullable public static @Nullable com.google.gson.JsonElement getFromArraySafe(com.google.gson.JsonArray array, int index)
      Returns a JSON element from an array, or null if the array is too short or the element is null