Skip to main content

Avatar Feature - Runtime Instance

When changing values in avatar profile, the change apply to every tracked entity using that avatar profile, which is not what we wanted most of the time.

Avatar runtime solves this problem by having a separate data that exists per tracked entity avatar profile (changing the tracker's avatar profile will clear current avatar runtimes and replace with the next avatar profile's runtimes)

Preparing Avatar Runtime​

Assuming you already have an avatar feature ready. If not, you can read it here.

Your class need to extend AvatarRuntime

package ...

import dev.proststuff.skinmatics.avatar.feature.runtime.AvatarRuntime;
import dev.proststuff.skinmatics.avatar.AvatarTracker;
import dev.proststuff.skinmatics.avatar.feature.AvatarFeatureData;
import net.minecraft.client.renderer.entity.state.AvatarRenderState;

public class CustomAvatarRuntime extends AvatarRuntime<CustomAvatarFeature> {
public CustomAvatarRuntime(AvatarTracker tracker, AvatarFeatureData<CustomAvatarFeature> featureData) {
super(tracker, featureData);
}

@Override
public void tick() {}
}

Registering Avatar Runtime​

AvatarRuntimeTypeRegistry.register(
CUSTOM_AVATAR_FEATURE,
factory -> factory
.factory(CustomAvatarRuntime::new)
.ticking() // Should avatar tracker tick call `CustomAvatarRuntime.tick()`
);

Getting Avatar Runtime​

Assuming you already have an avatar tracker. You can call AvatarTracker.getRuntime(<avatar_feature>)

AvatarTracker tracker = AvatarTrackerManager.get(avatar);
CustomAvatarRuntime runtime = tracker.getRuntime(CUSTOM_AVATAR_FEATURE);