Class AnimationUtils

java.lang.Object
de.murmelmeister.library.utils.AnimationUtils

public final class AnimationUtils extends Object
Utility class for animating strings with effects such as bouncing and color cycling. This class provides methods to create animated string effects based on input strings, color codes, and a floating-point speed multiplier that influences the animation state.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
     
    private static final long
     
    private static final long
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    animateBounce(String input, float speed)
    Animates a "bounce" effect on the input string by dynamically adjusting its length based on time-derived position.
    static String
    animateColor(List<String> colors, String input, float speed)
    Animates a given input string by prefixing it with a color code from a list, chosen based on a cyclic calculation using the provided speed value.
    static String
    animateFull(List<String> colors, String input, float speed)
    Animates an input string by first applying a "bounce" effect and then animating it with color codes from a list in a cyclic fashion.
    static String
    animatePerColorCycle(List<String> colors, String input, float speed)
    Animates a given input string by interleaving it with color codes from a list, based on a cyclic calculation using the provided speed value and the current system time.
    private static double
    bouncePhase(float speed)
    Converts the supplied speed multiplier into a phase using the current system time expressed in Minecraft ticks as the base.
    private static double
    colorPhase(float speed)
    Converts the supplied speed multiplier into a phase for color animations.
    private static double
    Computes the current tick time with fractional precision, wrapping periodically to retain double accuracy.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NANOS_PER_TICK

      private static final long NANOS_PER_TICK
    • PHASE_WRAP_TICKS

      private static final long PHASE_WRAP_TICKS
      See Also:
    • PHASE_WRAP_MASK

      private static final long PHASE_WRAP_MASK
      See Also:
  • Constructor Details

    • AnimationUtils

      private AnimationUtils()
  • Method Details

    • bouncePhase

      private static double bouncePhase(float speed)
      Converts the supplied speed multiplier into a phase using the current system time expressed in Minecraft ticks as the base. The phase increases (or decreases) continuously over time, ensuring deterministic animation steps driven by the supplied speed factor alone.
      Parameters:
      speed - The speed multiplier; positive values move the animation forward over time, negative values move it in reverse. A value of 1.0f corresponds to the base Minecraft tick rate (20 ticks per second).
      Returns:
      The current phase value for the bounce animation
    • colorPhase

      private static double colorPhase(float speed)
      Converts the supplied speed multiplier into a phase for color animations. The value represents how many color steps have elapsed with 1.0f equating to 20 ticks (one second) per step.
      Parameters:
      speed - The speed multiplier. Values greater than 1 speed up the cycle (fewer ticks per step), values between 0 and 1 slow it down (more ticks per step), and negative values reverse it.
      Returns:
      The current phase value for color animations
    • animateBounce

      public static String animateBounce(String input, float speed)
      Animates a "bounce" effect on the input string by dynamically adjusting its length based on time-derived position. The length modification occurs cyclically and can be accelerated or slowed down via the speed multiplier.
      Parameters:
      input - The input strings to be animated; if null, the method returns null
      speed - The speed multiplier measured against the game tick rate; values greater than 1 speed up the animation, values between 0 and 1 slow it down, and negative values reverse it
      Returns:
      A substring of the input, adjusted according to the bounce animation logic; if the input is null or its length is zero, the method returns the input as is
    • animateColor

      public static String animateColor(List<String> colors, String input, float speed)
      Animates a given input string by prefixing it with a color code from a list, chosen based on a cyclic calculation using the provided speed value. The current system time is used to derive the animation phase, meaning the animation continues to progress even if the method is invoked at irregular intervals.
      Parameters:
      colors - A list of color codes to select from; must not be null or empty
      input - The input strings to be animated; if null, the method returns null
      speed - A speed multiplier measured against the game tick rate; 1.0f advances the color once every 20 ticks (one second), 2.0f every 10 ticks, 0.5f every 40 ticks, and negative values reverse the direction
      Returns:
      The input string prefixed with the selected color code, or the input as is if colors are null, empty, or input is null
    • animatePerColorCycle

      public static String animatePerColorCycle(List<String> colors, String input, float speed)
      Animates a given input string by interleaving it with color codes from a list, based on a cyclic calculation using the provided speed value and the current system time. Each character in the input string is prefixed with a color code selected in a round-robin fashion from the provided list.
      Parameters:
      colors - A list of color codes to select from; must not be null or empty. Each color is assigned cyclically to the characters in the input string.
      input - The input strings to be animated; if null, the method returns null. If the color list is null or empty, the input string is returned as is.
      speed - A speed multiplier measured against the game tick rate; 1.0f advances one step every 20 ticks, 2.0f every 10 ticks, 0.5f every 40 ticks, and negative values reverse the direction
      Returns:
      The input string with each character prefixed by a cyclically assigned color code from the list. If colors are null, empty, or input is null, the method returns the input string unmodified.
    • animateFull

      public static String animateFull(List<String> colors, String input, float speed)
      Animates an input string by first applying a "bounce" effect and then animating it with color codes from a list in a cyclic fashion. The method combines the results of animateBounce and animatePerColorCycle to produce the final animated string.
      Parameters:
      colors - A list of color codes to select from; must not be null or empty. Color codes are applied cyclically to the characters in the input string.
      input - The input strings to be animated; if null, the method returns null. If the color list is null or empty, the input string is returned after the bounce effect is applied.
      speed - A speed multiplier measured against the game tick rate, influencing the results of both the bounce and color effects; 1.0f advances once every 20 ticks, 2.0f every 10 ticks, 0.5f every 40 ticks, and negative values reverse the direction
      Returns:
      An animated string with a "bounce" effect followed by cyclically applied color codes. If the input is null, the method returns null. If the color list is null or empty, the method returns the string with only the bounce effect applied.
    • currentTickTime

      private static double currentTickTime()
      Computes the current tick time with fractional precision, wrapping periodically to retain double accuracy.
      Returns:
      The current tick time in the range [0, PHASE_WRAP_TICKS) with fractional tick progress