枚举值参数
Entity anchor 参数
entity anchor 参数有两个有效输入:feet 和 eyes。返回的 LookAnchor 主要用于
Entity#lookAt(Position, LookAnchor) 或
Player#lookAt(Entity, LookAnchor, LookAnchor) 等方法。
使用示例
public static LiteralCommandNode<CommandSourceStack> entityAnchorArgument() {
return Commands.literal("entityanchor")
.then(Commands.argument("arg", ArgumentTypes.entityAnchor())
.executes(ctx -> {
final LookAnchor lookAnchor = ctx.getArgument("arg", LookAnchor.class);
ctx.getSource().getSender().sendRichMessage("你选择了 <aqua><anchor></aqua>!",
Placeholder.unparsed("anchor", lookAnchor.name())
);
return Command.SINGLE_SUCCESS;
}))
.build();
}
游戏内预览
GameMode 参数
游戏模式参数的工作方式与原版 /gamemode <gamemode> 命令的第一个参数相同。它接受任何 4 个有效的游戏模式,返回
一个 GameMode 枚举以在代码中使用。
使用示例
public static LiteralCommandNode<CommandSourceStack> gameModeArgument() {
return Commands.literal("gamemodearg")
.then(Commands.argument("arg", ArgumentTypes.gameMode())
.executes(ctx -> {
final GameMode gamemode = ctx.getArgument("arg", GameMode.class);
if (ctx.getSource().getExecutor() instanceof Player player) {
player.setGameMode(gamemode);
player.sendRichMessage("你的游戏模式已被设置为 <red><gamemode></red>!",
Placeholder.component("gamemode", Component.translatable(gamemode))
);
return Command.SINGLE_SUCCESS;
}
ctx.getSource().getSender().sendPlainMessage("此命令需要一个玩家!");
return Command.SINGLE_SUCCESS;
}))
.build();
}
游戏内预览
HeightMap 参数
HeightMap 参数包含以下有效输入:motion_blocking、motion_blocking_no_leaves、ocean_floor 和 world_surface。它经常
用于声明数据包的相对位置或 /execute positioned over <height_map> 命令。例如,world_surface
表示应该使用设定的 X/Z 值上世界表面的 Y 坐标。
使用示例
public static LiteralCommandNode<CommandSourceStack> heightMapArgument() {
return Commands.literal("heightmap")
.then(Commands.argument("arg", ArgumentTypes.heightMap())
.executes(ctx -> {
final HeightMap heightMap = ctx.getArgument("arg", HeightMap.class);
ctx.getSource().getSender().sendRichMessage("你选择了 <gold><selection></gold>",
Placeholder.unparsed("selection", heightMap.name())
);
return Command.SINGLE_SUCCESS;
}))
.build();
}
游戏内预览
Scoreboard display slot 参数
此参数允许你从用户那里检索 DisplaySlot 枚举值。
使用示例
public static LiteralCommandNode<CommandSourceStack> scoreboardDisplaySlotArgument() {
return Commands.literal("scoreboarddisplayslot")
.then(Commands.argument("slot", ArgumentTypes.scoreboardDisplaySlot())
.executes(ctx -> {
final DisplaySlot slot = ctx.getArgument("slot", DisplaySlot.class);
ctx.getSource().getSender().sendPlainMessage("你选择了:" + slot.getId());
return Command.SINGLE_SUCCESS;
})
).build();
}
游戏内预览
Template mirror 参数
在这里,用户有 3 个有效的输入选项:front_back、left_right 和 none。你可以将参数结果作为
Mirror 枚举值检索。
使用示例
public static LiteralCommandNode<CommandSourceStack> templateMirrorArgument() {
return Commands.literal("templatemirror")
.then(Commands.argument("mirror", ArgumentTypes.templateMirror())
.executes(ctx -> {
final Mirror mirror = ctx.getArgument("mirror", Mirror.class);
ctx.getSource().getSender().sendPlainMessage("你选择了:" + mirror.name());
return Command.SINGLE_SUCCESS;
})
).build();
}
游戏内预览
Template rotation 参数
对于模板旋转参数,用户有 4 个有效的输入选项:180、clockwise_90、counterclockwise_90 和 none。你可以将参数结果
作为 StructureRotation 枚举值检索。
使用示例
public static LiteralCommandNode<CommandSourceStack> templateRotationArgument() {
return Commands.literal("templaterotation")
.then(Commands.argument("rotation", ArgumentTypes.templateRotation())
.executes(ctx -> {
final StructureRotation rotation = ctx.getArgument("rotation", StructureRotation.class);
ctx.getSource().getSender().sendPlainMessage("你选择了:" + rotation.name());
return Command.SINGLE_SUCCESS;
})
).build();
}