Typewheel is a library for creating and serializing Minecraft text components. This project is loosely inspired by the Adventure project.
Components can be modified using both setters and the builder pattern, where each field has a method for setting its value directly, and for producing a new component with the new value.
use typewheel::{Component, TextColor};
fn main() {
// Setter pattern: setters pass back a reference for chaining.
let mut inner = Component::text("world");
inner.bold(true).color(0xAA7FFF);
assert_eq!(inner.style.bold, Some(true));
assert_eq!(inner.style.color, Some(TextColor::Hex(0xAA7FFF)));
// Builder pattern: builders accept ownership of `self` and return an owned value back.
let component = Component::text("Hello, ")
.with_color(TextColor::Gray)
.with_extra([inner, "!".into()]);
assert_eq!(component.style.color, Some(TextColor::Gray));
assert!(!component.extra.is_empty());
}
Components can be serialized and deserialized using codecs. The most commonly used format for
encoding components is JSON, which is implemented with the codec::JsonComponentCodec
struct.
Other serializers exist for a variety of formats and implementations.
json
: Enables the use ofcodec::JsonComponentCodec
viaserde_json
.nbt
: Enables setting NBT tags in item hovers.