下面列出了怎么用net.minecraftforge.common.model.animation.IClip的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* post-loading initialization hook.
*/
void initialize() {
if (parameters == null) {
throw new JsonParseException("Animation State Machine should contain \"parameters\" key.");
}
if (clips == null) {
throw new JsonParseException("Animation State Machine should contain \"clips\" key.");
}
if (states == null) {
throw new JsonParseException("Animation State Machine should contain \"states\" key.");
}
if (transitions == null) {
throw new JsonParseException("Animation State Machine should contain \"transitions\" key.");
}
shouldHandleSpecialEvents = true;
lastPollTime = Float.NEGATIVE_INFINITY;
// setting the starting state
IClip state = clips.get(startState);
if (!clips.containsKey(startState) || !states.contains(startState)) {
throw new IllegalStateException("unknown state: " + startState);
}
currentStateName = startState;
currentState = state;
}
@Deprecated
public HarvesterAnimationStateMachine(ImmutableMap<String, ITimeValue> parameters,
ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMap<String, String> transitions,
String startState) {
this(parameters, clips, states, ImmutableMultimap.copyOf(
Multimaps.newSetMultimap(Maps.transformValues(transitions, ImmutableSet::of), Sets::newHashSet)),
startState);
}
public HarvesterAnimationStateMachine(ImmutableMap<String, ITimeValue> parameters,
ImmutableMap<String, IClip> clips, ImmutableList<String> states,
ImmutableMultimap<String, String> transitions, String startState) {
this.parameters = parameters;
this.clips = clips;
this.states = states;
this.transitions = transitions;
this.startState = startState;
}
@Override
public void transition(String newState) {
IClip nc = clips.get(newState);
if (!clips.containsKey(newState) || !states.contains(newState)) {
throw new IllegalStateException("unknown state: " + newState);
}
if (!transitions.containsEntry(currentStateName, newState)) {
throw new IllegalArgumentException("no transition from current clip \"" + currentStateName
+ "\" to the clip \"" + newState + "\" found.");
}
currentStateName = newState;
currentState = nc;
}
@Override
public Optional<? extends IClip> getClip(String name) {
if (animation.getClips().containsKey(name)) {
return Optional.ofNullable(animation.getClips().get(name));
}
return Optional.empty();
}
private static ITransformExecutor createForClip(final IClip clip, final NumericExpr param) {
return (initial, joint, args) -> {
final float paramValue = param.evaluate(args);
final TRSRTransformation clipTransform = clip.apply(joint).apply(paramValue);
return initial.compose(clipTransform);
};
}
@Override
public IClip apply(String name) {
return asm.clips.get(name);
}
@Override
public ITransformExecutor bind(IClipProvider provider) {
final Optional<? extends IClip> clip = provider.get(clipName);
Preconditions.checkState(clip.isPresent(), "Can't find clip '%s'", clipName);
return createForClip(clip.get(), param);
}
public TestClipProvider put(String key, IClip clip) {
clips.put(key, clip);
return this;
}
@Override
public Optional<? extends IClip> get(String name) {
return Optional.ofNullable(clips.get(name));
}
private static TestClipProvider clips(String key, IClip clip) {
return new TestClipProvider().put(key, clip);
}
public Optional<? extends IClip> get(String name);