Package net.thewinnt.cutscenes.path
Interface PathLike.SegmentSerializer<T extends PathLike>
- Enclosing interface:
PathLike
public static interface PathLike.SegmentSerializer<T extends PathLike>
An object that constructs path segments from JSON and network.
-
Method Summary
Modifier and TypeMethodDescriptionReads a segment from JSON.fromNetwork(net.minecraft.network.FriendlyByteBuf buf, Path path) Reconstructs a segment from network, matching its server companion as closely as possible.static <T extends PathLike>
PathLike.SegmentSerializer<T> of(BiFunction<net.minecraft.network.FriendlyByteBuf, Path, T> network, BiFunction<com.google.gson.JsonObject, Path, T> json) A helper method to create a segment serializer from 2 functions.
-
Method Details
-
fromNetwork
Reconstructs a segment from network, matching its server companion as closely as possible.- Parameters:
buf- the buffer to read from. The data in this buffer is enough to fully recreate the original segment type.path- the path this segment belongs on. DO NOT ADD THE RESULTING SEGMENT TO THIS PATH! At the moment of construction, the constructed element is the last in the path, so its future index is equal to the current size of the path.- Returns:
- a segment reconstructed from network.
-
fromJSON
Reads a segment from JSON. The object created from here is stored on the server, and then serialized to network to be reconstructed on the client.- Parameters:
json- the JSON object representing this segment. It may not contain all the properties this segment has.path- the path this segment belongs on. DO NOT ADD THE RESULTING SEGMENT TO THIS PATH! At the moment of construction, the constructed element is the last in the path, so its future index is equal to the current size of the path.- Returns:
- a segment created from the given JSON object.
- Throws:
IllegalArgumentException- if there's not enough data to create a segment, or it is invalid
-
of
static <T extends PathLike> PathLike.SegmentSerializer<T> of(BiFunction<net.minecraft.network.FriendlyByteBuf, Path, T> network, BiFunction<com.google.gson.JsonObject, Path, T> json) A helper method to create a segment serializer from 2 functions.- Type Parameters:
T- the class for the segment type- Parameters:
network- afromNetwork(FriendlyByteBuf, Path)implementationjson- afromJSON(JsonObject, Path)implementation- Returns:
- a segment serializer for the given type
- See Also:
-