### Create Custom HUD Module (Java) Source: https://context7.com/1udens/parsec/llms.txt An example demonstrating how to create a new HUD module by extending the `HudModule` class. This specific module displays biome information for the player's current location in the Minecraft world. ```java package me.ludens.parsec.systems; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.world.biome.Biome; public class BiomeModule extends HudModule { public BiomeModule() { super("Biome", 10, 40); // Position below coordinates } @Override public void render(DrawContext drawContext, TextRenderer textRenderer) { if (!enabled) return; MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null || client.world == null) return; RegistryEntry biome = client.world.getBiome(client.player.getBlockPos()); String biomeName = biome.getIdAsString(); String text = "Biome: " + biomeName.substring(biomeName.lastIndexOf(':') + 1); int width = textRenderer.getWidth(text); drawBackground(drawContext, width); drawContext.drawText(textRenderer, text, x, y, 0xFFFFFFFF, true); } } ``` -------------------------------- ### Open Click GUI and Register Key Binding (Java) Source: https://context7.com/1udens/parsec/llms.txt This snippet demonstrates how to programmatically open the Click GUI screen and how to register a key binding (Right Shift) to trigger its opening. It utilizes MinecraftClient and KeyBindingHelper for integration. ```java // Open the GUI programmatically: MinecraftClient.getInstance().setScreen(new ClickGui()); // Key binding registration (from main class): KeyBinding mappingKey = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.parsec.open_gui", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_RIGHT_SHIFT, KeyBinding.Category.MISC )); ClientTickEvents.END_CLIENT_TICK.register(client -> { while (mappingKey.wasPressed()) { client.setScreen(new ClickGui()); } }); ``` -------------------------------- ### Save and Load Module Configurations (Java) Source: https://context7.com/1udens/parsec/llms.txt The ConfigManager handles persistence of HUD module settings, including enabled state, position, and background color. Configurations are saved to and loaded from a JSON file located in the Fabric config directory. ```java package me.ludens.parsec.config; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import me.ludens.parsec.systems.HudModule; import me.ludens.parsec.systems.ModuleRenderer; import net.fabricmc.loader.api.FabricLoader; import java.io.*; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; public class ConfigManager { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir(); private static final File CONFIG_FILE = CONFIG_DIR.resolve("parsec.json").toFile(); // Save all module configurations public static void save() { Map configMap = new HashMap<>(); for (HudModule module : ModuleRenderer.modules) { ModuleConfig config = new ModuleConfig(); config.enabled = module.enabled; config.x = module.x; config.y = module.y; config.backgroundColor = module.backgroundColor; configMap.put(module.name, config); } try (FileWriter writer = new FileWriter(CONFIG_FILE)) { GSON.toJson(configMap, writer); } catch (Exception e) { /* handle error */ } } // Load configurations and apply to registered modules public static void load() { if (!CONFIG_FILE.exists()) return; try (FileReader reader = new FileReader(CONFIG_FILE)) { Map configMap = GSON.fromJson(reader, Map.class); if (configMap == null) return; for (HudModule module : ModuleRenderer.modules) { ModuleConfig config = configMap.get(module.name); if (config != null) { module.enabled = config.enabled; module.x = config.x; module.y = config.y; module.backgroundColor = config.backgroundColor; } } } catch (Exception e) { /* handle error */ } } private static class ModuleConfig { boolean enabled; int x, y; int backgroundColor; } } // Config file location: .minecraft/config/parsec.json // Example JSON output: // { // "FPS": { // "enabled": true, // "x": 10, // "y": 10, // "backgroundColor": -1442840576 // }, // "Coordinates": { // "enabled": true, // "x": 10, // "y": 25, // "backgroundColor": -1442840576 // } // } ``` -------------------------------- ### Register Custom HUD Modules (Java) Source: https://context7.com/1udens/parsec/llms.txt A method snippet showing how to register custom HUD modules within the Parsec framework. This is typically done during the client's initialization phase to make the modules available. ```java // Register in parsec.java onInitializeClient(): private void registerModules() { ModuleRenderer.addModule(new FpsModule()); ModuleRenderer.addModule(new CordsModule()); ModuleRenderer.addModule(new BiomeModule()); // Add new module } ``` -------------------------------- ### Display Player Coordinates with Caching (Java) Source: https://context7.com/1udens/parsec/llms.txt The CordsModule displays the player's X, Y, and Z coordinates. It optimizes rendering by caching the coordinate string and only updating it when the player's position changes, reducing unnecessary string formatting. ```java package me.ludens.parsec.systems; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; public class CordsModule extends HudModule { private String cachedText = ""; private int lastX = Integer.MAX_VALUE; private int lastY = Integer.MAX_VALUE; private int lastZ = Integer.MAX_VALUE; public CordsModule() { super("Coordinates", 10, 25); // Default position: x=10, y=25 } @Override public void render(DrawContext drawContext, TextRenderer textRenderer) { if (!enabled) return; MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null) return; int xPos = (int) client.player.getX(); int yPos = (int) client.player.getY(); int zPos = (int) client.player.getZ(); // Only update text if position changed (optimization) if (xPos != lastX || yPos != lastY || zPos != lastZ) { cachedText = String.format("XYZ: %d, %d, %d", xPos, yPos, zPos); lastX = xPos; lastY = yPos; lastZ = zPos; } int width = textRenderer.getWidth(cachedText); drawBackground(drawContext, width); drawContext.drawText(textRenderer, cachedText, x, y, 0xFFAAAAAA, true); } } ``` -------------------------------- ### ModuleRenderer - Manages and Renders HUD Modules Source: https://context7.com/1udens/parsec/llms.txt The ModuleRenderer class acts as a central registry for all HUD modules within the Parsec mod. It maintains a static list of all registered HudModule instances and provides methods to add new modules and retrieve them by name. Modules are rendered each frame if they are enabled. This class depends on the HudModule class. ```java package me.ludens.parsec.systems; import java.util.ArrayList; import java.util.List; public class ModuleRenderer { public static final List modules = new ArrayList<>(); // Register a new module public static void addModule(HudModule module) { modules.add(module); } // Find module by name (case-insensitive) public static HudModule getModuleByName(String name) { return modules.stream() .filter(m -> m.name.equalsIgnoreCase(name)) .findFirst() .orElse(null); } } // Usage example - registering modules at startup: // ModuleRenderer.addModule(new FpsModule()); // ModuleRenderer.addModule(new CordsModule()); // Retrieving a module: // HudModule fps = ModuleRenderer.getModuleByName("FPS"); // if (fps != null) { // fps.enabled = true; // } ``` -------------------------------- ### FpsModule - Displays Current Frames Per Second (FPS) Source: https://context7.com/1udens/parsec/llms.txt The FpsModule is a concrete implementation of the HudModule class, designed to display the player's current Frames Per Second (FPS) on the screen. It renders the FPS count along with a customizable background. This module requires access to the Minecraft client's current FPS and TextRenderer. It inherits positioning and background rendering from the HudModule base class. ```java package me.ludens.parsec.systems; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; public class FpsModule extends HudModule { public FpsModule() { super("FPS", 10, 10); // Default position: x=10, y=10 } @Override public void render(DrawContext drawContext, TextRenderer textRenderer) { if (!enabled) return; int fps = MinecraftClient.getInstance().getCurrentFps(); String text = fps + " FPS"; int width = textRenderer.getWidth(text); drawBackground(drawContext, width); drawContext.drawText(textRenderer, text, x, y, 0xFFFFFFFF, true); } } ``` -------------------------------- ### Create RGB Color Component Slider Widget (Java) Source: https://context7.com/1udens/parsec/llms.txt A custom slider widget for adjusting individual RGB color channels (Red, Green, Blue) of a module's background color. It extends `SliderWidget` and updates the module's background color based on the slider's value. ```java package me.ludens.parsec.gui; import me.ludens.parsec.systems.HudModule; import net.minecraft.client.gui.widget.SliderWidget; import net.minecraft.text.Text; public class ColorSlider extends SliderWidget { private final HudModule module; private final Channel channel; private final Runnable onUpdate; public enum Channel { RED, GREEN, BLUE } public ColorSlider(int x, int y, int width, int height, HudModule module, Channel channel, Runnable onUpdate) { super(x, y, width, height, Text.of(""), 0); this.module = module; this.channel = channel; this.onUpdate = onUpdate; if (module != null) { this.value = getChannelValue() / 255.0; } updateMessage(); } @Override protected void applyValue() { if (module == null) return; int newChannelValue = (int) (this.value * 255); int currentARGB = module.backgroundColor; int a = (currentARGB >> 24) & 0xFF; int r = (currentARGB >> 16) & 0xFF; int g = (currentARGB >> 8) & 0xFF; int b = currentARGB & 0xFF; switch (channel) { case RED -> r = newChannelValue; case GREEN -> g = newChannelValue; case BLUE -> b = newChannelValue; } module.backgroundColor = (a << 24) | (r << 16) | (g << 8) | b; if (onUpdate != null) onUpdate.run(); } } ``` -------------------------------- ### HudModule Base Class - Abstract Module for HUD Elements Source: https://context7.com/1udens/parsec/llms.txt The abstract HudModule class serves as the foundation for all HUD display elements in the Parsec mod. It manages common properties like name, enabled state, position (x, y), and background color. It includes methods for updating the background color using hex RGB values and alpha percentages, and a protected method to draw the background. This class requires Fabric API and Minecraft client libraries. ```java package me.ludens.parsec.systems; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; public abstract class HudModule { public String name; public boolean enabled; public int x, y; public int backgroundColor = 0xAA000000; public HudModule(String name, int x, int y) { this.name = name; this.x = x; this.y = y; this.enabled = false; } // Update background color with hex RGB and alpha percentage (0-100) public void updateColor(String hex, int alphaPercent) { try { String cleanHex = hex.replace("#", ""); int alpha = (int) (alphaPercent * 2.55); int rgb = Integer.parseInt(cleanHex, 16); this.backgroundColor = (alpha << 24) | (rgb & 0x00FFFFFF); } catch (NumberFormatException e) { this.backgroundColor = 0xAA000000; // Fallback } } protected void drawBackground(DrawContext context, int width) { context.fill(x - 5, y - 5, x + width + 5, y + 12, this.backgroundColor); } public abstract void render(DrawContext drawContext, TextRenderer textRenderer); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.