TestFinder.java

net.minecraft.gametest.framework.TestFinder

信息

  • 全限定名:net.minecraft.gametest.framework.TestFinder
  • 类型:public class
  • 包:net.minecraft.gametest.framework
  • 源码路径:src/main/java/net/minecraft/gametest/framework/TestFinder.java
  • 起始行号:L14
  • 实现:TestInstanceFinder, TestPosFinder
  • 职责:

    TODO

字段/常量

  • NO_FUNCTIONS

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

      TODO

  • NO_STRUCTURES

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

      TODO

  • testInstanceFinder

    • 类型: TestInstanceFinder
    • 修饰符: private final
    • 源码定位: L17
    • 说明:

      TODO

  • testPosFinder

    • 类型: TestPosFinder
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • source

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

      TODO

内部类/嵌套类型

  • net.minecraft.gametest.framework.TestFinder.Builder
    • 类型: class
    • 修饰符: public static
    • 源码定位: L45
    • 说明:

      TODO

构造器

private TestFinder(CommandSourceStack source, TestInstanceFinder testInstanceFinder, TestPosFinder testPosFinder) @ L30

  • 构造器名:TestFinder
  • 源码定位:L30
  • 修饰符:private

参数:

  • source: CommandSourceStack
  • testInstanceFinder: TestInstanceFinder
  • testPosFinder: TestPosFinder

说明:

TODO

方法

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

public Stream<BlockPos> findTestPos() @ L21

  • 方法名:findTestPos
  • 源码定位:L21
  • 返回类型:Stream
  • 修饰符:public

参数:

说明:

TODO

public static TestFinder.Builder builder() @ L26

  • 方法名:builder
  • 源码定位:L26
  • 返回类型:TestFinder.Builder
  • 修饰符:public static

参数:

说明:

TODO

public CommandSourceStack source() @ L36

  • 方法名:source
  • 源码定位:L36
  • 返回类型:CommandSourceStack
  • 修饰符:public

参数:

说明:

TODO

public Stream<Holder.Reference<GameTestInstance>> findTests() @ L40

  • 方法名:findTests
  • 源码定位:L40
  • 返回类型:Stream<Holder.Reference>
  • 修饰符:public

参数:

说明:

TODO

代码

public class TestFinder implements TestInstanceFinder, TestPosFinder {
    private static final TestInstanceFinder NO_FUNCTIONS = Stream::empty;
    private static final TestPosFinder NO_STRUCTURES = Stream::empty;
    private final TestInstanceFinder testInstanceFinder;
    private final TestPosFinder testPosFinder;
    private final CommandSourceStack source;
 
    @Override
    public Stream<BlockPos> findTestPos() {
        return this.testPosFinder.findTestPos();
    }
 
    public static TestFinder.Builder builder() {
        return new TestFinder.Builder();
    }
 
    private TestFinder(CommandSourceStack source, TestInstanceFinder testInstanceFinder, TestPosFinder testPosFinder) {
        this.source = source;
        this.testInstanceFinder = testInstanceFinder;
        this.testPosFinder = testPosFinder;
    }
 
    public CommandSourceStack source() {
        return this.source;
    }
 
    @Override
    public Stream<Holder.Reference<GameTestInstance>> findTests() {
        return this.testInstanceFinder.findTests();
    }
 
    public static class Builder {
        private final UnaryOperator<Supplier<Stream<Holder.Reference<GameTestInstance>>>> testFinderWrapper;
        private final UnaryOperator<Supplier<Stream<BlockPos>>> structureBlockPosFinderWrapper;
 
        public Builder() {
            this.testFinderWrapper = f -> f;
            this.structureBlockPosFinderWrapper = f -> f;
        }
 
        private Builder(
            UnaryOperator<Supplier<Stream<Holder.Reference<GameTestInstance>>>> testFinderWrapper,
            UnaryOperator<Supplier<Stream<BlockPos>>> structureBlockPosFinderWrapper
        ) {
            this.testFinderWrapper = testFinderWrapper;
            this.structureBlockPosFinderWrapper = structureBlockPosFinderWrapper;
        }
 
        public TestFinder.Builder createMultipleCopies(int amount) {
            return new TestFinder.Builder(createCopies(amount), createCopies(amount));
        }
 
        private static <Q> UnaryOperator<Supplier<Stream<Q>>> createCopies(int amount) {
            return source -> {
                List<Q> copyList = new LinkedList<>();
                List<Q> sourceList = ((Stream)source.get()).toList();
 
                for (int i = 0; i < amount; i++) {
                    copyList.addAll(sourceList);
                }
 
                return copyList::stream;
            };
        }
 
        private TestFinder build(CommandSourceStack source, TestInstanceFinder testInstanceFinder, TestPosFinder testPosFinder) {
            return new TestFinder(
                source,
                this.testFinderWrapper.apply(testInstanceFinder::findTests)::get,
                this.structureBlockPosFinderWrapper.apply(testPosFinder::findTestPos)::get
            );
        }
 
        public TestFinder radius(CommandContext<CommandSourceStack> sourceStack, int radius) {
            CommandSourceStack source = sourceStack.getSource();
            BlockPos pos = BlockPos.containing(source.getPosition());
            return this.build(source, TestFinder.NO_FUNCTIONS, () -> StructureUtils.findTestBlocks(pos, radius, source.getLevel()));
        }
 
        public TestFinder nearest(CommandContext<CommandSourceStack> sourceStack) {
            CommandSourceStack source = sourceStack.getSource();
            BlockPos pos = BlockPos.containing(source.getPosition());
            return this.build(source, TestFinder.NO_FUNCTIONS, () -> StructureUtils.findNearestTest(pos, 15, source.getLevel()).stream());
        }
 
        public TestFinder allNearby(CommandContext<CommandSourceStack> sourceStack) {
            CommandSourceStack source = sourceStack.getSource();
            BlockPos pos = BlockPos.containing(source.getPosition());
            return this.build(source, TestFinder.NO_FUNCTIONS, () -> StructureUtils.findTestBlocks(pos, 250, source.getLevel()));
        }
 
        public TestFinder lookedAt(CommandContext<CommandSourceStack> sourceStack) {
            CommandSourceStack source = sourceStack.getSource();
            return this.build(
                source,
                TestFinder.NO_FUNCTIONS,
                () -> StructureUtils.lookedAtTestPos(BlockPos.containing(source.getPosition()), source.getPlayer().getCamera(), source.getLevel())
            );
        }
 
        public TestFinder failedTests(CommandContext<CommandSourceStack> sourceStack, boolean onlyRequiredTests) {
            return this.build(
                sourceStack.getSource(),
                () -> FailedTestTracker.getLastFailedTests().filter(test -> !onlyRequiredTests || test.value().required()),
                TestFinder.NO_STRUCTURES
            );
        }
 
        public TestFinder byResourceSelection(CommandContext<CommandSourceStack> sourceStack, Collection<Holder.Reference<GameTestInstance>> holders) {
            return this.build(sourceStack.getSource(), holders::stream, TestFinder.NO_STRUCTURES);
        }
 
        public TestFinder failedTests(CommandContext<CommandSourceStack> sourceStack) {
            return this.failedTests(sourceStack, false);
        }
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数/字段/返回值
  • BlockPos

    • 引用位置: 方法调用/返回值
    • 关联成员: BlockPos.containing()
  • Holder

    • 引用位置: 返回值
  • FailedTestTracker

    • 引用位置: 方法调用
    • 关联成员: FailedTestTracker.getLastFailedTests()
  • GameTestInstance

    • 引用位置: 返回值
  • StructureUtils

    • 引用位置: 方法调用
    • 关联成员: StructureUtils.findNearestTest(), StructureUtils.findTestBlocks(), StructureUtils.lookedAtTestPos()
  • TestInstanceFinder

    • 引用位置: 参数/字段/实现
  • TestPosFinder

    • 引用位置: 参数/字段/实现