minecraft-src/net/minecraft/client/animation/AnimationDefinition.java
2025-07-04 01:41:11 +03:00

40 lines
1.3 KiB
Java

package net.minecraft.client.animation;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public record AnimationDefinition(float lengthInSeconds, boolean looping, Map<String, List<AnimationChannel>> boneAnimations) {
@Environment(EnvType.CLIENT)
public static class Builder {
private final float length;
private final Map<String, List<AnimationChannel>> animationByBone = Maps.<String, List<AnimationChannel>>newHashMap();
private boolean looping;
public static AnimationDefinition.Builder withLength(float lengthInSeconds) {
return new AnimationDefinition.Builder(lengthInSeconds);
}
private Builder(float lengthInSeconds) {
this.length = lengthInSeconds;
}
public AnimationDefinition.Builder looping() {
this.looping = true;
return this;
}
public AnimationDefinition.Builder addAnimation(String bone, AnimationChannel animationChannel) {
((List)this.animationByBone.computeIfAbsent(bone, string -> new ArrayList())).add(animationChannel);
return this;
}
public AnimationDefinition build() {
return new AnimationDefinition(this.length, this.looping, this.animationByBone);
}
}
}