Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to create waypoint with coords #4172

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

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;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.commands.arguments.WaypointArgumentType;
import meteordevelopment.meteorclient.systems.waypoints.Waypoint;
import meteordevelopment.meteorclient.systems.waypoints.Waypoints;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import net.minecraft.command.CommandSource;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static meteordevelopment.meteorclient.MeteorClient.mc;
Expand Down Expand Up @@ -45,20 +48,16 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
return SINGLE_SUCCESS;
})));

builder.then(literal("add").then(argument("waypoint", StringArgumentType.greedyString()).executes(context -> {
if (mc.player == null) return -1;

Waypoint waypoint = new Waypoint.Builder()
.name(StringArgumentType.getString(context, "waypoint"))
.pos(mc.player.getBlockPos().up(2))
.dimension(PlayerUtils.getDimension())
.build();

Waypoints.get().add(waypoint);

info("Created waypoint with name: (highlight)%s(default)", waypoint.name.get());
return SINGLE_SUCCESS;
})));
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("waypoint", StringArgumentType.greedyString()).executes(context -> addWaypoint(context, false)))
);

builder.then(literal("delete").then(argument("waypoint", WaypointArgumentType.create()).executes(context -> {
Waypoint waypoint = WaypointArgumentType.get(context);
Expand All @@ -84,6 +83,21 @@ private String waypointPos(Waypoint waypoint) {
}

private String waypointFullPos(Waypoint waypoint) {
return "X: " + waypoint.pos.get().getX() + ", Y: " + waypoint.pos.get().getY() + ", Z: " + waypoint.pos.get().getZ();
return "X: " + waypoint.pos.get().getX() + ", Y: " + waypoint.pos.get().getY() + ", Z: " + waypoint.pos.get().getZ();
}

private int addWaypoint(CommandContext<CommandSource> context, boolean withCoords) {
if (mc.player == null) return -1;

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))
.dimension(PlayerUtils.getDimension())
.build();

Waypoints.get().add(waypoint);

info("Created waypoint with name: (highlight)%s(default)", waypoint.name.get());
return SINGLE_SUCCESS;
}
}