diff --git a/src/api/java/baritone/api/process/IGetToBlockProcess.java b/src/api/java/baritone/api/process/IGetToBlockProcess.java index a5a35577e..f58efbd35 100644 --- a/src/api/java/baritone/api/process/IGetToBlockProcess.java +++ b/src/api/java/baritone/api/process/IGetToBlockProcess.java @@ -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(); } diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index f1e098a2b..dd1a3004e 100644 --- a/src/main/java/baritone/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -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), diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java new file mode 100644 index 000000000..4103bd1e9 --- /dev/null +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -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 . + */ + +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 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 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 - Go to a block, wherever it is in the world", + "> goto - Go to a Y level", + "> goto - Go to an X,Z position", + "> goto - Go to an X,Y,Z position" + ); + } +} diff --git a/src/main/java/baritone/command/defaults/PathCommand.java b/src/main/java/baritone/command/defaults/PathCommand.java index ce1599e3d..fff61a70a 100644 --- a/src/main/java/baritone/command/defaults/PathCommand.java +++ b/src/main/java/baritone/command/defaults/PathCommand.java @@ -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 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 ", - "> path ", - "> path - Define the goal here" + "> path - Start the pathing." ); } } diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index d6b405c1e..00ec26091 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -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 knownLocations; private List 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);