Skip to main content

Avatar Feature - Data Serialization

Skinmatics only provide data serialization, tickings, as well as some abstract classes. You need to implement your own feature on your own through various methods (e.g. Minecraft itself, Mixins, Fabric API, etc.)

There are two things that you need:

  • A settings class as the data holder (record class is recommended)
  • A codec of said settings class to be able to save or load file

1. Avatar Settings & Codec​

The settings does not need to extends or implements any class or interfaces. It can just be a regular class or record of any scale, as long as the Minecraft codec can serialize/deserialize.

public record Body(boolean slim, Vec2 scale, boolean customBaseTexture, boolean emissive, boolean strongerEmissive, Animatable baseTextures, Animatable emissiveTextures) {
public static final Codec<Body> CODEC = RecordCodecBuilder.create(
inst -> inst.group(
Codec.BOOL.fieldOf("slim").forGetter(Body::slim),
Vec2.CODEC.fieldOf("scale").forGetter(Body::scale),
Codec.BOOL.fieldOf("customBaseTexture").forGetter(Body::customBaseTexture),
Codec.BOOL.fieldOf("emissive").forGetter(Body::emissive),
Codec.BOOL.fieldOf("strongerEmissive").forGetter(Body::strongerEmissive),
Animatable.CODEC.fieldOf("baseTextures").forGetter(Body::baseTextures),
Animatable.CODEC.fieldOf("emissiveTextures").forGetter(Body::emissiveTextures)
).apply(inst, Body::new)
);
}

2. Registering Avatar Feature​

Next step is registering the settings itself. You register it using dev.proststuff.skinmatics.avatar.feature.type.AvatarFeatureTypeRegistry.register(<id>, <codec>, <default>)

AvatarFeatureTypeRegistry.register(Identifier.fromNamespaceAndPath("skinmatics", "body"), Body.CODEC, () -> new Body(
false,
new Vec2(1.0F, 1.0F),
false, false, false,
new Animatable(), new Animatable()
)
);

And that's it! Run the game to make sure there's no error. Try adding a new avatar feature in the customize section to see whether it is being saved or not.

{
"features": {
"skinmatics:body": {
"slim": false,
"scale": [1.0, 1.0],
"customBaseTexture": false,
"emissive": false,
"strongerEmissive": false,
"baseTextures": {},
"emissiveTextures": {}
}
}
}

That's all for this page. The implementation is up to you.

You can join our Discord server to discuss or read the Skinmatics source code to see how we implement our own avatar feature.