WorldBorderCommand.java
net.minecraft.server.commands.WorldBorderCommand
信息
- 全限定名:net.minecraft.server.commands.WorldBorderCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/WorldBorderCommand.java
- 起始行号:L20
- 职责:
TODO
字段/常量
-
ERROR_SAME_CENTER- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
ERROR_SAME_SIZE- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
ERROR_TOO_SMALL- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
ERROR_TOO_BIG- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
ERROR_TOO_FAR_OUT- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
ERROR_SAME_WARNING_TIME- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
ERROR_SAME_WARNING_DISTANCE- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
ERROR_SAME_DAMAGE_BUFFER- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
ERROR_SAME_DAMAGE_AMOUNT- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L45 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L49
- 方法名:register
- 源码定位:L49
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int setDamageBuffer(CommandSourceStack source, float distance) @ L129
- 方法名:setDamageBuffer
- 源码定位:L129
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- distance: float
说明:
TODO
private static int setDamageAmount(CommandSourceStack source, float damagePerBlock) @ L140
- 方法名:setDamageAmount
- 源码定位:L140
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- damagePerBlock: float
说明:
TODO
private static int setWarningTime(CommandSourceStack source, int ticks) @ L153
- 方法名:setWarningTime
- 源码定位:L153
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- ticks: int
说明:
TODO
private static int setWarningDistance(CommandSourceStack source, int distance) @ L164
- 方法名:setWarningDistance
- 源码定位:L164
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- distance: int
说明:
TODO
private static int getSize(CommandSourceStack source) @ L175
- 方法名:getSize
- 源码定位:L175
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
private static int setCenter(CommandSourceStack source, Vec2 center) @ L181
- 方法名:setCenter
- 源码定位:L181
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- center: Vec2
说明:
TODO
private static int setSize(CommandSourceStack source, double distance, long ticks) @ L199
- 方法名:setSize
- 源码定位:L199
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- distance: double
- ticks: long
说明:
TODO
private static String formatTicksToSeconds(long ticks) @ L227
- 方法名:formatTicksToSeconds
- 源码定位:L227
- 返回类型:String
- 修饰符:private static
参数:
- ticks: long
说明:
TODO
代码
public class WorldBorderCommand {
private static final SimpleCommandExceptionType ERROR_SAME_CENTER = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.center.failed")
);
private static final SimpleCommandExceptionType ERROR_SAME_SIZE = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.set.failed.nochange")
);
private static final SimpleCommandExceptionType ERROR_TOO_SMALL = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.set.failed.small")
);
private static final SimpleCommandExceptionType ERROR_TOO_BIG = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.set.failed.big", 5.999997E7F)
);
private static final SimpleCommandExceptionType ERROR_TOO_FAR_OUT = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.set.failed.far", 2.9999984E7)
);
private static final SimpleCommandExceptionType ERROR_SAME_WARNING_TIME = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.warning.time.failed")
);
private static final SimpleCommandExceptionType ERROR_SAME_WARNING_DISTANCE = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.warning.distance.failed")
);
private static final SimpleCommandExceptionType ERROR_SAME_DAMAGE_BUFFER = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.damage.buffer.failed")
);
private static final SimpleCommandExceptionType ERROR_SAME_DAMAGE_AMOUNT = new SimpleCommandExceptionType(
Component.translatable("commands.worldborder.damage.amount.failed")
);
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("worldborder")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.literal("add")
.then(
Commands.argument("distance", DoubleArgumentType.doubleArg(-5.999997E7F, 5.999997E7F))
.executes(
c -> setSize(
c.getSource(), c.getSource().getLevel().getWorldBorder().getSize() + DoubleArgumentType.getDouble(c, "distance"), 0L
)
)
.then(
Commands.argument("time", TimeArgument.time(0))
.executes(
c -> setSize(
c.getSource(),
c.getSource().getLevel().getWorldBorder().getSize() + DoubleArgumentType.getDouble(c, "distance"),
c.getSource().getLevel().getWorldBorder().getLerpTime() + IntegerArgumentType.getInteger(c, "time")
)
)
)
)
)
.then(
Commands.literal("set")
.then(
Commands.argument("distance", DoubleArgumentType.doubleArg(-5.999997E7F, 5.999997E7F))
.executes(c -> setSize(c.getSource(), DoubleArgumentType.getDouble(c, "distance"), 0L))
.then(
Commands.argument("time", TimeArgument.time(0))
.executes(
c -> setSize(c.getSource(), DoubleArgumentType.getDouble(c, "distance"), IntegerArgumentType.getInteger(c, "time"))
)
)
)
)
.then(
Commands.literal("center")
.then(Commands.argument("pos", Vec2Argument.vec2()).executes(c -> setCenter(c.getSource(), Vec2Argument.getVec2(c, "pos"))))
)
.then(
Commands.literal("damage")
.then(
Commands.literal("amount")
.then(
Commands.argument("damagePerBlock", FloatArgumentType.floatArg(0.0F))
.executes(c -> setDamageAmount(c.getSource(), FloatArgumentType.getFloat(c, "damagePerBlock")))
)
)
.then(
Commands.literal("buffer")
.then(
Commands.argument("distance", FloatArgumentType.floatArg(0.0F))
.executes(c -> setDamageBuffer(c.getSource(), FloatArgumentType.getFloat(c, "distance")))
)
)
)
.then(Commands.literal("get").executes(c -> getSize(c.getSource())))
.then(
Commands.literal("warning")
.then(
Commands.literal("distance")
.then(
Commands.argument("distance", IntegerArgumentType.integer(0))
.executes(c -> setWarningDistance(c.getSource(), IntegerArgumentType.getInteger(c, "distance")))
)
)
.then(
Commands.literal("time")
.then(
Commands.argument("time", TimeArgument.time(0))
.executes(c -> setWarningTime(c.getSource(), IntegerArgumentType.getInteger(c, "time")))
)
)
)
);
}
private static int setDamageBuffer(CommandSourceStack source, float distance) throws CommandSyntaxException {
WorldBorder border = source.getLevel().getWorldBorder();
if (border.getSafeZone() == distance) {
throw ERROR_SAME_DAMAGE_BUFFER.create();
} else {
border.setSafeZone(distance);
source.sendSuccess(() -> Component.translatable("commands.worldborder.damage.buffer.success", String.format(Locale.ROOT, "%.2f", distance)), true);
return (int)distance;
}
}
private static int setDamageAmount(CommandSourceStack source, float damagePerBlock) throws CommandSyntaxException {
WorldBorder border = source.getLevel().getWorldBorder();
if (border.getDamagePerBlock() == damagePerBlock) {
throw ERROR_SAME_DAMAGE_AMOUNT.create();
} else {
border.setDamagePerBlock(damagePerBlock);
source.sendSuccess(
() -> Component.translatable("commands.worldborder.damage.amount.success", String.format(Locale.ROOT, "%.2f", damagePerBlock)), true
);
return (int)damagePerBlock;
}
}
private static int setWarningTime(CommandSourceStack source, int ticks) throws CommandSyntaxException {
WorldBorder border = source.getLevel().getWorldBorder();
if (border.getWarningTime() == ticks) {
throw ERROR_SAME_WARNING_TIME.create();
} else {
border.setWarningTime(ticks);
source.sendSuccess(() -> Component.translatable("commands.worldborder.warning.time.success", formatTicksToSeconds(ticks)), true);
return ticks;
}
}
private static int setWarningDistance(CommandSourceStack source, int distance) throws CommandSyntaxException {
WorldBorder border = source.getLevel().getWorldBorder();
if (border.getWarningBlocks() == distance) {
throw ERROR_SAME_WARNING_DISTANCE.create();
} else {
border.setWarningBlocks(distance);
source.sendSuccess(() -> Component.translatable("commands.worldborder.warning.distance.success", distance), true);
return distance;
}
}
private static int getSize(CommandSourceStack source) {
double size = source.getLevel().getWorldBorder().getSize();
source.sendSuccess(() -> Component.translatable("commands.worldborder.get", String.format(Locale.ROOT, "%.0f", size)), false);
return Mth.floor(size + 0.5);
}
private static int setCenter(CommandSourceStack source, Vec2 center) throws CommandSyntaxException {
WorldBorder border = source.getLevel().getWorldBorder();
if (border.getCenterX() == center.x && border.getCenterZ() == center.y) {
throw ERROR_SAME_CENTER.create();
} else if (!(Math.abs(center.x) > 2.9999984E7) && !(Math.abs(center.y) > 2.9999984E7)) {
border.setCenter(center.x, center.y);
source.sendSuccess(
() -> Component.translatable(
"commands.worldborder.center.success", String.format(Locale.ROOT, "%.2f", center.x), String.format(Locale.ROOT, "%.2f", center.y)
),
true
);
return 0;
} else {
throw ERROR_TOO_FAR_OUT.create();
}
}
private static int setSize(CommandSourceStack source, double distance, long ticks) throws CommandSyntaxException {
ServerLevel level = source.getLevel();
WorldBorder border = level.getWorldBorder();
double current = border.getSize();
if (current == distance) {
throw ERROR_SAME_SIZE.create();
} else if (distance < 1.0) {
throw ERROR_TOO_SMALL.create();
} else if (distance > 5.999997E7F) {
throw ERROR_TOO_BIG.create();
} else {
String formattedDistance = String.format(Locale.ROOT, "%.1f", distance);
if (ticks > 0L) {
border.lerpSizeBetween(current, distance, ticks, level.getGameTime());
if (distance > current) {
source.sendSuccess(() -> Component.translatable("commands.worldborder.set.grow", formattedDistance, formatTicksToSeconds(ticks)), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.worldborder.set.shrink", formattedDistance, formatTicksToSeconds(ticks)), true);
}
} else {
border.setSize(distance);
source.sendSuccess(() -> Component.translatable("commands.worldborder.set.immediate", formattedDistance), true);
}
return (int)(distance - current);
}
}
private static String formatTicksToSeconds(long ticks) {
return String.format(Locale.ROOT, "%.2f", ticks / 20.0);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TimeArgument.time()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Vec2Argument.getVec2(), Vec2Argument.vec2()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.floor()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: