diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java index cda0ad665..19312907e 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java @@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost { if (origin == null) { origin = BetterBlockPos.ORIGIN; } + final IArgConsumer consumer = ctx.getConsumer(); - List> coords = new ArrayList<>(); - final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably - for (int i = 0; i < 3; i++) { - if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { - coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o)); - copy.get(); // Consume so we actually decrement the remaining arguments - } + GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin); + if (goalBlock != null) { + return goalBlock; } - switch (coords.size()) { - case 0: - return new GoalBlock(origin); - case 1: - return new GoalYLevel( - MathHelper.floor(coords.get(0).apply((double) origin.y)) - ); - case 2: - return new GoalXZ( - MathHelper.floor(coords.get(0).apply((double) origin.x)), - MathHelper.floor(coords.get(1).apply((double) origin.z)) - ); - case 3: - return new GoalBlock( - MathHelper.floor(coords.get(0).apply((double) origin.x)), - MathHelper.floor(coords.get(1).apply((double) origin.y)), - MathHelper.floor(coords.get(2).apply((double) origin.z)) - ); - default: - throw new IllegalStateException("Unexpected coords size: " + coords.size()); + GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin); + if (goalXZ != null) { + return goalXZ; } + + GoalYLevel goalYLevel = consumer.peekDatatypePostOrNull(RelativeGoalYLevel.INSTANCE, origin); + if (goalYLevel != null) { + return goalYLevel; + } + + // when the user doesn't input anything, default to the origin + return new GoalBlock(origin); } @Override diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java index 427e67b2a..28e768296 100644 --- a/src/main/java/baritone/command/defaults/GotoCommand.java +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -41,9 +41,13 @@ public class GotoCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument... + // If we have a numeric first argument, then parse arguments as coordinates. + // Note: There is no reason to want to go where you're already at so there + // is no need to handle the case of empty arguments. + if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { + args.requireMax(3); BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); - Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin); + Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin); logDirect(String.format("Going to: %s", goal.toString())); baritone.getCustomGoalProcess().setGoalAndPath(goal); return;