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) {
|
||||
origin = BetterBlockPos.ORIGIN;
|
||||
}
|
||||
|
||||
final IArgConsumer consumer = ctx.getConsumer();
|
||||
|
||||
List<IDatatypePostFunction<Double, Double>> 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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user