-
Notifications
You must be signed in to change notification settings - Fork 95
/
LoadableField.java
39 lines (34 loc) · 1.12 KB
/
LoadableField.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package slimeknights.mantle.data.loadable.field;
import com.google.gson.JsonObject;
import net.minecraft.network.FriendlyByteBuf;
import slimeknights.mantle.data.loadable.record.RecordLoadable;
import slimeknights.mantle.util.typed.TypedMap;
/**
* Interface for a field in a JSON object, typically used in {@link RecordLoadable} but also usable statically.
* @param <P> Parent object
* @param <T> Loadable type
*/
public interface LoadableField<T,P> extends RecordField<T,P> {
/**
* Gets the loadable from the given JSON
* @param json JSON object
* @return Parsed loadable value
* @throws com.google.gson.JsonSyntaxException If unable to read from JSON
*/
T get(JsonObject json);
@Override
default T get(JsonObject json, TypedMap context) {
return get(json);
}
/**
* Parses this loadable from the network
* @param buffer Buffer instance
* @return Parsed field value
* @throws io.netty.handler.codec.DecoderException If unable to decode
*/
T decode(FriendlyByteBuf buffer);
@Override
default T decode(FriendlyByteBuf buffer, TypedMap context) {
return decode(buffer);
}
}