Package dev.kosmx.playerAnim.core.data
Class AnimationBinary
java.lang.Object
dev.kosmx.playerAnim.core.data.AnimationBinary
Utility class to convert animation data to a binary format.
Includes a size predictor, using
ByteBuffer
Does not pack extraData, that must be done manually-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateSize(KeyframeAnimation animation, int version) static booleangetBoolean(ByteBuffer buf) Reads a bool value from byteBufferstatic intCurrent animation binary versionstatic StringgetString(ByteBuffer buf) Reads string from buf, seeputString(ByteBuffer, String)static voidputBoolean(ByteBuffer byteBuffer, boolean bl) Writes a bool value into byteBuffer, using 1 byte per boolstatic voidputString(ByteBuffer buf, String str) Writes a binary string into byteBuf first 4 bytes for size, then string datastatic KeyframeAnimationread(ByteBuffer buf, int version) Read keyframe animation from binary data.static <T extends ByteBuffer>
Twrite(KeyframeAnimation animation, T buf) Write the animation into the ByteBuffer using the latest format versionstatic <T extends ByteBuffer>
Twrite(KeyframeAnimation animation, T buf, int version) Write the animation into the ByteBuffer.
-
Constructor Details
-
AnimationBinary
public AnimationBinary()
-
-
Method Details
-
write
public static <T extends ByteBuffer> T write(KeyframeAnimation animation, T buf, int version) throws BufferOverflowException Write the animation into the ByteBuffer. Versioning: 1. Emotecraft 2.1 features 2. New animation format for Animation library - including enable states, dynamic parts format type 1 takes fewer data, but only works for standard models and unable to send data for disabled states- Type Parameters:
T- ByteBuffer- Parameters:
animation- animationbuf- target byteBufversion- Binary version- Returns:
- target byteBuf for chaining
- Throws:
BufferOverflowException- if can't write into ByteBuf
-
write
public static <T extends ByteBuffer> T write(KeyframeAnimation animation, T buf) throws BufferOverflowException Write the animation into the ByteBuffer using the latest format version- Type Parameters:
T- ByteBuffer- Parameters:
animation- animationbuf- target byteBuf- Returns:
- target byteBuf for chaining
- Throws:
BufferOverflowException- if can't write into byteBuf
-
read
Read keyframe animation from binary data. creates a Bool extra property with validation data with namevalid- Parameters:
buf- byteBufversion- format version (not stored in binary)- Returns:
- KeyframeAnimation
- Throws:
BufferUnderflowException- if there is not enough data in ByteBufferIOException- if encounters invalid data
-
getCurrentVersion
public static int getCurrentVersion()Current animation binary version- Returns:
- version
-
calculateSize
-
putBoolean
Writes a bool value into byteBuffer, using 1 byte per bool- Parameters:
byteBuffer- bufbl- bool
-
getBoolean
Reads a bool value from byteBuffer- Parameters:
buf- buf- Returns:
- bool
-
putString
Writes a binary string into byteBuf first 4 bytes for size, then string data- Parameters:
buf- bufstr- str
-
getString
Reads string from buf, seeputString(ByteBuffer, String)- Parameters:
buf- buf- Returns:
- str
-