How Component sidebars work
mainComponent sidebars are a high-level abstraction that allows for cleaner, more modular sidebar design. Instead of managing indices manually, you compose a sidebar using SidebarComponents (static lines, dynamic lines, or animated lines) and wrap them in a ComponentSidebarLayout.
To update the sidebar (e.g., when a dynamic value changes or an animation advances), you must call layout.apply(sidebar) on your Sidebar instance. This should typically be done inside a tick loop.
// 1. Create components
SidebarComponent staticLine = SidebarComponent.staticLine(Component.text("A static line"));
SidebarComponent lines = SidebarComponent.builder()
.addComponent(staticLine)
.addStaticLine(Component.text("Another static line"))
.build();
// 2. Create the layout
ComponentSidebarLayout layout = new ComponentSidebarLayout(
SidebarComponent.staticLine(Component.text("Sidebar Title")),
lines
);
// 3. Apply to a sidebar
Sidebar sidebar = scoreboardLibrary.createSidebar();
layout.apply(sidebar);