minecraft-src/net/minecraft/server/commands/DebugMobSpawningCommand.java
2025-07-04 01:41:11 +03:00

34 lines
1.3 KiB
Java

package net.minecraft.server.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.NaturalSpawner;
public class DebugMobSpawningCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
LiteralArgumentBuilder<CommandSourceStack> literalArgumentBuilder = Commands.literal("debugmobspawning")
.requires(commandSourceStack -> commandSourceStack.hasPermission(2));
for (MobCategory mobCategory : MobCategory.values()) {
literalArgumentBuilder.then(
Commands.literal(mobCategory.getName())
.then(
Commands.argument("at", BlockPosArgument.blockPos())
.executes(commandContext -> spawnMobs(commandContext.getSource(), mobCategory, BlockPosArgument.getLoadedBlockPos(commandContext, "at")))
)
);
}
dispatcher.register(literalArgumentBuilder);
}
private static int spawnMobs(CommandSourceStack source, MobCategory mobCategory, BlockPos pos) {
NaturalSpawner.spawnCategoryForPosition(mobCategory, source.getLevel(), pos);
return 1;
}
}