FillBiomeCommand.java
net.minecraft.server.commands.FillBiomeCommand
信息
- 全限定名:net.minecraft.server.commands.FillBiomeCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/FillBiomeCommand.java
- 起始行号:L35
- 职责:
TODO
字段/常量
-
ERROR_NOT_LOADED- 类型:
SimpleCommandExceptionType - 修饰符:
public static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
ERROR_VOLUME_TOO_LARGE- 类型:
Dynamic2CommandExceptionType - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) @ L41
- 方法名:register
- 源码定位:L41
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
- context: CommandBuildContext
说明:
TODO
private static int quantize(int blockCoord) @ L81
- 方法名:quantize
- 源码定位:L81
- 返回类型:int
- 修饰符:private static
参数:
- blockCoord: int
说明:
TODO
private static BlockPos quantize(BlockPos block) @ L85
- 方法名:quantize
- 源码定位:L85
- 返回类型:BlockPos
- 修饰符:private static
参数:
- block: BlockPos
说明:
TODO
private static BiomeResolver makeResolver(MutableInt count, ChunkAccess chunk, BoundingBox region, Holder<Biome> toFill, Predicate<Holder<Biome>> filter) @ L89
- 方法名:makeResolver
- 源码定位:L89
- 返回类型:BiomeResolver
- 修饰符:private static
参数:
- count: MutableInt
- chunk: ChunkAccess
- region: BoundingBox
- toFill: Holder
- filter: Predicate<Holder
>
说明:
TODO
public static Either<Integer,CommandSyntaxException> fill(ServerLevel level, BlockPos rawFrom, BlockPos rawTo, Holder<Biome> biome) @ L104
- 方法名:fill
- 源码定位:L104
- 返回类型:Either<Integer,CommandSyntaxException>
- 修饰符:public static
参数:
- level: ServerLevel
- rawFrom: BlockPos
- rawTo: BlockPos
- biome: Holder
说明:
TODO
public static Either<Integer,CommandSyntaxException> fill(ServerLevel level, BlockPos rawFrom, BlockPos rawTo, Holder<Biome> biome, Predicate<Holder<Biome>> filter, Consumer<Supplier<Component>> successMessageConsumer) @ L108
- 方法名:fill
- 源码定位:L108
- 返回类型:Either<Integer,CommandSyntaxException>
- 修饰符:public static
参数:
- level: ServerLevel
- rawFrom: BlockPos
- rawTo: BlockPos
- biome: Holder
- filter: Predicate<Holder
> - successMessageConsumer: Consumer<Supplier
>
说明:
TODO
private static int fill(CommandSourceStack source, BlockPos rawFrom, BlockPos rawTo, Holder.Reference<Biome> biome, Predicate<Holder<Biome>> filter) @ L161
- 方法名:fill
- 源码定位:L161
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- rawFrom: BlockPos
- rawTo: BlockPos
- biome: Holder.Reference
- filter: Predicate<Holder
>
说明:
TODO
代码
public class FillBiomeCommand {
public static final SimpleCommandExceptionType ERROR_NOT_LOADED = new SimpleCommandExceptionType(Component.translatable("argument.pos.unloaded"));
private static final Dynamic2CommandExceptionType ERROR_VOLUME_TOO_LARGE = new Dynamic2CommandExceptionType(
(max, count) -> Component.translatableEscape("commands.fillbiome.toobig", max, count)
);
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
dispatcher.register(
Commands.literal("fillbiome")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.argument("from", BlockPosArgument.blockPos())
.then(
Commands.argument("to", BlockPosArgument.blockPos())
.then(
Commands.argument("biome", ResourceArgument.resource(context, Registries.BIOME))
.executes(
c -> fill(
c.getSource(),
BlockPosArgument.getLoadedBlockPos(c, "from"),
BlockPosArgument.getLoadedBlockPos(c, "to"),
ResourceArgument.getResource(c, "biome", Registries.BIOME),
b -> true
)
)
.then(
Commands.literal("replace")
.then(
Commands.argument("filter", ResourceOrTagArgument.resourceOrTag(context, Registries.BIOME))
.executes(
c -> fill(
c.getSource(),
BlockPosArgument.getLoadedBlockPos(c, "from"),
BlockPosArgument.getLoadedBlockPos(c, "to"),
ResourceArgument.getResource(c, "biome", Registries.BIOME),
ResourceOrTagArgument.getResourceOrTag(c, "filter", Registries.BIOME)
)
)
)
)
)
)
)
);
}
private static int quantize(int blockCoord) {
return QuartPos.toBlock(QuartPos.fromBlock(blockCoord));
}
private static BlockPos quantize(BlockPos block) {
return new BlockPos(quantize(block.getX()), quantize(block.getY()), quantize(block.getZ()));
}
private static BiomeResolver makeResolver(MutableInt count, ChunkAccess chunk, BoundingBox region, Holder<Biome> toFill, Predicate<Holder<Biome>> filter) {
return (quartX, quartY, quartZ, sampler) -> {
int blockX = QuartPos.toBlock(quartX);
int blockY = QuartPos.toBlock(quartY);
int blockZ = QuartPos.toBlock(quartZ);
Holder<Biome> currentBiome = chunk.getNoiseBiome(quartX, quartY, quartZ);
if (region.isInside(blockX, blockY, blockZ) && filter.test(currentBiome)) {
count.increment();
return toFill;
} else {
return currentBiome;
}
};
}
public static Either<Integer, CommandSyntaxException> fill(ServerLevel level, BlockPos rawFrom, BlockPos rawTo, Holder<Biome> biome) {
return fill(level, rawFrom, rawTo, biome, b -> true, m -> {});
}
public static Either<Integer, CommandSyntaxException> fill(
ServerLevel level,
BlockPos rawFrom,
BlockPos rawTo,
Holder<Biome> biome,
Predicate<Holder<Biome>> filter,
Consumer<Supplier<Component>> successMessageConsumer
) {
BlockPos from = quantize(rawFrom);
BlockPos to = quantize(rawTo);
BoundingBox region = BoundingBox.fromCorners(from, to);
long volume = (long)region.getXSpan() * region.getYSpan() * region.getZSpan();
int limit = level.getGameRules().get(GameRules.MAX_BLOCK_MODIFICATIONS);
if (volume > limit) {
return Either.right(ERROR_VOLUME_TOO_LARGE.create(limit, volume));
} else {
List<ChunkAccess> chunks = new ArrayList<>();
for (int chunkZ = SectionPos.blockToSectionCoord(region.minZ()); chunkZ <= SectionPos.blockToSectionCoord(region.maxZ()); chunkZ++) {
for (int chunkX = SectionPos.blockToSectionCoord(region.minX()); chunkX <= SectionPos.blockToSectionCoord(region.maxX()); chunkX++) {
ChunkAccess chunk = level.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false);
if (chunk == null) {
return Either.right(ERROR_NOT_LOADED.create());
}
chunks.add(chunk);
}
}
MutableInt changedCount = new MutableInt(0);
for (ChunkAccess chunk : chunks) {
chunk.fillBiomesFromNoise(makeResolver(changedCount, chunk, region, biome, filter), level.getChunkSource().randomState().sampler());
chunk.markUnsaved();
}
level.getChunkSource().chunkMap.resendBiomesForChunks(chunks);
successMessageConsumer.accept(
() -> Component.translatable(
"commands.fillbiome.success.count",
changedCount.intValue(),
region.minX(),
region.minY(),
region.minZ(),
region.maxX(),
region.maxY(),
region.maxZ()
)
);
return Either.left(changedCount.intValue());
}
}
private static int fill(CommandSourceStack source, BlockPos rawFrom, BlockPos rawTo, Holder.Reference<Biome> biome, Predicate<Holder<Biome>> filter) throws CommandSyntaxException {
Either<Integer, CommandSyntaxException> result = fill(source.getLevel(), rawFrom, rawTo, biome, filter, m -> source.sendSuccess(m, true));
Optional<CommandSyntaxException> exception = result.right();
if (exception.isPresent()) {
throw (CommandSyntaxException)exception.get();
} else {
return result.left().get();
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ResourceArgument.getResource(), ResourceArgument.resource()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ResourceOrTagArgument.getResourceOrTag(), ResourceOrTagArgument.resourceOrTag()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
BlockPosArgument.blockPos(), BlockPosArgument.getLoadedBlockPos()
- 引用位置:
-
- 引用位置:
参数/构造调用/返回值 - 关联成员:
BlockPos()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
QuartPos.fromBlock(), QuartPos.toBlock()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SectionPos.blockToSectionCoord()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Component.translatable(), Component.translatableEscape()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
BoundingBox.fromCorners()
- 引用位置: