EntityAnchorArgument.java

net.minecraft.commands.arguments.EntityAnchorArgument

信息

  • 全限定名:net.minecraft.commands.arguments.EntityAnchorArgument
  • 类型:public class
  • 包:net.minecraft.commands.arguments
  • 源码路径:src/main/java/net/minecraft/commands/arguments/EntityAnchorArgument.java
  • 起始行号:L24
  • 实现:ArgumentType<EntityAnchorArgument.Anchor>
  • 职责:

    TODO

字段/常量

  • EXAMPLES

    • 类型: Collection<String>
    • 修饰符: private static final
    • 源码定位: L25
    • 说明:

      TODO

  • ERROR_INVALID

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

      TODO

内部类/嵌套类型

  • net.minecraft.commands.arguments.EntityAnchorArgument.Anchor
    • 类型: enum
    • 修饰符: public static
    • 源码定位: L60
    • 说明:

      TODO

构造器

方法

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

public static EntityAnchorArgument.Anchor getAnchor(CommandContext<CommandSourceStack> context, String name) @ L30

  • 方法名:getAnchor
  • 源码定位:L30
  • 返回类型:EntityAnchorArgument.Anchor
  • 修饰符:public static

参数:

  • context: CommandContext
  • name: String

说明:

TODO

public static EntityAnchorArgument anchor() @ L34

  • 方法名:anchor
  • 源码定位:L34
  • 返回类型:EntityAnchorArgument
  • 修饰符:public static

参数:

说明:

TODO

public EntityAnchorArgument.Anchor parse(StringReader reader) @ L38

  • 方法名:parse
  • 源码定位:L38
  • 返回类型:EntityAnchorArgument.Anchor
  • 修饰符:public

参数:

  • reader: StringReader

说明:

TODO

public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) @ L50

  • 方法名:listSuggestions
  • 源码定位:L50
  • 返回类型: CompletableFuture
  • 修饰符:public

参数:

  • context: CommandContext
  • builder: SuggestionsBuilder

说明:

TODO

public Collection<String> getExamples() @ L55

  • 方法名:getExamples
  • 源码定位:L55
  • 返回类型:Collection
  • 修饰符:public

参数:

说明:

TODO

代码

public class EntityAnchorArgument implements ArgumentType<EntityAnchorArgument.Anchor> {
    private static final Collection<String> EXAMPLES = Arrays.asList("eyes", "feet");
    private static final DynamicCommandExceptionType ERROR_INVALID = new DynamicCommandExceptionType(
        name -> Component.translatableEscape("argument.anchor.invalid", name)
    );
 
    public static EntityAnchorArgument.Anchor getAnchor(CommandContext<CommandSourceStack> context, String name) {
        return context.getArgument(name, EntityAnchorArgument.Anchor.class);
    }
 
    public static EntityAnchorArgument anchor() {
        return new EntityAnchorArgument();
    }
 
    public EntityAnchorArgument.Anchor parse(StringReader reader) throws CommandSyntaxException {
        int start = reader.getCursor();
        String name = reader.readUnquotedString();
        EntityAnchorArgument.Anchor anchor = EntityAnchorArgument.Anchor.getByName(name);
        if (anchor == null) {
            reader.setCursor(start);
            throw ERROR_INVALID.createWithContext(reader, name);
        } else {
            return anchor;
        }
    }
 
    @Override
    public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
        return SharedSuggestionProvider.suggest(EntityAnchorArgument.Anchor.BY_NAME.keySet(), builder);
    }
 
    @Override
    public Collection<String> getExamples() {
        return EXAMPLES;
    }
 
    public static enum Anchor {
        FEET("feet", (p, e) -> p),
        EYES("eyes", (p, e) -> new Vec3(p.x, p.y + e.getEyeHeight(), p.z));
 
        private static final Map<String, EntityAnchorArgument.Anchor> BY_NAME = Util.make(Maps.newHashMap(), map -> {
            for (EntityAnchorArgument.Anchor anchor : values()) {
                map.put(anchor.name, anchor);
            }
        });
        private final String name;
        private final BiFunction<Vec3, Entity, Vec3> transform;
 
        private Anchor(String name, BiFunction<Vec3, Entity, Vec3> transform) {
            this.name = name;
            this.transform = transform;
        }
 
        public static EntityAnchorArgument.@Nullable Anchor getByName(String name) {
            return BY_NAME.get(name);
        }
 
        public Vec3 apply(Entity entity) {
            return this.transform.apply(entity.position(), entity);
        }
 
        public Vec3 apply(CommandSourceStack source) {
            Entity entity = source.getEntity();
            return entity == null ? source.getPosition() : this.transform.apply(source.getPosition(), entity);
        }
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • SharedSuggestionProvider

    • 引用位置: 方法调用
    • 关联成员: SharedSuggestionProvider.suggest()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatableEscape()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.make()
  • Vec3

    • 引用位置: 构造调用
    • 关联成员: Vec3()