Package de.murmelmeister.library.utils
Class AnimationUtils
java.lang.Object
de.murmelmeister.library.utils.AnimationUtils
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
FieldsModifier and TypeFieldDescriptionprivate static final longprivate static final longprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringanimateBounce(String input, float speed) Animates a "bounce" effect on the input string by dynamically adjusting its length based on time-derived position.static StringanimateColor(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 StringanimateFull(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 StringanimatePerColorCycle(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 doublebouncePhase(float speed) Converts the supplied speed multiplier into a phase using the current system time expressed in Minecraft ticks as the base.private static doublecolorPhase(float speed) Converts the supplied speed multiplier into a phase for color animations.private static doubleComputes the current tick time with fractional precision, wrapping periodically to retain double accuracy.
-
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 of1.0fcorresponds 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 with1.0fequating 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
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 thespeedmultiplier.- Parameters:
input- The input strings to be animated; if null, the method returns nullspeed- 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
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 emptyinput- The input strings to be animated; if null, the method returns nullspeed- A speed multiplier measured against the game tick rate;1.0fadvances the color once every 20 ticks (one second),2.0fevery 10 ticks,0.5fevery 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
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.0fadvances one step every 20 ticks,2.0fevery 10 ticks,0.5fevery 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
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 ofanimateBounceandanimatePerColorCycleto 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.0fadvances once every 20 ticks,2.0fevery 10 ticks,0.5fevery 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
-