Skip to content

Player Renderer Event

liopyu edited this page Aug 20, 2024 · 5 revisions

The AnimationJS.playerRenderer Client Script provides a way to directly hook into the player renderer and execute custom rendering logic allowing modification to how player entities are rendered in-game. Here it shadows the client player tick event to give us the client player and other arguements.

renderBodyItem Method

  • Renders an item on the body of a player with customizable position and rotation.
  • Example Usage:
    AnimationJS.playerRenderer(event => {
        event.renderBodyItem("minecraft:diamond_axe", 0, 0.5, 0.25, 180, 0, 0);
    })
    • itemStack: Object - The item stack to render (String (item ID), ResourceLocation, or ItemStack)
    • xOffset: Float - The offset along the X-axis
    • yOffset: Float - The offset along the Y-axis
    • zOffset: Float - The offset along the Z-axis
    • xRotation: Float - The rotation around the X-axis (in degrees)
    • yRotation: Float - The rotation around the Y-axis (in degrees)
    • zRotation: Float - The rotation around the Z-axis (in degrees)

renderBodyItem Method with Item Lighting Overlay

  • Renders an item on the body of a player with customizable position and rotation with item lighting overlay option.
  • Example Usage:
    AnimationJS.playerRenderer(event => {
        event.renderBodyItem("minecraft:diamond_axe", 0.25, 1, 0, 0, 90, 0, 15);
    })
    • itemStack: Object - The item stack to render (String (item ID), ResourceLocation, or ItemStack)
    • xOffset: Float - The offset along the X-axis
    • yOffset: Float - The offset along the Y-axis
    • zOffset: Float - The offset along the Z-axis
    • xRotation: Float - The rotation around the X-axis (in degrees)
    • yRotation: Float - The rotation around the Y-axis (in degrees)
    • zRotation: Float - The rotation around the Z-axis (in degrees)
    • packedLight: int - The light level of the item's model

render Method which provides a direct hook into the player renderer method

  • Inside the event.render method, you can implement your custom rendering logic using the provided context.
AnimationJS.playerRenderer(event => {
    event.render(context => {
        const { renderer, entity, entityYaw, partialTicks, poseStack, buffer, packedLight } = context;
        // Your custom rendering logic goes here
    });
});

getRenderContext Method

  • Retrieves the render context, providing access to various parameters for custom rendering.
  • Example Usage:
    AnimationJS.playerRenderer(event => {
        const { renderer, entity, entityYaw, partialTicks, poseStack, buffer, packedLight } = event.getRenderContext();
    })
    This method returns a PlayerRenderContext object containing:
    • renderer: PlayerRenderer - The player renderer instance.
    • entity: AbstractClientPlayer - The client player entity being rendered.
    • entityYaw: float - The yaw rotation of the entity.
    • partialTicks: float - The partial tick time.
    • poseStack: PoseStack - The pose stack for applying transformations.
    • buffer: MultiBufferSource - The buffer for rendering.
    • packedLight: int - The packed light level.

Cancel Default Renderer

  • The event is cancellable with event.cancel(). This halts the default Minecraft renderer method without disabling AnimationJS' animation render logic.
  • Example Usage:
    AnimationJS.playerRenderer(event => {
        event.cancel();
    })

Clone this wiki locally