kyori-component-json

Crates.iokyori-component-json
lib.rskyori-component-json
version0.2.1
created_at2025-05-19 09:48:30.018734+00
updated_at2025-08-17 22:58:30.555021+00
descriptionA library for serializing and deserializing Kyori Component JSON content
homepage
repositoryhttps://github.com/walker84837/kyori-component-json
max_upload_size
id1679525
size75,756
winlogon (walker84837)

documentation

README

kyori-component-json

Minecraft text formatting made easy

Crates.io Docs.rs License

A simple Rust library for creating and working with Minecraft's JSON text components (Java Edition 1.21.5+). This is the same system used in commands like /tellraw, books, signs, and more!

What can you do with this?

Mainly:

  • Create tooling around Minecraft clients and servers easily
  • Easier interop between Rust objects and Minecraft's text component format

But it also empowers you to:

  • Create colorful chat messages with formatting (bold, italic, etc.)
  • Add clickable text that runs commands when clicked
  • Make hover text that shows extra information

When would you use this?

  1. Command Generators: Create /tellraw or /title commands programmatically
  2. Custom UIs: Make interactive books or signs
  3. Data Packs: Generate dynamic text components

Simple Examples

Basic Colored Text

use kyori_component_json::*;

let message = Component::text("Hello Minecraft!")
    .color(Some(Color::Named(NamedColor::Red)))
    .decoration(TextDecoration::Bold, Some(true));

// Use in /tellraw command:
// /tellraw @a {"text":"Hello Minecraft!","color":"red","bold":true}

Clickable Text

let clickable = Component::text("Click me!")
    .click_event(Some(ClickEvent::RunCommand {
        command: "/say Hello!".into()
    }))
    .hover_event(Some(HoverEvent::ShowText {
        value: Component::text("This will run a command!")
    }));

Combining Components

let combined = Component::text("Welcome, ")
    .append(
        Component::text("Player")
            .color(Some(Color::Named(NamedColor::Gold)))
    .append_newline()
    .append(clickable); // From previous example

More Advanced Example

// Create a formatted message with multiple parts
let message = Component::text("Server Notice: ")
    .color(Some(Color::Named(NamedColor::Red)))
    .append(
        Component::text("Important update!")
            .color(Some(Color::Named(NamedColor::Gold)))
    .append_newline()
    .append(
        Component::text("Click for details")
            .click_event(Some(ClickEvent::RunCommand {
                command: "/update".into()
            }))
            .hover_event(Some(HoverEvent::ShowText {
                value: Component::text("Run /update command")
            }))
    );

// Convert to Minecraft JSON
let json = serde_json::to_string(&message).unwrap();

Learning More

License

This project is licensed under either of

at your option.

Contribution

Contributions are welcome! Please feel free to submit a pull request.

Commit count: 7

cargo fmt