DebugPathCommand.java
net.minecraft.server.commands.DebugPathCommand
信息
- 全限定名:net.minecraft.server.commands.DebugPathCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/DebugPathCommand.java
- 起始行号:L16
- 职责:
TODO
字段/常量
-
ERROR_NOT_MOB- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
ERROR_NO_PATH- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
ERROR_NOT_COMPLETE- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L19 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L21
- 方法名:register
- 源码定位:L21
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int fillBlocks(CommandSourceStack source, BlockPos target) @ L31
- 方法名:fillBlocks
- 源码定位:L31
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- target: BlockPos
说明:
TODO
代码
public class DebugPathCommand {
private static final SimpleCommandExceptionType ERROR_NOT_MOB = new SimpleCommandExceptionType(Component.literal("Source is not a mob"));
private static final SimpleCommandExceptionType ERROR_NO_PATH = new SimpleCommandExceptionType(Component.literal("Path not found"));
private static final SimpleCommandExceptionType ERROR_NOT_COMPLETE = new SimpleCommandExceptionType(Component.literal("Target not reached"));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("debugpath")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.argument("to", BlockPosArgument.blockPos()).executes(c -> fillBlocks(c.getSource(), BlockPosArgument.getLoadedBlockPos(c, "to")))
)
);
}
private static int fillBlocks(CommandSourceStack source, BlockPos target) throws CommandSyntaxException {
if (!(source.getEntity() instanceof Mob mob)) {
throw ERROR_NOT_MOB.create();
} else {
PathNavigation pathNavigation = new GroundPathNavigation(mob, source.getLevel());
Path path = pathNavigation.createPath(target, 0);
if (path == null) {
throw ERROR_NO_PATH.create();
} else if (!path.canReach()) {
throw ERROR_NOT_COMPLETE.create();
} else {
source.sendSuccess(() -> Component.literal("Made path"), true);
return 1;
}
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
BlockPosArgument.blockPos(), BlockPosArgument.getLoadedBlockPos()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.literal()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
GroundPathNavigation()
- 引用位置: