Added the feature to only farm within range of a waypoint.

This commit is contained in:
millennIumAMbiguity 2020-10-22 00:36:19 +02:00
parent 5d3522ca0a
commit 65a5677b33

View File

@ -18,15 +18,23 @@
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.cache.IWaypoint;
import baritone.api.command.Command;
import baritone.api.command.datatypes.ForWaypoints;
import baritone.api.command.exception.CommandException;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.Paginator;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class FarmCommand extends Command {
public FarmCommand(IBaritone baritone) {
@ -35,12 +43,49 @@ public class FarmCommand extends Command {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(1);
args.requireMax(2);
int range = 0;
if (args.hasExactly(1)) {
BetterBlockPos origin;
//range
if (args.has(1)) {
range = args.getAs(Integer.class);
}
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
//waypoint
if (args.hasExactly(1)){
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
IWaypoint waypoint = null;
if (args.hasAny() && args.peekString().equals("@")) {
long timestamp = args.getAs(Long.class);
for (IWaypoint iWaypoint : waypoints) {
if (iWaypoint.getCreationTimestamp() == timestamp) {
waypoint = iWaypoint;
break;
}
}
if (waypoint == null) {
throw new CommandInvalidStateException("Timestamp was specified but no waypoint was found");
}
} else {
switch (waypoints.length) {
case 0:
throw new CommandInvalidStateException("No waypoints found");
case 1:
waypoint = waypoints[0];
break;
default:
break;
}
}
if (waypoint == null) {
throw new CommandInvalidStateException("Multiple waypoints were found");
} else {
origin = waypoint.getLocation();
}
} else {
origin = baritone.getPlayerContext().playerFeet();
}
baritone.getFarmProcess().farm(range, origin);
logDirect("Farming");
}
@ -62,7 +107,8 @@ public class FarmCommand extends Command {
"",
"Usage:",
"> farm - farms every crop it can find.",
"> farm 100 - farm crops within a 100 block radius from the starting position."
"> farm <range> - farm crops within range from the starting position.",
"> farm <range> <waypoint> - farm crops within range from waypoint."
);
}
}