1 package com.irtimaled.bbor.client.commands;
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.providers.SpawningSphereProvider;
5 import com.mojang.brigadier.CommandDispatcher;
6 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
7 import com.mojang.brigadier.context.CommandContext;
8 import com.mojang.brigadier.exceptions.CommandSyntaxException;
9 import net.minecraft.client.Minecraft;
10 import net.minecraft.command.CommandSource;
11 import net.minecraft.command.Commands;
12 import net.minecraft.command.ISuggestionProvider;
13 import net.minecraft.world.LightType;
14 import net.minecraft.world.World;
16 public class SpawningSphereCommand {
17 private static final String COMMAND = "bbor:spawningSphere";
18 private static final String CALCULATE_SPAWNABLE = "calculateSpawnable";
20 public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
21 LiteralArgumentBuilder command = Commands.literal(COMMAND)
22 .then(Commands.literal(ArgumentNames.SET)
23 .then(Commands.argument(ArgumentNames.POS, Arguments.point())
24 .executes(SpawningSphereCommand::setSphere))
25 .executes(SpawningSphereCommand::setSphere))
26 .then(Commands.literal(ArgumentNames.CLEAR)
27 .executes(context -> {
28 boolean cleared = SpawningSphereProvider.clear();
30 String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
31 CommandHelper.feedback(context, format);
34 .then(Commands.literal(CALCULATE_SPAWNABLE)
35 .executes(context -> {
36 if(!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
37 CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
41 Counts counts = new Counts();
42 World world = Minecraft.getInstance().world;
43 SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
45 if(world.getLightFor(LightType.SKY, pos) > 7)
46 counts.nightSpawnable++;
48 SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);
50 CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
51 String.format("%,d", counts.spawnable),
52 String.format("%,d", counts.nightSpawnable));
55 commandDispatcher.register(command);
58 public static int setSphere(CommandContext<CommandSource> context) throws CommandSyntaxException {
59 SpawningSphereProvider.setSphere(Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d));
61 CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
65 private static class Counts {
66 private int spawnable = 0;
67 private int nightSpawnable = 0;