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 net.minecraft.client.Minecraft;
8 import net.minecraft.command.Commands;
9 import net.minecraft.command.ISuggestionProvider;
10 import net.minecraft.command.arguments.Vec3Argument;
11 import net.minecraft.util.math.Vec3d;
12 import net.minecraft.world.EnumLightType;
13 import net.minecraft.world.World;
15 public class SpawningSphereCommand {
16 private static final String COMMAND = "bbor:spawningSphere";
17 private static final String SET = "set";
18 private static final String POS = "pos";
19 private static final String CLEAR = "clear";
20 private static final String CALCULATE_SPAWNABLE = "calculateSpawnable";
22 public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
23 LiteralArgumentBuilder command = Commands.literal(COMMAND)
24 .then(Commands.literal(SET)
25 .then(Commands.argument(POS, Vec3Argument.vec3())
26 .executes(context -> {
27 Vec3d pos = Vec3Argument.getVec3(context, POS);
28 SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
30 CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
33 .executes(context -> {
34 Vec3d pos = context.getSource().getPos();
35 SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
37 CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
40 .then(Commands.literal(CLEAR)
41 .executes(context -> {
42 boolean cleared = SpawningSphereProvider.clear();
44 String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
45 CommandHelper.feedback(context, format);
48 .then(Commands.literal(CALCULATE_SPAWNABLE)
49 .executes(context -> {
50 if(!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
51 CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
55 Counts counts = new Counts();
56 World world = Minecraft.getInstance().world;
57 SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
59 if(world.getLightFor(EnumLightType.SKY, pos) > 7)
60 counts.nightSpawnable++;
62 SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);
64 CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
65 String.format("%,d", counts.spawnable),
66 String.format("%,d", counts.nightSpawnable));
69 commandDispatcher.register(command);
72 private static class Counts {
73 private int spawnable = 0;
74 private int nightSpawnable = 0;