]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/SpawningSphereCommand.java
cf3594675920757d2c0b031048688ac92dff1e99
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / commands / SpawningSphereCommand.java
1 package com.irtimaled.bbor.client.commands;
2
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;
14
15 public class SpawningSphereCommand {
16     private static final String COMMAND = "bbor:spawningSphere";
17     private static final String CALCULATE_SPAWNABLE = "calculateSpawnable";
18
19     public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
20         LiteralArgumentBuilder command = Commands.literal(COMMAND)
21                 .then(Commands.literal(ArgumentNames.SET)
22                         .then(Commands.argument(ArgumentNames.POS, Vec3Argument.vec3())
23                                 .executes(context -> {
24                                     Vec3d pos = Vec3Argument.getVec3(context, ArgumentNames.POS);
25                                     SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
26
27                                     CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
28                                     return 0;
29                                 }))
30                         .executes(context -> {
31                             Vec3d pos = context.getSource().getPos();
32                             SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
33
34                             CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
35                             return 0;
36                         }))
37                 .then(Commands.literal(ArgumentNames.CLEAR)
38                         .executes(context -> {
39                             boolean cleared = SpawningSphereProvider.clear();
40
41                             String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
42                             CommandHelper.feedback(context, format);
43                             return 0;
44                         }))
45                 .then(Commands.literal(CALCULATE_SPAWNABLE)
46                         .executes(context -> {
47                             if(!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
48                                 CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
49                                 return 0;
50                             }
51
52                             Counts counts = new Counts();
53                             World world = Minecraft.getInstance().world;
54                             SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
55                                 counts.spawnable++;
56                                 if(world.getLightFor(EnumLightType.SKY, pos) > 7)
57                                     counts.nightSpawnable++;
58                             });
59                             SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);
60
61                             CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
62                                     String.format("%,d", counts.spawnable),
63                                     String.format("%,d", counts.nightSpawnable));
64                             return 0;
65                         }));
66         commandDispatcher.register(command);
67     }
68
69     private static class Counts {
70         private int spawnable = 0;
71         private int nightSpawnable = 0;
72
73     }
74 }