WeatherCommand.java

net.minecraft.server.commands.WeatherCommand

信息

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

    TODO

字段/常量

  • DEFAULT_TIME
    • 类型: int
    • 修饰符: private static final
    • 源码定位: L13
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L15

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

参数:

  • dispatcher: CommandDispatcher

说明:

TODO

private static int getDuration(CommandSourceStack source, int input, IntProvider defaultDistribution) @ L46

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

参数:

  • source: CommandSourceStack
  • input: int
  • defaultDistribution: IntProvider

说明:

TODO

private static int setClear(CommandSourceStack source, int duration) @ L50

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

参数:

  • source: CommandSourceStack
  • duration: int

说明:

TODO

private static int setRain(CommandSourceStack source, int duration) @ L56

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

参数:

  • source: CommandSourceStack
  • duration: int

说明:

TODO

private static int setThunder(CommandSourceStack source, int duration) @ L62

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

参数:

  • source: CommandSourceStack
  • duration: int

说明:

TODO

代码

public class WeatherCommand {
    private static final int DEFAULT_TIME = -1;
 
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
            Commands.literal("weather")
                .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
                .then(
                    Commands.literal("clear")
                        .executes(c -> setClear(c.getSource(), -1))
                        .then(
                            Commands.argument("duration", TimeArgument.time(1))
                                .executes(c -> setClear(c.getSource(), IntegerArgumentType.getInteger(c, "duration")))
                        )
                )
                .then(
                    Commands.literal("rain")
                        .executes(c -> setRain(c.getSource(), -1))
                        .then(
                            Commands.argument("duration", TimeArgument.time(1))
                                .executes(c -> setRain(c.getSource(), IntegerArgumentType.getInteger(c, "duration")))
                        )
                )
                .then(
                    Commands.literal("thunder")
                        .executes(c -> setThunder(c.getSource(), -1))
                        .then(
                            Commands.argument("duration", TimeArgument.time(1))
                                .executes(c -> setThunder(c.getSource(), IntegerArgumentType.getInteger(c, "duration")))
                        )
                )
        );
    }
 
    private static int getDuration(CommandSourceStack source, int input, IntProvider defaultDistribution) {
        return input == -1 ? defaultDistribution.sample(source.getLevel().getRandom()) : input;
    }
 
    private static int setClear(CommandSourceStack source, int duration) {
        source.getServer().setWeatherParameters(getDuration(source, duration, ServerLevel.RAIN_DELAY), 0, false, false);
        source.sendSuccess(() -> Component.translatable("commands.weather.set.clear"), true);
        return duration;
    }
 
    private static int setRain(CommandSourceStack source, int duration) {
        source.getServer().setWeatherParameters(0, getDuration(source, duration, ServerLevel.RAIN_DURATION), true, false);
        source.sendSuccess(() -> Component.translatable("commands.weather.set.rain"), true);
        return duration;
    }
 
    private static int setThunder(CommandSourceStack source, int duration) {
        source.getServer().setWeatherParameters(0, getDuration(source, duration, ServerLevel.THUNDER_DURATION), true, true);
        source.sendSuccess(() -> Component.translatable("commands.weather.set.thunder"), true);
        return duration;
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

    • 引用位置: 方法调用
    • 关联成员: TimeArgument.time()
  • Component

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

    • 引用位置: 参数