PlaceCommand.java
net.minecraft.server.commands.PlaceCommand
信息
- 全限定名:net.minecraft.server.commands.PlaceCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/PlaceCommand.java
- 起始行号:L43
- 职责:
TODO
字段/常量
-
ERROR_FEATURE_FAILED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
ERROR_JIGSAW_FAILED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L47 - 说明:
TODO
- 类型:
-
ERROR_STRUCTURE_FAILED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L48 - 说明:
TODO
- 类型:
-
ERROR_TEMPLATE_INVALID- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L51 - 说明:
TODO
- 类型:
-
ERROR_TEMPLATE_FAILED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L54 - 说明:
TODO
- 类型:
-
SUGGEST_TEMPLATES- 类型:
SuggestionProvider<CommandSourceStack> - 修饰符:
private static final - 源码定位:
L57 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L62
- 方法名:register
- 源码定位:L62
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
public static int placeFeature(CommandSourceStack source, Holder.Reference<ConfiguredFeature<?,?>> featureHolder, BlockPos pos) @ L251
- 方法名:placeFeature
- 源码定位:L251
- 返回类型:int
- 修饰符:public static
参数:
- source: CommandSourceStack
- featureHolder: Holder.Reference<ConfiguredFeature>
- pos: BlockPos
说明:
TODO
public static int placeJigsaw(CommandSourceStack source, Holder<StructureTemplatePool> pool, Identifier target, int maxDepth, BlockPos pos) @ L265
- 方法名:placeJigsaw
- 源码定位:L265
- 返回类型:int
- 修饰符:public static
参数:
- source: CommandSourceStack
- pool: Holder
- target: Identifier
- maxDepth: int
- pos: BlockPos
说明:
TODO
public static int placeStructure(CommandSourceStack source, Holder.Reference<Structure> structureHolder, BlockPos pos) @ L277
- 方法名:placeStructure
- 源码定位:L277
- 返回类型:int
- 修饰符:public static
参数:
- source: CommandSourceStack
- structureHolder: Holder.Reference
- pos: BlockPos
说明:
TODO
public static int placeTemplate(CommandSourceStack source, Identifier template, BlockPos pos, Rotation rotation, Mirror mirror, float integrity, int seed, boolean strict) @ L319
- 方法名:placeTemplate
- 源码定位:L319
- 返回类型:int
- 修饰符:public static
参数:
- source: CommandSourceStack
- template: Identifier
- pos: BlockPos
- rotation: Rotation
- mirror: Mirror
- integrity: float
- seed: int
- strict: boolean
说明:
TODO
private static void checkLoaded(ServerLevel level, ChunkPos chunkMin, ChunkPos chunkMax) @ L355
- 方法名:checkLoaded
- 源码定位:L355
- 返回类型:void
- 修饰符:private static
参数:
- level: ServerLevel
- chunkMin: ChunkPos
- chunkMax: ChunkPos
说明:
TODO
代码
public class PlaceCommand {
private static final SimpleCommandExceptionType ERROR_FEATURE_FAILED = new SimpleCommandExceptionType(
Component.translatable("commands.place.feature.failed")
);
private static final SimpleCommandExceptionType ERROR_JIGSAW_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.place.jigsaw.failed"));
private static final SimpleCommandExceptionType ERROR_STRUCTURE_FAILED = new SimpleCommandExceptionType(
Component.translatable("commands.place.structure.failed")
);
private static final DynamicCommandExceptionType ERROR_TEMPLATE_INVALID = new DynamicCommandExceptionType(
value -> Component.translatableEscape("commands.place.template.invalid", value)
);
private static final SimpleCommandExceptionType ERROR_TEMPLATE_FAILED = new SimpleCommandExceptionType(
Component.translatable("commands.place.template.failed")
);
private static final SuggestionProvider<CommandSourceStack> SUGGEST_TEMPLATES = (context, builder) -> {
StructureTemplateManager structureManager = context.getSource().getLevel().getStructureManager();
return SharedSuggestionProvider.suggestResource(structureManager.listTemplates(), builder);
};
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("place")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.literal("feature")
.then(
Commands.argument("feature", ResourceKeyArgument.key(Registries.CONFIGURED_FEATURE))
.executes(
c -> placeFeature(
c.getSource(), ResourceKeyArgument.getConfiguredFeature(c, "feature"), BlockPos.containing(c.getSource().getPosition())
)
)
.then(
Commands.argument("pos", BlockPosArgument.blockPos())
.executes(
c -> placeFeature(
c.getSource(),
ResourceKeyArgument.getConfiguredFeature(c, "feature"),
BlockPosArgument.getLoadedBlockPos(c, "pos")
)
)
)
)
)
.then(
Commands.literal("jigsaw")
.then(
Commands.argument("pool", ResourceKeyArgument.key(Registries.TEMPLATE_POOL))
.then(
Commands.argument("target", IdentifierArgument.id())
.then(
Commands.argument("max_depth", IntegerArgumentType.integer(1, 20))
.executes(
c -> placeJigsaw(
c.getSource(),
ResourceKeyArgument.getStructureTemplatePool(c, "pool"),
IdentifierArgument.getId(c, "target"),
IntegerArgumentType.getInteger(c, "max_depth"),
BlockPos.containing(c.getSource().getPosition())
)
)
.then(
Commands.argument("position", BlockPosArgument.blockPos())
.executes(
c -> placeJigsaw(
c.getSource(),
ResourceKeyArgument.getStructureTemplatePool(c, "pool"),
IdentifierArgument.getId(c, "target"),
IntegerArgumentType.getInteger(c, "max_depth"),
BlockPosArgument.getLoadedBlockPos(c, "position")
)
)
)
)
)
)
)
.then(
Commands.literal("structure")
.then(
Commands.argument("structure", ResourceKeyArgument.key(Registries.STRUCTURE))
.executes(
c -> placeStructure(
c.getSource(), ResourceKeyArgument.getStructure(c, "structure"), BlockPos.containing(c.getSource().getPosition())
)
)
.then(
Commands.argument("pos", BlockPosArgument.blockPos())
.executes(
c -> placeStructure(
c.getSource(), ResourceKeyArgument.getStructure(c, "structure"), BlockPosArgument.getLoadedBlockPos(c, "pos")
)
)
)
)
)
.then(
Commands.literal("template")
.then(
Commands.argument("template", IdentifierArgument.id())
.suggests(SUGGEST_TEMPLATES)
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPos.containing(c.getSource().getPosition()),
Rotation.NONE,
Mirror.NONE,
1.0F,
0,
false
)
)
.then(
Commands.argument("pos", BlockPosArgument.blockPos())
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
Rotation.NONE,
Mirror.NONE,
1.0F,
0,
false
)
)
.then(
Commands.argument("rotation", TemplateRotationArgument.templateRotation())
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
TemplateRotationArgument.getRotation(c, "rotation"),
Mirror.NONE,
1.0F,
0,
false
)
)
.then(
Commands.argument("mirror", TemplateMirrorArgument.templateMirror())
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
TemplateRotationArgument.getRotation(c, "rotation"),
TemplateMirrorArgument.getMirror(c, "mirror"),
1.0F,
0,
false
)
)
.then(
Commands.argument("integrity", FloatArgumentType.floatArg(0.0F, 1.0F))
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
TemplateRotationArgument.getRotation(c, "rotation"),
TemplateMirrorArgument.getMirror(c, "mirror"),
FloatArgumentType.getFloat(c, "integrity"),
0,
false
)
)
.then(
Commands.argument("seed", IntegerArgumentType.integer())
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
TemplateRotationArgument.getRotation(c, "rotation"),
TemplateMirrorArgument.getMirror(c, "mirror"),
FloatArgumentType.getFloat(c, "integrity"),
IntegerArgumentType.getInteger(c, "seed"),
false
)
)
.then(
Commands.literal("strict")
.executes(
c -> placeTemplate(
c.getSource(),
IdentifierArgument.getId(c, "template"),
BlockPosArgument.getLoadedBlockPos(c, "pos"),
TemplateRotationArgument.getRotation(c, "rotation"),
TemplateMirrorArgument.getMirror(c, "mirror"),
FloatArgumentType.getFloat(c, "integrity"),
IntegerArgumentType.getInteger(c, "seed"),
true
)
)
)
)
)
)
)
)
)
)
);
}
public static int placeFeature(CommandSourceStack source, Holder.Reference<ConfiguredFeature<?, ?>> featureHolder, BlockPos pos) throws CommandSyntaxException {
ServerLevel level = source.getLevel();
ConfiguredFeature<?, ?> feature = featureHolder.value();
ChunkPos chunkPos = ChunkPos.containing(pos);
checkLoaded(level, new ChunkPos(chunkPos.x() - 1, chunkPos.z() - 1), new ChunkPos(chunkPos.x() + 1, chunkPos.z() + 1));
if (!feature.place(level, level.getChunkSource().getGenerator(), level.getRandom(), pos)) {
throw ERROR_FEATURE_FAILED.create();
} else {
String id = featureHolder.key().identifier().toString();
source.sendSuccess(() -> Component.translatable("commands.place.feature.success", id, pos.getX(), pos.getY(), pos.getZ()), true);
return 1;
}
}
public static int placeJigsaw(CommandSourceStack source, Holder<StructureTemplatePool> pool, Identifier target, int maxDepth, BlockPos pos) throws CommandSyntaxException {
ServerLevel level = source.getLevel();
ChunkPos chunk = ChunkPos.containing(pos);
checkLoaded(level, chunk, chunk);
if (!JigsawPlacement.generateJigsaw(level, pool, target, maxDepth, pos, false)) {
throw ERROR_JIGSAW_FAILED.create();
} else {
source.sendSuccess(() -> Component.translatable("commands.place.jigsaw.success", pos.getX(), pos.getY(), pos.getZ()), true);
return 1;
}
}
public static int placeStructure(CommandSourceStack source, Holder.Reference<Structure> structureHolder, BlockPos pos) throws CommandSyntaxException {
ServerLevel level = source.getLevel();
Structure structure = structureHolder.value();
ChunkGenerator chunkGenerator = level.getChunkSource().getGenerator();
StructureStart start = structure.generate(
structureHolder,
level.dimension(),
source.registryAccess(),
chunkGenerator,
chunkGenerator.getBiomeSource(),
level.getChunkSource().randomState(),
level.getStructureManager(),
level.getSeed(),
ChunkPos.containing(pos),
0,
level,
b -> true
);
if (!start.isValid()) {
throw ERROR_STRUCTURE_FAILED.create();
} else {
BoundingBox boundingBox = start.getBoundingBox();
ChunkPos chunkMin = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.minX()), SectionPos.blockToSectionCoord(boundingBox.minZ()));
ChunkPos chunkMax = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.maxX()), SectionPos.blockToSectionCoord(boundingBox.maxZ()));
checkLoaded(level, chunkMin, chunkMax);
ChunkPos.rangeClosed(chunkMin, chunkMax)
.forEach(
c -> start.placeInChunk(
level,
level.structureManager(),
chunkGenerator,
level.getRandom(),
new BoundingBox(c.getMinBlockX(), level.getMinY(), c.getMinBlockZ(), c.getMaxBlockX(), level.getMaxY() + 1, c.getMaxBlockZ()),
c
)
);
String id = structureHolder.key().identifier().toString();
source.sendSuccess(() -> Component.translatable("commands.place.structure.success", id, pos.getX(), pos.getY(), pos.getZ()), true);
return 1;
}
}
public static int placeTemplate(
CommandSourceStack source, Identifier template, BlockPos pos, Rotation rotation, Mirror mirror, float integrity, int seed, boolean strict
) throws CommandSyntaxException {
ServerLevel level = source.getLevel();
StructureTemplateManager manager = level.getStructureManager();
Optional<StructureTemplate> maybeStructureTemplate;
try {
maybeStructureTemplate = manager.get(template);
} catch (IdentifierException var14) {
throw ERROR_TEMPLATE_INVALID.create(template);
}
if (maybeStructureTemplate.isEmpty()) {
throw ERROR_TEMPLATE_INVALID.create(template);
} else {
StructureTemplate structureTemplate = maybeStructureTemplate.get();
checkLoaded(level, ChunkPos.containing(pos), ChunkPos.containing(pos.offset(structureTemplate.getSize())));
StructurePlaceSettings placeSettings = new StructurePlaceSettings().setMirror(mirror).setRotation(rotation).setKnownShape(strict);
if (integrity < 1.0F) {
placeSettings.clearProcessors().addProcessor(new BlockRotProcessor(integrity)).setRandom(StructureBlockEntity.createRandom(seed));
}
boolean placed = structureTemplate.placeInWorld(level, pos, pos, placeSettings, StructureBlockEntity.createRandom(seed), 2 | (strict ? 816 : 0));
if (!placed) {
throw ERROR_TEMPLATE_FAILED.create();
} else {
source.sendSuccess(
() -> Component.translatable("commands.place.template.success", Component.translationArg(template), pos.getX(), pos.getY(), pos.getZ()),
true
);
return 1;
}
}
}
private static void checkLoaded(ServerLevel level, ChunkPos chunkMin, ChunkPos chunkMax) throws CommandSyntaxException {
if (ChunkPos.rangeClosed(chunkMin, chunkMax).filter(c -> !level.isLoaded(c.getWorldPosition())).findAny().isPresent()) {
throw BlockPosArgument.ERROR_NOT_LOADED.create();
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggestResource()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
IdentifierArgument.getId(), IdentifierArgument.id()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ResourceKeyArgument.getConfiguredFeature(), ResourceKeyArgument.getStructure(), ResourceKeyArgument.getStructureTemplatePool(), ResourceKeyArgument.key()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TemplateMirrorArgument.getMirror(), TemplateMirrorArgument.templateMirror()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TemplateRotationArgument.getRotation(), TemplateRotationArgument.templateRotation()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
BlockPosArgument.blockPos(), BlockPosArgument.getLoadedBlockPos()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
BlockPos.containing()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SectionPos.blockToSectionCoord()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable(), Component.translatableEscape(), Component.translationArg()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用/构造调用 - 关联成员:
ChunkPos(), ChunkPos.containing(), ChunkPos.rangeClosed()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StructureBlockEntity.createRandom()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BoundingBox()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
JigsawPlacement.generateJigsaw()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BlockRotProcessor()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StructurePlaceSettings()
- 引用位置: