BlockDataAccessor.java
net.minecraft.server.commands.data.BlockDataAccessor
信息
- 全限定名:net.minecraft.server.commands.data.BlockDataAccessor
- 类型:public class
- 包:net.minecraft.server.commands.data
- 源码路径:src/main/java/net/minecraft/server/commands/data/BlockDataAccessor.java
- 起始行号:L25
- 实现:DataAccessor
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
ERROR_NOT_A_BLOCK_ENTITY- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
PROVIDER- 类型:
Function<String,DataCommands.DataProvider> - 修饰符:
public static final public public - 源码定位:
L30 - 说明:
TODO
- 类型:
-
entity- 类型:
BlockEntity - 修饰符:
private final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
pos- 类型:
BlockPos - 修饰符:
private final - 源码定位:
L50 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public BlockDataAccessor(BlockEntity entity, BlockPos pos) @ L52
- 构造器名:BlockDataAccessor
- 源码定位:L52
- 修饰符:public
参数:
- entity: BlockEntity
- pos: BlockPos
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void setData(CompoundTag tag) @ L57
- 方法名:setData
- 源码定位:L57
- 返回类型:void
- 修饰符:public
参数:
- tag: CompoundTag
说明:
TODO
public CompoundTag getData() @ L68
- 方法名:getData
- 源码定位:L68
- 返回类型:CompoundTag
- 修饰符:public
参数:
- 无
说明:
TODO
public Component getModifiedSuccess() @ L73
- 方法名:getModifiedSuccess
- 源码定位:L73
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public Component getPrintSuccess(Tag data) @ L78
- 方法名:getPrintSuccess
- 源码定位:L78
- 返回类型:Component
- 修饰符:public
参数:
- data: Tag
说明:
TODO
public Component getPrintSuccess(NbtPathArgument.NbtPath path, double scale, int value) @ L83
- 方法名:getPrintSuccess
- 源码定位:L83
- 返回类型:Component
- 修饰符:public
参数:
- path: NbtPathArgument.NbtPath
- scale: double
- value: int
说明:
TODO
代码
public class BlockDataAccessor implements DataAccessor {
private static final Logger LOGGER = LogUtils.getLogger();
private static final SimpleCommandExceptionType ERROR_NOT_A_BLOCK_ENTITY = new SimpleCommandExceptionType(
Component.translatable("commands.data.block.invalid")
);
public static final Function<String, DataCommands.DataProvider> PROVIDER = argPrefix -> new DataCommands.DataProvider() {
@Override
public DataAccessor access(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
BlockPos pos = BlockPosArgument.getLoadedBlockPos(context, argPrefix + "Pos");
BlockEntity entity = context.getSource().getLevel().getBlockEntity(pos);
if (entity == null) {
throw BlockDataAccessor.ERROR_NOT_A_BLOCK_ENTITY.create();
} else {
return new BlockDataAccessor(entity, pos);
}
}
@Override
public ArgumentBuilder<CommandSourceStack, ?> wrap(
ArgumentBuilder<CommandSourceStack, ?> parent, Function<ArgumentBuilder<CommandSourceStack, ?>, ArgumentBuilder<CommandSourceStack, ?>> function
) {
return parent.then(Commands.literal("block").then(function.apply(Commands.argument(argPrefix + "Pos", BlockPosArgument.blockPos()))));
}
};
private final BlockEntity entity;
private final BlockPos pos;
public BlockDataAccessor(BlockEntity entity, BlockPos pos) {
this.entity = entity;
this.pos = pos;
}
@Override
public void setData(CompoundTag tag) {
BlockState state = this.entity.getLevel().getBlockState(this.pos);
try (ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(this.entity.problemPath(), LOGGER)) {
this.entity.loadWithComponents(TagValueInput.create(reporter, this.entity.getLevel().registryAccess(), tag));
this.entity.setChanged();
this.entity.getLevel().sendBlockUpdated(this.pos, state, state, 3);
}
}
@Override
public CompoundTag getData() {
return this.entity.saveWithFullMetadata(this.entity.getLevel().registryAccess());
}
@Override
public Component getModifiedSuccess() {
return Component.translatable("commands.data.block.modified", this.pos.getX(), this.pos.getY(), this.pos.getZ());
}
@Override
public Component getPrintSuccess(Tag data) {
return Component.translatable("commands.data.block.query", this.pos.getX(), this.pos.getY(), this.pos.getZ(), NbtUtils.toPrettyComponent(data));
}
@Override
public Component getPrintSuccess(NbtPathArgument.NbtPath path, double scale, int value) {
return Component.translatable(
"commands.data.block.get", path.asString(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), String.format(Locale.ROOT, "%.2f", scale), value
);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.literal()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
BlockPosArgument.blockPos(), BlockPosArgument.getLoadedBlockPos()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NbtUtils.toPrettyComponent()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
字段/方法调用/构造调用 - 关联成员:
DataCommands.DataProvider(), DataProvider()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
ProblemReporter.ScopedCollector(), ScopedCollector()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TagValueInput.create()
- 引用位置: