Remove hack, add comment, don't use default when arg is required
This commit is contained in:
parent
82d520d808
commit
0db4b193e1
@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost<Goal, BetterBlockPos> {
|
|||||||
if (origin == null) {
|
if (origin == null) {
|
||||||
origin = BetterBlockPos.ORIGIN;
|
origin = BetterBlockPos.ORIGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
final IArgConsumer consumer = ctx.getConsumer();
|
final IArgConsumer consumer = ctx.getConsumer();
|
||||||
|
|
||||||
List<IDatatypePostFunction<Double, Double>> coords = new ArrayList<>();
|
GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin);
|
||||||
final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably
|
if (goalBlock != null) {
|
||||||
for (int i = 0; i < 3; i++) {
|
return goalBlock;
|
||||||
if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
|
|
||||||
coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o));
|
|
||||||
copy.get(); // Consume so we actually decrement the remaining arguments
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (coords.size()) {
|
GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin);
|
||||||
case 0:
|
if (goalXZ != null) {
|
||||||
return new GoalBlock(origin);
|
return goalXZ;
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
|
@ -41,9 +41,13 @@ public class GotoCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
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();
|
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()));
|
logDirect(String.format("Going to: %s", goal.toString()));
|
||||||
baritone.getCustomGoalProcess().setGoalAndPath(goal);
|
baritone.getCustomGoalProcess().setGoalAndPath(goal);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user