Package net.thewinnt.cutscenes.util
Class JsonHelper
java.lang.Object
net.thewinnt.cutscenes.util.JsonHelper
A class containing some helpful functions for JSON parsing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @org.jetbrains.annotations.Nullable float[]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.JsonElementgetFromArraySafe(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 nullstatic @Nullable com.google.gson.JsonObjectgetNullableObject(com.google.gson.JsonObject json, String name) Returns a JSON object from another object, or null if it's absent or nullstatic @Nullable PointProviderpointFromJson(com.google.gson.JsonElement json) Returns a point provider from a JSON object.static @Nullable PointProviderpointFromJson(com.google.gson.JsonObject json, String name) Returns a point provider from a JSON object.static @Nullable net.minecraft.world.phys.Vec3vec3FromJson(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.Vec3vec3FromJson(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]
-
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 inname- 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 atypefield and returns the PointProvider corresponding to that type.- Parameters:
json- The JSON object to look forname- The name of the field- Returns:
- a point provider
-
pointFromJson
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 atypefield 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 inname- The name of the fielddefaultAlpha- 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
-