24package com.dreamfirestudios.dreamcore.DreamArmorStand;
27import org.bukkit.entity.ArmorStand;
28import org.bukkit.util.EulerAngle;
32import java.util.concurrent.CopyOnWriteArrayList;
44 private UUID animatorID;
46 private ArmorStand targetArmorStand;
47 private List<ArmorStandAnimationFrameData> frames =
new CopyOnWriteArrayList<>();
48 private int currentFrameIndex = 0;
49 private int currentFrameTick = 0;
51 private volatile boolean paused =
true;
67 if (frames.isEmpty() || targetArmorStand ==
null)
return true;
68 if (paused)
return false;
75 EulerAngle newHead =
new EulerAngle(
80 targetArmorStand.setHeadPose(newHead);
84 EulerAngle newBody =
new EulerAngle(
89 targetArmorStand.setBodyPose(newBody);
93 EulerAngle newLeftArm =
new EulerAngle(
98 targetArmorStand.setLeftArmPose(newLeftArm);
102 EulerAngle newRightArm =
new EulerAngle(
107 targetArmorStand.setRightArmPose(newRightArm);
111 EulerAngle newLeftLeg =
new EulerAngle(
116 targetArmorStand.setLeftLegPose(newLeftLeg);
120 EulerAngle newRightLeg =
new EulerAngle(
125 targetArmorStand.setRightLegPose(newRightLeg);
130 currentFrameIndex = (currentFrameIndex + 1) % frames.size();
131 currentFrameTick = 0;
136 private double interpolate(
double start,
double end,
double t) {
137 return start + (end - start) * t;
144 if (!paused) paused =
true;
151 if (paused) paused =
false;
166 private UUID animatorID = UUID.randomUUID();
167 private final List<ArmorStandAnimationFrameData> frames =
new CopyOnWriteArrayList<>();
168 private ArmorStand targetArmorStand;
176 if (animatorID !=
null) this.animatorID = animatorID;
189 if (armorStand ==
null)
throw new IllegalArgumentException(
"ArmorStand cannot be null");
190 this.targetArmorStand = armorStand;
201 if (frame ==
null || repeatFrames <= 0)
return this;
202 for (
int i = 0; i < repeatFrames; i++) {
214 if (frame !=
null) frames.add(frame);
226 if (targetArmorStand ==
null)
227 throw new IllegalArgumentException(
"Target ArmorStand must be set");
228 if (frames.isEmpty())
229 throw new IllegalArgumentException(
"At least one frame must be added");
231 animator.animatorID = animatorID;
232 animator.targetArmorStand = targetArmorStand;
233 animator.frames = frames;
Represents a single animation frame for an armor stand, defining start and end angles for each body p...
long getDurationTicks()
Gets the duration of this frame in ticks.
EulerAngle getLeftLegStart()
Gets the starting angle for the left leg.
EulerAngle getRightArmEnd()
Gets the ending angle for the right arm.
EulerAngle getRightArmStart()
Gets the starting angle for the right arm.
EulerAngle getBodyEnd()
Gets the ending angle for the body.
EulerAngle getBodyStart()
Gets the starting angle for the body.
EulerAngle getRightLegEnd()
Gets the ending angle for the right leg.
EulerAngle getRightLegStart()
Gets the starting angle for the right leg.
EulerAngle getHeadEnd()
Gets the ending angle for the head.
EulerAngle getLeftArmEnd()
Gets the ending angle for the left arm.
EulerAngle getLeftArmStart()
Gets the starting angle for the left arm.
EulerAngle getHeadStart()
Gets the starting angle for the head.
EulerAngle getLeftLegEnd()
Gets the ending angle for the left leg.
Builder for creating a DreamArmorStandAnimator.
DreamArmorStandAnimator build()
Builds and returns a DreamArmorStandAnimator.
Builder targetArmorStand(ArmorStand armorStand)
Sets the target armor stand to animate.
Builder animatorID(UUID animatorID)
Sets a custom ID for the animator.
Builder addFrame(ArmorStandAnimationFrameData frame)
Adds a single frame to the animation.
Builder addFrame(ArmorStandAnimationFrameData frame, int repeatFrames)
Adds a frame to the animation with a specified number of repeats.
Provides functionality to animate an ArmorStand by interpolating between ArmorStandAnimationFrameData...
void pause()
Pauses the animation.
void stop()
Stops the animation and clears all frames.
void play()
Resumes the animation.
boolean displayNextFrame()
Displays the next frame on the target armor stand.