EntityDataAccessor.java

net.minecraft.server.commands.data.EntityDataAccessor

信息

  • 全限定名:net.minecraft.server.commands.data.EntityDataAccessor
  • 类型:public class
  • 包:net.minecraft.server.commands.data
  • 源码路径:src/main/java/net/minecraft/server/commands/data/EntityDataAccessor.java
  • 起始行号:L26
  • 实现:DataAccessor
  • 职责:

    TODO

字段/常量

  • LOGGER

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

      TODO

  • ERROR_NO_PLAYERS

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

      TODO

  • PROVIDER

    • 类型: Function<String,DataCommands.DataProvider>
    • 修饰符: public static final public public
    • 源码定位: L29
    • 说明:

      TODO

  • entity

    • 类型: Entity
    • 修饰符: private final
    • 源码定位: L42
    • 说明:

      TODO

内部类/嵌套类型

构造器

public EntityDataAccessor(Entity entity) @ L44

  • 构造器名:EntityDataAccessor
  • 源码定位:L44
  • 修饰符:public

参数:

  • entity: Entity

说明:

TODO

方法

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

public void setData(CompoundTag tag) @ L48

  • 方法名:setData
  • 源码定位:L48
  • 返回类型:void
  • 修饰符:public

参数:

  • tag: CompoundTag

说明:

TODO

public CompoundTag getData() @ L62

  • 方法名:getData
  • 源码定位:L62
  • 返回类型:CompoundTag
  • 修饰符:public

参数:

说明:

TODO

public Component getModifiedSuccess() @ L67

  • 方法名:getModifiedSuccess
  • 源码定位:L67
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public Component getPrintSuccess(Tag data) @ L72

  • 方法名:getPrintSuccess
  • 源码定位:L72
  • 返回类型:Component
  • 修饰符:public

参数:

  • data: Tag

说明:

TODO

public Component getPrintSuccess(NbtPathArgument.NbtPath path, double scale, int value) @ L77

  • 方法名:getPrintSuccess
  • 源码定位:L77
  • 返回类型:Component
  • 修饰符:public

参数:

  • path: NbtPathArgument.NbtPath
  • scale: double
  • value: int

说明:

TODO

代码

public class EntityDataAccessor implements DataAccessor {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final SimpleCommandExceptionType ERROR_NO_PLAYERS = new SimpleCommandExceptionType(Component.translatable("commands.data.entity.invalid"));
    public static final Function<String, DataCommands.DataProvider> PROVIDER = arg -> new DataCommands.DataProvider() {
        @Override
        public DataAccessor access(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
            return new EntityDataAccessor(EntityArgument.getEntity(context, arg));
        }
 
        @Override
        public ArgumentBuilder<CommandSourceStack, ?> wrap(
            ArgumentBuilder<CommandSourceStack, ?> parent, Function<ArgumentBuilder<CommandSourceStack, ?>, ArgumentBuilder<CommandSourceStack, ?>> function
        ) {
            return parent.then(Commands.literal("entity").then(function.apply(Commands.argument(arg, EntityArgument.entity()))));
        }
    };
    private final Entity entity;
 
    public EntityDataAccessor(Entity entity) {
        this.entity = entity;
    }
 
    @Override
    public void setData(CompoundTag tag) throws CommandSyntaxException {
        if (this.entity instanceof Player) {
            throw ERROR_NO_PLAYERS.create();
        } else {
            UUID uuid = this.entity.getUUID();
 
            try (ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(this.entity.problemPath(), LOGGER)) {
                this.entity.load(TagValueInput.create(reporter, this.entity.registryAccess(), tag));
                this.entity.setUUID(uuid);
            }
        }
    }
 
    @Override
    public CompoundTag getData() {
        return NbtPredicate.getEntityTagToCompare(this.entity);
    }
 
    @Override
    public Component getModifiedSuccess() {
        return Component.translatable("commands.data.entity.modified", this.entity.getDisplayName());
    }
 
    @Override
    public Component getPrintSuccess(Tag data) {
        return Component.translatable("commands.data.entity.query", this.entity.getDisplayName(), NbtUtils.toPrettyComponent(data));
    }
 
    @Override
    public Component getPrintSuccess(NbtPathArgument.NbtPath path, double scale, int value) {
        return Component.translatable(
            "commands.data.entity.get", path.asString(), this.entity.getDisplayName(), String.format(Locale.ROOT, "%.2f", scale), value
        );
    }
}

引用的其他类

  • NbtPredicate

    • 引用位置: 方法调用
    • 关联成员: NbtPredicate.getEntityTagToCompare()
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.argument(), Commands.literal()
  • EntityArgument

    • 引用位置: 方法调用
    • 关联成员: EntityArgument.entity(), EntityArgument.getEntity()
  • NbtPathArgument

    • 引用位置: 参数
  • CompoundTag

    • 引用位置: 参数/返回值
  • NbtUtils

    • 引用位置: 方法调用
    • 关联成员: NbtUtils.toPrettyComponent()
  • Tag

    • 引用位置: 参数
  • Component

    • 引用位置: 方法调用/返回值
    • 关联成员: Component.translatable()
  • DataAccessor

    • 引用位置: 实现
  • DataCommands

    • 引用位置: 字段/方法调用/构造调用
    • 关联成员: DataCommands.DataProvider(), DataProvider()
  • ProblemReporter

    • 引用位置: 方法调用/构造调用
    • 关联成员: ProblemReporter.ScopedCollector(), ScopedCollector()
  • Entity

    • 引用位置: 参数/字段
  • TagValueInput

    • 引用位置: 方法调用
    • 关联成员: TagValueInput.create()