1 package com.irtimaled.bbor.client.commands;
3 import com.irtimaled.bbor.client.providers.CustomSphereProvider;
4 import com.irtimaled.bbor.common.models.Point;
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;
11 class SphereCommandBuilder {
12 public static final String RADIUS = "radius";
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();
26 CommandHelper.feedback(context, "bbor.commands.sphere.cleared.all");
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);
35 String format = removed ? "bbor.commands.sphere.cleared" : "bbor.commands.sphere.notFound";
36 CommandHelper.feedback(context, format,
37 pos.getX(), pos.getY(), pos.getZ());
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);
47 CommandHelper.feedback(context, "bbor.commands.sphere.added",
48 pos.getX(), pos.getY(), pos.getZ(), radius);