1 package com.irtimaled.bbor.client.commands;
3 import com.irtimaled.bbor.client.models.Point;
4 import com.irtimaled.bbor.client.providers.CustomLineProvider;
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 LineCommandBuilder {
12 private static final String WIDTH = "width";
14 static LiteralArgumentBuilder<CommandSource> build(String command) {
15 return Commands.literal(command)
16 .then(Commands.literal(ArgumentNames.ADD)
17 .then(Commands.argument(ArgumentNames.FROM, Arguments.point())
18 .then(Commands.argument(ArgumentNames.TO, Arguments.point())
19 .executes(LineCommandBuilder::addLine)
20 .then(Commands.argument(WIDTH, Arguments.doubleArg())
21 .executes(LineCommandBuilder::addLine)))))
22 .then(Commands.literal(ArgumentNames.CLEAR)
23 .executes(context -> {
24 CustomLineProvider.clear();
26 CommandHelper.feedback(context, "bbor.commands.line.cleared.all");
29 .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
30 .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
31 .executes(context -> {
32 Point from = Arguments.getPoint(context, ArgumentNames.FROM).snapXZ(0.5d);
33 Point to = Arguments.getPoint(context, ArgumentNames.TO).snapXZ(0.5d);
34 boolean removed = CustomLineProvider.remove(from, to);
36 String format = removed ? "bbor.commands.line.cleared" : "bbor.commands.line.notFound";
37 CommandHelper.feedback(context, format,
38 from.getX(), from.getY(), from.getZ(),
39 to.getX(), to.getY(), to.getZ());
44 private static int addLine(CommandContext<CommandSource> context) throws CommandSyntaxException {
45 Point from = Arguments.getPoint(context, ArgumentNames.FROM).snapXZ(0.5d);
46 Point to = Arguments.getPoint(context, ArgumentNames.TO).snapXZ(0.5d);
47 Double width = Arguments.getDouble(context, WIDTH);
48 CustomLineProvider.add(from, to, width);
50 CommandHelper.feedback(context, "bbor.commands.line.added",
51 from.getX(), from.getY(), from.getZ(),
52 to.getX(), to.getY(), to.getZ());