Class Motion

java.lang.Object
net.ixdarklord.coolcatcanvas.api.armature.Motion

public final class Motion extends Object
How to play one clip: how it loops, how fast, and how it blends in from whatever was playing. Motions are immutable values, so keep them in constants; each method returns a changed copy. Both sides know them, so the server can send one with ArmatureControl.
static final Motion WALK = Motion.loop("walk");                                   // the layer's transition rules
static final Motion RUN = Motion.loop("run").transition(Transition.crossfade(0.3F));
static final Motion ATTACK = Motion.once("attack").speed(1.5F).then(Motion.loop("idle"));
static final Motion SPIN = Motion.loop("spin").repeat(3).fade(0.1F).ease(Easing.BACK_OUT);
A motion that names no transition (transition, fade(float), ease(Easing)) blends in the way its layer's rules say, so how animations meet can be set in one place.
  • Field Details

    • DEFAULT_FADE

      public static final float DEFAULT_FADE
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.FriendlyByteBuf, Motion> STREAM_CODEC
  • Method Details

    • of

      public static Motion of(String clip)
      A clip, looping the way its file says (Blockbench's loop setting, or Bedrock's loop).
    • loop

      public static Motion loop(String clip)
    • once

      public static Motion once(String clip)
    • hold

      public static Motion hold(String clip)
    • pingPong

      public static Motion pingPong(String clip)
    • loopMode

      public Motion loopMode(@Nullable @Nullable LoopMode loop)
    • repeat

      public Motion repeat(int times)
      Loops this many times, then ends as LoopMode.ONCE would; 0 loops forever. Makes it a LoopMode.LOOP.
    • speed

      public Motion speed(float speed)
      Plays faster (2) or slower (0.5); negative plays backwards.
    • transition

      public Motion transition(@Nullable @Nullable Transition transition)
      How it blends in from what was playing, whatever its layer's rules say; null leaves it to them.
    • fade

      public Motion fade(float seconds)
      Seconds to blend in from what was playing (a crossfade unless transition says otherwise). 0 cuts.
    • ease

      public Motion ease(Easing easing)
      The curve of the blend in. Only named curves (Easings) can be sent from the server.
    • fadeOut

      public Motion fadeOut(float seconds)
      Seconds to blend back to rest when a LoopMode.ONCE clip ends with nothing after it (else its blend-in time).
    • startAt

      public Motion startAt(float seconds)
      Starts this many seconds into the clip.
    • restart

      public Motion restart()
      Plays from the start even if this clip is already playing on the layer. Without it, asking for the clip that is playing changes nothing, which is what a driver asked every frame needs.
    • then

      public Motion then(Motion next)
      What plays when this ends (a LoopMode.ONCE clip, or a loop with a repeat count). Chains can be long.
    • clip

      public String clip()
    • loop

      @Nullable public @Nullable LoopMode loop()
      The loop mode asked for; null means the clip's own.
    • repeat

      public int repeat()
    • speed

      public float speed()
    • transition

      @Nullable public @Nullable Transition transition()
      The transition asked for; null leaves it to the layer.
    • fadeIn

      public float fadeIn()
      Seconds it blends in over, as asked; the default if it leaves that to its layer.
    • fadeOutAsked

      public float fadeOutAsked()
      Seconds to blend back to rest at its end, if asked; negative when not (its blend-in time is used).
    • fadeOut

      public float fadeOut()
    • easing

      public Easing easing()
    • startAt

      public float startAt()
    • restarts

      public boolean restarts()
    • next

      @Nullable public @Nullable Motion next()
    • sameAs

      public boolean sameAs(Motion other)
      Whether the two would play the same thing, so switching from one to the other needs no new blend.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object