]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/SphereCommandBuilder.java
Move client side only models to client side
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / commands / SphereCommandBuilder.java
1 package com.irtimaled.bbor.client.commands;
2
3 import com.irtimaled.bbor.client.models.Point;
4 import com.irtimaled.bbor.client.providers.CustomSphereProvider;
5 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
6 import com.mojang.brigadier.context.CommandContext;
7 import com.mojang.brigadier.exceptions.CommandSyntaxException;
8 import net.minecraft.command.CommandSource;
9 import net.minecraft.command.Commands;
10
11 class SphereCommandBuilder {
12     public static final String RADIUS = "radius";
13
14     static LiteralArgumentBuilder<CommandSource> build(String command) {
15         return Commands.literal(command)
16                 .then(Commands.literal(ArgumentNames.ADD)
17                         .then(Commands.argument(ArgumentNames.POS, Arguments.point())
18                                 .then(Commands.argument(RADIUS, Arguments.integer())
19                                         .executes(SphereCommandBuilder::addSphere)))
20                         .then(Commands.argument(RADIUS, Arguments.integer())
21                                 .executes(SphereCommandBuilder::addSphere)))
22                 .then(Commands.literal(ArgumentNames.CLEAR)
23                         .executes(context -> {
24                             CustomSphereProvider.clear();
25
26                             CommandHelper.feedback(context, "bbor.commands.sphere.cleared.all");
27                             return 0;
28                         })
29                         .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
30                                 .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
31                                         .executes(context -> {
32                                             Point pos = Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d);
33                                             boolean removed = CustomSphereProvider.remove(pos);
34
35                                             String format = removed ? "bbor.commands.sphere.cleared" : "bbor.commands.sphere.notFound";
36                                             CommandHelper.feedback(context, format,
37                                                     pos.getX(), pos.getY(), pos.getZ());
38                                             return 0;
39                                         }))));
40     }
41
42     private static int addSphere(CommandContext<CommandSource> context) throws CommandSyntaxException {
43         Point pos = Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d);
44         int radius = Arguments.getInteger(context, RADIUS);
45         CustomSphereProvider.add(pos, radius);
46
47         CommandHelper.feedback(context, "bbor.commands.sphere.added",
48                 pos.getX(), pos.getY(), pos.getZ(), radius);
49         return 0;
50     }
51 }