ObjectContents.java

net.minecraft.network.chat.contents.ObjectContents

信息

  • 全限定名:net.minecraft.network.chat.contents.ObjectContents
  • 类型:public record
  • 包:net.minecraft.network.chat.contents
  • 源码路径:src/main/java/net/minecraft/network/chat/contents/ObjectContents.java
  • 起始行号:L18
  • 实现:ComponentContents
  • 职责:

    TODO

字段/常量

  • PLACEHOLDER

    • 类型: String
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

  • MAP_CODEC

    • 类型: MapCodec<ObjectContents>
    • 修饰符: public static final
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public MapCodec<ObjectContents> codec() @ L28

  • 方法名:codec
  • 源码定位:L28
  • 返回类型:MapCodec
  • 修饰符:public

参数:

说明:

TODO

public MutableComponent resolve(ResolutionContext context, int recursionDepth) @ L33

  • 方法名:resolve
  • 源码定位:L33
  • 返回类型:MutableComponent
  • 修饰符:public

参数:

  • context: ResolutionContext
  • recursionDepth: int

说明:

TODO

public <T> Optional<T> visit(FormattedText.ContentConsumer<T> output) @ L42

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

参数:

  • output: FormattedText.ContentConsumer

说明:

TODO

public <T> Optional<T> visit(FormattedText.StyledContentConsumer<T> output, Style currentStyle) @ L47

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

参数:

  • output: FormattedText.StyledContentConsumer
  • currentStyle: Style

说明:

TODO

代码

public record ObjectContents(ObjectInfo contents, Optional<Component> fallback) implements ComponentContents {
    private static final String PLACEHOLDER = Character.toString('\ufffc');
    public static final MapCodec<ObjectContents> MAP_CODEC = RecordCodecBuilder.mapCodec(
        i -> i.group(
                ObjectInfos.CODEC.forGetter(ObjectContents::contents),
                ComponentSerialization.CODEC.optionalFieldOf("fallback").forGetter(ObjectContents::fallback)
            )
            .apply(i, ObjectContents::new)
    );
 
    @Override
    public MapCodec<ObjectContents> codec() {
        return MAP_CODEC;
    }
 
    @Override
    public MutableComponent resolve(ResolutionContext context, int recursionDepth) throws CommandSyntaxException {
        Optional<MutableComponent> fallback = ComponentUtils.resolve(context, this.fallback, recursionDepth);
        ObjectInfo validatedContents = context.validate(this.contents);
        return validatedContents == null
            ? fallback.orElseGet(() -> Component.literal(this.contents.defaultFallback()))
            : MutableComponent.create(new ObjectContents(validatedContents, fallback.map(o -> (Component)o)));
    }
 
    @Override
    public <T> Optional<T> visit(FormattedText.ContentConsumer<T> output) {
        return this.fallback.isPresent() ? this.fallback.get().visit(output) : output.accept(this.contents.defaultFallback());
    }
 
    @Override
    public <T> Optional<T> visit(FormattedText.StyledContentConsumer<T> output, Style currentStyle) {
        return output.accept(currentStyle.withFont(this.contents.fontDescription()), PLACEHOLDER);
    }
}

引用的其他类