Merge branch 'master' into 1.13.2

This commit is contained in:
Leijurv
2019-10-06 15:51:27 -07:00
99 changed files with 1883 additions and 1468 deletions

View File

@@ -29,7 +29,7 @@ import baritone.event.GameEventHandler;
import baritone.process.*;
import baritone.selection.SelectionManager;
import baritone.utils.*;
import baritone.utils.command.manager.CommandManager;
import baritone.command.manager.CommandManager;
import baritone.utils.player.PrimaryPlayerContext;
import net.minecraft.client.Minecraft;

View File

@@ -20,8 +20,10 @@ package baritone;
import baritone.api.IBaritone;
import baritone.api.IBaritoneProvider;
import baritone.api.cache.IWorldScanner;
import baritone.utils.command.BaritoneChatControl;
import baritone.api.command.ICommandSystem;
import baritone.command.BaritoneChatControl;
import baritone.cache.WorldScanner;
import baritone.command.CommandSystem;
import java.util.Collections;
import java.util.List;
@@ -57,4 +59,9 @@ public final class BaritoneProvider implements IBaritoneProvider {
public IWorldScanner getWorldScanner() {
return WorldScanner.INSTANCE;
}
@Override
public ICommandSystem getCommandSystem() {
return CommandSystem.INSTANCE;
}
}

View File

@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command;
package baritone.command;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
@@ -26,13 +26,14 @@ import baritone.api.event.events.TabCompleteEvent;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.utils.Helper;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.command.argument.CommandArgument;
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.utils.command.exception.CommandNotFoundException;
import baritone.api.utils.command.execution.ICommandExecution;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.utils.command.manager.ICommandManager;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandNotFoundException;
import baritone.command.helpers.arguments.ArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager;
import baritone.command.argument.CommandArguments;
import baritone.command.manager.CommandManager;
import net.minecraft.util.Tuple;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
@@ -46,7 +47,7 @@ import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class BaritoneChatControl implements Helper, AbstractGameEventListener {
@@ -67,7 +68,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
event.cancel();
String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length());
if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) {
new CommandNotFoundException(ICommandExecution.expand(commandStr).getA()).handle(null, null);
new CommandNotFoundException(CommandManager.expand(commandStr).getA()).handle(null, null);
}
} else if ((settings.chatControl.value || settings.chatControlAnyway.value) && runCommand(msg)) {
event.cancel();
@@ -106,7 +107,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
if (msg.isEmpty()) {
return this.runCommand("help");
}
Tuple<String, List<CommandArgument>> pair = ICommandExecution.expand(msg);
Tuple<String, List<ICommandArgument>> pair = CommandManager.expand(msg);
String command = pair.getA();
String rest = msg.substring(pair.getA().length());
ArgConsumer argc = new ArgConsumer(this.manager, pair.getB());
@@ -155,7 +156,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
return;
}
String msg = prefix.substring(commandPrefix.length());
List<CommandArgument> args = CommandArgument.from(msg, true);
List<ICommandArgument> args = CommandArguments.from(msg, true);
Stream<String> stream = tabComplete(msg);
if (args.size() == 1) {
stream = stream.map(x -> commandPrefix + x);
@@ -165,7 +166,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
public Stream<String> tabComplete(String msg) {
try {
List<CommandArgument> args = CommandArgument.from(msg, true);
List<ICommandArgument> args = CommandArguments.from(msg, true);
ArgConsumer argc = new ArgConsumer(this.manager, args);
if (argc.hasAtMost(2)) {
if (argc.hasExactly(1)) {

View File

@@ -0,0 +1,35 @@
/*
* 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;
import baritone.api.command.ICommandSystem;
import baritone.command.argparser.ArgParserManager;
import baritone.api.command.argparser.IArgParserManager;
/**
* @author Brady
* @since 10/4/2019
*/
public enum CommandSystem implements ICommandSystem {
INSTANCE;
@Override
public IArgParserManager getParserManager() {
return ArgParserManager.INSTANCE;
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.argparser;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.argparser.IArgParserManager;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.exception.CommandNoParserForTypeException;
import baritone.api.command.registry.Registry;
public enum ArgParserManager implements IArgParserManager {
INSTANCE;
public final Registry<IArgParser> registry = new Registry<>();
ArgParserManager() {
DefaultArgParsers.ALL.forEach(this.registry::register);
}
@Override
public <T> IArgParser.Stateless<T> getParserStateless(Class<T> type) {
//noinspection unchecked
return this.registry.descendingStream()
.filter(IArgParser.Stateless.class::isInstance)
.map(IArgParser.Stateless.class::cast)
.filter(parser -> parser.getTarget().isAssignableFrom(type))
.findFirst()
.orElse(null);
}
@Override
public <T, S> IArgParser.Stated<T, S> getParserStated(Class<T> type, Class<S> stateKlass) {
//noinspection unchecked
return this.registry.descendingStream()
.filter(IArgParser.Stated.class::isInstance)
.map(IArgParser.Stated.class::cast)
.filter(parser -> parser.getTarget().isAssignableFrom(type))
.filter(parser -> parser.getStateType().isAssignableFrom(stateKlass))
.map(IArgParser.Stated.class::cast)
.findFirst()
.orElse(null);
}
@Override
public <T> T parseStateless(Class<T> type, ICommandArgument arg) throws CommandInvalidTypeException {
IArgParser.Stateless<T> parser = this.getParserStateless(type);
if (parser == null) {
throw new CommandNoParserForTypeException(type);
}
try {
return parser.parseArg(arg);
} catch (Exception exc) {
throw new CommandInvalidTypeException(arg, type.getSimpleName());
}
}
@Override
public <T, S> T parseStated(Class<T> type, Class<S> stateKlass, ICommandArgument arg, S state) throws CommandInvalidTypeException {
IArgParser.Stated<T, S> parser = this.getParserStated(type, stateKlass);
if (parser == null) {
throw new CommandNoParserForTypeException(type);
}
try {
return parser.parseArg(arg, state);
} catch (Exception exc) {
throw new CommandInvalidTypeException(arg, type.getSimpleName());
}
}
@Override
public Registry<IArgParser> getRegistry() {
return this.registry;
}
}

View File

@@ -0,0 +1,124 @@
/*
* 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.argparser;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.argument.ICommandArgument;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class DefaultArgParsers {
public enum IntArgumentParser implements IArgParser.Stateless<Integer> {
INSTANCE;
@Override
public Class<Integer> getTarget() {
return Integer.class;
}
@Override
public Integer parseArg(ICommandArgument arg) throws RuntimeException {
return Integer.parseInt(arg.getValue());
}
}
public enum LongArgumentParser implements IArgParser.Stateless<Long> {
INSTANCE;
@Override
public Class<Long> getTarget() {
return Long.class;
}
@Override
public Long parseArg(ICommandArgument arg) throws RuntimeException {
return Long.parseLong(arg.getValue());
}
}
public enum FloatArgumentParser implements IArgParser.Stateless<Float> {
INSTANCE;
@Override
public Class<Float> getTarget() {
return Float.class;
}
@Override
public Float parseArg(ICommandArgument arg) throws RuntimeException {
String value = arg.getValue();
if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) {
throw new IllegalArgumentException("failed float format check");
}
return Float.parseFloat(value);
}
}
public enum DoubleArgumentParser implements IArgParser.Stateless<Double> {
INSTANCE;
@Override
public Class<Double> getTarget() {
return Double.class;
}
@Override
public Double parseArg(ICommandArgument arg) throws RuntimeException {
String value = arg.getValue();
if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) {
throw new IllegalArgumentException("failed double format check");
}
return Double.parseDouble(value);
}
}
public static class BooleanArgumentParser implements IArgParser.Stateless<Boolean> {
public static final BooleanArgumentParser INSTANCE = new BooleanArgumentParser();
public static final List<String> TRUTHY_VALUES = Arrays.asList("1", "true", "yes", "t", "y", "on", "enable");
public static final List<String> FALSY_VALUES = Arrays.asList("0", "false", "no", "f", "n", "off", "disable");
@Override
public Class<Boolean> getTarget() {
return Boolean.class;
}
@Override
public Boolean parseArg(ICommandArgument arg) throws RuntimeException {
String value = arg.getValue();
if (TRUTHY_VALUES.contains(value.toLowerCase(Locale.US))) {
return true;
} else if (FALSY_VALUES.contains(value.toLowerCase(Locale.US))) {
return false;
} else {
throw new IllegalArgumentException("invalid boolean");
}
}
}
public static final List<IArgParser<?>> ALL = Arrays.asList(
IntArgumentParser.INSTANCE,
LongArgumentParser.INSTANCE,
FloatArgumentParser.INSTANCE,
DoubleArgumentParser.INSTANCE,
BooleanArgumentParser.INSTANCE
);
}

View File

@@ -0,0 +1,96 @@
/*
* 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.argument;
import baritone.command.argparser.ArgParserManager;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandInvalidTypeException;
import java.util.stream.Stream;
/**
* The default implementation of {@link ICommandArgument}
*
* @author LoganDark
*/
class CommandArgument implements ICommandArgument {
private final int index;
private final String value;
private final String rawRest;
CommandArgument(int index, String value, String rawRest) {
this.index = index;
this.value = value;
this.rawRest = rawRest;
}
@Override
public int getIndex() {
return this.index;
}
@Override
public String getValue() {
return this.value;
}
@Override
public String getRawRest() {
return this.rawRest;
}
@Override
public <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException {
return Stream.of(enumClass.getEnumConstants())
.filter(e -> e.name().equalsIgnoreCase(value))
.findFirst()
.orElseThrow(() -> new CommandInvalidTypeException(this, enumClass.getSimpleName()));
}
@Override
public <T> T getAs(Class<T> type) throws CommandInvalidTypeException {
return ArgParserManager.INSTANCE.parseStateless(type, this);
}
@Override
public <T> boolean is(Class<T> type) {
try {
getAs(type);
return true;
} catch (Throwable t) {
return false;
}
}
@SuppressWarnings("UnusedReturnValue")
@Override
public <T, S> T getAs(Class<T> type, Class<S> stateType, S state) throws CommandInvalidTypeException {
return ArgParserManager.INSTANCE.parseStated(type, stateType, this, state);
}
@Override
public <T, S> boolean is(Class<T> type, Class<S> stateType, S state) {
try {
getAs(type, stateType, state);
return true;
} catch (Throwable t) {
return false;
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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.argument;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandInvalidArgumentException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author LoganDark
*/
public final class CommandArguments {
private CommandArguments() {}
private static final Pattern ARG_PATTERN = Pattern.compile("\\S+");
/**
* Turn a string into a list of {@link ICommandArgument}s. This is needed because of {@link ICommandArgument#getRawRest()}
*
* @param string The string to convert
* @param preserveEmptyLast If the string ends with whitespace, add an empty {@link ICommandArgument} to the end This
* is useful for tab completion
* @return A list of {@link ICommandArgument}s
*/
public static List<ICommandArgument> from(String string, boolean preserveEmptyLast) {
List<ICommandArgument> args = new ArrayList<>();
Matcher argMatcher = ARG_PATTERN.matcher(string);
int lastEnd = -1;
while (argMatcher.find()) {
args.add(new CommandArgument(
args.size(),
argMatcher.group(),
string.substring(argMatcher.start())
));
lastEnd = argMatcher.end();
}
if (preserveEmptyLast && lastEnd < string.length()) {
args.add(new CommandArgument(args.size(), "", ""));
}
return args;
}
/**
* @see #from(String, boolean)
*/
public static List<ICommandArgument> from(String string) {
return from(string, false);
}
/**
* Returns an "unknown" {@link CommandArgument}. This shouldn't be used unless you absolutely have no information -
* ESPECIALLY not with {@link CommandInvalidArgumentException}s
*
* @return The unknown {@link CommandArgument}
*/
public static CommandArgument unknown() {
return new CommandArgument(-1, "<unknown>", "");
}
}

View File

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalAxis;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -31,11 +31,11 @@ import java.util.stream.Stream;
public class AxisCommand extends Command {
public AxisCommand(IBaritone baritone) {
super(baritone, Arrays.asList("axis", "highway"));
super(baritone, "axis", "highway");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
Goal goal = new GoalAxis();
baritone.getCustomGoalProcess().setGoal(goal);
@@ -43,7 +43,7 @@ public class AxisCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.process.IGetToBlockProcess;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -35,7 +35,7 @@ public class BlacklistCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
IGetToBlockProcess proc = baritone.getGetToBlockProcess();
if (!proc.isActive()) {
@@ -49,7 +49,7 @@ public class BlacklistCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,16 +15,16 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.RelativeBlockPos;
import baritone.api.utils.command.datatypes.RelativeFile;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.datatypes.RelativeFile;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import net.minecraft.client.Minecraft;
import java.io.File;
@@ -42,7 +42,7 @@ public class BuildCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
file = new File(file.getAbsolutePath() + ".schematic");
@@ -64,7 +64,7 @@ public class BuildCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
return RelativeFile.tabComplete(args, schematicsDir);
} else if (args.has(2)) {

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -29,18 +29,18 @@ import java.util.stream.Stream;
public class CancelCommand extends Command {
public CancelCommand(IBaritone baritone) {
super(baritone, Arrays.asList("cancel", "stop"));
super(baritone, "cancel", "stop");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,15 +15,15 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.cache.IRememberedInventory;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
@@ -41,7 +41,7 @@ public class ChestsCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
Set<Map.Entry<BlockPos, IRememberedInventory>> entries =
ctx.worldData().getContainerMemory().getRememberedInventories().entrySet();
@@ -62,7 +62,7 @@ public class ChestsCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,14 +33,14 @@ public class ClickCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.openClick();
logDirect("aight dude");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
@@ -37,7 +37,7 @@ public class ComeCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
Entity entity = mc.getRenderViewEntity();
if (entity == null) {
@@ -48,7 +48,7 @@ public class ComeCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,11 +15,11 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Collections;
import java.util.List;
@@ -31,7 +31,7 @@ public class CommandAlias extends Command {
public final String target;
public CommandAlias(IBaritone baritone, List<String> names, String shortDesc, String target) {
super(baritone, names);
super(baritone, names.toArray(new String[0]));
this.shortDesc = shortDesc;
this.target = target;
}
@@ -43,12 +43,12 @@ public class CommandAlias extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) {
public void execute(String label, IArgConsumer args) {
this.baritone.getCommandManager().execute(String.format("%s %s", target, args.rawRest()));
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return this.baritone.getCommandManager().tabComplete(String.format("%s %s", target, args.rawRest()));
}

View File

@@ -15,10 +15,10 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.command.Command;
import java.util.*;
@@ -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

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.RelativeGoalXZ;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeGoalXZ;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -35,7 +35,7 @@ public class ExploreCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
if (args.hasAny()) {
args.requireExactly(2);
} else {
@@ -49,7 +49,7 @@ public class ExploreCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
if (args.hasAtMost(2)) {
return args.tabCompleteDatatype(RelativeGoalXZ.INSTANCE);
}

View File

@@ -15,15 +15,15 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.RelativeFile;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeFile;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import com.google.gson.JsonSyntaxException;
import java.io.File;
@@ -39,7 +39,7 @@ public class ExploreFilterCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(2);
File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile());
boolean invert = false;
@@ -63,7 +63,7 @@ public class ExploreFilterCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
return RelativeFile.tabComplete(args, RelativeFile.gameDir());
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,14 +33,14 @@ public class FarmCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getFarmProcess().farm();
logDirect("Farming");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.BlockById;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import net.minecraft.block.Block;
import net.minecraft.util.registry.IRegistry;
@@ -38,7 +38,7 @@ public class FindCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
List<Block> toFind = new ArrayList<>();
while (args.hasAny()) {
toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
@@ -60,7 +60,7 @@ public class FindCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return args.tabCompleteDatatype(BlockById.INSTANCE);
}

View File

@@ -15,16 +15,16 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.EntityClassById;
import baritone.api.utils.command.datatypes.IDatatypeFor;
import baritone.api.utils.command.datatypes.NearbyPlayer;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.Command;
import baritone.api.command.datatypes.EntityClassById;
import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.NearbyPlayer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityType;
@@ -43,7 +43,7 @@ public class FollowCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMin(1);
FollowGroup group;
FollowList list;
@@ -89,7 +89,7 @@ public class FollowCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
return new TabCompleteHelper()
.append(FollowGroup.class)

View File

@@ -15,13 +15,13 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.behavior.IPathingBehavior;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -34,7 +34,7 @@ public class ForceCancelCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
pathingBehavior.cancelEverything();
@@ -43,7 +43,7 @@ public class ForceCancelCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,14 +33,14 @@ public class GcCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
System.gc();
logDirect("ok called System.gc()");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,18 +15,18 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.ICustomGoalProcess;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.RelativeCoordinate;
import baritone.api.utils.command.datatypes.RelativeGoal;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
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.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import java.util.Arrays;
import java.util.List;
@@ -39,7 +39,7 @@ public class GoalCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) {
args.requireMax(1);
@@ -59,7 +59,7 @@ public class GoalCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
TabCompleteHelper helper = new TabCompleteHelper();
if (args.hasExactlyOne()) {
helper.append("reset", "clear", "none", "~");

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;
}
args.requireMax(1);
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

@@ -15,15 +15,15 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandNotFoundException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.pagination.Paginator;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandNotFoundException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.pagination.Paginator;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
@@ -35,16 +35,16 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class HelpCommand extends Command {
public HelpCommand(IBaritone baritone) {
super(baritone, Arrays.asList("help", "?"));
super(baritone, "help", "?");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(1);
if (!args.hasAny() || args.is(Integer.class)) {
Paginator.paginate(
@@ -55,8 +55,8 @@ public class HelpCommand extends Command {
),
() -> logDirect("All Baritone commands (clickable):"),
command -> {
String names = String.join("/", command.names);
String name = command.names.get(0);
String names = String.join("/", command.getNames());
String name = command.getNames().get(0);
ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
ITextComponent namesComponent = new TextComponentString(names);
@@ -66,7 +66,7 @@ public class HelpCommand extends Command {
hoverComponent.appendSibling(namesComponent);
hoverComponent.appendText("\n" + command.getShortDesc());
hoverComponent.appendText("\n\nClick to view full help");
String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.names.get(0));
String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.getNames().get(0));
ITextComponent component = new TextComponentString(name);
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(shortDescComponent);
@@ -83,7 +83,7 @@ public class HelpCommand extends Command {
if (command == null) {
throw new CommandNotFoundException(commandName);
}
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc()));
logDirect(String.format("%s - %s", String.join(" / ", command.getNames()), command.getShortDesc()));
logDirect("");
command.getLongDesc().forEach(this::logDirect);
logDirect("");
@@ -97,7 +97,7 @@ public class HelpCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
return new TabCompleteHelper()
.addCommands(this.baritone.getCommandManager())

View File

@@ -15,16 +15,16 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalInverted;
import baritone.api.process.ICustomGoalProcess;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -37,7 +37,7 @@ public class InvertCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal;
@@ -54,7 +54,7 @@ public class InvertCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,15 +15,15 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.BlockById;
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.cache.WorldScanner;
import java.util.ArrayList;
@@ -38,7 +38,7 @@ public class MineCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
int quantity = args.getAsOrDefault(Integer.class, 0);
args.requireMin(1);
List<BlockOptionalMeta> boms = new ArrayList<>();
@@ -51,7 +51,7 @@ public class MineCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return args.tabCompleteDatatype(BlockById.INSTANCE);
}

View File

@@ -0,0 +1,65 @@
/*
* 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.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.process.ICustomGoalProcess;
import baritone.cache.WorldScanner;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class PathCommand extends Command {
public PathCommand(IBaritone baritone) {
super(baritone, "path");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
args.requireMax(0);
WorldScanner.INSTANCE.repack(ctx);
customGoalProcess.path();
logDirect("Now pathing");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Start heading towards the goal";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The path command tells Baritone to head towards the current goal.",
"",
"Usage:",
"> path - Start the pathing."
);
}
}

View File

@@ -15,16 +15,16 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -79,7 +79,7 @@ public class PauseResumeCommands {
);
pauseCommand = new Command(baritone, "pause") {
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
if (paused[0]) {
throw new CommandInvalidStateException("Already paused");
@@ -89,7 +89,7 @@ public class PauseResumeCommands {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@@ -112,8 +112,9 @@ public class PauseResumeCommands {
};
resumeCommand = new Command(baritone, "resume") {
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getBuilderProcess().resume();
if (!paused[0]) {
throw new CommandInvalidStateException("Not paused");
}
@@ -122,7 +123,7 @@ public class PauseResumeCommands {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@@ -143,13 +144,13 @@ public class PauseResumeCommands {
};
pausedCommand = new Command(baritone, "paused") {
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,16 +15,16 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -37,7 +37,7 @@ public class ProcCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
@@ -62,7 +62,7 @@ public class ProcCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,14 +33,14 @@ public class ReloadAllCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
ctx.worldData().getCachedWorld().reloadAllFromDisk();
logDirect("Reloaded");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,13 +15,13 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -34,7 +34,7 @@ public class RenderCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
BetterBlockPos origin = ctx.playerFeet();
int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16;
@@ -50,7 +50,7 @@ public class RenderCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.cache.WorldScanner;
import java.util.Arrays;
@@ -30,17 +30,17 @@ import java.util.stream.Stream;
public class RepackCommand extends Command {
public RepackCommand(IBaritone baritone) {
super(baritone, Arrays.asList("repack", "rescan"));
super(baritone, "repack", "rescan");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,14 +33,14 @@ public class SaveAllCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
ctx.worldData().getCachedWorld().save();
logDirect("Saved");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -33,13 +33,13 @@ public class SchematicaCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getBuilderProcess().buildOpenSchematic();
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone;
@@ -28,15 +28,15 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.ISchematic;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
import baritone.api.utils.command.datatypes.ForEnumFacing;
import baritone.api.utils.command.datatypes.RelativeBlockPos;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.Command;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.ForEnumFacing;
import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.utils.IRenderer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
@@ -56,7 +56,7 @@ public class SelCommand extends Command {
private BetterBlockPos pos1 = null;
public SelCommand(IBaritone baritone) {
super(baritone, Arrays.asList("sel", "selection", "s"));
super(baritone, "sel", "selection", "s");
baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() {
@Override
public void onRenderPass(RenderEvent event) {
@@ -75,7 +75,7 @@ public class SelCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
Action action = Action.getByName(args.getString());
if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action");
@@ -186,7 +186,7 @@ public class SelCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
return new TabCompleteHelper()
.append(Action.getAllNames())

View File

@@ -15,18 +15,18 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.Settings;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.pagination.Paginator;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.pagination.Paginator;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
@@ -41,16 +41,16 @@ import java.util.stream.Stream;
import static baritone.api.utils.SettingsUtil.settingTypeToString;
import static baritone.api.utils.SettingsUtil.settingValueToString;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class SetCommand extends Command {
public SetCommand(IBaritone baritone) {
super(baritone, Arrays.asList("set", "setting", "settings"));
super(baritone, "set", "setting", "settings");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list";
if (Arrays.asList("s", "save").contains(arg)) {
SettingsUtil.save(Baritone.settings());
@@ -186,7 +186,7 @@ public class SetCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasAny()) {
String arg = args.getString();
if (args.hasExactlyOne() && !Arrays.asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) {

View File

@@ -15,13 +15,13 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -30,11 +30,11 @@ import java.util.stream.Stream;
public class ThisWayCommand extends Command {
public ThisWayCommand(IBaritone baritone) {
super(baritone, Arrays.asList("thisway", "forward"));
super(baritone, "thisway", "forward");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireExactly(1);
GoalXZ goal = GoalXZ.fromDirection(
ctx.playerFeetAsVec(),
@@ -46,7 +46,7 @@ public class ThisWayCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,14 +15,14 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalStrictDirection;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -35,7 +35,7 @@ public class TunnelCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
Goal goal = new GoalStrictDirection(
ctx.playerFeet(),
@@ -46,7 +46,7 @@ public class TunnelCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,13 +15,13 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Arrays;
import java.util.List;
@@ -34,7 +34,7 @@ public class VersionCommand extends Command {
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
@@ -45,7 +45,7 @@ public class VersionCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}

View File

@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.command.defaults;
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.cache.IWaypoint;
@@ -23,15 +23,15 @@ import baritone.api.cache.Waypoint;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.ForWaypoints;
import baritone.api.utils.command.datatypes.RelativeBlockPos;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.pagination.Paginator;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.Command;
import baritone.api.command.datatypes.ForWaypoints;
import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.helpers.pagination.Paginator;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
@@ -43,16 +43,16 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class WaypointsCommand extends Command {
public WaypointsCommand(IBaritone baritone) {
super(baritone, Arrays.asList("waypoints", "waypoint", "wp"));
super(baritone, "waypoints", "waypoint", "wp");
}
@Override
protected void executed(String label, ArgConsumer args) throws CommandException {
public void execute(String label, IArgConsumer args) throws CommandException {
Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST;
if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action");
@@ -241,7 +241,7 @@ public class WaypointsCommand extends Command {
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasAny()) {
if (args.hasExactlyOne()) {
return new TabCompleteHelper()

View File

@@ -0,0 +1,444 @@
/*
* 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.helpers.arguments;
import baritone.api.IBaritone;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.datatypes.IDatatype;
import baritone.api.command.datatypes.IDatatypeContext;
import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.IDatatypePost;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.manager.ICommandManager;
import baritone.command.argument.CommandArguments;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;
public class ArgConsumer implements IArgConsumer {
/**
* The parent {@link ICommandManager} for this {@link IArgConsumer}}. Used by {@link #context}.
*/
private final ICommandManager manager;
/**
* The {@link IDatatypeContext} instance for this {@link IArgConsumer}}, passed to
* datatypes when an operation is performed upon them.
*
* @see IDatatype
* @see IDatatypeContext
*/
private final IDatatypeContext context;
/**
* The list of arguments in this ArgConsumer
*/
private final LinkedList<ICommandArgument> args;
/**
* The list of consumed arguments for this ArgConsumer. The most recently consumed argument is the last one
*/
private final Deque<ICommandArgument> consumed;
private ArgConsumer(ICommandManager manager, Deque<ICommandArgument> args, Deque<ICommandArgument> consumed) {
this.manager = manager;
this.context = this.new Context();
this.args = new LinkedList<>(args);
this.consumed = new LinkedList<>(consumed);
}
public ArgConsumer(ICommandManager manager, List<ICommandArgument> args) {
this(manager, new LinkedList<>(args), new LinkedList<>());
}
@Override
public LinkedList<ICommandArgument> getArgs() {
return this.args;
}
@Override
public Deque<ICommandArgument> getConsumed() {
return this.consumed;
}
@Override
public boolean has(int num) {
return args.size() >= num;
}
@Override
public boolean hasAny() {
return has(1);
}
@Override
public boolean hasAtMost(int num) {
return args.size() <= num;
}
@Override
public boolean hasAtMostOne() {
return hasAtMost(1);
}
@Override
public boolean hasExactly(int num) {
return args.size() == num;
}
@Override
public boolean hasExactlyOne() {
return hasExactly(1);
}
@Override
public ICommandArgument peek(int index) throws CommandNotEnoughArgumentsException {
requireMin(index + 1);
return args.get(index);
}
@Override
public ICommandArgument peek() throws CommandNotEnoughArgumentsException {
return peek(0);
}
@Override
public boolean is(Class<?> type, int index) throws CommandNotEnoughArgumentsException {
return peek(index).is(type);
}
@Override
public boolean is(Class<?> type) throws CommandNotEnoughArgumentsException {
return is(type, 0);
}
@Override
public String peekString(int index) throws CommandNotEnoughArgumentsException {
return peek(index).getValue();
}
@Override
public String peekString() throws CommandNotEnoughArgumentsException {
return peekString(0);
}
@Override
public <E extends Enum<?>> E peekEnum(Class<E> enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return peek(index).getEnum(enumClass);
}
@Override
public <E extends Enum<?>> E peekEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return peekEnum(enumClass, 0);
}
@Override
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass, int index) throws CommandNotEnoughArgumentsException {
try {
return peekEnum(enumClass, index);
} catch (CommandInvalidTypeException e) {
return null;
}
}
@Override
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException {
return peekEnumOrNull(enumClass, 0);
}
@Override
public <T> T peekAs(Class<T> type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return peek(index).getAs(type);
}
@Override
public <T> T peekAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return peekAs(type, 0);
}
@Override
public <T> T peekAsOrDefault(Class<T> type, T def, int index) throws CommandNotEnoughArgumentsException {
try {
return peekAs(type, index);
} catch (CommandInvalidTypeException e) {
return def;
}
}
@Override
public <T> T peekAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException {
return peekAsOrDefault(type, def, 0);
}
@Override
public <T> T peekAsOrNull(Class<T> type, int index) throws CommandNotEnoughArgumentsException {
return peekAsOrDefault(type, null, index);
}
@Override
public <T> T peekAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException {
return peekAsOrNull(type, 0);
}
@Override
public <T> T peekDatatype(IDatatypeFor<T> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return copy().getDatatypeFor(datatype);
}
@Override
public <T, O> T peekDatatype(IDatatypePost<T, O> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return this.peekDatatype(datatype, null);
}
@Override
public <T, O> T peekDatatype(IDatatypePost<T, O> datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return copy().getDatatypePost(datatype, original);
}
@Override
public <T> T peekDatatypeOrNull(IDatatypeFor<T> datatype) {
return copy().getDatatypeForOrNull(datatype);
}
@Override
public <T, O> T peekDatatypeOrNull(IDatatypePost<T, O> datatype) {
return copy().getDatatypePostOrNull(datatype, null);
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return copy().getDatatypePost(datatype, original);
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T peekDatatypePostOrDefault(D datatype, O original, T def) {
return copy().getDatatypePostOrDefault(datatype, original, def);
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T peekDatatypePostOrNull(D datatype, O original) {
return peekDatatypePostOrDefault(datatype, original, null);
}
@Override
public <T, D extends IDatatypeFor<T>> T peekDatatypeFor(Class<D> datatype) {
return copy().peekDatatypeFor(datatype);
}
@Override
public <T, D extends IDatatypeFor<T>> T peekDatatypeForOrDefault(Class<D> datatype, T def) {
return copy().peekDatatypeForOrDefault(datatype, def);
}
@Override
public <T, D extends IDatatypeFor<T>> T peekDatatypeForOrNull(Class<D> datatype) {
return peekDatatypeForOrDefault(datatype, null);
}
@Override
public ICommandArgument get() throws CommandNotEnoughArgumentsException {
requireMin(1);
ICommandArgument arg = args.removeFirst();
consumed.add(arg);
return arg;
}
@Override
public String getString() throws CommandNotEnoughArgumentsException {
return get().getValue();
}
@Override
public <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return get().getEnum(enumClass);
}
@Override
public <E extends Enum<?>> E getEnumOrDefault(Class<E> enumClass, E def) throws CommandNotEnoughArgumentsException {
try {
peekEnum(enumClass);
return getEnum(enumClass);
} catch (CommandInvalidTypeException e) {
return def;
}
}
@Override
public <E extends Enum<?>> E getEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException {
return getEnumOrDefault(enumClass, null);
}
@Override
public <T> T getAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
return get().getAs(type);
}
@Override
public <T> T getAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException {
try {
T val = peek().getAs(type);
get();
return val;
} catch (CommandInvalidTypeException e) {
return def;
}
}
@Override
public <T> T getAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException {
return getAsOrDefault(type, null);
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
try {
return datatype.apply(this.context, original);
} catch (Exception e) {
e.printStackTrace();
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
}
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T getDatatypePostOrDefault(D datatype, O original, T _default) {
final List<ICommandArgument> argsSnapshot = new ArrayList<>(this.args);
final List<ICommandArgument> consumedSnapshot = new ArrayList<>(this.consumed);
try {
return this.getDatatypePost(datatype, original);
} catch (Exception e) {
this.args.clear();
this.args.addAll(argsSnapshot);
this.consumed.clear();
this.consumed.addAll(consumedSnapshot);
return _default;
}
}
@Override
public <T, O, D extends IDatatypePost<T, O>> T getDatatypePostOrNull(D datatype, O original) {
return this.getDatatypePostOrDefault(datatype, original, null);
}
@Override
public <T, D extends IDatatypeFor<T>> T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
try {
return datatype.get(this.context);
} catch (Exception e) {
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
}
}
@Override
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrDefault(D datatype, T def) {
final List<ICommandArgument> argsSnapshot = new ArrayList<>(this.args);
final List<ICommandArgument> consumedSnapshot = new ArrayList<>(this.consumed);
try {
return this.getDatatypeFor(datatype);
} catch (Exception e) {
this.args.clear();
this.args.addAll(argsSnapshot);
this.consumed.clear();
this.consumed.addAll(consumedSnapshot);
return def;
}
}
@Override
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrNull(D datatype) {
return this.getDatatypeForOrDefault(datatype, null);
}
@Override
public <T extends IDatatype> Stream<String> tabCompleteDatatype(T datatype) {
try {
return datatype.tabComplete(this.context);
} catch (Exception e) {
e.printStackTrace();
}
return Stream.empty();
}
@Override
public String rawRest() {
return args.size() > 0 ? args.getFirst().getRawRest() : "";
}
@Override
public void requireMin(int min) throws CommandNotEnoughArgumentsException {
if (args.size() < min) {
throw new CommandNotEnoughArgumentsException(min + consumed.size());
}
}
@Override
public void requireMax(int max) throws CommandTooManyArgumentsException {
if (args.size() > max) {
throw new CommandTooManyArgumentsException(max + consumed.size());
}
}
@Override
public void requireExactly(int args) throws CommandException {
requireMin(args);
requireMax(args);
}
@Override
public boolean hasConsumed() {
return !consumed.isEmpty();
}
@Override
public ICommandArgument consumed() {
return consumed.size() > 0 ? consumed.getLast() : CommandArguments.unknown();
}
@Override
public String consumedString() {
return consumed().getValue();
}
@Override
public ArgConsumer copy() {
return new ArgConsumer(manager, args, consumed);
}
/**
* Implementation of {@link IDatatypeContext} which adapts to the parent {@link IArgConsumer}}
*/
private final class Context implements IDatatypeContext {
@Override
public final IBaritone getBaritone() {
return ArgConsumer.this.manager.getBaritone();
}
@Override
public final ArgConsumer getConsumer() {
return ArgConsumer.this;
}
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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.manager;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandUnhandledException;
import baritone.api.command.exception.ICommandException;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager;
import baritone.api.command.registry.Registry;
import baritone.command.argument.CommandArguments;
import baritone.command.defaults.DefaultCommands;
import baritone.command.helpers.arguments.ArgConsumer;
import net.minecraft.util.Tuple;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
/**
* The default, internal implementation of {@link ICommandManager}
*
* @author Brady
* @since 9/21/2019
*/
public class CommandManager implements ICommandManager {
private final Registry<Command> registry = new Registry<>();
private final Baritone baritone;
public CommandManager(Baritone baritone) {
this.baritone = baritone;
DefaultCommands.createAll(baritone).forEach(this.registry::register);
}
@Override
public IBaritone getBaritone() {
return this.baritone;
}
@Override
public Registry<Command> getRegistry() {
return this.registry;
}
@Override
public Command getCommand(String name) {
for (Command command : this.registry.entries) {
if (command.getNames().contains(name.toLowerCase(Locale.US))) {
return command;
}
}
return null;
}
@Override
public boolean execute(String string) {
return this.execute(expand(string));
}
@Override
public boolean execute(Tuple<String, List<ICommandArgument>> expanded) {
ExecutionWrapper execution = this.from(expanded);
if (execution != null) {
execution.execute();
}
return execution != null;
}
@Override
public Stream<String> tabComplete(Tuple<String, List<ICommandArgument>> expanded) {
ExecutionWrapper execution = this.from(expanded);
return execution == null ? Stream.empty() : execution.tabComplete();
}
@Override
public Stream<String> tabComplete(String prefix) {
Tuple<String, List<ICommandArgument>> pair = expand(prefix, true);
String label = pair.getA();
List<ICommandArgument> args = pair.getB();
if (args.isEmpty()) {
return new TabCompleteHelper()
.addCommands(this.baritone.getCommandManager())
.filterPrefix(label)
.stream();
} else {
return tabComplete(pair);
}
}
private ExecutionWrapper from(Tuple<String, List<ICommandArgument>> expanded) {
String label = expanded.getA();
ArgConsumer args = new ArgConsumer(this, expanded.getB());
Command command = this.getCommand(label);
return command == null ? null : new ExecutionWrapper(command, label, args);
}
private static Tuple<String, List<ICommandArgument>> expand(String string, boolean preserveEmptyLast) {
String label = string.split("\\s", 2)[0];
List<ICommandArgument> args = CommandArguments.from(string.substring(label.length()), preserveEmptyLast);
return new Tuple<>(label, args);
}
public static Tuple<String, List<ICommandArgument>> expand(String string) {
return expand(string, false);
}
private static final class ExecutionWrapper {
private Command command;
private String label;
private ArgConsumer args;
private ExecutionWrapper(Command command, String label, ArgConsumer args) {
this.command = command;
this.label = label;
this.args = args;
}
private void execute() {
try {
this.command.execute(this.label, this.args);
} catch (Throwable t) {
// Create a handleable exception, wrap if needed
ICommandException exception = t instanceof ICommandException
? (ICommandException) t
: new CommandUnhandledException(t);
exception.handle(command, args.getArgs());
}
}
private Stream<String> tabComplete() {
try {
return this.command.tabComplete(this.label, this.args);
} catch (Throwable t) {
return Stream.empty();
}
}
}
}

View File

@@ -380,7 +380,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
@Override
public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive;
return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
}
@Override

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;
@@ -33,14 +34,11 @@ import net.minecraft.init.Blocks;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
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;
@@ -53,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();
@@ -109,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);
@@ -175,16 +173,16 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
}
private synchronized void rescan(List<BlockPos> known, CalculationContext context) {
List<BlockPos> positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo), 64, known, blacklist);
List<BlockPos> positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo), 64, known, blacklist, Collections.emptyList());
positions.removeIf(blacklist::contains);
knownLocations = positions;
}
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);

View File

@@ -39,7 +39,6 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.*;
import java.util.stream.Collectors;
@@ -58,6 +57,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private BlockOptionalMetaLookup filter;
private List<BlockPos> knownOreLocations;
private List<BlockPos> blacklist; // inaccessible
private Map<BlockPos, Long> anticipatedDrops;
private BlockPos branchPoint;
private GoalRunAway branchPointRunaway;
private int desiredQuantity;
@@ -101,6 +101,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
cancel();
return null;
}
updateLoucaSystem();
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
@@ -141,6 +142,23 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return command;
}
private void updateLoucaSystem() {
Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops);
ctx.getSelectedBlock().ifPresent(pos -> {
if (knownOreLocations.contains(pos)) {
copy.put(pos, System.currentTimeMillis() + Baritone.settings().mineDropLoiterDurationMSThanksLouca.value);
}
});
// elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this
// don't want to slow everything down with a gross lock do we now
for (BlockPos pos : anticipatedDrops.keySet()) {
if (copy.get(pos) < System.currentTimeMillis()) {
copy.remove(pos);
}
}
anticipatedDrops = copy;
}
@Override
public void onLostControl() {
mine(0, (BlockOptionalMetaLookup) null);
@@ -155,9 +173,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
boolean legit = Baritone.settings().legitMine.value;
List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) {
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), filter, ORE_LOCATIONS_COUNT, blacklist);
CalculationContext context = new CalculationContext(baritone);
List<BlockPos> locs2 = prune(context, new ArrayList<>(locs), filter, ORE_LOCATIONS_COUNT, blacklist, droppedItemsScan());
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new));
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2, context)).toArray(Goal[]::new));
knownOreLocations = locs2;
return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
@@ -197,8 +216,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (Baritone.settings().legitMine.value) {
return;
}
List<BlockPos> locs = searchWorld(context, filter, ORE_LOCATIONS_COUNT, already, blacklist);
locs.addAll(droppedItemsScan(filter, ctx.world()));
List<BlockPos> dropped = droppedItemsScan();
List<BlockPos> locs = searchWorld(context, filter, ORE_LOCATIONS_COUNT, already, blacklist, dropped);
locs.addAll(dropped);
if (locs.isEmpty()) {
logDirect("No locations for " + filter + " known, cancelling");
cancel();
@@ -207,19 +227,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
knownOreLocations = locs;
}
private boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List<BlockPos> locs) {
private boolean internalMiningGoal(BlockPos pos, CalculationContext context, List<BlockPos> locs) {
// Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of)
if (locs.contains(pos)) {
return true;
}
IBlockState state = BlockStateInterface.get(ctx, pos);
IBlockState state = context.bsi.get0(pos);
if (Baritone.settings().internalMiningAirException.value && state.getBlock() instanceof BlockAir) {
return true;
}
return filter.has(state);
return filter.has(state) && plausibleToBreak(context, pos);
}
private Goal coalesce(BlockPos loc, List<BlockPos> locs) {
private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) {
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling);
if (!Baritone.settings().forceInternalMining.value) {
if (assumeVerticalShaftMine) {
@@ -230,9 +250,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return new GoalTwoBlocks(loc);
}
}
boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs);
boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs);
boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs);
boolean upwardGoal = internalMiningGoal(loc.up(), context, locs);
boolean downwardGoal = internalMiningGoal(loc.down(), context, locs);
boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), context, locs);
if (upwardGoal == downwardGoal) { // symmetric
if (doubleDownwardGoal && assumeVerticalShaftMine) {
// we have a checkerboard like pattern
@@ -281,12 +301,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
public static List<BlockPos> droppedItemsScan(BlockOptionalMetaLookup filter, World world) {
public List<BlockPos> droppedItemsScan() {
if (!Baritone.settings().mineScanDroppedItems.value) {
return Collections.emptyList();
}
List<BlockPos> ret = new ArrayList<>();
for (Entity entity : world.loadedEntityList) {
for (Entity entity : ctx.world().loadedEntityList) {
if (entity instanceof EntityItem) {
EntityItem ei = (EntityItem) entity;
if (filter.has(ei.getItem())) {
@@ -294,10 +314,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
}
ret.addAll(anticipatedDrops.keySet());
return ret;
}
public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist) {
public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) {
List<BlockPos> locs = new ArrayList<>();
List<Block> untracked = new ArrayList<>();
for (BlockOptionalMeta bom : filter.blocks()) {
@@ -318,7 +339,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
locs = prune(ctx, locs, filter, max, blacklist);
locs = prune(ctx, locs, filter, max, blacklist, dropped);
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
@@ -332,11 +353,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
locs.addAll(alreadyKnown);
return prune(ctx, locs, filter, max, blacklist);
return prune(ctx, locs, filter, max, blacklist, dropped);
}
private void addNearby() {
knownOreLocations.addAll(droppedItemsScan(filter, ctx.world()));
List<BlockPos> dropped = droppedItemsScan();
knownOreLocations.addAll(dropped);
BlockPos playerFeet = ctx.playerFeet();
BlockStateInterface bsi = new BlockStateInterface(ctx);
int searchDist = 10;
@@ -355,11 +377,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
}
knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist);
knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped);
}
private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, BlockOptionalMetaLookup filter, int max, List<BlockPos> blacklist) {
List<BlockPos> dropped = droppedItemsScan(filter, ctx.world);
private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, BlockOptionalMetaLookup filter, int max, List<BlockPos> blacklist, List<BlockPos> dropped) {
dropped.removeIf(drop -> {
for (BlockPos pos : locs2) {
if (pos.distanceSq(drop) <= 9 && filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx, pos)) { // TODO maybe drop also has to be supported? no lava below?
@@ -416,6 +437,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
this.blacklist = new ArrayList<>();
this.branchPoint = null;
this.branchPointRunaway = null;
this.anticipatedDrops = new HashMap<>();
if (filter != null) {
rescan(new ArrayList<>(), new CalculationContext(baritone));
}

View File

@@ -39,7 +39,7 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Collections;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends GuiScreen {

View File

@@ -1,94 +0,0 @@
/*
* 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.utils.command.defaults;
import baritone.api.IBaritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.ICustomGoalProcess;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.RelativeCoordinate;
import baritone.api.utils.command.datatypes.RelativeGoal;
import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.cache.WorldScanner;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class PathCommand extends Command {
public PathCommand(IBaritone baritone) {
super(baritone, Arrays.asList("path", "goto"));
}
@Override
protected void executed(String label, ArgConsumer 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);
logDirect("Now pathing");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer 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";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"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"
);
}
}

View File

@@ -1,85 +0,0 @@
/*
* 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.utils.command.execution;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandUnhandledException;
import baritone.api.utils.command.exception.ICommandException;
import baritone.api.utils.command.execution.ICommandExecution;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.utils.command.manager.CommandManager;
import java.util.stream.Stream;
/**
* The default, internal implementation of {@link ICommandExecution}, which is used by {@link CommandManager}
*
* @author LoganDark, Brady
*/
public class CommandExecution implements ICommandExecution {
/**
* The command itself
*/
private final Command command;
/**
* The name this command was called with
*/
private final String label;
/**
* The arg consumer
*/
private final ArgConsumer args;
public CommandExecution(Command command, String label, ArgConsumer args) {
this.command = command;
this.label = label;
this.args = args;
}
@Override
public String getLabel() {
return this.label;
}
@Override
public ArgConsumer getArguments() {
return this.args;
}
@Override
public void execute() {
try {
command.execute(this);
} catch (Throwable t) {
// Create a handleable exception, wrap if needed
ICommandException exception = t instanceof ICommandException
? (ICommandException) t
: new CommandUnhandledException(t);
exception.handle(command, args.args);
}
}
@Override
public Stream<String> tabComplete() {
return command.tabComplete(this);
}
}

View File

@@ -1,115 +0,0 @@
/*
* 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.utils.command.manager;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.argument.CommandArgument;
import baritone.api.utils.command.execution.ICommandExecution;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.utils.command.manager.ICommandManager;
import baritone.api.utils.command.registry.Registry;
import baritone.utils.command.defaults.DefaultCommands;
import baritone.utils.command.execution.CommandExecution;
import net.minecraft.util.Tuple;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
/**
* The default, internal implementation of {@link ICommandManager}
*
* @author Brady
* @since 9/21/2019
*/
public class CommandManager implements ICommandManager {
private final Registry<Command> registry = new Registry<>();
private final Baritone baritone;
public CommandManager(Baritone baritone) {
this.baritone = baritone;
DefaultCommands.createAll(baritone).forEach(this.registry::register);
}
@Override
public IBaritone getBaritone() {
return this.baritone;
}
@Override
public Registry<Command> getRegistry() {
return this.registry;
}
@Override
public Command getCommand(String name) {
for (Command command : this.registry.entries) {
if (command.names.contains(name.toLowerCase(Locale.US))) {
return command;
}
}
return null;
}
@Override
public boolean execute(String string) {
return this.execute(ICommandExecution.expand(string));
}
@Override
public boolean execute(Tuple<String, List<CommandArgument>> expanded) {
ICommandExecution execution = this.from(expanded);
if (execution != null) {
execution.execute();
}
return execution != null;
}
@Override
public Stream<String> tabComplete(Tuple<String, List<CommandArgument>> expanded) {
ICommandExecution execution = this.from(expanded);
return execution == null ? Stream.empty() : execution.tabComplete();
}
@Override
public Stream<String> tabComplete(String prefix) {
Tuple<String, List<CommandArgument>> pair = ICommandExecution.expand(prefix, true);
String label = pair.getA();
List<CommandArgument> args = pair.getB();
if (args.isEmpty()) {
return new TabCompleteHelper()
.addCommands(this.baritone.getCommandManager())
.filterPrefix(label)
.stream();
} else {
return tabComplete(pair);
}
}
private ICommandExecution from(Tuple<String, List<CommandArgument>> expanded) {
String label = expanded.getA();
ArgConsumer args = new ArgConsumer(this, expanded.getB());
Command command = this.getCommand(label);
return command == null ? null : new CommandExecution(command, label, args);
}
}