ComponentRenderUtils.java
net.minecraft.client.gui.components.ComponentRenderUtils
信息
- 全限定名:net.minecraft.client.gui.components.ComponentRenderUtils
- 类型:public class
- 包:net.minecraft.client.gui.components
- 源码路径:src/main/java/net/minecraft/client/gui/components/ComponentRenderUtils.java
- 起始行号:L20
- 职责:
TODO
字段/常量
INDENT- 类型:
FormattedCharSequence - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static String stripColor(String input) @ L23
- 方法名:stripColor
- 源码定位:L23
- 返回类型:String
- 修饰符:private static
参数:
- input: String
说明:
TODO
public static List<FormattedCharSequence> wrapComponents(FormattedText message, int maxWidth, Font font) @ L27
- 方法名:wrapComponents
- 源码定位:L27
- 返回类型:List
- 修饰符:public static
参数:
- message: FormattedText
- maxWidth: int
- font: Font
说明:
TODO
public static FormattedCharSequence clipText(Component text, Font font, int width) @ L41
- 方法名:clipText
- 源码定位:L41
- 返回类型:FormattedCharSequence
- 修饰符:public static
参数:
- text: Component
- font: Font
- width: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ComponentRenderUtils {
private static final FormattedCharSequence INDENT = FormattedCharSequence.codepoint(32, Style.EMPTY);
private static String stripColor(String input) {
return Minecraft.getInstance().options.chatColors().get() ? input : ChatFormatting.stripFormatting(input);
}
public static List<FormattedCharSequence> wrapComponents(FormattedText message, int maxWidth, Font font) {
ComponentCollector collector = new ComponentCollector();
message.visit((style, contents) -> {
collector.append(FormattedText.of(stripColor(contents), style));
return Optional.empty();
}, Style.EMPTY);
List<FormattedCharSequence> result = Lists.newArrayList();
font.getSplitter().splitLines(collector.getResultOrEmpty(), maxWidth, Style.EMPTY, (text, wrapped) -> {
FormattedCharSequence reorderedText = Language.getInstance().getVisualOrder(text);
result.add(wrapped ? FormattedCharSequence.composite(INDENT, reorderedText) : reorderedText);
});
return (List<FormattedCharSequence>)(result.isEmpty() ? Lists.newArrayList(FormattedCharSequence.EMPTY) : result);
}
public static FormattedCharSequence clipText(Component text, Font font, int width) {
FormattedText clippedText = font.substrByWidth(text, width - font.width(CommonComponents.ELLIPSIS));
return Language.getInstance().getVisualOrder(FormattedText.composite(clippedText, CommonComponents.ELLIPSIS));
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
ChatFormatting.stripFormatting()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ComponentCollector()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Language.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
FormattedText.composite(), FormattedText.of()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
FormattedCharSequence.codepoint(), FormattedCharSequence.composite()
- 引用位置: