goto is back

This commit is contained in:
Leijurv 2019-10-06 13:44:37 -07:00
parent 22d5cb8068
commit d19039e3e5
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 100 additions and 40 deletions

View File

@ -17,6 +17,7 @@
package baritone.api.process;
import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.block.Block;
/**
@ -24,7 +25,11 @@ import net.minecraft.block.Block;
*/
public interface IGetToBlockProcess extends IBaritoneProcess {
void getToBlock(Block block);
void getToBlock(BlockOptionalMeta block);
default void getToBlock(Block block) {
getToBlock(new BlockOptionalMeta(block));
}
boolean blacklistClosest();
}

View File

@ -34,6 +34,7 @@ public final class DefaultCommands {
new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),
new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"),
new GoalCommand(baritone),
new GotoCommand(baritone),
new PathCommand(baritone),
new ProcCommand(baritone),
new VersionCommand(baritone),

View File

@ -0,0 +1,82 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.pathing.goals.Goal;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class GotoCommand extends Command {
protected GotoCommand(IBaritone baritone) {
super(baritone, "goto");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument...
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin);
logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal);
return;
}
BlockOptionalMeta destination = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
baritone.getGetToBlockProcess().getToBlock(destination);
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
// since it's either a goal or a block, I don't think we can tab complete properly?
// so just tab complete for the block variant
return args.tabCompleteDatatype(BlockById.INSTANCE);
}
@Override
public String getShortDesc() {
return "Go to a coordinate or block";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The got command tells Baritone to head towards a given goal or block.",
"",
"Wherever a coordinate is expected, you can use ~ just like in regular Minecraft commands. Or, you can just use regular numbers.",
"",
"Usage:",
"> goto <block> - Go to a block, wherever it is in the world",
"> goto <y> - Go to a Y level",
"> goto <x> <z> - Go to an X,Z position",
"> goto <x> <y> <z> - Go to an X,Y,Z position"
);
}
}

View File

@ -18,15 +18,10 @@
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.ICustomGoalProcess;
import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.process.ICustomGoalProcess;
import baritone.cache.WorldScanner;
import java.util.Arrays;
@ -36,47 +31,26 @@ import java.util.stream.Stream;
public class PathCommand extends Command {
public PathCommand(IBaritone baritone) {
super(baritone, "path", "goto");
super(baritone, "path");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal;
if (args.hasAny()) {
args.requireMax(3);
goal = args.getDatatypePost(RelativeGoal.INSTANCE, ctx.playerFeet());
} else if ((goal = customGoalProcess.getGoal()) == null) {
throw new CommandInvalidStateException("No goal");
}
args.requireMax(0);
WorldScanner.INSTANCE.repack(ctx);
customGoalProcess.setGoalAndPath(goal);
customGoalProcess.path();
logDirect("Now pathing");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasAny() && !args.has(4)) {
while (args.has(2)) {
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) == null) {
break;
}
args.get();
if (!args.has(2)) {
return new TabCompleteHelper()
.append("~")
.filterPrefix(args.getString())
.stream();
}
}
}
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Start heading towards a goal";
return "Start heading towards the goal";
}
@Override
@ -85,10 +59,7 @@ public class PathCommand extends Command {
"The path command tells Baritone to head towards the current goal.",
"",
"Usage:",
"> path - Start the pathing.",
"> path <y>",
"> path <x> <z>",
"> path <x> <y> <z> - Define the goal here"
"> path - Start the pathing."
);
}
}

View File

@ -22,6 +22,7 @@ import baritone.api.pathing.goals.*;
import baritone.api.process.IGetToBlockProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
@ -37,7 +38,7 @@ import java.util.*;
public final class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
private Block gettingTo;
private BlockOptionalMeta gettingTo;
private List<BlockPos> knownLocations;
private List<BlockPos> blacklist; // locations we failed to calc to
private BlockPos start;
@ -50,7 +51,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
}
@Override
public void getToBlock(Block block) {
public void getToBlock(BlockOptionalMeta block) {
onLostControl();
gettingTo = block;
start = ctx.playerFeet();
@ -106,7 +107,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
}
if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) {
// we're there
if (rightClickOnArrival(gettingTo)) {
if (rightClickOnArrival(gettingTo.getBlock())) {
if (rightClick()) {
onLostControl();
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
@ -178,10 +179,10 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
}
private Goal createGoal(BlockPos pos) {
if (walkIntoInsteadOfAdjacent(gettingTo)) {
if (walkIntoInsteadOfAdjacent(gettingTo.getBlock())) {
return new GoalTwoBlocks(pos);
}
if (blockOnTopMustBeRemoved(gettingTo) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
if (blockOnTopMustBeRemoved(gettingTo.getBlock()) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
return new GoalBlock(pos.up());
}
return new GoalGetToBlock(pos);