AnimationMetadataSectionSerializer .java

net.minecraft.client.resources.data.AnimationMetadataSectionSerializer (class): members: serialize, getSectionName, deserialize. strings: "Invalid height".

net.minecraft.client.resources.dataclass144 linesclientextends BaseMetadataSectionSerializer<AnimationMetadataSection>5.1 KB

Implements

API Surface (3)

AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_)
JsonElement serialize(AnimationMetadataSection p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
String getSectionName()

String literals (16)

"metadata section"
"frametime"
"Invalid default frame time"
"frames"
"Invalid animation->frames: expected array, was "
"width"
"height"
"Invalid width"
"Invalid height"
"interpolate"
"frames["
"time"
"Invalid frame time"
"index"
"Invalid frame index"
"animation"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

AnimationMetadataSectionSerializer.java144 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.resources.data;
2
3
import com.google.common.collect.Lists;
4
import com.google.gson.JsonArray;
5
import com.google.gson.JsonDeserializationContext;
6
import com.google.gson.JsonElement;
7
import com.google.gson.JsonObject;
8
import com.google.gson.JsonParseException;
9
import com.google.gson.JsonPrimitive;
10
import com.google.gson.JsonSerializationContext;
11
import com.google.gson.JsonSerializer;
12
import java.lang.reflect.Type;
13
import java.util.List;
14
import net.minecraft.util.JsonUtils;
15
import org.apache.commons.lang3.Validate;
16
17
public class AnimationMetadataSectionSerializer extends BaseMetadataSectionSerializer<AnimationMetadataSection> implements JsonSerializer<AnimationMetadataSection>
18
{
19
    public AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
20
    {
21
        List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
22
        JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "metadata section");
23
        int i = JsonUtils.getInt(jsonobject, "frametime", 1);
24
25
        if (i != 1)
26
        {
27
            Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid default frame time");
28
        }
29
30
        if (jsonobject.has("frames"))
31
        {
32
            try
33
            {
34
                JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "frames");
35
36
                for (int j = 0; j < jsonarray.size(); ++j)
37
                {
38
                    JsonElement jsonelement = jsonarray.get(j);
39
                    AnimationFrame animationframe = this.parseAnimationFrame(j, jsonelement);
40
41
                    if (animationframe != null)
42
                    {
43
                        list.add(animationframe);
44
                    }
45
                }
46
            }
47
            catch (ClassCastException classcastexception)
48
            {
49
                throw new JsonParseException("Invalid animation->frames: expected array, was " + jsonobject.get("frames"), classcastexception);
50
            }
51
        }
52
53
        int k = JsonUtils.getInt(jsonobject, "width", -1);
54
        int l = JsonUtils.getInt(jsonobject, "height", -1);
55
56
        if (k != -1)
57
        {
58
            Validate.inclusiveBetween(1L, 2147483647L, (long)k, "Invalid width");
59
        }
60
61
        if (l != -1)
62
        {
63
            Validate.inclusiveBetween(1L, 2147483647L, (long)l, "Invalid height");
64
        }
65
66
        boolean flag = JsonUtils.getBoolean(jsonobject, "interpolate", false);
67
        return new AnimationMetadataSection(list, k, l, i, flag);
68
    }
69
70
    private AnimationFrame parseAnimationFrame(int p_110492_1_, JsonElement p_110492_2_)
71
    {
72
        if (p_110492_2_.isJsonPrimitive())
73
        {
74
            return new AnimationFrame(JsonUtils.getInt(p_110492_2_, "frames[" + p_110492_1_ + "]"));
75
        }
76
        else if (p_110492_2_.isJsonObject())
77
        {
78
            JsonObject jsonobject = JsonUtils.getJsonObject(p_110492_2_, "frames[" + p_110492_1_ + "]");
79
            int i = JsonUtils.getInt(jsonobject, "time", -1);
80
81
            if (jsonobject.has("time"))
82
            {
83
                Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid frame time");
84
            }
85
86
            int j = JsonUtils.getInt(jsonobject, "index");
87
            Validate.inclusiveBetween(0L, 2147483647L, (long)j, "Invalid frame index");
88
            return new AnimationFrame(j, i);
89
        }
90
        else
91
        {
92
            return null;
93
        }
94
    }
95
96
    public JsonElement serialize(AnimationMetadataSection p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
97
    {
98
        JsonObject jsonobject = new JsonObject();
99
        jsonobject.addProperty("frametime", (Number)Integer.valueOf(p_serialize_1_.getFrameTime()));
100
101
        if (p_serialize_1_.getFrameWidth() != -1)
102
        {
103
            jsonobject.addProperty("width", (Number)Integer.valueOf(p_serialize_1_.getFrameWidth()));
104
        }
105
106
        if (p_serialize_1_.getFrameHeight() != -1)
107
        {
108
            jsonobject.addProperty("height", (Number)Integer.valueOf(p_serialize_1_.getFrameHeight()));
109
        }
110
111
        if (p_serialize_1_.getFrameCount() > 0)
112
        {
113
            JsonArray jsonarray = new JsonArray();
114
115
            for (int i = 0; i < p_serialize_1_.getFrameCount(); ++i)
116
            {
117
                if (p_serialize_1_.frameHasTime(i))
118
                {
119
                    JsonObject jsonobject1 = new JsonObject();
120
                    jsonobject1.addProperty("index", (Number)Integer.valueOf(p_serialize_1_.getFrameIndex(i)));
121
                    jsonobject1.addProperty("time", (Number)Integer.valueOf(p_serialize_1_.getFrameTimeSingle(i)));
122
                    jsonarray.add(jsonobject1);
123
                }
124
                else
125
                {
126
                    jsonarray.add(new JsonPrimitive(Integer.valueOf(p_serialize_1_.getFrameIndex(i))));
127
                }
128
            }
129
130
            jsonobject.add("frames", jsonarray);
131
        }
132
133
        return jsonobject;
134
    }
135
136
    /**
137
     * The name of this section type as it appears in JSON.
138
     */
139
    public String getSectionName()
140
    {
141
        return "animation";
142
    }
143
}
144

Deobfuscated MCP 1.8.9 source of AnimationMetadataSectionSerializer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/resources/data/AnimationMetadataSectionSerializer.java), stored verbatim.