Component.java

net.minecraft.network.chat.Component

信息

  • 全限定名:net.minecraft.network.chat.Component
  • 类型:public interface
  • 包:net.minecraft.network.chat
  • 源码路径:src/main/java/net/minecraft/network/chat/Component.java
  • 起始行号:L30
  • 继承:Message, FormattedText
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

Style getStyle() @ L31

  • 方法名:getStyle
  • 源码定位:L31
  • 返回类型:Style
  • 修饰符:package-private

参数:

说明:

TODO

ComponentContents getContents() @ L33

  • 方法名:getContents
  • 源码定位:L33
  • 返回类型:ComponentContents
  • 修饰符:package-private

参数:

说明:

TODO

default String getString() @ L35

  • 方法名:getString
  • 源码定位:L35
  • 返回类型:String
  • 修饰符:default

参数:

说明:

TODO

default String getString(int limit) @ L40

  • 方法名:getString
  • 源码定位:L40
  • 返回类型:String
  • 修饰符:default

参数:

  • limit: int

说明:

TODO

List<Component> getSiblings() @ L54

  • 方法名:getSiblings
  • 源码定位:L54
  • 返回类型:List
  • 修饰符:package-private

参数:

说明:

TODO

default String tryCollapseToString() @ L56

  • 方法名:tryCollapseToString
  • 源码定位:L56
  • 返回类型:String
  • 修饰符:default

参数:

说明:

TODO

default MutableComponent plainCopy() @ L60

  • 方法名:plainCopy
  • 源码定位:L60
  • 返回类型:MutableComponent
  • 修饰符:default

参数:

说明:

TODO

default MutableComponent copy() @ L64

  • 方法名:copy
  • 源码定位:L64
  • 返回类型:MutableComponent
  • 修饰符:default

参数:

说明:

TODO

FormattedCharSequence getVisualOrderText() @ L68

  • 方法名:getVisualOrderText
  • 源码定位:L68
  • 返回类型:FormattedCharSequence
  • 修饰符:package-private

参数:

说明:

TODO

default <T> Optional<T> visit(FormattedText.StyledContentConsumer<T> output, Style parentStyle) @ L70

  • 方法名:visit
  • 源码定位:L70
  • 返回类型: Optional
  • 修饰符:default

参数:

  • output: FormattedText.StyledContentConsumer
  • parentStyle: Style

说明:

TODO

default <T> Optional<T> visit(FormattedText.ContentConsumer<T> output) @ L88

  • 方法名:visit
  • 源码定位:L88
  • 返回类型: Optional
  • 修饰符:default

参数:

  • output: FormattedText.ContentConsumer

说明:

TODO

default List<Component> toFlatList() @ L105

  • 方法名:toFlatList
  • 源码定位:L105
  • 返回类型:List
  • 修饰符:default

参数:

说明:

TODO

default List<Component> toFlatList(Style rootStyle) @ L109

  • 方法名:toFlatList
  • 源码定位:L109
  • 返回类型:List
  • 修饰符:default

参数:

  • rootStyle: Style

说明:

TODO

default boolean contains(Component other) @ L121

  • 方法名:contains
  • 源码定位:L121
  • 返回类型:boolean
  • 修饰符:default

参数:

  • other: Component

说明:

TODO

static Component nullToEmpty(String text) @ L131

  • 方法名:nullToEmpty
  • 源码定位:L131
  • 返回类型:Component
  • 修饰符:static

参数:

  • text: String

说明:

TODO

static MutableComponent literal(String text) @ L135

  • 方法名:literal
  • 源码定位:L135
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • text: String

说明:

TODO

static MutableComponent translatable(String key) @ L139

  • 方法名:translatable
  • 源码定位:L139
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • key: String

说明:

TODO

static MutableComponent translatable(String key, Object... args) @ L143

  • 方法名:translatable
  • 源码定位:L143
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • key: String
  • args: Object…

说明:

TODO

static MutableComponent translatableEscape(String key, Object... args) @ L147

  • 方法名:translatableEscape
  • 源码定位:L147
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • key: String
  • args: Object…

说明:

TODO

static MutableComponent translatableWithFallback(String key, String fallback) @ L158

  • 方法名:translatableWithFallback
  • 源码定位:L158
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • key: String
  • fallback: String

说明:

TODO

static MutableComponent translatableWithFallback(String key, String fallback, Object... args) @ L162

  • 方法名:translatableWithFallback
  • 源码定位:L162
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • key: String
  • fallback: String
  • args: Object…

说明:

TODO

static MutableComponent empty() @ L166

  • 方法名:empty
  • 源码定位:L166
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

说明:

TODO

static MutableComponent keybind(String name) @ L170

  • 方法名:keybind
  • 源码定位:L170
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • name: String

说明:

TODO

static MutableComponent nbt(CompilableString<NbtPathArgument.NbtPath> nbtPath, boolean interpreting, boolean plain, Optional<Component> separator, DataSource dataSource) @ L174

  • 方法名:nbt
  • 源码定位:L174
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • nbtPath: CompilableString<NbtPathArgument.NbtPath>
  • interpreting: boolean
  • plain: boolean
  • separator: Optional
  • dataSource: DataSource

说明:

TODO

static MutableComponent score(CompilableString<EntitySelector> pattern, String objective) @ L180

  • 方法名:score
  • 源码定位:L180
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • pattern: CompilableString
  • objective: String

说明:

TODO

static MutableComponent score(String name, String objective) @ L184

  • 方法名:score
  • 源码定位:L184
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • name: String
  • objective: String

说明:

TODO

static MutableComponent selector(CompilableString<EntitySelector> pattern, Optional<Component> separator) @ L188

  • 方法名:selector
  • 源码定位:L188
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • pattern: CompilableString
  • separator: Optional

说明:

TODO

static MutableComponent object(ObjectInfo info) @ L192

  • 方法名:object
  • 源码定位:L192
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • info: ObjectInfo

说明:

TODO

static MutableComponent object(ObjectInfo info, Component fallback) @ L196

  • 方法名:object
  • 源码定位:L196
  • 返回类型:MutableComponent
  • 修饰符:static

参数:

  • info: ObjectInfo
  • fallback: Component

说明:

TODO

static Component translationArg(Date date) @ L200

  • 方法名:translationArg
  • 源码定位:L200
  • 返回类型:Component
  • 修饰符:static

参数:

  • date: Date

说明:

TODO

static Component translationArg(Message message) @ L204

  • 方法名:translationArg
  • 源码定位:L204
  • 返回类型:Component
  • 修饰符:static

参数:

  • message: Message

说明:

TODO

static Component translationArg(UUID uuid) @ L208

  • 方法名:translationArg
  • 源码定位:L208
  • 返回类型:Component
  • 修饰符:static

参数:

  • uuid: UUID

说明:

TODO

static Component translationArg(Identifier id) @ L212

  • 方法名:translationArg
  • 源码定位:L212
  • 返回类型:Component
  • 修饰符:static

参数:

  • id: Identifier

说明:

TODO

static Component translationArg(ChunkPos chunkPos) @ L216

  • 方法名:translationArg
  • 源码定位:L216
  • 返回类型:Component
  • 修饰符:static

参数:

  • chunkPos: ChunkPos

说明:

TODO

static Component translationArg(URI uri) @ L220

  • 方法名:translationArg
  • 源码定位:L220
  • 返回类型:Component
  • 修饰符:static

参数:

  • uri: URI

说明:

TODO

代码

public interface Component extends Message, FormattedText {
    Style getStyle();
 
    ComponentContents getContents();
 
    @Override
    default String getString() {
        return FormattedText.super.getString();
    }
 
    default String getString(int limit) {
        StringBuilder builder = new StringBuilder();
        this.visit(contents -> {
            int remaining = limit - builder.length();
            if (remaining <= 0) {
                return STOP_ITERATION;
            } else {
                builder.append(contents.length() <= remaining ? contents : contents.substring(0, remaining));
                return Optional.empty();
            }
        });
        return builder.toString();
    }
 
    List<Component> getSiblings();
 
    default @Nullable String tryCollapseToString() {
        return this.getContents() instanceof PlainTextContents text && this.getSiblings().isEmpty() && this.getStyle().isEmpty() ? text.text() : null;
    }
 
    default MutableComponent plainCopy() {
        return MutableComponent.create(this.getContents());
    }
 
    default MutableComponent copy() {
        return new MutableComponent(this.getContents(), new ArrayList<>(this.getSiblings()), this.getStyle());
    }
 
    FormattedCharSequence getVisualOrderText();
 
    @Override
    default <T> Optional<T> visit(FormattedText.StyledContentConsumer<T> output, Style parentStyle) {
        Style selfStyle = this.getStyle().applyTo(parentStyle);
        Optional<T> selfResult = this.getContents().visit(output, selfStyle);
        if (selfResult.isPresent()) {
            return selfResult;
        } else {
            for (Component sibling : this.getSiblings()) {
                Optional<T> result = sibling.visit(output, selfStyle);
                if (result.isPresent()) {
                    return result;
                }
            }
 
            return Optional.empty();
        }
    }
 
    @Override
    default <T> Optional<T> visit(FormattedText.ContentConsumer<T> output) {
        Optional<T> selfResult = this.getContents().visit(output);
        if (selfResult.isPresent()) {
            return selfResult;
        } else {
            for (Component sibling : this.getSiblings()) {
                Optional<T> result = sibling.visit(output);
                if (result.isPresent()) {
                    return result;
                }
            }
 
            return Optional.empty();
        }
    }
 
    default List<Component> toFlatList() {
        return this.toFlatList(Style.EMPTY);
    }
 
    default List<Component> toFlatList(Style rootStyle) {
        List<Component> result = Lists.newArrayList();
        this.visit((style, contents) -> {
            if (!contents.isEmpty()) {
                result.add(literal(contents).withStyle(style));
            }
 
            return Optional.empty();
        }, rootStyle);
        return result;
    }
 
    default boolean contains(Component other) {
        if (this.equals(other)) {
            return true;
        } else {
            List<Component> flat = this.toFlatList();
            List<Component> otherFlat = other.toFlatList(this.getStyle());
            return Collections.indexOfSubList(flat, otherFlat) != -1;
        }
    }
 
    static Component nullToEmpty(@Nullable String text) {
        return (Component)(text != null ? literal(text) : CommonComponents.EMPTY);
    }
 
    static MutableComponent literal(String text) {
        return MutableComponent.create(PlainTextContents.create(text));
    }
 
    static MutableComponent translatable(String key) {
        return MutableComponent.create(new TranslatableContents(key, null, TranslatableContents.NO_ARGS));
    }
 
    static MutableComponent translatable(String key, Object... args) {
        return MutableComponent.create(new TranslatableContents(key, null, args));
    }
 
    static MutableComponent translatableEscape(String key, Object... args) {
        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            if (!TranslatableContents.isAllowedPrimitiveArgument(arg) && !(arg instanceof Component)) {
                args[i] = String.valueOf(arg);
            }
        }
 
        return translatable(key, args);
    }
 
    static MutableComponent translatableWithFallback(String key, @Nullable String fallback) {
        return MutableComponent.create(new TranslatableContents(key, fallback, TranslatableContents.NO_ARGS));
    }
 
    static MutableComponent translatableWithFallback(String key, @Nullable String fallback, Object... args) {
        return MutableComponent.create(new TranslatableContents(key, fallback, args));
    }
 
    static MutableComponent empty() {
        return MutableComponent.create(PlainTextContents.EMPTY);
    }
 
    static MutableComponent keybind(String name) {
        return MutableComponent.create(new KeybindContents(name));
    }
 
    static MutableComponent nbt(
        CompilableString<NbtPathArgument.NbtPath> nbtPath, boolean interpreting, boolean plain, Optional<Component> separator, DataSource dataSource
    ) {
        return MutableComponent.create(new NbtContents(nbtPath, interpreting, plain, separator, dataSource));
    }
 
    static MutableComponent score(CompilableString<EntitySelector> pattern, String objective) {
        return MutableComponent.create(new ScoreContents(Either.left(pattern), objective));
    }
 
    static MutableComponent score(String name, String objective) {
        return MutableComponent.create(new ScoreContents(Either.right(name), objective));
    }
 
    static MutableComponent selector(CompilableString<EntitySelector> pattern, Optional<Component> separator) {
        return MutableComponent.create(new SelectorContents(pattern, separator));
    }
 
    static MutableComponent object(ObjectInfo info) {
        return MutableComponent.create(new ObjectContents(info, Optional.empty()));
    }
 
    static MutableComponent object(ObjectInfo info, Component fallback) {
        return MutableComponent.create(new ObjectContents(info, Optional.of(fallback)));
    }
 
    static Component translationArg(Date date) {
        return literal(date.toString());
    }
 
    static Component translationArg(Message message) {
        return (Component)(message instanceof Component component ? component : literal(message.getString()));
    }
 
    static Component translationArg(UUID uuid) {
        return literal(uuid.toString());
    }
 
    static Component translationArg(Identifier id) {
        return literal(id.toString());
    }
 
    static Component translationArg(ChunkPos chunkPos) {
        return literal(chunkPos.toString());
    }
 
    static Component translationArg(URI uri) {
        return literal(uri.toString());
    }
}

引用的其他类