Merge branch 'master' into bot-system

This commit is contained in:
Brady
2020-01-01 19:23:01 -06:00
131 changed files with 1270 additions and 695 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code) ![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code)
[![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/)
[![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/)
[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.8%20/%20v1.3.4%20/%20v1.4.1-brightgreen.svg)](https://impactclient.net/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/)
[![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/)
[![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api)
[![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/)
+13 -7
View File
@@ -8,11 +8,23 @@ Baritone commands can also by default be typed in the chatbox. However if you ma
To disable direct chat control (with no prefix), turn off the `chatControl` setting. To disable chat control with the `#` prefix, turn off the `prefixControl` setting. In Impact, `.b` cannot be disabled. Be careful that you don't leave yourself with all control methods disabled (if you do, reset your settings by deleting the file `minecraft/baritone/settings.txt` and relaunching). To disable direct chat control (with no prefix), turn off the `chatControl` setting. To disable chat control with the `#` prefix, turn off the `prefixControl` setting. In Impact, `.b` cannot be disabled. Be careful that you don't leave yourself with all control methods disabled (if you do, reset your settings by deleting the file `minecraft/baritone/settings.txt` and relaunching).
# For Baritone 1.2.10+, 1.3.5+, 1.4.2+
Lots of the commands have changed, BUT `#help` is improved vastly (its clickable! commands have tab completion! oh my!).
Try `#help` I promise it won't just send you back here =)
"wtf where is cleararea" -> look at `#help sel`
"wtf where is goto death, goto waypoint" -> look at `#help wp` (a "tag" is like "home" (created automatically on right clicking a bed) or "death" (created automatically on death) or "user" (has to be created manually)). So you might want `#wp save user coolbiome` then, to set the goal `#wp goal coolbiome` then `#path` to path to it. For death, `#wp goal death` (remember stuff is clickable!).
just look at `#help` lmao
# Commands # Commands
**All** of these commands may need a prefix before them, as above ^. **All** of these commands may need a prefix before them, as above ^.
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java#L47). `help`
To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`. To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`.
@@ -38,12 +50,6 @@ Some common examples:
- `version` to get the version of Baritone you're running - `version` to get the version of Baritone you're running
- `damn` daniel - `damn` daniel
New commands:
- `sel` to manage selections
- some others
For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java). For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java).
All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>. All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>.
+1 -1
View File
@@ -16,7 +16,7 @@
*/ */
group 'baritone' group 'baritone'
version '1.2.9' version '1.2.10'
buildscript { buildscript {
repositories { repositories {
@@ -19,8 +19,9 @@ package baritone.api;
import baritone.api.bot.IUserManager; import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner; import baritone.api.cache.IWorldScanner;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem; import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import java.util.List; import java.util.List;
@@ -83,9 +84,14 @@ public interface IBaritoneProvider {
/** /**
* Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone} * Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
* instance because {@link ICommandSystem} itself controls global behavior for {@link Command}s. * instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
* *
* @return The {@link ICommandSystem} instance. * @return The {@link ICommandSystem} instance.
*/ */
ICommandSystem getCommandSystem(); ICommandSystem getCommandSystem();
/**
* @return The {@link ISchematicSystem} instance.
*/
ISchematicSystem getSchematicSystem();
} }
+31 -1
View File
@@ -184,6 +184,20 @@ public final class Settings {
Blocks.WALL_SIGN Blocks.WALL_SIGN
))); )));
/**
* A list of blocks to be treated as if they're air.
* <p>
* If a schematic asks for air at a certain position, and that position currently contains a block on this list, it will be treated as correct.
*/
public final Setting<List<Block>> buildIgnoreBlocks = new Setting<>(new ArrayList<>(Arrays.asList(
)));
/**
* If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks.
*/
public final Setting<Boolean> buildIgnoreExisting = new Setting<>(false);
/** /**
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
* <p> * <p>
@@ -234,7 +248,7 @@ public final class Settings {
/** /**
* If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway. * If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway.
* <p> * <p>
* This helps with speed at >=20m/s * This helps with speed exceeding 20m/s
*/ */
public final Setting<Boolean> overshootTraverse = new Setting<>(true); public final Setting<Boolean> overshootTraverse = new Setting<>(true);
@@ -248,6 +262,11 @@ public final class Settings {
*/ */
public final Setting<Integer> rightClickSpeed = new Setting<>(4); public final Setting<Integer> rightClickSpeed = new Setting<>(4);
/**
* Block reach distance
*/
public final Setting<Float> blockReachDistance = new Setting<>(4.5f);
/** /**
* How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable
*/ */
@@ -738,6 +757,11 @@ public final class Settings {
*/ */
public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0)); public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
/**
* How many times to buildrepeat. -1 for infinite.
*/
public final Setting<Integer> buildRepeatCount = new Setting<>(-1);
/** /**
* Allow standing above a block while mining it, in BuilderProcess * Allow standing above a block while mining it, in BuilderProcess
* <p> * <p>
@@ -787,6 +811,12 @@ public final class Settings {
*/ */
public final Setting<Boolean> schematicOrientationZ = new Setting<>(false); public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
/**
* The fallback used by the build command when no extension is specified. This may be useful if schematics of a
* particular format are used often, and the user does not wish to have to specify the extension with every usage.
*/
public final Setting<String> schematicFallbackExtension = new Setting<>("schematic");
/** /**
* Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above) * Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above)
* is only necessary in very large schematics where rescanning the whole thing is costly. * is only necessary in very large schematics where rescanning the whole thing is costly.
-2
View File
@@ -81,6 +81,4 @@ public interface ICachedWorld {
* in a new thread by default. * in a new thread by default.
*/ */
void save(); void save();
} }
+13 -3
View File
@@ -77,10 +77,20 @@ public interface IWorldScanner {
} }
/** /**
* Repacks 40 chunks around the player. * Overload of {@link #repack(IPlayerContext, int)} where the value of the {@code range} parameter is {@code 40}.
* *
* @param ctx The player context for that player. * @param ctx The player, describing the origin
* @return The number of chunks queued for repacking. * @return The amount of chunks successfully queued for repacking
*/ */
int repack(IPlayerContext ctx); int repack(IPlayerContext ctx);
/**
* Queues the chunks in a square formation around the specified player, using the specified
* range, which represents 1/2 the square's dimensions, where the player is in the center.
*
* @param ctx The player, describing the origin
* @param range The range to repack
* @return The amount of chunks successfully queued for repacking
*/
int repack(IPlayerContext ctx, int range);
} }
+14 -32
View File
@@ -18,10 +18,7 @@
package baritone.api.command; package baritone.api.command;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -29,7 +26,19 @@ import java.util.Locale;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public abstract class Command implements Helper { /**
* A default implementation of {@link ICommand} which provides easy access to the
* command's bound {@link IBaritone} instance, {@link IPlayerContext} and an easy
* way to provide multiple valid command execution names through the default constructor.
* <p>
* So basically, you should use it because it provides a small amount of boilerplate,
* but you're not forced to use it.
*
* @see ICommand
*
* @author LoganDark
*/
public abstract class Command implements ICommand {
protected IBaritone baritone; protected IBaritone baritone;
protected IPlayerContext ctx; protected IPlayerContext ctx;
@@ -52,34 +61,7 @@ public abstract class Command implements Helper {
this.ctx = baritone.getPlayerContext(); this.ctx = baritone.getPlayerContext();
} }
/** @Override
* Called when this command is executed.
*/
public abstract void execute(String label, IArgConsumer args) throws CommandException;
/**
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
* list.
*/
public abstract Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException;
/**
* @return A <b>single-line</b> string containing a short description of this command's purpose.
*/
public abstract String getShortDesc();
/**
* @return A list of lines that will be printed by the help command when the user wishes to view them.
*/
public abstract List<String> getLongDesc();
/**
* @return {@code true} if this command should be hidden from the help menu
*/
public boolean hiddenFromHelp() {
return false;
}
public final List<String> getNames() { public final List<String> getNames() {
return this.names; return this.names;
} }
@@ -0,0 +1,67 @@
/*
* 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.api.command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.utils.Helper;
import java.util.List;
import java.util.stream.Stream;
/**
* The base for a command.
*
* @author Brady
* @since 10/7/2019
*/
public interface ICommand extends Helper {
/**
* Called when this command is executed.
*/
void execute(String label, IArgConsumer args) throws CommandException;
/**
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
* list.
*/
Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException;
/**
* @return A <b>single-line</b> string containing a short description of this command's purpose.
*/
String getShortDesc();
/**
* @return A list of lines that will be printed by the help command when the user wishes to view them.
*/
List<String> getLongDesc();
/**
* @return A list of the names that can be accepted to have arguments passed to this command
*/
List<String> getNames();
/**
* @return {@code true} if this command should be hidden from the help menu
*/
default boolean hiddenFromHelp() {
return false;
}
}
@@ -22,6 +22,10 @@ import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.registry.Registry; import baritone.api.command.registry.Registry;
/** /**
* Used to retrieve {@link IArgParser} instances from the registry, by their target class.
* It can be assumed that a {@link IArgParser} exists for {@link Integer}, {@link Long},
* {@link Float}, {@link Double} and {@link Boolean}.
*
* @author Brady * @author Brady
* @since 10/4/2019 * @since 10/4/2019
*/ */
@@ -15,13 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.api.command.helpers.arguments; package baritone.api.command.argument;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandTooManyArgumentsException; import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.api.command.argparser.IArgParser; import baritone.api.command.argparser.IArgParser;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.datatypes.IDatatype; import baritone.api.command.datatypes.IDatatype;
import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.IDatatypePost; import baritone.api.command.datatypes.IDatatypePost;
@@ -35,7 +34,7 @@ import java.util.LinkedList;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* The {@link IArgConsumer} is how {@link Command}s read the arguments passed to them. This class has many benefits: * The {@link IArgConsumer} is how {@link ICommand}s read the arguments passed to them. This class has many benefits:
* *
* <ul> * <ul>
* <li>Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way * <li>Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way
@@ -17,7 +17,6 @@
package baritone.api.command.argument; package baritone.api.command.argument;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argparser.IArgParser; import baritone.api.command.argparser.IArgParser;
import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.exception.CommandInvalidTypeException;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -20,7 +20,7 @@ package baritone.api.command.datatypes;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.cache.IWaypoint; import baritone.api.cache.IWaypoint;
import baritone.api.cache.IWaypointCollection; import baritone.api.cache.IWaypointCollection;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import java.util.Comparator; import java.util.Comparator;
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.argparser.IArgParser; import baritone.api.command.argparser.IArgParser;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
/** /**
* Provides an {@link IDatatype} with contextual information so * Provides an {@link IDatatype} with contextual information so
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import java.io.File; import java.io.File;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalXZ; import baritone.api.pathing.goals.GoalXZ;
@@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost<Goal, BetterBlockPos> {
if (origin == null) { if (origin == null) {
origin = BetterBlockPos.ORIGIN; origin = BetterBlockPos.ORIGIN;
} }
final IArgConsumer consumer = ctx.getConsumer(); final IArgConsumer consumer = ctx.getConsumer();
List<IDatatypePostFunction<Double, Double>> coords = new ArrayList<>(); GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin);
final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably if (goalBlock != null) {
for (int i = 0; i < 3; i++) { return goalBlock;
if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o));
copy.get(); // Consume so we actually decrement the remaining arguments
}
} }
switch (coords.size()) { GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin);
case 0: if (goalXZ != null) {
return new GoalBlock(origin); return goalXZ;
case 1:
return new GoalYLevel(
MathHelper.floor(coords.get(0).apply((double) origin.y))
);
case 2:
return new GoalXZ(
MathHelper.floor(coords.get(0).apply((double) origin.x)),
MathHelper.floor(coords.get(1).apply((double) origin.z))
);
case 3:
return new GoalBlock(
MathHelper.floor(coords.get(0).apply((double) origin.x)),
MathHelper.floor(coords.get(1).apply((double) origin.y)),
MathHelper.floor(coords.get(2).apply((double) origin.z))
);
default:
throw new IllegalStateException("Unexpected coords size: " + coords.size());
} }
GoalYLevel goalYLevel = consumer.peekDatatypePostOrNull(RelativeGoalYLevel.INSTANCE, origin);
if (goalYLevel != null) {
return goalYLevel;
}
// when the user doesn't input anything, default to the origin
return new GoalBlock(origin);
} }
@Override @Override
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalXZ; import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
@@ -17,7 +17,7 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalYLevel; import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
@@ -22,4 +22,8 @@ public abstract class CommandErrorMessageException extends CommandException {
protected CommandErrorMessageException(String reason) { protected CommandErrorMessageException(String reason) {
super(reason); super(reason);
} }
protected CommandErrorMessageException(String reason, Throwable cause) {
super(reason, cause);
}
} }
@@ -22,4 +22,8 @@ public abstract class CommandException extends Exception implements ICommandExce
protected CommandException(String reason) { protected CommandException(String reason) {
super(reason); super(reason);
} }
protected CommandException(String reason, Throwable cause) {
super(reason, cause);
}
} }
@@ -23,12 +23,21 @@ public abstract class CommandInvalidArgumentException extends CommandErrorMessag
public final ICommandArgument arg; public final ICommandArgument arg;
protected CommandInvalidArgumentException(ICommandArgument arg, String reason) { protected CommandInvalidArgumentException(ICommandArgument arg, String message) {
super(String.format( super(formatMessage(arg, message));
"Error at argument #%s: %s",
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
reason
));
this.arg = arg; this.arg = arg;
} }
protected CommandInvalidArgumentException(ICommandArgument arg, String message, Throwable cause) {
super(formatMessage(arg, message), cause);
this.arg = arg;
}
private static String formatMessage(ICommandArgument arg, String message) {
return String.format(
"Error at argument #%s: %s",
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
message
);
}
} }
@@ -26,7 +26,7 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) { public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) {
super(arg, String.format("Expected %s.\nMore details: %s", expected, cause.getMessage())); super(arg, String.format("Expected %s", expected), cause);
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) { public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) {
@@ -34,6 +34,6 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) { public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) {
super(arg, String.format("Expected %s, but got %s instead.\nMore details: %s", expected, got, cause.getMessage())); super(arg, String.format("Expected %s, but got %s instead", expected, got), cause);
} }
} }
@@ -17,7 +17,7 @@
package baritone.api.command.exception; package baritone.api.command.exception;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import java.util.List; import java.util.List;
@@ -34,7 +34,7 @@ public class CommandNotFoundException extends CommandException {
} }
@Override @Override
public void handle(Command command, List<ICommandArgument> args) { public void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect(getMessage()); HELPER.logDirect(getMessage());
} }
} }
@@ -17,7 +17,7 @@
package baritone.api.command.exception; package baritone.api.command.exception;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@@ -36,7 +36,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm
} }
@Override @Override
public void handle(Command command, List<ICommandArgument> args) { public void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect("An unhandled exception occurred. " + HELPER.logDirect("An unhandled exception occurred. " +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues", "The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED); TextFormatting.RED);
@@ -17,7 +17,7 @@
package baritone.api.command.exception; package baritone.api.command.exception;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@@ -27,7 +27,7 @@ import static baritone.api.utils.Helper.HELPER;
/** /**
* The base for a Baritone Command Exception, checked or unchecked. Provides a * The base for a Baritone Command Exception, checked or unchecked. Provides a
* {@link #handle(Command, List)} method that is used to provide useful output * {@link #handle(ICommand, List)} method that is used to provide useful output
* to the user for diagnosing issues that may have occurred during execution. * to the user for diagnosing issues that may have occurred during execution.
* <p> * <p>
* Anything implementing this interface should be assignable to {@link Exception}. * Anything implementing this interface should be assignable to {@link Exception}.
@@ -49,7 +49,7 @@ public interface ICommandException {
* @param command The command that threw it. * @param command The command that threw it.
* @param args The arguments the command was called with. * @param args The arguments the command was called with.
*/ */
default void handle(Command command, List<ICommandArgument> args) { default void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect(this.getMessage(), TextFormatting.RED); HELPER.logDirect(this.getMessage(), TextFormatting.RED);
} }
} }
@@ -15,12 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.api.command.helpers.pagination; package baritone.api.command.helpers;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@@ -15,13 +15,13 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.api.command.helpers.tabcomplete; package baritone.api.command.helpers;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.Settings; import baritone.api.Settings;
import baritone.api.event.events.TabCompleteEvent; import baritone.api.event.events.TabCompleteEvent;
import baritone.api.utils.SettingsUtil; import baritone.api.utils.SettingsUtil;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.manager.ICommandManager; import baritone.api.command.manager.ICommandManager;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -18,7 +18,7 @@
package baritone.api.command.manager; package baritone.api.command.manager;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.registry.Registry; import baritone.api.command.registry.Registry;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
@@ -34,13 +34,13 @@ public interface ICommandManager {
IBaritone getBaritone(); IBaritone getBaritone();
Registry<Command> getRegistry(); Registry<ICommand> getRegistry();
/** /**
* @param name The command name to search for. * @param name The command name to search for.
* @return The command, if found. * @return The command, if found.
*/ */
Command getCommand(String name); ICommand getCommand(String name);
boolean execute(String string); boolean execute(String string);
@@ -23,31 +23,13 @@ import baritone.api.event.events.type.Overrideable;
/** /**
* @author LoganDark * @author LoganDark
*/ */
public abstract class TabCompleteEvent extends Cancellable { public class TabCompleteEvent extends Cancellable {
public final Overrideable<String> prefix; public final String prefix;
public final Overrideable<String[]> completions; public String[] completions;
TabCompleteEvent(String prefix, String[] completions) { public TabCompleteEvent(String prefix) {
this.prefix = new Overrideable<>(prefix); this.prefix = prefix;
this.completions = new Overrideable<>(completions); this.completions = null;
}
public boolean wasModified() {
return prefix.wasModified() || completions.wasModified();
}
public static final class Pre extends TabCompleteEvent {
public Pre(String prefix) {
super(prefix, null);
}
}
public static final class Post extends TabCompleteEvent {
public Post(String prefix, String[] completions) {
super(prefix, completions);
}
} }
} }
@@ -19,22 +19,20 @@ package baritone.api.event.events;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import java.util.function.BiFunction;
public final class TickEvent { public final class TickEvent {
private static int overallTickCount;
private final EventState state; private final EventState state;
private final Type type; private final Type type;
private final int count; private final int count;
private static int overallTickCount; public TickEvent(EventState state, Type type, int count) {
public TickEvent(EventState state, Type type) {
this.state = state; this.state = state;
this.type = type; this.type = type;
this.count = incrementCount(); this.count = count;
}
private static synchronized int incrementCount() {
return overallTickCount++;
} }
public int getCount() { public int getCount() {
@@ -49,6 +47,10 @@ public final class TickEvent {
return state; return state;
} }
public static synchronized BiFunction<EventState, Type, TickEvent> createNextProvider() {
final int count = overallTickCount++;
return (state, type) -> new TickEvent(state, type, count);
}
public enum Type { public enum Type {
/** /**
@@ -40,10 +40,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
default void onSendChatMessage(ChatEvent event) {} default void onSendChatMessage(ChatEvent event) {}
@Override @Override
default void onPreTabComplete(TabCompleteEvent.Pre event) {} default void onPreTabComplete(TabCompleteEvent event) {}
@Override
default void onPostTabComplete(TabCompleteEvent.Post event) {}
@Override @Override
default void onChunkEvent(ChunkEvent event) {} default void onChunkEvent(ChunkEvent event) {}
@@ -62,15 +62,7 @@ public interface IGameEventListener {
* *
* @param event The event * @param event The event
*/ */
void onPreTabComplete(TabCompleteEvent.Pre event); void onPreTabComplete(TabCompleteEvent event);
/**
* Runs whenever the client player tries to tab complete in chat once completions have been recieved from the
* server. This will only be called if the {@link TabCompleteEvent#cancel()} method was not called.
*
* @param event The event
*/
void onPostTabComplete(TabCompleteEvent.Post event);
/** /**
* Runs before and after whenever a chunk is either loaded, unloaded, or populated. * Runs before and after whenever a chunk is either loaded, unloaded, or populated.
@@ -17,7 +17,7 @@
package baritone.api.process; package baritone.api.process;
import baritone.api.utils.ISchematic; import baritone.api.schematic.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -17,14 +17,16 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
public abstract class AbstractSchematic implements ISchematic { public abstract class AbstractSchematic implements ISchematic {
protected int x; protected int x;
protected int y; protected int y;
protected int z; protected int z;
public AbstractSchematic() {
this(0, 0, 0);
}
public AbstractSchematic(int x, int y, int z) { public AbstractSchematic(int x, int y, int z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -17,7 +17,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import java.util.ArrayList; import java.util.ArrayList;
@@ -17,8 +17,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
public class CompositeSchematicEntry { public class CompositeSchematicEntry {
public final ISchematic schematic; public final ISchematic schematic;
@@ -32,6 +32,10 @@ public class FillSchematic extends AbstractSchematic {
this.bom = bom; this.bom = bom;
} }
public FillSchematic(int x, int y, int z, IBlockState state) {
this(x, y, z, new BlockOptionalMeta(state.getBlock(), state.getBlock().getMetaFromState(state)));
}
public BlockOptionalMeta getBom() { public BlockOptionalMeta getBom() {
return bom; return bom;
} }
@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.api.utils; package baritone.api.schematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -0,0 +1,44 @@
/*
* 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.api.schematic;
import baritone.api.command.registry.Registry;
import baritone.api.schematic.format.ISchematicFormat;
import java.io.File;
import java.util.Optional;
/**
* @author Brady
* @since 12/23/2019
*/
public interface ISchematicSystem {
/**
* @return The registry of supported schematic formats
*/
Registry<ISchematicFormat> getRegistry();
/**
* Attempts to find an {@link ISchematicFormat} that supports the specified schematic file.
*
* @param file A schematic file
* @return The corresponding format for the file, {@link Optional#empty()} if no candidates were found.
*/
Optional<ISchematicFormat> getByFile(File file);
}
@@ -0,0 +1,60 @@
/*
* 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.api.schematic;
import net.minecraft.block.state.IBlockState;
/**
* A static schematic is capable of providing the desired state at a given position without
* additional context. Schematics of this type are expected to have non-varying contents.
*
* @see #getDirect(int, int, int)
*
* @author Brady
* @since 12/24/2019
*/
public interface IStaticSchematic extends ISchematic {
/**
* Gets the {@link IBlockState} for a given position in this schematic. It should be guaranteed
* that the return value of this method will not change given that the parameters are the same.
*
* @param x The X block position
* @param y The Y block position
* @param z The Z block position
* @return The desired state at the specified position.
*/
IBlockState getDirect(int x, int y, int z);
/**
* Returns an {@link IBlockState} array of size {@link #heightY()} which contains all
* desired block states in the specified vertical column. The index of {@link IBlockState}s
* in the array are equivalent to their Y position in the schematic.
*
* @param x The X column position
* @param z The Z column position
* @return An {@link IBlockState} array
*/
default IBlockState[] getColumn(int x, int z) {
IBlockState[] column = new IBlockState[this.heightY()];
for (int i = 0; i < this.heightY(); i++) {
column[i] = getDirect(x, i, z);
}
return column;
}
}
@@ -17,7 +17,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import java.util.List; import java.util.List;
@@ -18,7 +18,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.BlockOptionalMetaLookup; import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
public class ReplaceSchematic extends MaskSchematic { public class ReplaceSchematic extends MaskSchematic {
@@ -17,7 +17,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
public class ShellSchematic extends MaskSchematic { public class ShellSchematic extends MaskSchematic {
@@ -17,7 +17,6 @@
package baritone.api.schematic; package baritone.api.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
public class WallsSchematic extends MaskSchematic { public class WallsSchematic extends MaskSchematic {
@@ -0,0 +1,45 @@
/*
* 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.api.schematic.format;
import baritone.api.schematic.ISchematic;
import baritone.api.schematic.IStaticSchematic;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* The base of a {@link ISchematic} file format
*
* @author Brady
* @since 12/23/2019
*/
public interface ISchematicFormat {
/**
* @return The parser for creating schematics of this format
*/
IStaticSchematic parse(InputStream input) throws IOException;
/**
* @param file The file to check against
* @return Whether or not the specified file matches this schematic format
*/
boolean isFileType(File file);
}
@@ -17,7 +17,7 @@
package baritone.api.utils; package baritone.api.utils;
import baritone.api.accessor.IItemStack; import baritone.api.utils.accessor.IItemStack;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
@@ -178,16 +178,27 @@ public final class BlockOptionalMeta {
normalizations = Collections.unmodifiableMap(_normalizations); normalizations = Collections.unmodifiableMap(_normalizations);
} }
private static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) { public static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) {
//noinspection unchecked //noinspection unchecked
return (P) value; return (P) value;
} }
private static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) { public static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) {
//noinspection unchecked //noinspection unchecked
return (C) value; return (C) value;
} }
/**
* Normalizes the specified blockstate by setting meta-affecting properties which
* are not being targeted by the meta parameter to their default values.
* <p>
* For example, block variant/color is the primary target for the meta value, so properties
* such as rotation/facing direction will be set to default values in order to nullify
* the effect that they have on the state's meta value.
*
* @param state The state to normalize
* @return The normalized block state
*/
public static IBlockState normalize(IBlockState state) { public static IBlockState normalize(IBlockState state) {
IBlockState newState = state; IBlockState newState = state;
@@ -220,6 +231,15 @@ public final class BlockOptionalMeta {
return newState; return newState;
} }
/**
* Evaluate the target meta value for the specified state. The target meta value is
* most often that which is influenced by the variant/color property of the block state.
*
* @see #normalize(IBlockState)
*
* @param state The state to check
* @return The target meta of the state
*/
public static int stateMeta(IBlockState state) { public static int stateMeta(IBlockState state) {
return state.getBlock().getMetaFromState(normalize(state)); return state.getBlock().getMetaFromState(normalize(state));
} }
@@ -27,6 +27,9 @@ import java.util.Arrays;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* An ease-of-access interface to provide the {@link Minecraft} game instance,
* chat and console logging mechanisms, and the Baritone chat prefix.
*
* @author Brady * @author Brady
* @since 8/1/2018 * @since 8/1/2018
*/ */
@@ -17,6 +17,7 @@
package baritone.api.utils; package baritone.api.utils;
import baritone.api.BaritoneAPI;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType; import net.minecraft.inventory.ClickType;
@@ -58,6 +59,6 @@ public interface IPlayerController {
void setHittingBlock(boolean hittingBlock); void setHittingBlock(boolean hittingBlock);
default double getBlockReachDistance() { default double getBlockReachDistance() {
return this.getGameType().isCreative() ? 5.0F : 4.5F; return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value;
} }
} }
@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.api.accessor; package baritone.api.utils.accessor;
public interface IItemStack { public interface IItemStack {
@@ -43,30 +43,6 @@ public abstract class MixinBitArray implements IBitArray {
@Final @Final
private int arraySize; private int arraySize;
/**
* why did mojang divide by 64 instead of shifting right by 6 (2^6=64)?
* why did mojang modulo by 64 instead of ANDing with 63?
* also removed validation check
*
* @author LoganDark
*/
@Override
@Unique
public int getAtFast(int index) {
final int b = bitsPerEntry;
final long mev = maxEntryValue;
final int i = index * b;
final int j = i >> 6;
final int l = i & 63;
final int k = ((index + 1) * b - 1) >> 6;
if (j == k) {
return (int) (this.longArray[j] >>> l & mev);
} else {
return (int) ((this.longArray[j] >>> l | longArray[k] << (64 - l)) & mev);
}
}
@Override @Override
@Unique @Unique
public int[] toArray() { public int[] toArray() {
@@ -25,8 +25,6 @@ import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.world.chunk.IBlockStatePalette; import net.minecraft.world.chunk.IBlockStatePalette;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(BlockStateContainer.class) @Mixin(BlockStateContainer.class)
public abstract class MixinBlockStateContainer implements IBlockStateContainer { public abstract class MixinBlockStateContainer implements IBlockStateContainer {
@@ -37,20 +35,6 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer {
@Shadow @Shadow
protected IBlockStatePalette palette; protected IBlockStatePalette palette;
@Override
@Accessor
public abstract BitArray getStorage();
@Override
@Accessor
public abstract IBlockStatePalette getPalette();
@Override
@Unique
public IBlockState getFast(int index) {
return palette.getBlockState(((IBitArray) storage).getAtFast(index));
}
@Override @Override
public IBlockState getAtPalette(int index) { public IBlockState getAtPalette(int index) {
return palette.getBlockState(index); return palette.getBlockState(index);
@@ -26,14 +26,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiChat.ChatTabCompleter.class) @Mixin(GuiChat.ChatTabCompleter.class)
public abstract class MixinChatTabCompleter extends MixinTabCompleter { public abstract class MixinChatTabCompleter extends MixinTabCompleter {
@Inject(
method = "<init>*",
at = @At("RETURN")
)
private void onConstruction(CallbackInfo ci) {
isChatCompleter = true;
}
@Inject( @Inject(
method = "complete", method = "complete",
at = @At("HEAD"), at = @At("HEAD"),
@@ -1,45 +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.launch.mixins;
import baritone.utils.accessor.ITabCompleter;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.util.TabCompleter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiChat.class)
public abstract class MixinGuiChat implements net.minecraft.util.ITabCompleter {
@Shadow
private TabCompleter tabCompleter;
@Inject(
method = "setCompletions",
at = @At("HEAD"),
cancellable = true
)
private void onSetCompletions(String[] newCompl, CallbackInfo ci) {
if (((ITabCompleter) tabCompleter).onGuiChatSetCompletions(newCompl)) {
ci.cancel();
}
}
}
@@ -17,7 +17,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.api.accessor.IGuiScreen; import baritone.utils.accessor.IGuiScreen;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
@@ -17,7 +17,7 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.api.accessor.IItemStack; import baritone.api.utils.accessor.IItemStack;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@@ -41,6 +41,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.BiFunction;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 * @since 7/31/2018
@@ -84,13 +86,15 @@ public class MixinMinecraft {
) )
) )
private void runTick(CallbackInfo ci) { private void runTick(CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { final BiFunction<EventState, TickEvent.Type, TickEvent> tickProvider = TickEvent.createNextProvider();
TickEvent.Type type = ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().world() != null for (IBaritone baritone : BaritoneAPI.getProvider().getAllBaritones()) {
TickEvent.Type type = baritone.getPlayerContext().player() != null && baritone.getPlayerContext().world() != null
? TickEvent.Type.IN ? TickEvent.Type.IN
: TickEvent.Type.OUT; : TickEvent.Type.OUT;
ibaritone.getGameEventHandler().onTick(new TickEvent(EventState.PRE, type)); baritone.getGameEventHandler().onTick(tickProvider.apply(EventState.PRE, type));
} }
} }
@@ -20,7 +20,7 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.event.events.TabCompleteEvent; import baritone.api.event.events.TabCompleteEvent;
import baritone.utils.accessor.ITabCompleter; import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.TabCompleter; import net.minecraft.util.TabCompleter;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@@ -32,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TabCompleter.class) @Mixin(TabCompleter.class)
public abstract class MixinTabCompleter implements ITabCompleter { public abstract class MixinTabCompleter {
@Shadow @Shadow
@Final @Final
@@ -44,36 +44,22 @@ public abstract class MixinTabCompleter implements ITabCompleter {
@Shadow @Shadow
public abstract void setCompletions(String... newCompl); public abstract void setCompletions(String... newCompl);
@Unique
protected boolean isChatCompleter = false;
@Unique @Unique
protected boolean dontComplete = false; protected boolean dontComplete = false;
@Override
public String getPrefix() {
return textField.getText().substring(0, textField.getCursorPosition());
}
@Override
public void setPrefix(String prefix) {
textField.setText(prefix + textField.getText().substring(textField.getCursorPosition()));
textField.setCursorPosition(prefix.length());
}
@Inject( @Inject(
method = "requestCompletions", method = "requestCompletions",
at = @At("HEAD"), at = @At("HEAD"),
cancellable = true cancellable = true
) )
private void onRequestCompletions(String prefix, CallbackInfo ci) { private void onRequestCompletions(String prefix, CallbackInfo ci) {
if (!isChatCompleter) { if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
return; return;
} }
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone(); IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
TabCompleteEvent.Pre event = new TabCompleteEvent.Pre(prefix); TabCompleteEvent event = new TabCompleteEvent(prefix);
baritone.getGameEventHandler().onPreTabComplete(event); baritone.getGameEventHandler().onPreTabComplete(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@@ -81,50 +67,17 @@ public abstract class MixinTabCompleter implements ITabCompleter {
return; return;
} }
if (event.prefix.wasModified()) { if (event.completions != null) {
setPrefix(event.prefix.get());
}
if (event.completions.wasModified()) {
ci.cancel(); ci.cancel();
dontComplete = true; this.dontComplete = true;
try { try {
requestedCompletions = true; this.requestedCompletions = true;
setCompletions(event.completions.get()); setCompletions(event.completions);
} finally { } finally {
dontComplete = false; this.dontComplete = false;
} }
} }
} }
@Override
public boolean onGuiChatSetCompletions(String[] newCompl) {
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
if (baritone == null) {
return false;
}
TabCompleteEvent.Post event = new TabCompleteEvent.Post(getPrefix(), newCompl);
baritone.getGameEventHandler().onPostTabComplete(event);
if (event.isCancelled()) {
return true;
}
if (event.prefix.wasModified()) {
String prefix = event.prefix.get();
textField.setText(prefix + textField.getText().substring(textField.getCursorPosition()));
textField.setCursorPosition(prefix.length());
}
if (event.completions.wasModified()) {
setCompletions(event.completions.get());
return true;
}
return false;
}
} }
@@ -19,7 +19,6 @@
"MixinEntityLivingBase", "MixinEntityLivingBase",
"MixinEntityPlayerSP", "MixinEntityPlayerSP",
"MixinEntityRenderer", "MixinEntityRenderer",
"MixinGuiChat",
"MixinGuiScreen", "MixinGuiScreen",
"MixinItemStack", "MixinItemStack",
"MixinMinecraft", "MixinMinecraft",
+8 -1
View File
@@ -24,10 +24,12 @@ import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner; import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommandSystem; import baritone.api.command.ICommandSystem;
import baritone.bot.UserManager; import baritone.bot.UserManager;
import baritone.cache.WorldScanner; import baritone.api.schematic.ISchematicSystem;
import baritone.command.BaritoneChatControl; import baritone.command.BaritoneChatControl;
import baritone.cache.WorldScanner;
import baritone.command.CommandSystem; import baritone.command.CommandSystem;
import baritone.utils.player.PrimaryPlayerContext; import baritone.utils.player.PrimaryPlayerContext;
import baritone.utils.schematic.SchematicSystem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -76,4 +78,9 @@ public final class BaritoneProvider implements IBaritoneProvider {
public ICommandSystem getCommandSystem() { public ICommandSystem getCommandSystem() {
return CommandSystem.INSTANCE; return CommandSystem.INSTANCE;
} }
@Override
public ISchematicSystem getSchematicSystem() {
return SchematicSystem.INSTANCE;
}
} }
@@ -151,7 +151,7 @@ public final class InventoryBehavior extends Behavior {
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) { public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
EntityPlayerSP p = ctx.player(); EntityPlayerSP p = ctx.player();
NonNullList<ItemStack> inv = p.inventory.mainInventory; NonNullList<ItemStack> inv = p.inventory.mainInventory;
for (byte i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i); ItemStack item = inv.get(i);
// this usage of settings() is okay because it's only called once during pathing // this usage of settings() is okay because it's only called once during pathing
// (while creating the CalculationContext at the very beginning) // (while creating the CalculationContext at the very beginning)
@@ -171,7 +171,7 @@ public final class InventoryBehavior extends Behavior {
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem // we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
// so we need to select in the main hand something that doesn't right click // so we need to select in the main hand something that doesn't right click
// so not a shovel, not a hoe, not a block, etc // so not a shovel, not a hoe, not a block, etc
for (byte i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i); ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) { if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
if (select) { if (select) {
+35 -22
View File
@@ -111,6 +111,41 @@ public enum WorldScanner implements IWorldScanner {
return res; return res;
} }
@Override
public int repack(IPlayerContext ctx) {
return this.repack(ctx, 40);
}
@Override
public int repack(IPlayerContext ctx, int range) {
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int minX = playerChunkX - range;
int minZ = playerChunkZ - range;
int maxX = playerChunkX + range;
int maxZ = playerChunkZ + range;
int queued = 0;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
Chunk chunk = chunkProvider.getLoadedChunk(x, z);
if (chunk != null && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
return queued;
}
private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) { private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray();
boolean foundWithinY = false; boolean foundWithinY = false;
@@ -147,26 +182,4 @@ public enum WorldScanner implements IWorldScanner {
} }
return foundWithinY; return foundWithinY;
} }
public int repack(IPlayerContext ctx) {
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int queued = 0;
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
Chunk chunk = chunkProvider.getLoadedChunk(x, z);
if (chunk != null && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
return queued;
}
} }
@@ -20,7 +20,7 @@ package baritone.command;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.Settings; import baritone.api.Settings;
import baritone.api.accessor.IGuiScreen; import baritone.utils.accessor.IGuiScreen;
import baritone.api.event.events.ChatEvent; import baritone.api.event.events.ChatEvent;
import baritone.api.event.events.TabCompleteEvent; import baritone.api.event.events.TabCompleteEvent;
import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.event.listener.AbstractGameEventListener;
@@ -29,8 +29,8 @@ import baritone.api.utils.SettingsUtil;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandNotEnoughArgumentsException; import baritone.api.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandNotFoundException; import baritone.api.command.exception.CommandNotFoundException;
import baritone.command.helpers.arguments.ArgConsumer; import baritone.command.argument.ArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager; import baritone.api.command.manager.ICommandManager;
import baritone.command.argument.CommandArguments; import baritone.command.argument.CommandArguments;
import baritone.command.manager.CommandManager; import baritone.command.manager.CommandManager;
@@ -146,11 +146,11 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
} }
@Override @Override
public void onPreTabComplete(TabCompleteEvent.Pre event) { public void onPreTabComplete(TabCompleteEvent event) {
if (!settings.prefixControl.value) { if (!settings.prefixControl.value) {
return; return;
} }
String prefix = event.prefix.get(); String prefix = event.prefix;
String commandPrefix = settings.prefix.value; String commandPrefix = settings.prefix.value;
if (!prefix.startsWith(commandPrefix)) { if (!prefix.startsWith(commandPrefix)) {
return; return;
@@ -161,7 +161,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
if (args.size() == 1) { if (args.size() == 1) {
stream = stream.map(x -> commandPrefix + x); stream = stream.map(x -> commandPrefix + x);
} }
event.completions.set(stream.toArray(String[]::new)); event.completions = stream.toArray(String[]::new);
} }
public Stream<String> tabComplete(String msg) { public Stream<String> tabComplete(String msg) {
@@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.command.helpers.arguments; package baritone.command.argument;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
@@ -27,9 +27,8 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.exception.CommandNotEnoughArgumentsException; import baritone.api.command.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandTooManyArgumentsException; import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.manager.ICommandManager; import baritone.api.command.manager.ICommandManager;
import baritone.command.argument.CommandArguments;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Deque; import java.util.Deque;
@@ -317,8 +316,7 @@ public class ArgConsumer implements IArgConsumer {
try { try {
return datatype.apply(this.context, original); return datatype.apply(this.context, original);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
} }
} }
@@ -347,7 +345,7 @@ public class ArgConsumer implements IArgConsumer {
try { try {
return datatype.get(this.context); return datatype.get(this.context);
} catch (Exception e) { } catch (Exception e) {
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
} }
} }
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalAxis; import baritone.api.pathing.goals.GoalAxis;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -22,7 +22,7 @@ import baritone.api.process.IGetToBlockProcess;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -17,6 +17,7 @@
package baritone.command.defaults; package baritone.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command; import baritone.api.command.Command;
@@ -24,13 +25,13 @@ import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.datatypes.RelativeFile; import baritone.api.command.datatypes.RelativeFile;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.apache.commons.io.FilenameUtils;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.stream.Stream; import java.util.stream.Stream;
public class BuildCommand extends Command { public class BuildCommand extends Command {
@@ -44,8 +45,8 @@ public class BuildCommand extends Command {
@Override @Override
public void execute(String label, IArgConsumer args) throws CommandException { public void execute(String label, IArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) { if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
file = new File(file.getAbsolutePath() + ".schematic"); file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension);
} }
BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin; BetterBlockPos buildOrigin;
@@ -1,61 +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.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 java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class CancelCommand extends Command {
public CancelCommand(IBaritone baritone) {
super(baritone, "cancel", "stop");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Cancel what Baritone is currently doing";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The cancel command tells Baritone to stop whatever it's currently doing.",
"",
"Usage:",
"> cancel"
);
}
}
@@ -23,7 +23,7 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.GoalBlock;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -19,7 +19,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -18,17 +18,18 @@
package baritone.command.defaults; package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.ICommand;
import java.util.*; import java.util.*;
public final class DefaultCommands { public final class DefaultCommands {
private DefaultCommands() {} private DefaultCommands() {
}
public static List<Command> createAll(IBaritone baritone) { public static List<ICommand> createAll(IBaritone baritone) {
Objects.requireNonNull(baritone); Objects.requireNonNull(baritone);
List<Command> commands = new ArrayList<>(Arrays.asList( List<ICommand> commands = new ArrayList<>(Arrays.asList(
new HelpCommand(baritone), new HelpCommand(baritone),
new SetCommand(baritone), new SetCommand(baritone),
new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"), new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),
@@ -43,7 +44,6 @@ public final class DefaultCommands {
new SchematicaCommand(baritone), new SchematicaCommand(baritone),
new ComeCommand(baritone), new ComeCommand(baritone),
new AxisCommand(baritone), new AxisCommand(baritone),
new CancelCommand(baritone),
new ForceCancelCommand(baritone), new ForceCancelCommand(baritone),
new GcCommand(baritone), new GcCommand(baritone),
new InvertCommand(baritone), new InvertCommand(baritone),
@@ -66,10 +66,11 @@ public final class DefaultCommands {
new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"), new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
new SelCommand(baritone) new SelCommand(baritone)
)); ));
PauseResumeCommands prc = new PauseResumeCommands(baritone); ExecutionControlCommands prc = new ExecutionControlCommands(baritone);
commands.add(prc.pauseCommand); commands.add(prc.pauseCommand);
commands.add(prc.resumeCommand); commands.add(prc.resumeCommand);
commands.add(prc.pausedCommand); commands.add(prc.pausedCommand);
commands.add(prc.cancelCommand);
return Collections.unmodifiableList(commands); return Collections.unmodifiableList(commands);
} }
} }
@@ -18,13 +18,13 @@
package baritone.command.defaults; package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.process.IBaritoneProcess; import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType; import baritone.api.process.PathingCommandType;
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.Arrays;
import java.util.List; import java.util.List;
@@ -37,13 +37,14 @@ import java.util.stream.Stream;
* TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE * TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE
* REQUEST_PAUSE} as needed. * REQUEST_PAUSE} as needed.
*/ */
public class PauseResumeCommands { public class ExecutionControlCommands {
Command pauseCommand; Command pauseCommand;
Command resumeCommand; Command resumeCommand;
Command pausedCommand; Command pausedCommand;
Command cancelCommand;
public PauseResumeCommands(IBaritone baritone) { public ExecutionControlCommands(IBaritone baritone) {
// array for mutability, non-field so reflection can't touch it // array for mutability, non-field so reflection can't touch it
final boolean[] paused = {false}; final boolean[] paused = {false};
baritone.getPathingControlManager().registerProcess( baritone.getPathingControlManager().registerProcess(
@@ -64,7 +65,8 @@ public class PauseResumeCommands {
} }
@Override @Override
public void onLostControl() {} public void onLostControl() {
}
@Override @Override
public double priority() { public double priority() {
@@ -169,5 +171,36 @@ public class PauseResumeCommands {
); );
} }
}; };
cancelCommand = new Command(baritone, "cancel", "stop") {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
if (paused[0]) {
paused[0] = false;
}
baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Cancel what Baritone is currently doing";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The cancel command tells Baritone to stop whatever it's currently doing.",
"",
"Usage:",
"> cancel"
);
}
};
} }
} }
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.GoalXZ;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeGoalXZ; import baritone.api.command.datatypes.RelativeGoalXZ;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -23,7 +23,7 @@ import baritone.api.command.datatypes.RelativeFile;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.exception.CommandInvalidTypeException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -22,7 +22,7 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById; import baritone.api.command.datatypes.BlockById;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import java.util.ArrayList; import java.util.ArrayList;
@@ -23,8 +23,8 @@ import baritone.api.command.datatypes.EntityClassById;
import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.NearbyPlayer; import baritone.api.command.datatypes.NearbyPlayer;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
import baritone.api.behavior.IPathingBehavior; import baritone.api.behavior.IPathingBehavior;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -25,8 +25,8 @@ import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeCoordinate; import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal; import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -24,7 +24,7 @@ import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.RelativeCoordinate; import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal; import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.Goal;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta; import baritone.api.utils.BlockOptionalMeta;
@@ -41,9 +41,13 @@ public class GotoCommand extends Command {
@Override @Override
public void execute(String label, IArgConsumer args) throws CommandException { public void execute(String label, IArgConsumer args) throws CommandException {
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument... // If we have a numeric first argument, then parse arguments as coordinates.
// Note: There is no reason to want to go where you're already at so there
// is no need to handle the case of empty arguments.
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
args.requireMax(3);
BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin); Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
logDirect(String.format("Going to: %s", goal.toString())); logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal); baritone.getCustomGoalProcess().setGoalAndPath(goal);
return; return;
@@ -19,11 +19,12 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandNotFoundException; import baritone.api.command.exception.CommandNotFoundException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.helpers.pagination.Paginator; import baritone.api.command.helpers.Paginator;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@@ -79,7 +80,7 @@ public class HelpCommand extends Command {
); );
} else { } else {
String commandName = args.getString().toLowerCase(); String commandName = args.getString().toLowerCase();
Command command = this.baritone.getCommandManager().getCommand(commandName); ICommand command = this.baritone.getCommandManager().getCommand(commandName);
if (command == null) { if (command == null) {
throw new CommandNotFoundException(commandName); throw new CommandNotFoundException(commandName);
} }
@@ -24,7 +24,7 @@ import baritone.api.process.ICustomGoalProcess;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -23,7 +23,7 @@ import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById; import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta; import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import java.util.ArrayList; import java.util.ArrayList;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.process.ICustomGoalProcess; import baritone.api.process.ICustomGoalProcess;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
@@ -24,7 +24,7 @@ import baritone.api.process.PathingCommand;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import java.util.Arrays; import java.util.Arrays;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command; import baritone.api.command.Command;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

Some files were not shown because too many files have changed in this diff Show More