Skip to content

The Basics

SpaceClouds42 edited this page Apr 5, 2021 · 5 revisions

To create a Minecraft Text object, ekho() { } is used. This method is the base of any Text object generated with Ekho.

Ekho Structure

ekho() { } has 2 optional parameters: the base string, passed into the parentheses, and a lambda. The base string is what the root of the generated Text object will be. By default, any style applied to the root is inherited by all following components. It is the equivalent of 'root' in LiteralText("root").append(LiteralText("component")). The lambda is used to define the style of the ekho, and the components that are appended to the root. To add components, simply invoke a string inside the lambda.

Example:

// Using Text:
LiteralText("root")
    .append(
        LiteralText("component1")
            .append(
                LiteralText("component2")
            )
    )

// Using Ekho:
ekho("root") {
    "component1"()
    "component2"()
}

Keep in mind that the root parameter is optional, ekho can also be invoked by doing ekho { "component1"() } which will make the root an empty string.

Keywords

That's right, I added keywords! yeef

For more specifics and a full list of all available keywords, see the Keywords page

There are keywords for all available Minecraft formats, both color and style. They can be applied to using the style() { } method.

newLine is a handy keyword for adding in a new line without having to do "\n"()

Components

Each component is appended to the root, and each component can be its own root with subcomponents, by passing in a lambda, just like the ekho { .. } lambda. This is useful for having a component with a style that is then inherited by its subcomponents.

Example:

ekho("root") {
    "component1" {
        "subcomponent1.1"()
        newLine
        "subcomponent1.2"()
    }
    newLine
    "component2" {
        "subcomponent2.1"()
    }
}
// The resulting Text's string representation:
"""
rootcomponent1subcomponent1.1
subcomponent1.2
component2subcomponent2.1
"""

Because the lambda that is passed into the String invocation is the same type as the lambda passed in to ekho { .. }, each component can have its own subcomponents, and them with their subcomponents, in an infinite chain.

The ekho Method

Below is the code for the method found in Ekho.kt

/**
 * Create a [Text] object using [EkhoBuilder]
 *
 * @param base the first part of the text, optional, defaults to empty string
 * @return a [Text] object
 */
fun ekho(base: String = "", method: EkhoBuilder.() -> Unit = { }): Text {
    return EkhoBuilder(LiteralText(base), method).create()
}