### Complete Component Example: SettingsScreen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md Example of building a settings screen using various owo-ui components like labels, checkboxes, sliders, dropdowns, and buttons. Demonstrates component composition and event handling. ```java public class SettingsScreen extends BaseOwoScreen { @Override protected OwoUIAdapter createAdapter() { return OwoUIAdapter.create(this, FlowLayout::new); } @Override protected void build(FlowLayout root) { root .child(Components.label(Component.literal("Settings")) .positioning(Positioning.relative(10, 10))) .child(Components.checkbox(Component.literal("Enable Debug")) .positioning(Positioning.relative(10, 30)) .onChanged(enabled -> config.debug = enabled)) .child(Components.slider(Sizing.fixed(200, 20)) .positioning(Positioning.relative(10, 50)) .min(0).max(100).value(50) .onChanged(v -> config.quality = (int)v)) .child(Components.dropdown(Sizing.fixed(150, 20)) .positioning(Positioning.relative(10, 75)) .option(Component.literal("Easy"), 0) .option(Component.literal("Hard"), 1)) .child(Components.button(Component.literal("Save"), btn -> { config.save(); minecraft.setScreen(null); }).positioning(Positioning.relative(10, 110))); } } ``` -------------------------------- ### Example Usage of OverlayContainer Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md This example demonstrates creating an overlay with a black box component. The overlay is positioned absolutely, offset by 10 pixels from the current mouse coordinates. ```Java UIContainers.overlay( Components.box(Sizing.fixed(150, 100), Sizing.fixed(100, 100)) .color(Color.ofArgb(0xFF_000000)) ) .positioning(Positioning.absolute(mouseX + 10, mouseY + 10)) ``` -------------------------------- ### Example Configuration JSON File Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Configurations are stored as JSON files in the Minecraft config directory. This example shows the structure for the ModConfig class. ```json { "enableFeatures": true, "maxEntities": 100, "speedMultiplier": 1.5, "playerName": "MyPlayer", "graphics": { "brightness": 120, "shadows": false, "fov": 80 } } ``` -------------------------------- ### JSON Language File Example Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/09-text-and-serialization.md Example of a language file in JSON format used for in-game translations. It defines a chat message with placeholders for dynamic content. ```json { "chat.mymod.death": "§c%s was killed by %s" } ``` -------------------------------- ### Complex UI Layout Example Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md Demonstrates creating a complex UI layout with nested vertical and horizontal flows, scrollable content, and interactive elements like checkboxes, sliders, and buttons. This example showcases chaining multiple container configurations and component additions. ```java UIContainers.verticalFlow(Sizing.fixed(400, 300)) .positioning(Positioning.center()) .surface(Surface.VANILLA_TRANSLUCENT) .gap(10) .child(Components.label(Component.literal("Settings"))) // Options section .child(UIContainers.verticalFlow(Sizing.expand(), Sizing.content()) .gap(8) .child(Components.checkbox(Component.literal("Enable Feature A"))) .child(Components.checkbox(Component.literal("Enable Feature B"))) .child(Components.slider(Sizing.fixed(380, 20))) ) // Scrollable list .child(UIContainers.verticalScroll( Sizing.expand(), Sizing.fixed(400, 150), UIContainers.verticalFlow(Sizing.expand(), Sizing.content()) .gap(5) // Add many items )) // Buttons .child(UIContainers.horizontalFlow(Sizing.expand(), Sizing.content()) .gap(5) .child(Components.button(Component.literal("Save"), btn -> save())) .child(Components.button(Component.literal("Cancel"), btn -> close())) ) ``` -------------------------------- ### Example Usage of CollapsibleContainer Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md This example creates a collapsible container for 'Advanced Options' that is initially not expanded. It includes a checkbox and a slider as child components within the collapsible section. ```Java UIContainers.collapsible(Sizing.fixed(300, 200), Sizing.content(), Component.literal("Advanced Options"), false) .positioning(Positioning.relative(10, 50)) .child(Components.checkbox(Component.literal("Debug Mode"))) .child(Components.slider(Sizing.fixed(280, 20))) ``` -------------------------------- ### OwoLib Networking Usage Example Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Demonstrates the complete lifecycle of registering and sending packets using OwoNetChannel. Includes defining packet records, registering handlers for clientbound and serverbound packets, and sending packets from both client and server. ```java public record PositionUpdatePacket(int entityId, double x, double y, double z) {} public record ActionPacket(String action, int duration) {} // Initialization var channel = OwoNetChannel.create(new Identifier("mymod", "net")); // Register clientbound packet channel.registerClientbound(PositionUpdatePacket.class, (packet, access) -> { var world = Minecraft.getInstance().level; if (world != null) { var entity = world.getEntity(packet.entityId()); if (entity != null) { entity.setPos(packet.x(), packet.y(), packet.z()); } } }); // Register serverbound packet channel.registerServerbound(ActionPacket.class, (packet, access) -> { var player = access.player(); performAction(player, packet.action(), packet.duration()); }); // Send from client var handle = channel.clientHandle(); handle.send(new ActionPacket("jump", 10)); // Send from server var serverHandle = channel.serverHandle(player); serverHandle.send(new PositionUpdatePacket(entity.getId(), x, y, z)); ``` -------------------------------- ### Example Usage of ScrollContainer Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md This example demonstrates creating a vertical scrollable list of labels. It first builds a vertical flow container for the content and then wraps it in a vertical scroll container with specified dimensions and padding. ```Java var contentList = UIContainers.verticalFlow(Sizing.fixed(280, 100)) .gap(5); for (var item : items) { contentList.child(Components.label(item.getName())); } UIContainers.verticalScroll(Sizing.fixed(300, 150), Sizing.content(), contentList) .positioning(Positioning.relative(10, 10)) .scrollPaddingRight(5) ``` -------------------------------- ### Example Usage of DraggableContainer Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md This example shows how to make a red box component draggable. It sets fixed dimensions for the draggable container and positions it relatively on the screen. ```Java UIContainers.draggable(Sizing.fixed(100, 100), Sizing.fixed(100, 100), Components.box(Sizing.expand(), Sizing.expand()) .color(Color.ofArgb(0xFF_FF0000))) .positioning(Positioning.relative(50, 50)) ``` -------------------------------- ### Observable Configuration Tracking with ModState Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Demonstrates how to use Observables for tracking configuration changes like brightness and enabled status. It includes methods to set and get brightness, with observers reacting to changes. ```java public class ModState { private final Observable brightness = Observable.of(100); private final Observable enabled = Observable.of(true); public ModState() { brightness.observe(newBrightness -> { applyBrightness(newBrightness); }); Observable.observeAll(() -> { reloadConfig(); }, brightness, enabled); } public void setBrightness(int value) { brightness.set(value); } public int getBrightness() { return brightness.get(); } } ``` -------------------------------- ### Kotlin DSL Buildscript Setup for owo-lib Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/README.md Configure your Kotlin DSL buildscript to include the owo-lib dependency. Ensure the Maven repository is added and specify the owo-version from properties. ```kotlin repositories { maven("https://maven.wispforest.io") } dependencies { modImplementation("io.wispforest:owo-lib:${properties["owo_version"]}") // only if you plan to use owo-config annotationProcessor("io.wispforest:owo-lib:${properties["owo_version"]}") // include this if you don't want force your users to install owo // sentinel will warn them and give the option to download it automatically include("io.wispforest:owo-sentinel:${properties["owo_version"]}") } ``` -------------------------------- ### Inserting Text Content Example Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/09-text-and-serialization.md Demonstrates how to use custom text content to insert dynamic text from keys in language files. This is useful for creating templates with placeholders. ```json { "text.example.greeting": "Hello, [index=player_name]!", "text.example.message": "The answer is [index=answer]" } ``` -------------------------------- ### Example of Registering a Custom Endec Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Demonstrates how to register a custom endec for a specific class using the builder. Ensure the custom type's Endec is correctly implemented. ```java channel.addEndecs(builder -> { builder.register(MyCustomType.ENDEC, MyCustomType.class); }); ``` -------------------------------- ### Gradle Buildscript Setup for owo-lib Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/README.md Configure your Gradle buildscript to include the owo-lib dependency. Ensure the Maven repository is added and specify the owo-lib version in your properties. ```properties owo_version=... ``` ```groovy repositories { maven { url 'https://maven.wispforest.io' } } <...> dependencies { modImplementation "io.wispforest:owo-lib:${project.owo_version}" // only if you plan to use owo-config annotationProcessor "io.wispforest:owo-lib:${project.owo_version}" // include this if you don't want force your users to install owo // sentinel will warn them and give the option to download it automatically include "io.wispforest:owo-sentinel:${project.owo_version}" } ``` -------------------------------- ### serverHandle(MinecraftServer server) Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Gets the handle for sending packets from the server to all connected players. ```APIDOC ## serverHandle(MinecraftServer server) ### Description Gets the handle for sending packets from the server to all connected players. ### Method ```java public ServerHandle serverHandle(MinecraftServer server) ``` ### Parameters #### Path Parameters - **server** (MinecraftServer) - Required - Server instance ### Returns ServerHandle — Handle for broadcast packets ``` -------------------------------- ### Send Packet from Client Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Example of sending a custom packet from the client to the server using the obtained client handle. Ensure the packet class and its contents are correctly defined. ```java var clientHandle = channel.clientHandle(); clientHandle.send(new MyPacket(123, "hello", new Vec3(0, 0, 0))); ``` -------------------------------- ### clientHandle() Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Gets the handle for sending packets from the client to the server. ```APIDOC ## clientHandle() ### Description Gets the handle for sending packets from the client to the server. ### Method ```java public ClientHandle clientHandle() ``` ### Returns ClientHandle — Handle for outbound client packets ### Example ```java var clientHandle = channel.clientHandle(); clientHandle.send(new MyPacket(123, "hello", new Vec3(0, 0, 0))); ``` ``` -------------------------------- ### serverHandle(Player player) Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Gets the handle for sending packets from the server to a specific player. ```APIDOC ## serverHandle(Player player) ### Description Gets the handle for sending packets from the server to a specific player. ### Method ```java public ServerHandle serverHandle(Player player) ``` ### Parameters #### Path Parameters - **player** (Player) - Required - Target player ### Returns ServerHandle — Handle for sending to the player ### Example ```java var handle = channel.serverHandle(player); handle.send(new UpdatePacket(42)); ``` ``` -------------------------------- ### Bidirectional Networking with Packets Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md Defines packet structures, initializes a network channel, and registers handlers for server-bound and client-bound packets. This setup is crucial for custom mod communication. ```java public record PlayerActionPacket(int playerId, String action, int duration) {} public record EntityUpdatePacket(int entityId, double x, double y, double z) {} public class NetworkSetup { public static final OwoNetChannel CHANNEL = OwoNetChannel.create( new Identifier("mymod", "net") ); public static void init() { // Server-bound: Client sends to server CHANNEL.registerServerbound(PlayerActionPacket.class, (packet, access) -> { ServerPlayer player = access.player(); performAction(player, packet.action(), packet.duration()); }); // Client-bound: Server sends to client CHANNEL.registerClientbound(EntityUpdatePacket.class, (packet, access) -> { ClientLevel world = Minecraft.getInstance().level; if (world != null) { Entity entity = world.getEntity(packet.entityId()); if (entity != null) { entity.setPos(packet.x(), packet.y(), packet.z()); } } }); } private static void performAction(ServerPlayer player, String action, int duration) { switch (action) { case "jump" -> player.jumpFromGround(); case "sprint" -> player.setSprinting(true); case "sleep" -> { // Handle sleep } } } } public class ClientActionHandler { public static void sendAction(String action, int duration) { NetworkSetup.CHANNEL.clientHandle() .send(new PlayerActionPacket(Minecraft.getInstance().player.getId(), action, duration)); } } public class ServerBroadcaster { public static void updateEntity(ServerPlayer player, Entity entity) { NetworkSetup.CHANNEL.serverHandle(player) .send(new EntityUpdatePacket(entity.getId(), entity.getX(), entity.getY(), entity.getZ())); } public static void broadcastToAll(ServerLevel level, Entity entity) { NetworkSetup.CHANNEL.serverHandle(level.getServer()) .send(new EntityUpdatePacket(entity.getId(), entity.getX(), entity.getY(), entity.getZ())); } } ``` -------------------------------- ### RegistryHelper.get Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Gets or creates the RegistryHelper singleton for a given registry. This is a static factory method used to obtain an instance of RegistryHelper. ```APIDOC ## RegistryHelper.get ### Description Gets or creates the RegistryHelper singleton for a given registry. ### Method static ### Signature get(Registry registry) ### Parameters #### Path Parameters - **registry** (Registry) - Required - Target registry ### Returns RegistryHelper - Helper instance for the registry ``` -------------------------------- ### Get RegistryHelper Instance Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Retrieves or creates a singleton instance of RegistryHelper for a specific Minecraft registry. This is the entry point for using conditional registry actions. ```java public static RegistryHelper get(Registry registry) ``` -------------------------------- ### Complex Conditional Registration Action Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Implement a `RegistryAction` with `preCheck` and `update` methods for intricate conditional logic. This allows for complex setup that depends on the presence and state of multiple registry entries. ```java public void initializeComplexSystem() { RegistryHelper.get(Registries.BLOCK).runWhenPresent( new ComplexRegistryAction() { private boolean blockPresent = false; private boolean itemPresent = false; @Override public boolean preCheck(Registry registry) { return registry.containsKey(MY_BLOCK_ID) && registry.containsKey(MY_ITEM_ID); } @Override public boolean update(Identifier id, List actions) { if (id.equals(MY_BLOCK_ID)) blockPresent = true; if (id.equals(MY_ITEM_ID)) itemPresent = true; if (blockPresent && itemPresent) { actions.add(() -> initializeSystem()); return true; } return false; } } ); } private void initializeSystem() { var block = Registries.BLOCK.get(MY_BLOCK_ID); var item = Registries.ITEM.get(MY_ITEM_ID); // Setup logic } ``` -------------------------------- ### Reflection-Based Configuration Initialization Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Illustrates using reflection utilities to create configuration objects. It ensures the configuration class has a zero-argument constructor and attempts to instantiate it. ```java public class ConfigInitializer { public static ConfigWrapper createConfig(Class configClass) { ReflectionUtils.requireZeroArgsConstructor(configClass, name -> "Config class " + name + " requires a zero-arg constructor"); var instance = ReflectionUtils.tryInstantiateWithNoArgs(configClass); return new ConfigWrapper(configClass); } } ``` -------------------------------- ### ReflectionUtils.tryInstantiateWithNoArgs Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Creates an instance using the zero-argument constructor, or throws if unavailable. ```APIDOC ## tryInstantiateWithNoArgs(Class clazz) ### Description Creates an instance using the zero-argument constructor, or throws if unavailable. ### Parameters #### Path Parameters - **clazz** (Class) - Required - The class to instantiate. ### Returns T — An instance of the provided class. ``` -------------------------------- ### BaseOwoScreen.createAdapter() Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Initializes and returns the UI adapter for this screen. Typically calls `OwoUIAdapter.create()`. ```APIDOC ## BaseOwoScreen.createAdapter() ### Description Initializes and returns the UI adapter for this screen. Typically calls `OwoUIAdapter.create()`. ### Method protected abstract OwoUIAdapter createAdapter() ### Returns OwoUIAdapter — The UI adapter ``` -------------------------------- ### Create a Basic Screen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Extends BaseOwoScreen to create a simple UI screen. Requires implementing createAdapter and build methods. Components need explicit positioning and sizing. ```java public class SimpleScreen extends BaseOwoScreen { @Override protected OwoUIAdapter createAdapter() { return OwoUIAdapter.create(this, FlowLayout::new); } @Override protected void build(FlowLayout root) { root .surface(Surface.VANILLA_TRANSLUCENT) .positioning(Positioning.center()) .sizing(Sizing.fixed(200, 150)) .child( Components.label(Component.literal("Hello World")) .positioning(Positioning.relative(10, 10)) .margins(Insets.of(5)) ); } } ``` -------------------------------- ### Try Instantiate With No Arguments Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Attempts to create an instance of a class using its zero-argument constructor. Throws an exception if the constructor is not available. ```java public static T tryInstantiateWithNoArgs(Class clazz) ``` -------------------------------- ### builder() Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Gets the underlying endec builder for advanced type registration. ```APIDOC ## builder() ### Description Gets the underlying endec builder for advanced type registration. ### Method ```java public ReflectiveEndecBuilder builder() ``` ### Returns ReflectiveEndecBuilder — The builder instance ``` -------------------------------- ### Complex Settings UI Screen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md Demonstrates building a complex settings screen with nested containers, various UI components like labels, sliders, checkboxes, and buttons. It also shows how to manage configuration changes and save them. ```java public class SettingsScreen extends BaseOwoScreen { private final ConfigWrapper config; public SettingsScreen(ConfigWrapper config) { super(Component.literal("Settings")); this.config = config; } @Override protected OwoUIAdapter createAdapter() { return OwoUIAdapter.create(this, FlowLayout::new); } @Override protected void build(FlowLayout root) { root .surface(Surface.VANILLA_TRANSLUCENT) .positioning(Positioning.center()) .sizing(Sizing.fixed(400, 500)) .child(buildHeader()) .child(buildSettingsPanel()) .child(buildButtonBar()); } private UIComponent buildHeader() { return Components.label(Component.literal("Game Settings")) .positioning(Positioning.relative(10, 10)) .sizing(Sizing.content()); } private UIComponent buildSettingsPanel() { return UIContainers.verticalScroll( Sizing.fixed(380, 380), Sizing.content(), UIContainers.verticalFlow(Sizing.fixed(360, 0), Sizing.content()) .gap(15) .child(buildRenderQualityOption()) .child(buildGraphicsOptions()) .child(buildAdvancedOptions()) ) .positioning(Positioning.relative(10, 50)) .scrollPaddingRight(5); } private UIComponent buildRenderQualityOption() { var current = config.instance().renderQuality; return UIContainers.horizontalFlow(Sizing.expand(), Sizing.content()) .gap(5) .child(Components.label(Component.literal("Render Quality:")) .positioning(Positioning.relative(0, 0))) .child(Components.discreteSlider(Sizing.fixed(200, 20), 0, 5) .positioning(Positioning.relative(0, 0)) .value(current) .onChanged(quality -> { config.instance().renderQuality = (int) quality; })); } private UIComponent buildGraphicsOptions() { var graphics = config.instance().graphics; return UIContainers.collapsible( Sizing.expand(), Sizing.content(), Component.literal("Graphics Settings"), true ) .positioning(Positioning.relative(0, 0)) .child(UIContainers.verticalFlow(Sizing.expand(), Sizing.content()) .gap(8) .child(Components.label(Component.literal("Brightness:"))) .child(Components.slider(Sizing.fixed(350, 20)) .min(0).max(200).value(graphics.brightness) .onChanged(b -> graphics.brightness = (int) b)) .child(Components.checkbox(Component.literal("Enable Shadows")) .checked(graphics.enableShadows) .onChanged(enabled -> graphics.enableShadows = enabled))); } private UIComponent buildAdvancedOptions() { return UIContainers.collapsible( Sizing.expand(), Sizing.content(), Component.literal("Advanced"), false ) .positioning(Positioning.relative(0, 0)) .child(Components.label(Component.literal("FOV:")) .positioning(Positioning.relative(0, 0))) .child(Components.discreteSlider(Sizing.fixed(350, 20), 30, 120) .positioning(Positioning.relative(0, 25)) .value(config.instance().graphics.fov) .onChanged(fov -> config.instance().graphics.fov = (int) fov)); } private UIComponent buildButtonBar() { return UIContainers.horizontalFlow(Sizing.fixed(380, 30), Sizing.content()) .positioning(Positioning.relative(10, 455)) .gap(5) .child(Components.button(Component.literal("Save"), btn -> { config.save(); this.onClose(); }) .positioning(Positioning.relative(0, 0))) .child(Components.button(Component.literal("Cancel"), btn -> { this.onClose(); }) .positioning(Positioning.relative(0, 0))); } } ``` -------------------------------- ### Create a Custom Screen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/00-index.md Extend BaseOwoScreen to create a custom UI screen. Implement createAdapter to define the UI adapter and build to define the screen's layout and components. ```java public class MyScreen extends BaseOwoScreen { @Override protected OwoUIAdapter createAdapter() { return OwoUIAdapter.create(this, FlowLayout::new); } @Override protected void build(FlowLayout root) { root.child(Components.button(Component.literal("Click me"), btn -> { // Handle click })); } } ``` -------------------------------- ### BaseOwoScreen.build() Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Called after initialization to build the component hierarchy. This is where UI components are created and configured. ```APIDOC ## BaseOwoScreen.build(R rootComponent) ### Description Called after initialization to build the component hierarchy. This is where UI components are created and configured. ### Method protected abstract void build(R rootComponent) ### Parameters #### Path Parameters - **rootComponent** (R) - Required - Root UI component to build within ``` -------------------------------- ### Get Child Components Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Returns a list of all child components currently managed by this parent. ```java List children() ``` -------------------------------- ### ReflectionUtils.getCallingClassName Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Gets the name of the class that called this method at the specified depth in the call stack. ```APIDOC ## getCallingClassName(int depth) ### Description Gets the name of the class that called this method at the specified depth in the call stack. ### Parameters #### Path Parameters - **depth** (int) - Required - Stack depth (0 = immediate caller) ### Returns String — Fully qualified class name ``` -------------------------------- ### Create a Custom Owo Screen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Extend BaseOwoScreen to create a custom UI screen. Implement createAdapter to set up the UI adapter and build to define the component hierarchy. ```java public class MyConfigScreen extends BaseOwoScreen { @Override protected OwoUIAdapter createAdapter() { return OwoUIAdapter.create(this, FlowLayout::new); } @Override protected void build(FlowLayout rootComponent) { rootComponent.child( Components.button(Component.literal("Button"), btn -> { // Handle click }) ); } } ``` -------------------------------- ### ColorPickerComponent Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md A color selection widget that allows getting and setting the selected color, and registering a change listener. ```APIDOC ## ColorPickerComponent ### Description A color selection widget. ### Method Signature ```java public static ColorPickerComponent colorPicker() ``` ### Methods - `color()` - Gets selected color - `color(Color value)` - Sets color - `onChanged(Consumer)` - Sets change listener ``` -------------------------------- ### Initialize Recipes When Registries Are Present Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md This Java snippet shows how to use RegistryHelper to set up recipes. It waits for specific items and blocks to be registered before executing initialization logic. Use this when your mod's recipes or features rely on other registered content. ```java public class RecipeManager { public static void init() { // Wait for items to be registered before setting up recipes RegistryHelper.get(Registries.ITEM).runWhenPresent( new Identifier("mymod", "custom_gem"), gem -> setupGemRecipes(gem) ); // Complex dependency: wait for multiple blocks RegistryHelper.get(Registries.BLOCK).runWhenPresent(new ComplexRegistryAction() { private boolean block1Present = false; private boolean block2Present = false; @Override public boolean preCheck(Registry registry) { return registry.containsKey(BLOCK1_ID) && registry.containsKey(BLOCK2_ID); } @Override public boolean update(Identifier id, List actions) { if (id.equals(BLOCK1_ID)) block1Present = true; if (id.equals(BLOCK2_ID)) block2Present = true; if (block1Present && block2Present) { actions.add(() -> setupCombinedRecipes()); return true; } return false; } }); } private static void setupGemRecipes(Item gem) { // Create recipes using the registered gem } private static void setupCombinedRecipes() { // Create recipes combining both blocks } } ``` -------------------------------- ### CheckboxComponent Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md Creates a toggleable checkbox with a label. It supports getting and setting its checked state, and registering a listener for changes. ```APIDOC ## CheckboxComponent ### Description Creates a toggleable checkbox with a label. It supports getting and setting its checked state, and registering a listener for changes. ### Constructor `public static CheckboxComponent checkbox(Component message)` ### Parameters #### Path Parameters - **message** (Component) - Required - Label text ### Methods - `checked()` - Returns boolean checked state - `checked(boolean value)` - Sets checked state - `onChanged(Consumer)` - Sets change listener ### Request Example ```java Components.checkbox(Component.literal("Enable Feature")) .positioning(Positioning.relative(10, 10)) .onChanged(enabled -> { config.enableFeature = enabled; }) ``` ``` -------------------------------- ### TextAreaComponent Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md A multi-line text input component. It allows setting and getting the text content and handling changes to the text. ```APIDOC ## TextAreaComponent ### Description A multi-line text input. ### Methods - `value()`: Returns the current text value. - `setValue(String)`: Sets the text value. - `onChanged(Consumer)`: Registers a consumer to be called when the text value changes. ``` -------------------------------- ### Get Parent UI Component Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Returns the parent component in the UI hierarchy. This is useful for navigating up the component tree. ```java @Contract(pure = true) @Nullable ParentUIComponent parent() ``` -------------------------------- ### Define Configuration Model with Annotations Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md Defines a configuration model using owo-lib annotations for basic options, options with change hooks, nested configurations, and internal settings. Requires restart for some options. ```java @Config(name = "mymod") @Modmenu(modId = "mymod") public class MyConfig { // Basic option with restart requirement @RestartRequired public boolean enableFeature = true; // Option with change hook @Hook("onQualityChanged") public int renderQuality = 2; // Nested configuration @Expanded public GraphicsSettings graphics = new GraphicsSettings(); // Internal option, excluded from UI @ExcludeFromScreen private String internalState = ""; public void onQualityChanged(int newQuality) { if (newQuality < 0 || newQuality > 5) { Owo.LOGGER.warn("Invalid quality level: {}", newQuality); } else { updateGraphicsQuality(newQuality); } } } public class GraphicsSettings { public int brightness = 100; public boolean enableShadows = true; public int fov = 70; } ``` -------------------------------- ### Observable Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md Represents a container with support for change observation. It allows getting and setting values, and registering observers to be notified of changes. ```APIDOC ## Observable ### Description Container with change observation support. ### Class `io.wispforest.owo.util.Observable` ### Methods - `public static Observable of(T initial)`: Creates a new Observable with an initial value. - `public T get()`: Retrieves the current value of the Observable. - `public void set(T newValue)`: Sets a new value for the Observable. - `public void observe(Consumer observer)`: Registers a consumer to be notified when the Observable's value changes. ``` -------------------------------- ### serverHandle(ServerLevel level, BlockPos pos) Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Gets the handle for sending packets to all players tracking a specific block position. ```APIDOC ## serverHandle(ServerLevel level, BlockPos pos) ### Description Gets the handle for sending packets to all players tracking a specific block position. ### Method ```java public ServerHandle serverHandle(ServerLevel level, BlockPos pos) ``` ### Parameters #### Path Parameters - **level** (ServerLevel) - Required - Server world - **pos** (BlockPos) - Required - Block position to track around ### Returns ServerHandle — Handle for position-based broadcasting ### Example ```java var handle = channel.serverHandle(world, blockPos); handle.send(new BlockUpdatePacket(blockPos, newState)); ``` ``` -------------------------------- ### Get Focus Handler Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Returns the focus handler associated with this component's hierarchy. This is used for managing keyboard focus. ```java @Contract(pure = true) @Nullable FocusHandler focusHandler() ``` -------------------------------- ### VectorRandomUtils.getRandomOffset Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Generates a random offset from a center position. Each axis gets a random value from -0.5 to 0.5, scaled by the scalar. ```APIDOC ## VectorRandomUtils.getRandomOffset ### Description Generates a random offset from a center position. Each axis gets a random value from -0.5 to 0.5, scaled by the scalar. ### Method `public static Vec3 getRandomOffset(Level world, Vec3 center, double scalar)` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **world** (Level) - Required - World for random number generation - **center** (Vec3) - Required - Center position - **scalar** (double) - Required - Scale factor for randomness ### Returns Vec3 — Randomized position ``` -------------------------------- ### Access and Modify Configuration at Runtime Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md Provides a utility class to initialize, load, access, and modify owo-lib configurations at runtime. Ensures configuration changes are saved. ```java public class ConfigManager { private static ConfigWrapper wrapper; public static void init() { wrapper = ConfigManager.getInstance(MyConfig.class); wrapper.load(); } public static int getQuality() { return wrapper.instance().renderQuality; } public static void setQuality(int quality) { wrapper.instance().renderQuality = quality; wrapper.save(); } } ``` -------------------------------- ### ConfigWrapper Load Method Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Loads configuration settings from disk into the current in-memory state. ```java public void load() ``` -------------------------------- ### TextBoxComponent Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md A single-line text input component. It supports setting and getting text, defining a maximum length, and handling text changes. ```APIDOC ## TextBoxComponent ### Description A single-line text input. ### Methods - `text()`: Returns the current text. - `text(String)`: Sets the text. - `maxLength(int)`: Sets the maximum length of the text. - `onChanged(Consumer)`: Registers a consumer to be called when the text changes. ``` -------------------------------- ### Option Methods Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Methods for interacting with individual configuration options, including setting values, retrieving current values, and verifying constraints. ```APIDOC ## Option Methods ### Description Provides functionality to manage and query individual configuration options. ### Methods - **set(T value)**: Updates the option's value if it meets constraints. - **value()**: Retrieves the current value of the option. - **clazz()**: Returns the Class object representing the option's value type. - **verifyConstraint(T value)**: Checks if a given value satisfies the option's constraints. ### Method Signatures ```java public void set(T value) public T value() public Class clazz() public boolean verifyConstraint(T value) ``` ``` -------------------------------- ### Get UI Component Positioning Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Returns the component's current positioning configuration. This is an animatable property, allowing for smooth transitions. ```java @Contract(pure = true) AnimatableProperty positioning() ``` -------------------------------- ### Get Reflective Endec Builder Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Retrieves the underlying endec builder instance for advanced and fine-grained type registration. This provides more control over serialization. ```java public ReflectiveEndecBuilder builder() ``` -------------------------------- ### Accessing and Updating Configuration Values Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Demonstrates how to retrieve configuration values, update them, and persist changes using the ConfigManager. Ensure your configuration model class has a zero-argument constructor. ```java var config = ConfigManager.getInstance(MyConfig.class); boolean enabled = config.instance().enableFeatures; int quality = config.instance().qualityLevel; config.instance().enableFeatures = false; config.instance().qualityLevel = 3; config.save(); ``` -------------------------------- ### Run Action When Registry Entry Present Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Executes a consumer action when a specific registry entry becomes available. If the entry is already registered, the action runs immediately. Requires an Identifier for the registry entry. ```java public void runWhenPresent(Identifier id, Consumer action) ``` ```java RegistryHelper.get(Registries.BLOCK).runWhenPresent( new Identifier("mymod", "custom_block"), block -> { // This runs when mymod:custom_block is registered configureBlock(block); } ); ``` -------------------------------- ### Send Packet from Server Based on Block Position Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Example of sending a packet to players tracking a specific block. This is useful for block-related updates or interactions. ```java var handle = channel.serverHandle(world, blockPos); handle.send(new BlockUpdatePacket(blockPos, newState)); ``` -------------------------------- ### BaseOwoScreen Abstract Class Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md Abstract base class for creating owo-ui screens. Implement `createAdapter` and `build` to define screen behavior. ```java public abstract class BaseOwoScreen extends Screen { protected abstract OwoUIAdapter createAdapter() protected abstract void build(R rootComponent) } ``` -------------------------------- ### Option Class Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md The Option class represents a single configuration option. It provides methods to get and set the value, retrieve its type, and verify constraints. ```APIDOC ## Option ### Description Represents a single configuration option with value, type, and constraint validation. ### Methods - **value()**: Returns the current value of the option. - **set(T value)**: Sets a new value for the option. - **clazz()**: Returns the class of the option's type. - **verifyConstraint(T value)**: Verifies if the given value satisfies the option's constraints. ``` -------------------------------- ### Get Server Handle for Broadcasting Packets Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Retrieves the handle used by the server to send packets to all connected players. Use this for global announcements or updates. ```java public ServerHandle serverHandle(MinecraftServer server) ``` -------------------------------- ### Get Server Handle for Sending to Specific Player Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Retrieves the handle used by the server to send packets to a particular player. This is essential for targeted communication. ```java public ServerHandle serverHandle(Player player) ``` -------------------------------- ### BaseOwoScreen Constructor Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/03-ui-core.md Creates a new owo screen with the specified title. This is the primary class to extend when creating UI screens. ```APIDOC ## BaseOwoScreen Constructor ### Description Creates a new owo screen with the specified title. ### Method Constructor ### Parameters #### Path Parameters - **title** (Component) - Optional - Screen title/name ``` -------------------------------- ### Get Client Handle for Sending Packets Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Retrieves the handle used by the client to send packets to the server. Use this when your client needs to initiate communication. ```java public ClientHandle clientHandle() ``` -------------------------------- ### Get Calling Class Name Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Retrieves the name of the calling class based on the specified stack depth. Use depth 0 for the immediate caller. ```java public static String getCallingClassName(int depth) ``` -------------------------------- ### ComplexRegistryAction preCheck Method Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Implement this method to perform an initial check if all required registry entries are already present. Returns true if all dependencies are met, false otherwise. ```java boolean preCheck(Registry registry) ``` -------------------------------- ### Create a Label Component Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md Use this to display static or dynamic text. The text is provided as a Component. ```java Components.label(Component.literal("Health: 20")) .positioning(Positioning.relative(10, 10)) ``` -------------------------------- ### Send Packet from Server to Specific Player Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Example of sending a packet from the server to a specific player using the server handle. This is used for targeted updates or messages. ```java var handle = channel.serverHandle(player); handle.send(new UpdatePacket(42)); ``` -------------------------------- ### Content-Based Sizing for UI Elements Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md Use `Sizing.content()` to make a UI element size itself to precisely fit its children. ```rust Sizing.content() ``` -------------------------------- ### Observable-Based Player Stats Binding Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/11-practical-examples.md Demonstrates how to use Observables to manage and react to changes in player statistics like health, hunger, and experience. Useful for game state management where real-time updates and event handling are crucial. ```java public class PlayerStats { public final Observable health = Observable.of(20); public final Observable hunger = Observable.of(10); public final Observable experience = Observable.of(0.0); private final List> updateListeners = new ArrayList<>(); public PlayerStats() { // React to individual stat changes health.observe(newHealth -> { if (newHealth <= 0) triggerGameOver(); }); hunger.observe(newHunger -> { if (newHunger < 3) applyHungerEffect(); }); // React to any change Observable.observeAll(() -> { notifyListeners(); }, health, hunger, experience); } public void takeHealth(int amount) { health.set(Math.max(0, health.get() - amount)); } public void addExperience(double amount) { experience.set(experience.get() + amount); } public void addUpdateListener(Consumer listener) { updateListeners.add(listener); } private void notifyListeners() { for (var listener : updateListeners) { listener.accept(this); } } private void triggerGameOver() { // Handle death } private void applyHungerEffect() { // Apply hunger slowness } } ``` -------------------------------- ### Getting an Endec for a Type Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/09-text-and-serialization.md Retrieve an Endec for a given Java Type from the ReflectiveEndecBuilder. If an Endec is not already registered, the builder will attempt to create one via reflection. ```java Endec endec = builder.get(Type.getType(MyClass.class)); ``` -------------------------------- ### Create an Overlay Container Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md Use the overlay utility to render a child component on top of all other UI elements, suitable for tooltips or floating panels. This function takes the UI component to be displayed as an overlay. ```Java public static OverlayContainer overlay(C child) ``` -------------------------------- ### Create and Register a Network Channel Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/00-index.md Create a network channel using OwoNetChannel.registerServerbound to register a serverbound packet. The packet class must be a record. Client-side sending is handled via channel.clientHandle().send(). ```java OwoNetChannel channel = OwoNetChannel.create(new Identifier("mymod", "net")); public record MyPacket(int value, String text) {} channel.registerServerbound(MyPacket.class, (packet, access) -> { handlePacket(access.player(), packet); }); channel.clientHandle().send(new MyPacket(42, "hello")); ``` -------------------------------- ### RegistryHelper Methods Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md Provides utilities for conditional registry entry handling. Use `runWhenPresent` to safely interact with registry entries. ```java public static RegistryHelper get(Registry registry) public void runWhenPresent(Identifier id, Consumer action) public void runWhenPresent(ComplexRegistryAction action) ``` -------------------------------- ### ConfigWrapper Methods Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Provides methods for loading, saving, and accessing the configuration instance within a generated ConfigWrapper. ```APIDOC ## ConfigWrapper Methods ### Description Methods to manage the configuration lifecycle and access its instance. ### Methods - **load()**: Loads configuration from disk. - **save()**: Saves the current configuration to disk. - **instance()**: Returns the current configuration object. ### Method Signatures ```java public void load() public void save() public C instance() ``` ``` -------------------------------- ### Create OwoNetChannel Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md Creates a new OwoNetChannel for packet-based communication. ```java public static OwoNetChannel create(Identifier id) public static OwoNetChannel createOptional(Identifier id) ``` -------------------------------- ### ConfigWrapper Instance Method Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/02-config.md Retrieves the configuration model instance that holds the current configuration values. ```java public C instance() ``` -------------------------------- ### SliderComponent Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md A slider component for selecting a value within a continuous range. It allows setting minimum and maximum values, getting and setting the current value, and handling value changes. ```APIDOC ## SliderComponent ### Description A continuous value slider. ### Methods - `min(double)`: Sets the minimum value. - `max(double)`: Sets the maximum value. - `value()`: Returns the current value. - `value(double)`: Sets the current value. - `onChanged(Consumer)`: Registers a consumer to be called when the value changes. ``` -------------------------------- ### Wait for Specific Item Registration Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/06-registration.md Use `runWhenPresent` to execute logic only after a specific item (e.g., apple) has been registered. This is useful for setting up configurations or dependent features. ```java public void initializeRecipes() { var helper = RegistryHelper.get(Registries.ITEM); // Configure when apple is registered helper.runWhenPresent(Items.APPLE.getRegistryName(), apple -> { // Set up apple-related logic appleConfig = new AppleConfiguration(apple); }); } ``` -------------------------------- ### BaseOwoScreen Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/10-types-reference.md The base abstract class for creating screens using owo-ui. It requires the implementation of methods to create an adapter and build the UI. ```APIDOC ## BaseOwoScreen ### Description Base class for creating owo-ui screens. ### Class `io.wispforest.owo.ui.base.BaseOwoScreen` ### Abstract Methods - `protected abstract OwoUIAdapter createAdapter()`: Creates the OwoUIAdapter for the screen. - `protected abstract void build(R rootComponent)`: Builds the root component of the screen's UI. ``` -------------------------------- ### Get Server Handle for Sending to Players Tracking a Block Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Retrieves the handle used by the server to send packets to players currently tracking a specific block position. Useful for localized events. ```java public ServerHandle serverHandle(ServerLevel level, BlockPos pos) ``` -------------------------------- ### Create an Optional OwoNetChannel Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/01-networking.md Creates a new optional network channel. The remote side does not need this channel registered to connect. Ensure the Identifier is unique to your mod. ```java Identifier channelId = new Identifier("mymod", "optional_channel"); OwoNetChannel channel = OwoNetChannel.createOptional(channelId); ``` -------------------------------- ### Generate Random Offset Vector Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/08-utilities.md Generates a random offset from a center position. Each axis gets a random value from -0.5 to 0.5, scaled by the scalar. Requires a Level for random number generation. ```java public static Vec3 getRandomOffset(Level world, Vec3 center, double scalar) ``` -------------------------------- ### Create a Spacer Component Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md Use this to add empty space for layout. The 'percent' parameter determines the percentage of available space to fill. ```java Components.spacer(percent) ``` -------------------------------- ### Add owo-lib Maven Dependency Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/00-index.md Configure your project's build.gradle file to include the owo-lib Maven repository and dependency. Replace ${owo_version} with the desired version. ```gradle repositories { maven { url 'https://maven.wispforest.io' } } dependencies { modImplementation "io.wispforest:owo-lib:${owo_version}" annotationProcessor "io.wispforest:owo-lib:${owo_version}" } ``` -------------------------------- ### Expand Sizing for UI Elements Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/05-ui-containers.md Use `Sizing.expand()` to make a UI element fill all available space within its parent container. ```rust Sizing.expand() ``` -------------------------------- ### Create an Item Component Source: https://github.com/wisp-forest/owo-lib/blob/braid-ui/_autodocs/04-ui-components.md Use this to display an item stack, including its count and tooltips. An ItemStack is required. ```java var stack = new ItemStack(Items.DIAMOND, 64); Components.item(stack) .positioning(Positioning.relative(10, 10)) ```