Skip to content

Commit

Permalink
Improve WaypointCommand
Browse files Browse the repository at this point in the history
Allow the usage of relative coords, via `Vec3ArgumentType`.
Thanks to Crosby for carrying me as always.
  • Loading branch information
Big-Iron-Cheems authored and MineGame159 committed Oct 30, 2023
1 parent 4f923a7 commit b996ff0
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package meteordevelopment.meteorclient.commands.commands;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
Expand All @@ -15,6 +14,8 @@
import meteordevelopment.meteorclient.systems.waypoints.Waypoints;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.PosArgument;
import net.minecraft.command.argument.Vec3ArgumentType;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;

Expand Down Expand Up @@ -49,13 +50,10 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
})));

builder.then(literal("add")
.then(argument("x", IntegerArgumentType.integer())
.then(argument("y", IntegerArgumentType.integer())
.then(argument("z", IntegerArgumentType.integer())
.then(argument("waypoint", StringArgumentType.greedyString()).executes(context -> addWaypoint(context, true)))
)
)
.then(argument("pos", Vec3ArgumentType.vec3())
.then(argument("waypoint", StringArgumentType.greedyString()).executes(context -> addWaypoint(context, true)))
)

.then(argument("waypoint", StringArgumentType.greedyString()).executes(context -> addWaypoint(context, false)))
);

Expand Down Expand Up @@ -89,9 +87,10 @@ private String waypointFullPos(Waypoint waypoint) {
private int addWaypoint(CommandContext<CommandSource> context, boolean withCoords) {
if (mc.player == null) return -1;

BlockPos pos = withCoords ? context.getArgument("pos", PosArgument.class).toAbsoluteBlockPos(mc.player.getCommandSource()) : mc.player.getBlockPos().up(2);
Waypoint waypoint = new Waypoint.Builder()
.name(StringArgumentType.getString(context, "waypoint"))
.pos(withCoords ? BlockPos.ofFloored(IntegerArgumentType.getInteger(context, "x"), IntegerArgumentType.getInteger(context, "y"), IntegerArgumentType.getInteger(context, "z")) : mc.player.getBlockPos().up(2))
.pos(pos)
.dimension(PlayerUtils.getDimension())
.build();

Expand Down

0 comments on commit b996ff0

Please sign in to comment.