CollectFields.java

net.minecraft.nbt.visitors.CollectFields

信息

  • 全限定名:net.minecraft.nbt.visitors.CollectFields
  • 类型:public class
  • 包:net.minecraft.nbt.visitors
  • 源码路径:src/main/java/net/minecraft/nbt/visitors/CollectFields.java
  • 起始行号:L12
  • 继承:CollectToTag
  • 职责:

    TODO

字段/常量

  • fieldsToGetCount

    • 类型: int
    • 修饰符: private
    • 源码定位: L13
    • 说明:

      TODO

  • wantedTypes

    • 类型: Set<TagType<?>>
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

  • stack

    • 类型: Deque<FieldTree>
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

public CollectFields(FieldSelector... wantedFields) @ L17

  • 构造器名:CollectFields
  • 源码定位:L17
  • 修饰符:public

参数:

  • wantedFields: FieldSelector…

说明:

TODO

方法

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

public StreamTagVisitor.ValueResult visitRootEntry(TagType<?> type) @ L32

  • 方法名:visitRootEntry
  • 源码定位:L32
  • 返回类型:StreamTagVisitor.ValueResult
  • 修饰符:public

参数:

  • type: TagType<?>

说明:

TODO

public StreamTagVisitor.EntryResult visitEntry(TagType<?> type) @ L37

  • 方法名:visitEntry
  • 源码定位:L37
  • 返回类型:StreamTagVisitor.EntryResult
  • 修饰符:public

参数:

  • type: TagType<?>

说明:

TODO

public StreamTagVisitor.EntryResult visitEntry(TagType<?> type, String id) @ L49

  • 方法名:visitEntry
  • 源码定位:L49
  • 返回类型:StreamTagVisitor.EntryResult
  • 修饰符:public

参数:

  • type: TagType<?>
  • id: String

说明:

TODO

public StreamTagVisitor.ValueResult visitContainerEnd() @ L70

  • 方法名:visitContainerEnd
  • 源码定位:L70
  • 返回类型:StreamTagVisitor.ValueResult
  • 修饰符:public

参数:

说明:

TODO

public int getMissingFieldCount() @ L79

  • 方法名:getMissingFieldCount
  • 源码定位:L79
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

代码

public class CollectFields extends CollectToTag {
    private int fieldsToGetCount;
    private final Set<TagType<?>> wantedTypes;
    private final Deque<FieldTree> stack = new ArrayDeque<>();
 
    public CollectFields(FieldSelector... wantedFields) {
        this.fieldsToGetCount = wantedFields.length;
        Builder<TagType<?>> wantedTypes = ImmutableSet.builder();
        FieldTree rootFrame = FieldTree.createRoot();
 
        for (FieldSelector wantedField : wantedFields) {
            rootFrame.addEntry(wantedField);
            wantedTypes.add(wantedField.type());
        }
 
        this.stack.push(rootFrame);
        wantedTypes.add(CompoundTag.TYPE);
        this.wantedTypes = wantedTypes.build();
    }
 
    @Override
    public StreamTagVisitor.ValueResult visitRootEntry(TagType<?> type) {
        return type != CompoundTag.TYPE ? StreamTagVisitor.ValueResult.HALT : super.visitRootEntry(type);
    }
 
    @Override
    public StreamTagVisitor.EntryResult visitEntry(TagType<?> type) {
        FieldTree currentFrame = this.stack.element();
        if (this.depth() > currentFrame.depth()) {
            return super.visitEntry(type);
        } else if (this.fieldsToGetCount <= 0) {
            return StreamTagVisitor.EntryResult.BREAK;
        } else {
            return !this.wantedTypes.contains(type) ? StreamTagVisitor.EntryResult.SKIP : super.visitEntry(type);
        }
    }
 
    @Override
    public StreamTagVisitor.EntryResult visitEntry(TagType<?> type, String id) {
        FieldTree currentFrame = this.stack.element();
        if (this.depth() > currentFrame.depth()) {
            return super.visitEntry(type, id);
        } else if (currentFrame.selectedFields().remove(id, type)) {
            this.fieldsToGetCount--;
            return super.visitEntry(type, id);
        } else {
            if (type == CompoundTag.TYPE) {
                FieldTree newFrame = currentFrame.fieldsToRecurse().get(id);
                if (newFrame != null) {
                    this.stack.push(newFrame);
                    return super.visitEntry(type, id);
                }
            }
 
            return StreamTagVisitor.EntryResult.SKIP;
        }
    }
 
    @Override
    public StreamTagVisitor.ValueResult visitContainerEnd() {
        if (this.depth() == this.stack.element().depth()) {
            this.stack.pop();
        }
 
        return super.visitContainerEnd();
    }
 
    public int getMissingFieldCount() {
        return this.fieldsToGetCount;
    }
}

引用的其他类