
聊天消息库
用于文本的StringBuilder,适用于命令和命令行工具。
弃用通知
我将不再主动支持此模组,请使用 Fabric 和 NeoForge Adventure API 移植版,创建你自己的实现,或在 Github 上 fork 以继续使用它。
Chat Message Library
我因为 net.minecraft.text.Text 没有类似于 java.lang.StringBuilder 的等价物而感到烦恼,所以我决定自己构建一个。
对于用户;
这是一个库模组,本身不会向游戏中添加任何内容。
下载该模组并将其放入你的 .minecraft/mods/ 文件夹中。
此模组还需要 Fabric API 才能工作。
对于开发者;
要使用该库,请分别将以下内容添加到你的 build.gradle、gradle.properties 以及你的模组的 ModInitializer 类中:
build.gradle:
repositories {
maven { url = "https://api.modrinth.com/maven" }
}
dependencies {
modApi include("maven.modrinth:chatmsglib:${project.cml_version}")
}
gradle.properties:
# This may be out of date!!
cml_version=1.1
你的 ModInitializer:
public class YourMod implements ModInitializer {
public static final ChatMessage CML = new ChatMessage();
/*
* This text is generated at startup and is held until server stop
* To send it, use "msg::send", "msg.send(PlayerEntity)", or "msg.send(CommandContext)"
* You can also modify it on the fly by adding more text
*/
private static final ChatMessage msg = CML
.header("This is always be displayed at the top of the message", Formatting.AQUA)
.footer("This is always be displayed at the bottom of the message", Formatting.BOLD, Formatting.BLUE)
.literal("Just a literal string, nothing special", Formatting.BLUE)
.literal("Option for an \"on\" statement as well",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help"))
.object(
// A List<Integer> turned into Text form
new IntList(yourInts)
// No spaces are added for Prefixes and Suffixes and must be added manually!
.prefix("What comes before the number is printed ")
.suffix(" What comes after the number is printed")
.create())
.object(
// A JsonObject turned into Text form
new JsonList(yourJson)
.prefix("- ")
.indent(1)
.create()
)
.object(
// All text added to this object will display on the same line
new Singleton()
.add(Text.literal("Singletons are used to display text in one line only"))
.add(
Text.literal("Also, commands in-line as well")
.styled(style -> style.withClickEvent(
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help")
))
)
.create()
)
.object(
/*
* You can create your own lists by extending xyz.blurple.chatmsglib.list.ChatList
* It has to output List<Text>, everything else is your choice!
*/
new YourList(yourInput)
.prefix("= ")
.create()
);
@Override
public void onInitialize() {
// This command simply prints out msg with the formatting you chose
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
dispatcher.register(
CommandManager.literal("your_command")
.executes(msg::send)
)
);
}
}
如果你对该库有请求或问题,请提交 issue,我会尝试添加它。
你可以随意对这个代码做任何你想做的事;fork、学习,随你喜欢。
正在加载版本记录…
正在加载评论…
评论在新手盒子客户端中发表,这里同步展示。