Class Tracker
java.lang.Object
kr.toxicity.model.api.tracker.Tracker
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DummyTracker, EntityTracker
Represents the core controller for a specific model instance.
A Tracker manages the lifecycle, rendering, animation, and player interaction of a model.
It coordinates with the RenderPipeline to update bone positions and send packets to players.
- Since:
- 1.15.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classHolds different types of packet bundlers for a tracker tick.static enumReason for closing a tracker.static interfaceFunctional interface for handling scheduled packets. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe multiplier to convert tracker ticks to Minecraft ticks (50ms).protected final TrackerModifierprotected final RenderPipelineprotected ModelRotatorprotected ModelScalerstatic final intThe interval in milliseconds between tracker ticks. -
Constructor Summary
ConstructorsConstructorDescriptionTracker(@NotNull RenderPipeline pipeline, @NotNull TrackerModifier modifier) Creates a new tracker. -
Method Summary
Modifier and TypeMethodDescriptionbooleanPlays an animation by name with default settings.booleananimate(@NotNull String animation, @NotNull AnimationModifier modifier) Plays an animation by name with a modifier.booleananimate(@NotNull String animation, @NotNull AnimationModifier modifier, @NotNull Runnable removeTask) Plays an animation by name with a modifier and a completion task.booleananimate(@NotNull BlueprintAnimation animation, @NotNull AnimationModifier modifier) Plays a blueprint animation with a modifier.booleananimate(@NotNull BlueprintAnimation animation, @NotNull AnimationModifier modifier, @NotNull Runnable removeTask) Plays a blueprint animation on filtered bones.booleananimate(@NotNull TrackerAnimation<?> animation) booleananimate(@NotNull TrackerAnimation<?> animation, @NotNull Runnable removeTask) @Nullable RenderedBoneRetrieves a bone by name string.@Nullable RenderedBonebone(@NotNull Predicate<RenderedBone> predicate) Retrieves the first bone matching a predicate.@Nullable RenderedBoneRetrieves a bone by name.@NotNull @Unmodifiable Collection<RenderedBone> bones()Returns a collection of all bones in the model.voidclose()protected voidclose(@NotNull Tracker.CloseReason reason) booleancreateHitBox(@NotNull BaseEntity entity, @Nullable HitBoxListener listener, @NotNull BonePredicate predicate) Creates a hitbox for bones matching a predicate.booleancreateNametag(@NotNull BonePredicate predicate, @NotNull BiConsumer<RenderedBone, ModelNametag> consumer) Creates a nametag for bones matching a predicate.voiddespawn()Despawns the model for all players without closing the tracker completely.@NotNull Stream<ModelDisplay> displays()Returns a stream of all model displays.booleanbooleanforceUpdate(boolean force) Flags the tracker for a forced update on the next tick.booleanChecks if the tracker is marked for removal.voidforRemoval(boolean removal) Marks the tracker for removal.voidframe(@NotNull Tracker.ScheduledPacketHandler handler) Registers a handler to run every frame (tracker tick).voidhandleCloseEvent(@NotNull BiConsumer<Tracker, Tracker.CloseReason> consumer) Registers a handler for the tracker close event.inthashCode()doubleheight()Calculates the height of the model based on its head bone position.booleanhide(@NotNull PlatformPlayer player) Hides the tracker from a specific player.@Nullable HitBoxhitbox(@NotNull BaseEntity entity, @Nullable HitBoxListener listener, @NotNull Predicate<RenderedBone> predicate) Retrieves or creates a hitbox for a specific bone.booleanisClosed()Checks if the tracker has been closed.booleanisHide(@NotNull PlatformPlayer player) Checks if the tracker is hidden from a specific player.booleanChecks if the tracker's update task is currently scheduled.booleanChecks if the model is spawned for a player (by UUID).booleanisSpawned(@NotNull PlatformPlayer player) Checks if the model is spawned for a player.<T extends HitBoxEvent>
voidlistenHitBox(@NotNull Class<T> eventClass, @NotNull Consumer<T> consumer) Registers a hitbox event listener for newly created hitboxes.voidlistenHitBox(@NotNull BiFunction<RenderedBone, HitBoxListener.Builder, HitBoxListener.Builder> function) Registers a hitbox-listener builder hook that is applied when hitboxes are created.abstract @NotNull PlatformLocationlocation()Returns the current location of the model.@NotNull TrackerModifiermodifier()Returns the tracker modifier.@NotNull Stringname()Returns the name of the model being tracked.booleanpause(boolean pause) Pauses or resumes the tracker's ticking.voidperPlayerTick(@NotNull BiConsumer<Tracker, PlatformPlayer> perPlayerHandler) Registers a handler to run every tick for each visible player.intReturns the number of players currently viewing the model.booleanremove(@NotNull PlatformPlayer player) Removes the model for a specific player.@NotNull ModelRendererrenderer()Returns the renderer associated with this tracker.booleanreplace(@NotNull String target, @NotNull String animation, @NotNull AnimationModifier modifier) Replaces a running animation on filtered bones.booleanreplace(@NotNull String target, @NotNull BlueprintAnimation animation, @NotNull AnimationModifier modifier) Replaces a running animation on filtered bones with a blueprint animation.@NotNull ModelRotationrotation()Returns the current rotation of the model.final voidrotation(@NotNull Supplier<ModelRotation> supplier) Sets the supplier for the base model rotation.final voidrotator(@NotNull ModelRotator rotator) Sets the model rotator strategy.@NotNull ModelScalerscaler()Returns the model scaler.voidscaler(@NotNull ModelScaler scaler) Sets the model scaler.voidschedule(long period, @NotNull Tracker.ScheduledPacketHandler handler) Schedules a handler to run periodically.booleanshow(@NotNull PlatformPlayer player) Shows the tracker to a specific player.protected booleanspawn(@NotNull PlatformPlayer player, @NotNull PacketBundler bundler) Spawns the model for a specific player.booleanstopAnimation(@NotNull String animation) Stops an animation by name.booleanstopAnimation(@NotNull Predicate<RenderedBone> filter, @NotNull String animation) Stops an animation on filtered bones.booleanstopAnimation(@NotNull Predicate<RenderedBone> filter, @NotNull String animation, @Nullable PlatformPlayer player) Stops an animation on filtered bones for a specific player (optional).voidSchedules a task to run on the next tracker tick.voidtick(long tick, @NotNull Tracker.ScheduledPacketHandler handler) Registers a handler to run every N Minecraft ticks.voidtick(@NotNull Tracker.ScheduledPacketHandler handler) Registers a handler to run every Minecraft tick (50ms).toString()booleantryUpdate(@NotNull BiPredicate<RenderedBone, BonePredicate> action, @NotNull BonePredicate predicate) Tries to apply an update action to bones matching a predicate.<T extends TrackerUpdateAction>
voidupdate(T action) Forces an update action on all bones.<T extends TrackerUpdateAction>
voidupdate(T action, @NotNull Predicate<RenderedBone> predicate) Forces an update action on filtered bones.<T extends TrackerUpdateAction>
voidupdate(T action, @NotNull BonePredicate predicate) Forces an update action on filtered bones.
-
Field Details
-
TRACKER_TICK_INTERVAL
public static final int TRACKER_TICK_INTERVALThe interval in milliseconds between tracker ticks.- Since:
- 1.15.2
- See Also:
-
MINECRAFT_TICK_MULTIPLIER
public static final int MINECRAFT_TICK_MULTIPLIERThe multiplier to convert tracker ticks to Minecraft ticks (50ms).- Since:
- 1.15.2
- See Also:
-
pipeline
-
modifier
-
rotator
-
scaler
-
-
Constructor Details
-
Tracker
public Tracker(@NotNull @NotNull RenderPipeline pipeline, @NotNull @NotNull TrackerModifier modifier) Creates a new tracker.- Parameters:
pipeline- the render pipelinemodifier- the tracker modifier- Since:
- 1.15.2
-
-
Method Details
-
isScheduled
public boolean isScheduled()Checks if the tracker's update task is currently scheduled.- Returns:
- true if scheduled, false otherwise
- Since:
- 1.15.2
-
rotation
Returns the current rotation of the model.- Returns:
- the model rotation
- Since:
- 1.15.2
-
rotation
Sets the supplier for the base model rotation.- Parameters:
supplier- the rotation supplier- Since:
- 1.15.2
-
rotator
Sets the model rotator strategy.- Parameters:
rotator- the rotator strategy- Since:
- 1.15.2
-
scaler
Returns the model scaler.- Returns:
- the scaler
- Since:
- 1.15.2
-
scaler
Sets the model scaler.- Parameters:
scaler- the new scaler- Since:
- 1.15.2
-
task
Schedules a task to run on the next tracker tick.- Parameters:
runnable- the task to run- Since:
- 1.15.2
-
frame
Registers a handler to run every frame (tracker tick).- Parameters:
handler- the packet handler- Since:
- 1.15.2
-
tick
Registers a handler to run every Minecraft tick (50ms).- Parameters:
handler- the packet handler- Since:
- 1.15.2
-
tick
Registers a handler to run every N Minecraft ticks.- Parameters:
tick- the interval in Minecraft tickshandler- the packet handler- Since:
- 1.15.2
-
perPlayerTick
Registers a handler to run every tick for each visible player.- Parameters:
perPlayerHandler- the per-player handler- Since:
- 1.15.2
-
schedule
Schedules a handler to run periodically.- Parameters:
period- the period in tracker tickshandler- the packet handler- Since:
- 1.15.2
-
name
Returns the name of the model being tracked.- Returns:
- the model name
- Since:
- 1.15.2
-
height
public double height()Calculates the height of the model based on its head bone position.- Returns:
- the height
- Since:
- 1.15.2
-
isClosed
public boolean isClosed()Checks if the tracker has been closed.- Returns:
- true if closed, false otherwise
- Since:
- 1.15.2
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
close
-
despawn
public void despawn()Despawns the model for all players without closing the tracker completely.- Since:
- 1.15.2
-
modifier
Returns the tracker modifier.- Returns:
- the modifier
- Since:
- 1.15.2
-
pause
public boolean pause(boolean pause) Pauses or resumes the tracker's ticking.- Parameters:
pause- true to pause, false to resume- Returns:
- true if the state changed, false otherwise
- Since:
- 1.15.2
-
forceUpdate
public boolean forceUpdate(boolean force) Flags the tracker for a forced update on the next tick.- Parameters:
force- true to force update- Returns:
- true if the state changed
- Since:
- 1.15.2
-
spawn
protected boolean spawn(@NotNull @NotNull PlatformPlayer player, @NotNull @NotNull PacketBundler bundler) Spawns the model for a specific player.- Parameters:
player- the target playerbundler- the packet bundler- Returns:
- true if spawned successfully
- Since:
- 1.15.2
-
remove
Removes the model for a specific player.- Parameters:
player- the target player- Returns:
- true if removed successfully
- Since:
- 1.15.2
-
playerCount
public int playerCount()Returns the number of players currently viewing the model.- Returns:
- the player count
- Since:
- 1.15.2
-
location
Returns the current location of the model.- Returns:
- the location
- Since:
- 1.15.2
-
animate
Plays an animation by name with default settings.- Parameters:
animation- the animation name- Returns:
- true if the animation started
- Since:
- 1.15.2
-
animate
public boolean animate(@NotNull @NotNull String animation, @NotNull @NotNull AnimationModifier modifier) Plays an animation by name with a modifier.- Parameters:
animation- the animation namemodifier- the animation modifier- Returns:
- true if the animation started
- Since:
- 1.15.2
-
animate
public boolean animate(@NotNull @NotNull String animation, @NotNull @NotNull AnimationModifier modifier, @NotNull @NotNull Runnable removeTask) Plays an animation by name with a modifier and a completion task.- Parameters:
animation- the animation namemodifier- the animation modifierremoveTask- the task to run when the animation ends- Returns:
- true if the animation started
- Since:
- 1.15.2
-
animate
public boolean animate(@NotNull @NotNull BlueprintAnimation animation, @NotNull @NotNull AnimationModifier modifier) Plays a blueprint animation with a modifier.- Parameters:
animation- the blueprint animationmodifier- the animation modifier- Returns:
- true if the animation started
- Since:
- 1.15.2
-
animate
-
animate
public boolean animate(@NotNull @NotNull TrackerAnimation<?> animation, @NotNull @NotNull Runnable removeTask) -
animate
public boolean animate(@NotNull @NotNull BlueprintAnimation animation, @NotNull @NotNull AnimationModifier modifier, @NotNull @NotNull Runnable removeTask) Plays a blueprint animation on filtered bones.- Parameters:
animation- the blueprint animationmodifier- the animation modifierremoveTask- the task to run when the animation ends- Returns:
- true if the animation started
- Since:
- 1.15.2
-
stopAnimation
Stops an animation by name.- Parameters:
animation- the animation name- Returns:
- true if the animation was stopped
- Since:
- 1.15.2
-
stopAnimation
public boolean stopAnimation(@NotNull @NotNull Predicate<RenderedBone> filter, @NotNull @NotNull String animation) Stops an animation on filtered bones.- Parameters:
filter- the bone filteranimation- the animation name- Returns:
- true if the animation was stopped
- Since:
- 1.15.2
-
stopAnimation
public boolean stopAnimation(@NotNull @NotNull Predicate<RenderedBone> filter, @NotNull @NotNull String animation, @Nullable @Nullable PlatformPlayer player) Stops an animation on filtered bones for a specific player (optional).- Parameters:
filter- the bone filteranimation- the animation nameplayer- the player (can be null)- Returns:
- true if the animation was stopped
- Since:
- 1.15.2
-
replace
public boolean replace(@NotNull @NotNull String target, @NotNull @NotNull String animation, @NotNull @NotNull AnimationModifier modifier) Replaces a running animation on filtered bones.- Parameters:
target- the name of the animation to replaceanimation- the name of the new animationmodifier- the modifier for the new animation- Returns:
- true if the replacement occurred
- Since:
- 1.15.2
-
replace
public boolean replace(@NotNull @NotNull String target, @NotNull @NotNull BlueprintAnimation animation, @NotNull @NotNull AnimationModifier modifier) Replaces a running animation on filtered bones with a blueprint animation.- Parameters:
target- the name of the animation to replaceanimation- the new blueprint animationmodifier- the modifier for the new animation- Returns:
- true if the replacement occurred
- Since:
- 1.15.2
-
listenHitBox
public void listenHitBox(@NotNull @NotNull BiFunction<RenderedBone, HitBoxListener.Builder, HitBoxListener.Builder> function) Registers a hitbox-listener builder hook that is applied when hitboxes are created.This delegates to
BoneEventDispatcher.handleCreateHitBox(BiFunction)in this tracker's render pipeline event dispatcher.tracker.listenHitBox((bone, builder) -> builder.interact(event -> { // custom interaction handling }));- Parameters:
function- the hitbox listener builder transformer- Since:
- 2.1.0
-
listenHitBox
public <T extends HitBoxEvent> void listenHitBox(@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Consumer<T> consumer) Registers a hitbox event listener for newly created hitboxes.This is a convenience wrapper over
listenHitBox(BiFunction).tracker.listenHitBox(HitBoxInteractEvent.class, event -> { // custom interaction handling });- Type Parameters:
T- event type- Parameters:
eventClass- target hitbox event classconsumer- event consumer- Since:
- 2.1.0
-
createHitBox
public boolean createHitBox(@NotNull @NotNull BaseEntity entity, @Nullable @Nullable HitBoxListener listener, @NotNull @NotNull BonePredicate predicate) Creates a hitbox for bones matching a predicate.- Parameters:
entity- the source entity for the hitboxlistener- the hitbox listenerpredicate- the bone predicate- Returns:
- true if any hitboxes were created
- Since:
- 1.15.2
-
hitbox
@Nullable public @Nullable HitBox hitbox(@NotNull @NotNull BaseEntity entity, @Nullable @Nullable HitBoxListener listener, @NotNull @NotNull Predicate<RenderedBone> predicate) Retrieves or creates a hitbox for a specific bone.- Parameters:
entity- the source entitylistener- the hitbox listenerpredicate- the bone predicate- Returns:
- the hitbox, or null if not found/created
- Since:
- 1.15.2
-
createNametag
public boolean createNametag(@NotNull @NotNull BonePredicate predicate, @NotNull @NotNull BiConsumer<RenderedBone, ModelNametag> consumer) Creates a nametag for bones matching a predicate.- Parameters:
predicate- the bone predicateconsumer- a consumer to configure the nametag- Returns:
- true if any nametags were created
- Since:
- 1.15.2
-
update
Forces an update action on all bones.- Type Parameters:
T- the action type- Parameters:
action- the update action- Since:
- 1.15.2
-
update
public <T extends TrackerUpdateAction> void update(@NotNull T action, @NotNull @NotNull Predicate<RenderedBone> predicate) Forces an update action on filtered bones.- Type Parameters:
T- the action type- Parameters:
action- the update actionpredicate- the bone predicate- Since:
- 1.15.2
-
update
public <T extends TrackerUpdateAction> void update(@NotNull T action, @NotNull @NotNull BonePredicate predicate) Forces an update action on filtered bones.- Type Parameters:
T- the action type- Parameters:
action- the update actionpredicate- the bone predicate- Since:
- 1.15.2
-
tryUpdate
public boolean tryUpdate(@NotNull @NotNull BiPredicate<RenderedBone, BonePredicate> action, @NotNull @NotNull BonePredicate predicate) Tries to apply an update action to bones matching a predicate.- Parameters:
action- the update actionpredicate- the bone predicate- Returns:
- true if any bones were updated
- Since:
- 1.15.2
-
bone
Retrieves a bone by name.- Parameters:
name- the bone name- Returns:
- the bone, or null if not found
- Since:
- 1.15.2
-
bone
Retrieves a bone by name string.- Parameters:
name- the bone name- Returns:
- the bone, or null if not found
- Since:
- 1.15.2
-
bone
Retrieves the first bone matching a predicate.- Parameters:
predicate- the bone predicate- Returns:
- the bone, or null if not found
- Since:
- 1.15.2
-
bones
Returns a collection of all bones in the model.- Returns:
- the bones
- Since:
- 1.15.2
-
displays
Returns a stream of all model displays.- Returns:
- the displays
- Since:
- 1.15.2
-
hide
Hides the tracker from a specific player.- Parameters:
player- the target player- Returns:
- true if hidden successfully
- Since:
- 1.15.2
-
isHide
Checks if the tracker is hidden from a specific player.- Parameters:
player- the target player- Returns:
- true if hidden
- Since:
- 1.15.2
-
show
Shows the tracker to a specific player.- Parameters:
player- the target player- Returns:
- true if shown successfully
- Since:
- 1.15.2
-
handleCloseEvent
Registers a handler for the tracker close event.- Parameters:
consumer- the handler- Since:
- 1.15.2
-
isSpawned
Checks if the model is spawned for a player (by UUID).- Parameters:
uuid- the player UUID- Returns:
- true if spawned
- Since:
- 1.15.2
-
isSpawned
Checks if the model is spawned for a player.- Parameters:
player- the player- Returns:
- true if spawned
- Since:
- 1.15.2
-
renderer
Returns the renderer associated with this tracker.- Returns:
- the renderer
- Since:
- 1.15.2
-
forRemoval
@Internal public void forRemoval(boolean removal) Marks the tracker for removal.- Parameters:
removal- true to mark for removal- Since:
- 1.15.2
-
forRemoval
@Internal public boolean forRemoval()Checks if the tracker is marked for removal.- Returns:
- true if marked for removal
- Since:
- 1.15.2
-
equals
-
hashCode
-
toString
-