@occultus/format-api
v0.21.0
Published
Star Tenon format tool
Maintainers
Readme
Star Tenon Format API
本包包含快速格式化文本工具,灵感来自于 LeviLamina - LegacyScriptEngine。
Format
Format 是一个用于快速格式化文本的工具类。
该类提供了多种文本格式化选项,适用于 Minecraft 基岩版中的文本格式化需求:
import { Format } from "@occultus/core";
// 创建格式化文本
const formattedText = `${Format.bold}加粗文本${Format.reset} ${Format.italics}斜体文本${Format.reset}`;
console.log(formattedText);
// 创建带有空白行的文本
const textWithBlankLines = `第一行${Format.blankLine(1)}第二行`;
console.log(textWithBlankLines);文本格式
bold:string- 将文本格式设置为加粗(代码:§l)italics:string- 将文本格式设置为斜体(代码:§o)underline:string- 将文本格式设置为带有下划线(代码:§n)
已废弃:由于 Mojang 自身原因,游戏中下划线文本无法正常格式化strikeThrough:string- 将文本格式设置为~~带有删除线~~(代码:§m) 已废弃:由于 Mojang 自身原因,游戏中删除线文本无法正常格式化random:string- 将文本格式设置为随机字符(代码:§k)注意:字体不为 Mojangles 时,会显示为
.......reset:string- 重置所有文本颜色和格式(代码:§r)newLine:string- 换行符(代码:\n)
blankLine(count: number = 1): string
创建数个空白行
- 参数:
count:number(可选,默认为 1) - 空白行的数量
- 返回值:
string- 一个包含空白行的字符串
Color
快速给文本添加颜色的工具:
world.getAllPlayers().forEach((player) => {
player.sendMessage(Color.black + "将文本设置为黑色!");
});
world.getAllPlayers().forEach((player) => {
player.sendMessage({
// 将本地化字符串设置为黑色!
rawtext: [{ text: Color.black }, { translate: "example.translate_string" }],
});
});该类提供的颜色较多,请到源代码中查看具体属性。
支持版本
本 API 支持任意可以运行 Script API 的游戏版本,甚至连 1.0.0 的脚本模块都支持。
协议
本项目使用 MIT License 授权:
The MIT License (MIT)
Copyright © 2025 CTN Studios
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.