WaypointCommand.java

net.minecraft.server.commands.WaypointCommand

信息

  • 全限定名:net.minecraft.server.commands.WaypointCommand
  • 类型:public class
  • 包:net.minecraft.server.commands
  • 源码路径:src/main/java/net/minecraft/server/commands/WaypointCommand.java
  • 起始行号:L32
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) @ L33

  • 方法名:register
  • 源码定位:L33
  • 返回类型:void
  • 修饰符:public static

参数:

  • dispatcher: CommandDispatcher
  • context: CommandBuildContext

说明:

TODO

private static int setWaypointStyle(CommandSourceStack source, WaypointTransmitter waypoint, ResourceKey<WaypointStyleAsset> style) @ L99

  • 方法名:setWaypointStyle
  • 源码定位:L99
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • waypoint: WaypointTransmitter
  • style: ResourceKey

说明:

TODO

private static int setWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint, ChatFormatting color) @ L105

  • 方法名:setWaypointColor
  • 源码定位:L105
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • waypoint: WaypointTransmitter
  • color: ChatFormatting

说明:

TODO

private static int setWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint, Integer color) @ L111

  • 方法名:setWaypointColor
  • 源码定位:L111
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • waypoint: WaypointTransmitter
  • color: Integer

说明:

TODO

private static int resetWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint) @ L122

  • 方法名:resetWaypointColor
  • 源码定位:L122
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • waypoint: WaypointTransmitter

说明:

TODO

private static int listWaypoints(CommandSourceStack source) @ L128

  • 方法名:listWaypoints
  • 源码定位:L128
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack

说明:

TODO

private static void mutateIcon(CommandSourceStack source, WaypointTransmitter waypoint, Consumer<Waypoint.Icon> iconConsumer) @ L166

  • 方法名:mutateIcon
  • 源码定位:L166
  • 返回类型:void
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • waypoint: WaypointTransmitter
  • iconConsumer: Consumer<Waypoint.Icon>

说明:

TODO

代码

public class WaypointCommand {
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
        dispatcher.register(
            Commands.literal("waypoint")
                .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
                .then(Commands.literal("list").executes(c -> listWaypoints(c.getSource())))
                .then(
                    Commands.literal("modify")
                        .then(
                            Commands.argument("waypoint", EntityArgument.entity())
                                .then(
                                    Commands.literal("color")
                                        .then(
                                            Commands.argument("color", ColorArgument.color())
                                                .executes(
                                                    c -> setWaypointColor(
                                                        c.getSource(), WaypointArgument.getWaypoint(c, "waypoint"), ColorArgument.getColor(c, "color")
                                                    )
                                                )
                                        )
                                        .then(
                                            Commands.literal("hex")
                                                .then(
                                                    Commands.argument("color", HexColorArgument.hexColor())
                                                        .executes(
                                                            c -> setWaypointColor(
                                                                c.getSource(),
                                                                WaypointArgument.getWaypoint(c, "waypoint"),
                                                                HexColorArgument.getHexColor(c, "color")
                                                            )
                                                        )
                                                )
                                        )
                                        .then(
                                            Commands.literal("reset")
                                                .executes(c -> resetWaypointColor(c.getSource(), WaypointArgument.getWaypoint(c, "waypoint")))
                                        )
                                )
                                .then(
                                    Commands.literal("style")
                                        .then(
                                            Commands.literal("reset")
                                                .executes(
                                                    c -> setWaypointStyle(
                                                        c.getSource(), WaypointArgument.getWaypoint(c, "waypoint"), WaypointStyleAssets.DEFAULT
                                                    )
                                                )
                                        )
                                        .then(
                                            Commands.literal("set")
                                                .then(
                                                    Commands.argument("style", IdentifierArgument.id())
                                                        .executes(
                                                            c -> setWaypointStyle(
                                                                c.getSource(),
                                                                WaypointArgument.getWaypoint(c, "waypoint"),
                                                                ResourceKey.create(WaypointStyleAssets.ROOT_ID, IdentifierArgument.getId(c, "style"))
                                                            )
                                                        )
                                                )
                                        )
                                )
                        )
                )
        );
    }
 
    private static int setWaypointStyle(CommandSourceStack source, WaypointTransmitter waypoint, ResourceKey<WaypointStyleAsset> style) {
        mutateIcon(source, waypoint, icon -> icon.style = style);
        source.sendSuccess(() -> Component.translatable("commands.waypoint.modify.style"), false);
        return 0;
    }
 
    private static int setWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint, ChatFormatting color) {
        mutateIcon(source, waypoint, icon -> icon.color = Optional.of(color.getColor()));
        source.sendSuccess(() -> Component.translatable("commands.waypoint.modify.color", Component.literal(color.getName()).withStyle(color)), false);
        return 0;
    }
 
    private static int setWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint, Integer color) {
        mutateIcon(source, waypoint, icon -> icon.color = Optional.of(color));
        source.sendSuccess(
            () -> Component.translatable(
                "commands.waypoint.modify.color", Component.literal(HexFormat.of().withUpperCase().toHexDigits(ARGB.color(0, color), 6)).withColor(color)
            ),
            false
        );
        return 0;
    }
 
    private static int resetWaypointColor(CommandSourceStack source, WaypointTransmitter waypoint) {
        mutateIcon(source, waypoint, icon -> icon.color = Optional.empty());
        source.sendSuccess(() -> Component.translatable("commands.waypoint.modify.color.reset"), false);
        return 0;
    }
 
    private static int listWaypoints(CommandSourceStack source) {
        ServerLevel level = source.getLevel();
        Set<WaypointTransmitter> waypoints = level.getWaypointManager().transmitters();
        String dimension = level.dimension().identifier().toString();
        if (waypoints.isEmpty()) {
            source.sendSuccess(() -> Component.translatable("commands.waypoint.list.empty", dimension), false);
            return 0;
        } else {
            Component waypointNames = ComponentUtils.formatList(
                waypoints.stream()
                    .map(
                        transmitter -> {
                            if (transmitter instanceof LivingEntity livingEntity) {
                                BlockPos pos = livingEntity.blockPosition();
                                return livingEntity.getFeedbackDisplayName()
                                    .copy()
                                    .withStyle(
                                        s -> s.withClickEvent(
                                                new ClickEvent.SuggestCommand(
                                                    "/execute in " + dimension + " run tp @s " + pos.getX() + " " + pos.getY() + " " + pos.getZ()
                                                )
                                            )
                                            .withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.coordinates.tooltip")))
                                            .withColor(transmitter.waypointIcon().color.orElse(-1))
                                    );
                            } else {
                                return Component.literal(transmitter.toString());
                            }
                        }
                    )
                    .toList(),
                Function.identity()
            );
            source.sendSuccess(() -> Component.translatable("commands.waypoint.list.success", waypoints.size(), dimension, waypointNames), false);
            return waypoints.size();
        }
    }
 
    private static void mutateIcon(CommandSourceStack source, WaypointTransmitter waypoint, Consumer<Waypoint.Icon> iconConsumer) {
        ServerLevel level = source.getLevel();
        level.getWaypointManager().untrackWaypoint(waypoint);
        iconConsumer.accept(waypoint.waypointIcon());
        level.getWaypointManager().trackWaypoint(waypoint);
    }
}

引用的其他类

  • ChatFormatting

    • 引用位置: 参数
  • CommandBuildContext

    • 引用位置: 参数
  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

    • 引用位置: 方法调用
    • 关联成员: ColorArgument.color(), ColorArgument.getColor()
  • EntityArgument

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

    • 引用位置: 方法调用
    • 关联成员: HexColorArgument.getHexColor(), HexColorArgument.hexColor()
  • IdentifierArgument

    • 引用位置: 方法调用
    • 关联成员: IdentifierArgument.getId(), IdentifierArgument.id()
  • WaypointArgument

    • 引用位置: 方法调用
    • 关联成员: WaypointArgument.getWaypoint()
  • ClickEvent

    • 引用位置: 方法调用/构造调用
    • 关联成员: ClickEvent.SuggestCommand(), SuggestCommand()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.literal(), Component.translatable()
  • ComponentUtils

    • 引用位置: 方法调用
    • 关联成员: ComponentUtils.formatList()
  • HoverEvent

    • 引用位置: 方法调用/构造调用
    • 关联成员: HoverEvent.ShowText(), ShowText()
  • ResourceKey

    • 引用位置: 参数/方法调用
    • 关联成员: ResourceKey.create()
  • ARGB

    • 引用位置: 方法调用
    • 关联成员: ARGB.color()
  • Waypoint

    • 引用位置: 参数
  • WaypointStyleAsset

    • 引用位置: 参数
  • WaypointTransmitter

    • 引用位置: 参数