Class RenderPipeline

java.lang.Object
kr.toxicity.model.api.data.renderer.RenderPipeline
All Implemented Interfaces:
Iterable<RenderedBone>, BoneEventHandler

public final class RenderPipeline extends Object implements BoneEventHandler, Iterable<RenderedBone>
Represents the rendering pipeline for a specific model instance.

This class manages the hierarchy of RenderedBones, handles player visibility and packet bundling, and coordinates animation updates and inverse kinematics (IK) solving.

Since:
1.15.2
  • Constructor Details

    • RenderPipeline

      public RenderPipeline(@NotNull @NotNull ModelRenderer parent, @NotNull @NotNull RenderSource<?> source, @NotNull @NotNull RenderedBone[] bones)
      Creates a new render pipeline.
      Parameters:
      parent - the parent model renderer
      source - the source of the rendering (entity or location)
      bones - the array of root bones
      Since:
      1.15.2
  • Method Details

    • createBundler

      @NotNull public @NotNull PacketBundler createBundler()
      Creates a packet bundler for this pipeline.
      Returns:
      a new packet bundler
      Since:
      1.15.2
    • channel

      @Nullable public @Nullable PlayerChannelHandler channel(@NotNull @NotNull UUID uuid)
      Retrieves the channel handler for a specific player.
      Parameters:
      uuid - the UUID of the player
      Returns:
      the channel handler, or null if not found
      Since:
      1.15.2
    • createAnimationBundler

      @NotNull public @NotNull AnimationBundler createAnimationBundler()
      Creates an animation packet bundler based on configuration.
      Returns:
      a new animation packet bundler
      Since:
      2.2.1
    • eventDispatcher

      @NotNull public @NotNull BoneEventDispatcher eventDispatcher()
      Specified by:
      eventDispatcher in interface BoneEventHandler
    • viewFilter

      public void viewFilter(@NotNull @NotNull Predicate<PlatformPlayer> filter)
      Adds a filter to restrict which players can view the model.
      Parameters:
      filter - the predicate to filter players
      Since:
      1.15.2
    • hideFilter

      public void hideFilter(@NotNull @NotNull Predicate<PlatformPlayer> filter)
      Adds a filter to determine if a player should be hidden from the model.
      Parameters:
      filter - the predicate to hide players
      Since:
      1.15.2
    • spawnPacketHandler

      public void spawnPacketHandler(@NotNull @NotNull Consumer<PacketBundler> spawnPacketHandler)
      Adds a handler for spawn packets.
      Parameters:
      spawnPacketHandler - the consumer to handle spawn packets
      Since:
      1.15.2
    • despawnPacketHandler

      public void despawnPacketHandler(@NotNull @NotNull Consumer<PacketBundler> despawnPacketHandler)
      Adds a handler for despawn packets.
      Parameters:
      despawnPacketHandler - the consumer to handle despawn packets
      Since:
      1.15.2
    • hidePacketHandler

      public void hidePacketHandler(@NotNull @NotNull Consumer<PacketBundler> despawnPacketHandler)
      Adds a handler for hide packets.
      Parameters:
      despawnPacketHandler - the consumer to handle hide packets
      Since:
      1.15.2
    • showPacketHandler

      public void showPacketHandler(@NotNull @NotNull Consumer<PacketBundler> despawnPacketHandler)
      Adds a handler for show packets.
      Parameters:
      despawnPacketHandler - the consumer to handle show packets
      Since:
      1.15.2
    • isSpawned

      public boolean isSpawned(@NotNull @NotNull UUID uuid)
      Checks if the model is spawned for a specific player.
      Parameters:
      uuid - the UUID of the player
      Returns:
      true if spawned, false otherwise
      Since:
      1.15.2
    • runningAnimation

      @Nullable public @Nullable RunningAnimation runningAnimation()
      Retrieves the currently running animation, if any.
      Returns:
      the running animation, or null if none
      Since:
      1.15.2
    • name

      @NotNull public @NotNull String name()
      Returns the name of the model.
      Returns:
      the model name
      Since:
      1.15.2
    • despawn

      public void despawn()
      Despawns the model for all players and clears internal state.
      Since:
      1.15.2
    • rotate

      public boolean rotate(@NotNull @NotNull ModelRotation rotation, @NotNull @NotNull PacketBundler bundler)
      Rotates the model to a new orientation.
      Parameters:
      rotation - the new rotation
      bundler - the packet bundler to use
      Returns:
      true if the rotation changed, false otherwise
      Since:
      1.15.2
    • tick

      public boolean tick(@NotNull @NotNull AnimationBundler bundler)
      Ticks the model, updating animations and IK.
      Parameters:
      bundler - the packet bundler to use
      Returns:
      true if any updates occurred
      Since:
      1.15.2
    • tick

      public boolean tick(@NotNull @NotNull UUID uuid, @NotNull @NotNull AnimationBundler bundler)
      Ticks the model for a specific player (e.g., for per-player animations).
      Parameters:
      uuid - the UUID of the player
      bundler - the packet bundler to use
      Returns:
      true if any updates occurred
      Since:
      1.15.2
    • defaultPosition

      public void defaultPosition(@NotNull @NotNull Function<org.joml.Vector3f, org.joml.Vector3f> movement)
      Sets the default position modifier for all bones.
      Parameters:
      movement - the movement function
      Since:
      1.15.2
    • scale

      public void scale(@NotNull @NotNull FloatSupplier scale)
      Scales the model.
      Parameters:
      scale - the scale supplier
      Since:
      1.15.2
    • addLocalRotModifier

      public boolean addLocalRotModifier(@NotNull @NotNull BonePredicate predicate, @NotNull @NotNull Function<org.joml.Quaternionf, org.joml.Quaternionf> mapper)
      Adds a local rotation modifier to matching bones.
      Parameters:
      predicate - the predicate to select bones
      mapper - the rotation mapping function
      Returns:
      true if any bones were modified
      Since:
      3.0.0
    • addGlobalRotModifier

      public boolean addGlobalRotModifier(@NotNull @NotNull BonePredicate predicate, @NotNull @NotNull Function<org.joml.Quaternionf, org.joml.Quaternionf> mapper)
      Adds a global rotation modifier to matching bones.
      Parameters:
      predicate - the predicate to select bones
      mapper - the rotation mapping function
      Returns:
      true if any bones were modified
      Since:
      3.0.0
    • addPositionModifier

      public boolean addPositionModifier(@NotNull @NotNull BonePredicate predicate, @NotNull @NotNull Function<org.joml.Vector3f, org.joml.Vector3f> mapper)
      Adds a position modifier to matching bones.
      Parameters:
      predicate - the predicate to select bones
      mapper - the position mapping function
      Returns:
      true if any bones were modified
      Since:
      1.15.2
    • bones

      @NotNull public @NotNull @Unmodifiable Collection<RenderedBone> bones()
      Returns a collection of all bones in this pipeline.
      Returns:
      the collection of bones
      Since:
      1.15.2
    • hitboxes

      @NotNull public @NotNull Stream<HitBox> hitboxes()
      Returns a stream of all hitboxes associated with this model.
      Returns:
      the stream of hitboxes
      Since:
      1.15.2
    • boneOf

      @Nullable public @Nullable RenderedBone boneOf(@NotNull @NotNull BoneName name)
      Retrieves a bone by its name.
      Parameters:
      name - the name of the bone
      Returns:
      the rendered bone, or null if not found
      Since:
      1.15.2
    • spawn

      @Internal public boolean spawn(@NotNull @NotNull PlatformPlayer player, @NotNull @NotNull PacketBundler bundler, @NotNull @NotNull Consumer<RenderPipeline.SpawnedPlayer> consumer)
      Spawns the model for a player.
      Parameters:
      player - the player to spawn for
      bundler - the packet bundler to use
      consumer - a consumer for the spawned player object
      Returns:
      true if spawned successfully
      Since:
      1.15.2
    • remove

      @Internal public boolean remove(@NotNull @NotNull PlatformPlayer player)
      Removes the model for a player.
      Parameters:
      player - the player to remove for
      Returns:
      true if removed successfully
      Since:
      1.15.2
    • matchTree

      public boolean matchTree(@NotNull @NotNull BonePredicate predicate, BiPredicate<RenderedBone, BonePredicate> mapper)
      Applies a mapper to bones matching a predicate.
      Parameters:
      predicate - the bone predicate
      mapper - the mapper function
      Returns:
      true if any bones matched
      Since:
      1.15.2
    • matchAnimation

      public boolean matchAnimation(@NotNull @NotNull BiPredicate<RenderedBone, AnimationOverrideState> mapper)
      Applies a mapper to bones matching an animation predicate.
      Parameters:
      mapper - the mapper function
      Returns:
      true if any bones matched
      Since:
      1.15.2
    • matchTree

      public boolean matchTree(@NotNull @NotNull Predicate<RenderedBone> predicate)
      Checks if any bones match a predicate.
      Parameters:
      predicate - the predicate
      Returns:
      true if any bones matched
      Since:
      1.15.2
    • firstNotNull

      @Nullable public <T> T firstNotNull(@NotNull @NotNull Function<RenderedBone, T> mapper)
      Finds the first non-null result of applying a mapper to all bones.
      Type Parameters:
      T - the result type
      Parameters:
      mapper - the mapper function
      Returns:
      the first non-null result, or null
      Since:
      1.15.2
    • playerCount

      public int playerCount()
      Returns the number of players currently viewing this model.
      Returns:
      the player count
      Since:
      1.15.2
    • allPlayer

      @NotNull public @NotNull Stream<PlayerChannelHandler> allPlayer()
      Returns a stream of all players viewing this model.
      Returns:
      the stream of players
      Since:
      1.15.2
    • nonHidePlayer

      @NotNull public @NotNull Stream<PlayerChannelHandler> nonHidePlayer()
      Returns a stream of players who are not hidden and pass the view filter.
      Returns:
      the stream of visible players
      Since:
      1.15.2
    • viewedPlayer

      @NotNull public @NotNull Stream<PlayerChannelHandler> viewedPlayer()
      Returns a stream of players who pass the view filter (regardless of hidden status).
      Returns:
      the stream of viewed players
      Since:
      1.15.2
    • hide

      public boolean hide(@NotNull @NotNull PlatformPlayer player)
      Hides the model from a specific player.
      Parameters:
      player - the player to hide from
      Returns:
      true if the player was successfully hidden
      Since:
      1.15.2
    • isHide

      public boolean isHide(@NotNull @NotNull PlatformPlayer player)
      Checks if the model is hidden from a specific player.
      Parameters:
      player - the player to check
      Returns:
      true if hidden
      Since:
      1.15.2
    • show

      public boolean show(@NotNull @NotNull PlatformPlayer player)
      Shows the model to a specific player (if previously hidden).
      Parameters:
      player - the player to show to
      Returns:
      true if the player was successfully shown
      Since:
      1.15.2
    • forEach

      public void forEach(@NotNull @NotNull Consumer<? super RenderedBone> action)
      Specified by:
      forEach in interface Iterable<RenderedBone>
    • iterator

      @NotNull public @NotNull Iterator<RenderedBone> iterator()
      Specified by:
      iterator in interface Iterable<RenderedBone>
    • spliterator

      @NotNull public @NotNull Spliterator<RenderedBone> spliterator()
      Specified by:
      spliterator in interface Iterable<RenderedBone>
    • stream

      @NotNull public @NotNull Stream<RenderedBone> stream()
      Returns a sequential Stream with the flattened bones as its source.
      Returns:
      a stream of all bones in this pipeline
      Since:
      2.2.0