📜  fabricmc concat text - Java (1)

📅  最后修改于: 2023-12-03 14:41:09.079000             🧑  作者: Mango

FabricMC Concat Text - Java

FabricMC Concat Text is a simple and lightweight Java library for concatenating text. This library is used by Fabric mods to concatenate text in-game, such as adding text to the chat, the hud, or the player's inventory.

Features
  • Concatenates text and formatting codes, such as colors and styles
  • Supports all Minecraft formatting codes
  • Lightweight and easy to use
Getting Started

To use FabricMC Concat Text in your mod, simply add the following to your build.gradle file:

repositories {
    maven {
        url 'https://maven.fabricmc.net'
    }
}

dependencies {
    modXCompile "net.fabricmc:concat-text:${fabric_version}"
}

Don't forget to replace modX with your mod ID and fabric_version with the version of Fabric Loader you are using.

Usage

To concatenate text, first create a new instance of TextConcat:

TextConcat concat = new TextConcat();

You can now use the append method to add text and formatting codes to the concatenation:

concat.append("Hello, ")
      .append(new TranslatableText("world"))
      .append("!")
      .color(TextColor.GREEN)
      .style(TextDecoration.BOLD);

In this example, we are first appending the string "Hello, ", then a translatable text component with the key "world", and finally the string "!". We are then setting the color to green and the style to bold.

Finally, you can get the result by calling the build method:

Text text = concat.build();
Conclusion

FabricMC Concat Text is a simple and lightweight Java library that allows you to concatenate text with formatting codes. Its usage is straightforward and it supports all Minecraft formatting codes. If you're developing a Fabric mod and need to concatenate text, this library is definitely worth considering.