
Chat Message Library
Important Notice: This mod is no longer actively supported. It is recommended to switch to the Fabric and NeoForge Adventure API port, create your own implementation, or fork the project on GitHub for continued use.
About the Project
This mod was created to address the lack of efficient tools for working with text messages in Minecraft, similar to java.lang.StringBuilder
for net.minecraft.text.Text
objects. It provides a convenient API for building complex text structures.
For Players
This is a library mod that does not add visible content to the game by itself. It is installed in the standard way into the .minecraft/mods/
folder and requires Fabric API for proper operation.
For Developers
Library Integration
Add the following settings to your project files:
build.gradle
:
repositories {
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
modApi include("maven.modrinth:chatmsglib:${project.cml_version}")
}
gradle.properties
:
# Version might be outdated!
cml_version=1.1
Usage Example
public class YourMod implements ModInitializer {
public static final ChatMessage CML = new ChatMessage();
/
This text is generated at startup and kept until server shutdown
Use methods "msg::send", "msg.send(PlayerEntity)" or "msg.send(CommandContext)" for sending
/
private static final ChatMessage msg = CML
.header("Header always displayed at the top of message", Formatting.AQUA)
.footer("Footer always displayed at the bottom of message", Formatting.BOLD, Formatting.BLUE)
.literal("Simple string literal", Formatting.BLUE)
.literal("Option with clickable action support",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help"))
.object(
// Convert List<Integer> to text format
new IntList(yourInts)
// Spaces for prefixes and suffixes must be added manually
.prefix("Text before numbers: ")
.suffix(" Text after numbers")
.create())
.object(
// JsonObject to text format
new JsonList(yourJson)
.prefix("- ")
.indent(1)
.create()
)
.object(
// Object content displayed in single line
new Singleton()
.add(Text.literal("Singleton used for single-line output"))
.add(
Text.literal("Support for inline commands")
.styled(style -> style.withClickEvent(
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help")
))
)
.create()
);
@Override
public void onInitialize() {
// Command to output formatted message
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
dispatcher.register(
CommandManager.literal("your_command")
.executes(msg::send)
)
);
}
}
Customization
For creating custom lists, inherit from class xyz.blurple.chatmsglib.list.ChatList
. The main requirement is to implement output in List<Text>
format, all other logic is fully customizable.
If you have ideas for improvements or encounter issues, create a corresponding issue. The project code is open for any use purposes - forking, learning, and other projects.