diff --git a/README.md b/README.md
index 19ec0e87..043aed08 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@

[](https://github.com/cabaletta/baritone/graphs/contributors/)
[](https://github.com/cabaletta/baritone/commit/)
-[](https://impactclient.net/)
+[](https://impactclient.net/)
[](https://github.com/fr1kin/ForgeHax/)
[](https://gitlab.com/emc-mods-indrit/baritone_api)
[](https://wweclient.com/)
diff --git a/USAGE.md b/USAGE.md
index 25fef11e..0f911efa 100644
--- a/USAGE.md
+++ b/USAGE.md
@@ -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).
+# 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
**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`.
@@ -38,12 +50,6 @@ Some common examples:
- `version` to get the version of Baritone you're running
- `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).
All the settings and documentation are here. If you find HTML easier to read than Javadoc, you can look here.
diff --git a/build.gradle b/build.gradle
index d0ba4720..117f1d63 100755
--- a/build.gradle
+++ b/build.gradle
@@ -16,7 +16,7 @@
*/
group 'baritone'
-version '1.2.9'
+version '1.2.10'
buildscript {
repositories {
diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java
index 24122c12..dcb7fb1d 100644
--- a/src/api/java/baritone/api/IBaritoneProvider.java
+++ b/src/api/java/baritone/api/IBaritoneProvider.java
@@ -19,8 +19,9 @@ package baritone.api;
import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
+import baritone.api.schematic.ISchematicSystem;
import net.minecraft.client.entity.EntityPlayerSP;
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}
- * 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.
*/
ICommandSystem getCommandSystem();
+
+ /**
+ * @return The {@link ISchematicSystem} instance.
+ */
+ ISchematicSystem getSchematicSystem();
}
diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java
index 776d8e61..69bcabcb 100644
--- a/src/api/java/baritone/api/Settings.java
+++ b/src/api/java/baritone/api/Settings.java
@@ -184,6 +184,20 @@ public final class Settings {
Blocks.WALL_SIGN
)));
+ /**
+ * A list of blocks to be treated as if they're air.
+ *
+ * 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> 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 buildIgnoreExisting = new Setting<>(false);
+
/**
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
*
@@ -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.
*
- * This helps with speed at >=20m/s
+ * This helps with speed exceeding 20m/s
*/
public final Setting overshootTraverse = new Setting<>(true);
@@ -248,6 +262,11 @@ public final class Settings {
*/
public final Setting rightClickSpeed = new Setting<>(4);
+ /**
+ * Block reach distance
+ */
+ public final Setting blockReachDistance = new Setting<>(4.5f);
+
/**
* 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 buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
+ /**
+ * How many times to buildrepeat. -1 for infinite.
+ */
+ public final Setting buildRepeatCount = new Setting<>(-1);
+
/**
* Allow standing above a block while mining it, in BuilderProcess
*
@@ -787,6 +811,12 @@ public final class Settings {
*/
public final Setting 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 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)
* is only necessary in very large schematics where rescanning the whole thing is costly.
diff --git a/src/api/java/baritone/api/cache/ICachedWorld.java b/src/api/java/baritone/api/cache/ICachedWorld.java
index 837ae076..e681ce51 100644
--- a/src/api/java/baritone/api/cache/ICachedWorld.java
+++ b/src/api/java/baritone/api/cache/ICachedWorld.java
@@ -81,6 +81,4 @@ public interface ICachedWorld {
* in a new thread by default.
*/
void save();
-
-
}
diff --git a/src/api/java/baritone/api/cache/IWorldScanner.java b/src/api/java/baritone/api/cache/IWorldScanner.java
index 325d4bd0..224f64c7 100644
--- a/src/api/java/baritone/api/cache/IWorldScanner.java
+++ b/src/api/java/baritone/api/cache/IWorldScanner.java
@@ -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.
- * @return The number of chunks queued for repacking.
+ * @param ctx The player, describing the origin
+ * @return The amount of chunks successfully queued for repacking
*/
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);
}
diff --git a/src/api/java/baritone/api/command/Command.java b/src/api/java/baritone/api/command/Command.java
index cd8fa5de..4db5c0f3 100644
--- a/src/api/java/baritone/api/command/Command.java
+++ b/src/api/java/baritone/api/command/Command.java
@@ -18,10 +18,7 @@
package baritone.api.command;
import baritone.api.IBaritone;
-import baritone.api.utils.Helper;
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.List;
@@ -29,7 +26,19 @@ import java.util.Locale;
import java.util.stream.Collectors;
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.
+ *
+ * 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 IPlayerContext ctx;
@@ -52,34 +61,7 @@ public abstract class Command implements Helper {
this.ctx = baritone.getPlayerContext();
}
- /**
- * 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 tabComplete(String label, IArgConsumer args) throws CommandException;
-
- /**
- * @return A single-line 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 getLongDesc();
-
- /**
- * @return {@code true} if this command should be hidden from the help menu
- */
- public boolean hiddenFromHelp() {
- return false;
- }
-
+ @Override
public final List getNames() {
return this.names;
}
diff --git a/src/api/java/baritone/api/command/ICommand.java b/src/api/java/baritone/api/command/ICommand.java
new file mode 100644
index 00000000..792de7c7
--- /dev/null
+++ b/src/api/java/baritone/api/command/ICommand.java
@@ -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 .
+ */
+
+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 tabComplete(String label, IArgConsumer args) throws CommandException;
+
+ /**
+ * @return A single-line 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 getLongDesc();
+
+ /**
+ * @return A list of the names that can be accepted to have arguments passed to this command
+ */
+ List getNames();
+
+ /**
+ * @return {@code true} if this command should be hidden from the help menu
+ */
+ default boolean hiddenFromHelp() {
+ return false;
+ }
+}
diff --git a/src/api/java/baritone/api/command/argparser/IArgParserManager.java b/src/api/java/baritone/api/command/argparser/IArgParserManager.java
index fe819150..f38b4624 100644
--- a/src/api/java/baritone/api/command/argparser/IArgParserManager.java
+++ b/src/api/java/baritone/api/command/argparser/IArgParserManager.java
@@ -22,6 +22,10 @@ import baritone.api.command.exception.CommandInvalidTypeException;
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
* @since 10/4/2019
*/
diff --git a/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java b/src/api/java/baritone/api/command/argument/IArgConsumer.java
similarity index 99%
rename from src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java
rename to src/api/java/baritone/api/command/argument/IArgConsumer.java
index c185c1f7..c9212fa4 100644
--- a/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java
+++ b/src/api/java/baritone/api/command/argument/IArgConsumer.java
@@ -15,13 +15,12 @@
* along with Baritone. If not, see .
*/
-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.utils.Helper;
import baritone.api.command.argparser.IArgParser;
-import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.datatypes.IDatatype;
import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.IDatatypePost;
@@ -35,7 +34,7 @@ import java.util.LinkedList;
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:
*
*
* - Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way
diff --git a/src/api/java/baritone/api/command/argument/ICommandArgument.java b/src/api/java/baritone/api/command/argument/ICommandArgument.java
index ab912d00..9f3ff613 100644
--- a/src/api/java/baritone/api/command/argument/ICommandArgument.java
+++ b/src/api/java/baritone/api/command/argument/ICommandArgument.java
@@ -17,7 +17,6 @@
package baritone.api.command.argument;
-import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.exception.CommandInvalidTypeException;
import net.minecraft.util.EnumFacing;
diff --git a/src/api/java/baritone/api/command/datatypes/BlockById.java b/src/api/java/baritone/api/command/datatypes/BlockById.java
index 98858d13..36b4264c 100644
--- a/src/api/java/baritone/api/command/datatypes/BlockById.java
+++ b/src/api/java/baritone/api/command/datatypes/BlockById.java
@@ -17,7 +17,7 @@
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 net.minecraft.block.Block;
import net.minecraft.init.Blocks;
diff --git a/src/api/java/baritone/api/command/datatypes/EntityClassById.java b/src/api/java/baritone/api/command/datatypes/EntityClassById.java
index 40d6ad10..aed7cdf4 100644
--- a/src/api/java/baritone/api/command/datatypes/EntityClassById.java
+++ b/src/api/java/baritone/api/command/datatypes/EntityClassById.java
@@ -17,7 +17,7 @@
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 net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
diff --git a/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java b/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java
index 23f8617c..f88b372a 100644
--- a/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java
+++ b/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java
@@ -17,7 +17,7 @@
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 net.minecraft.util.EnumFacing;
diff --git a/src/api/java/baritone/api/command/datatypes/ForWaypoints.java b/src/api/java/baritone/api/command/datatypes/ForWaypoints.java
index db506839..20878698 100644
--- a/src/api/java/baritone/api/command/datatypes/ForWaypoints.java
+++ b/src/api/java/baritone/api/command/datatypes/ForWaypoints.java
@@ -20,7 +20,7 @@ package baritone.api.command.datatypes;
import baritone.api.IBaritone;
import baritone.api.cache.IWaypoint;
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 java.util.Comparator;
diff --git a/src/api/java/baritone/api/command/datatypes/IDatatype.java b/src/api/java/baritone/api/command/datatypes/IDatatype.java
index 385154bc..60bf0c38 100644
--- a/src/api/java/baritone/api/command/datatypes/IDatatype.java
+++ b/src/api/java/baritone/api/command/datatypes/IDatatype.java
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes;
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 java.util.stream.Stream;
diff --git a/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java b/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java
index 4b8269c3..78358a26 100644
--- a/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java
+++ b/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes;
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
diff --git a/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java b/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java
index aa32fc76..a05e1181 100644
--- a/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java
+++ b/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java
@@ -18,7 +18,7 @@
package baritone.api.command.datatypes;
import baritone.api.IBaritone;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException;
import net.minecraft.entity.player.EntityPlayer;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java b/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java
index 513ef41f..082b649e 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java
@@ -17,7 +17,7 @@
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.command.exception.CommandException;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java
index dc4d5630..7d77a96c 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java
@@ -17,7 +17,7 @@
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 java.util.regex.Matcher;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeFile.java b/src/api/java/baritone/api/command/datatypes/RelativeFile.java
index f886a1c6..2c7adf98 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeFile.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeFile.java
@@ -17,7 +17,7 @@
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 java.io.File;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java
index 73bc6e0d..19312907 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java
@@ -17,7 +17,7 @@
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.GoalBlock;
import baritone.api.pathing.goals.GoalXZ;
@@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost {
if (origin == null) {
origin = BetterBlockPos.ORIGIN;
}
+
final IArgConsumer consumer = ctx.getConsumer();
- List> coords = new ArrayList<>();
- final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably
- for (int i = 0; i < 3; i++) {
- if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
- coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o));
- copy.get(); // Consume so we actually decrement the remaining arguments
- }
+ GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin);
+ if (goalBlock != null) {
+ return goalBlock;
}
- switch (coords.size()) {
- case 0:
- return new GoalBlock(origin);
- 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());
+ GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin);
+ if (goalXZ != null) {
+ return goalXZ;
}
+
+ 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
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java
index 19621b95..ae05c6ad 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java
@@ -17,7 +17,7 @@
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.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java
index 83d52de8..cd3977b6 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java
@@ -17,7 +17,7 @@
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.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java
index 4dd195a4..58d093f1 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java
@@ -17,7 +17,7 @@
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.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
diff --git a/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java
index 4a21bede..b3161516 100644
--- a/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java
+++ b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java
@@ -22,4 +22,8 @@ public abstract class CommandErrorMessageException extends CommandException {
protected CommandErrorMessageException(String reason) {
super(reason);
}
+
+ protected CommandErrorMessageException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
}
diff --git a/src/api/java/baritone/api/command/exception/CommandException.java b/src/api/java/baritone/api/command/exception/CommandException.java
index b8962c15..53b8e602 100644
--- a/src/api/java/baritone/api/command/exception/CommandException.java
+++ b/src/api/java/baritone/api/command/exception/CommandException.java
@@ -22,4 +22,8 @@ public abstract class CommandException extends Exception implements ICommandExce
protected CommandException(String reason) {
super(reason);
}
+
+ protected CommandException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
}
diff --git a/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java
index 1902d735..6997d6d6 100644
--- a/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java
+++ b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java
@@ -23,12 +23,21 @@ public abstract class CommandInvalidArgumentException extends CommandErrorMessag
public final ICommandArgument arg;
- protected CommandInvalidArgumentException(ICommandArgument arg, String reason) {
- super(String.format(
- "Error at argument #%s: %s",
- arg.getIndex() == -1 ? "" : Integer.toString(arg.getIndex() + 1),
- reason
- ));
+ protected CommandInvalidArgumentException(ICommandArgument arg, String message) {
+ super(formatMessage(arg, message));
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 ? "" : Integer.toString(arg.getIndex() + 1),
+ message
+ );
+ }
}
diff --git a/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java
index 516fd308..06658c3a 100644
--- a/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java
+++ b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java
@@ -26,7 +26,7 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
}
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) {
@@ -34,6 +34,6 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
}
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);
}
}
diff --git a/src/api/java/baritone/api/command/exception/CommandNotFoundException.java b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
index 123661c8..49ac6977 100644
--- a/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
+++ b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import java.util.List;
@@ -34,7 +34,7 @@ public class CommandNotFoundException extends CommandException {
}
@Override
- public void handle(Command command, List args) {
+ public void handle(ICommand command, List args) {
HELPER.logDirect(getMessage());
}
}
diff --git a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
index 394dd65e..02987d4e 100644
--- a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
+++ b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;
@@ -36,8 +36,8 @@ public class CommandUnhandledException extends RuntimeException implements IComm
}
@Override
- public void handle(Command command, List args) {
- HELPER.logDirect("An unhandled exception occurred." +
+ public void handle(ICommand command, List args) {
+ HELPER.logDirect("An unhandled exception occurred. " +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED);
diff --git a/src/api/java/baritone/api/command/exception/ICommandException.java b/src/api/java/baritone/api/command/exception/ICommandException.java
index 3c96cb52..58d13049 100644
--- a/src/api/java/baritone/api/command/exception/ICommandException.java
+++ b/src/api/java/baritone/api/command/exception/ICommandException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
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
- * {@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.
*
* 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 args The arguments the command was called with.
*/
- default void handle(Command command, List args) {
+ default void handle(ICommand command, List args) {
HELPER.logDirect(this.getMessage(), TextFormatting.RED);
}
}
diff --git a/src/api/java/baritone/api/command/helpers/pagination/Paginator.java b/src/api/java/baritone/api/command/helpers/Paginator.java
similarity index 98%
rename from src/api/java/baritone/api/command/helpers/pagination/Paginator.java
rename to src/api/java/baritone/api/command/helpers/Paginator.java
index e5bf9d55..29ddca2f 100644
--- a/src/api/java/baritone/api/command/helpers/pagination/Paginator.java
+++ b/src/api/java/baritone/api/command/helpers/Paginator.java
@@ -15,12 +15,12 @@
* along with Baritone. If not, see .
*/
-package baritone.api.command.helpers.pagination;
+package baritone.api.command.helpers;
import baritone.api.utils.Helper;
import baritone.api.command.exception.CommandException;
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.TextComponentString;
import net.minecraft.util.text.TextFormatting;
diff --git a/src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
similarity index 98%
rename from src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java
rename to src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
index 57192f0c..6274c683 100644
--- a/src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java
+++ b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
@@ -15,13 +15,13 @@
* along with Baritone. If not, see .
*/
-package baritone.api.command.helpers.tabcomplete;
+package baritone.api.command.helpers;
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
import baritone.api.event.events.TabCompleteEvent;
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 net.minecraft.util.ResourceLocation;
diff --git a/src/api/java/baritone/api/command/manager/ICommandManager.java b/src/api/java/baritone/api/command/manager/ICommandManager.java
index f74a3c26..3f2d81f2 100644
--- a/src/api/java/baritone/api/command/manager/ICommandManager.java
+++ b/src/api/java/baritone/api/command/manager/ICommandManager.java
@@ -18,7 +18,7 @@
package baritone.api.command.manager;
import baritone.api.IBaritone;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.registry.Registry;
import net.minecraft.util.Tuple;
@@ -34,13 +34,13 @@ public interface ICommandManager {
IBaritone getBaritone();
- Registry getRegistry();
+ Registry getRegistry();
/**
* @param name The command name to search for.
* @return The command, if found.
*/
- Command getCommand(String name);
+ ICommand getCommand(String name);
boolean execute(String string);
diff --git a/src/api/java/baritone/api/event/events/TabCompleteEvent.java b/src/api/java/baritone/api/event/events/TabCompleteEvent.java
index fea1da29..cf4c57a2 100644
--- a/src/api/java/baritone/api/event/events/TabCompleteEvent.java
+++ b/src/api/java/baritone/api/event/events/TabCompleteEvent.java
@@ -23,31 +23,13 @@ import baritone.api.event.events.type.Overrideable;
/**
* @author LoganDark
*/
-public abstract class TabCompleteEvent extends Cancellable {
+public class TabCompleteEvent extends Cancellable {
- public final Overrideable prefix;
- public final Overrideable completions;
+ public final String prefix;
+ public String[] completions;
- TabCompleteEvent(String prefix, String[] completions) {
- this.prefix = new Overrideable<>(prefix);
- this.completions = new Overrideable<>(completions);
- }
-
- 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);
- }
+ public TabCompleteEvent(String prefix) {
+ this.prefix = prefix;
+ this.completions = null;
}
}
diff --git a/src/api/java/baritone/api/event/events/TickEvent.java b/src/api/java/baritone/api/event/events/TickEvent.java
index da8f8878..5c484ae4 100644
--- a/src/api/java/baritone/api/event/events/TickEvent.java
+++ b/src/api/java/baritone/api/event/events/TickEvent.java
@@ -19,22 +19,20 @@ package baritone.api.event.events;
import baritone.api.event.events.type.EventState;
+import java.util.function.BiFunction;
+
public final class TickEvent {
+ private static int overallTickCount;
+
private final EventState state;
private final Type type;
private final int count;
- private static int overallTickCount;
-
- public TickEvent(EventState state, Type type) {
+ public TickEvent(EventState state, Type type, int count) {
this.state = state;
this.type = type;
- this.count = incrementCount();
- }
-
- private static synchronized int incrementCount() {
- return overallTickCount++;
+ this.count = count;
}
public int getCount() {
@@ -49,6 +47,10 @@ public final class TickEvent {
return state;
}
+ public static synchronized BiFunction createNextProvider() {
+ final int count = overallTickCount++;
+ return (state, type) -> new TickEvent(state, type, count);
+ }
public enum Type {
/**
diff --git a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java
index e7d4dc29..9eac8de4 100644
--- a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java
+++ b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java
@@ -40,10 +40,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
default void onSendChatMessage(ChatEvent event) {}
@Override
- default void onPreTabComplete(TabCompleteEvent.Pre event) {}
-
- @Override
- default void onPostTabComplete(TabCompleteEvent.Post event) {}
+ default void onPreTabComplete(TabCompleteEvent event) {}
@Override
default void onChunkEvent(ChunkEvent event) {}
diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java
index b7522125..b074e978 100644
--- a/src/api/java/baritone/api/event/listener/IGameEventListener.java
+++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java
@@ -62,15 +62,7 @@ public interface IGameEventListener {
*
* @param event The event
*/
- void onPreTabComplete(TabCompleteEvent.Pre 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);
+ void onPreTabComplete(TabCompleteEvent event);
/**
* Runs before and after whenever a chunk is either loaded, unloaded, or populated.
diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java
index c48c2a04..9063b990 100644
--- a/src/api/java/baritone/api/process/IBuilderProcess.java
+++ b/src/api/java/baritone/api/process/IBuilderProcess.java
@@ -17,7 +17,7 @@
package baritone.api.process;
-import baritone.api.utils.ISchematic;
+import baritone.api.schematic.ISchematic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
diff --git a/src/api/java/baritone/api/schematic/AbstractSchematic.java b/src/api/java/baritone/api/schematic/AbstractSchematic.java
index 7a24e803..cca6bc96 100644
--- a/src/api/java/baritone/api/schematic/AbstractSchematic.java
+++ b/src/api/java/baritone/api/schematic/AbstractSchematic.java
@@ -17,14 +17,16 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
-
public abstract class AbstractSchematic implements ISchematic {
protected int x;
protected int y;
protected int z;
+ public AbstractSchematic() {
+ this(0, 0, 0);
+ }
+
public AbstractSchematic(int x, int y, int z) {
this.x = x;
this.y = y;
diff --git a/src/api/java/baritone/api/schematic/CompositeSchematic.java b/src/api/java/baritone/api/schematic/CompositeSchematic.java
index 21df29b4..2f119de1 100644
--- a/src/api/java/baritone/api/schematic/CompositeSchematic.java
+++ b/src/api/java/baritone/api/schematic/CompositeSchematic.java
@@ -17,7 +17,6 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
import java.util.ArrayList;
diff --git a/src/api/java/baritone/api/schematic/CompositeSchematicEntry.java b/src/api/java/baritone/api/schematic/CompositeSchematicEntry.java
index a26f356b..10260542 100644
--- a/src/api/java/baritone/api/schematic/CompositeSchematicEntry.java
+++ b/src/api/java/baritone/api/schematic/CompositeSchematicEntry.java
@@ -17,8 +17,6 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
-
public class CompositeSchematicEntry {
public final ISchematic schematic;
diff --git a/src/api/java/baritone/api/schematic/FillSchematic.java b/src/api/java/baritone/api/schematic/FillSchematic.java
index aaaeb5dd..de9ccf97 100644
--- a/src/api/java/baritone/api/schematic/FillSchematic.java
+++ b/src/api/java/baritone/api/schematic/FillSchematic.java
@@ -32,6 +32,10 @@ public class FillSchematic extends AbstractSchematic {
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() {
return bom;
}
diff --git a/src/api/java/baritone/api/utils/ISchematic.java b/src/api/java/baritone/api/schematic/ISchematic.java
similarity index 99%
rename from src/api/java/baritone/api/utils/ISchematic.java
rename to src/api/java/baritone/api/schematic/ISchematic.java
index 2adcbdd5..88cfc899 100644
--- a/src/api/java/baritone/api/utils/ISchematic.java
+++ b/src/api/java/baritone/api/schematic/ISchematic.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package baritone.api.utils;
+package baritone.api.schematic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
diff --git a/src/api/java/baritone/api/schematic/ISchematicSystem.java b/src/api/java/baritone/api/schematic/ISchematicSystem.java
new file mode 100644
index 00000000..c8f03907
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/ISchematicSystem.java
@@ -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 .
+ */
+
+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 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 getByFile(File file);
+}
diff --git a/src/api/java/baritone/api/schematic/IStaticSchematic.java b/src/api/java/baritone/api/schematic/IStaticSchematic.java
new file mode 100644
index 00000000..268b1b1f
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/IStaticSchematic.java
@@ -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 .
+ */
+
+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;
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/MaskSchematic.java b/src/api/java/baritone/api/schematic/MaskSchematic.java
index fa9b8126..229f58d5 100644
--- a/src/api/java/baritone/api/schematic/MaskSchematic.java
+++ b/src/api/java/baritone/api/schematic/MaskSchematic.java
@@ -17,7 +17,6 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
import java.util.List;
diff --git a/src/api/java/baritone/api/schematic/ReplaceSchematic.java b/src/api/java/baritone/api/schematic/ReplaceSchematic.java
index 988cfd7f..f064435e 100644
--- a/src/api/java/baritone/api/schematic/ReplaceSchematic.java
+++ b/src/api/java/baritone/api/schematic/ReplaceSchematic.java
@@ -18,7 +18,6 @@
package baritone.api.schematic;
import baritone.api.utils.BlockOptionalMetaLookup;
-import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
public class ReplaceSchematic extends MaskSchematic {
diff --git a/src/api/java/baritone/api/schematic/ShellSchematic.java b/src/api/java/baritone/api/schematic/ShellSchematic.java
index 4ead61b6..275a4926 100644
--- a/src/api/java/baritone/api/schematic/ShellSchematic.java
+++ b/src/api/java/baritone/api/schematic/ShellSchematic.java
@@ -17,7 +17,6 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
public class ShellSchematic extends MaskSchematic {
diff --git a/src/api/java/baritone/api/schematic/WallsSchematic.java b/src/api/java/baritone/api/schematic/WallsSchematic.java
index e05de1e7..6e1cfa5f 100644
--- a/src/api/java/baritone/api/schematic/WallsSchematic.java
+++ b/src/api/java/baritone/api/schematic/WallsSchematic.java
@@ -17,7 +17,6 @@
package baritone.api.schematic;
-import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
public class WallsSchematic extends MaskSchematic {
diff --git a/src/api/java/baritone/api/schematic/format/ISchematicFormat.java b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java
new file mode 100644
index 00000000..3fe045bc
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java
@@ -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 .
+ */
+
+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);
+}
diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java
index c65b6d3d..020df814 100644
--- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java
+++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java
@@ -17,7 +17,7 @@
package baritone.api.utils;
-import baritone.api.accessor.IItemStack;
+import baritone.api.utils.accessor.IItemStack;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.*;
import net.minecraft.block.properties.IProperty;
@@ -178,16 +178,27 @@ public final class BlockOptionalMeta {
normalizations = Collections.unmodifiableMap(_normalizations);
}
- private static , P extends IProperty> P castToIProperty(Object value) {
+ public static , P extends IProperty> P castToIProperty(Object value) {
//noinspection unchecked
return (P) value;
}
- private static , P extends IProperty> C castToIPropertyValue(P iproperty, Object value) {
+ public static , P extends IProperty> C castToIPropertyValue(P iproperty, Object value) {
//noinspection unchecked
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.
+ *
+ * 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) {
IBlockState newState = state;
@@ -220,6 +231,15 @@ public final class BlockOptionalMeta {
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) {
return state.getBlock().getMetaFromState(normalize(state));
}
diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java
index 91d7890f..994d8c7b 100755
--- a/src/api/java/baritone/api/utils/Helper.java
+++ b/src/api/java/baritone/api/utils/Helper.java
@@ -27,6 +27,9 @@ import java.util.Arrays;
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
* @since 8/1/2018
*/
diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java
index f395c542..99f49cd1 100644
--- a/src/api/java/baritone/api/utils/IPlayerController.java
+++ b/src/api/java/baritone/api/utils/IPlayerController.java
@@ -17,6 +17,7 @@
package baritone.api.utils;
+import baritone.api.BaritoneAPI;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
@@ -58,6 +59,6 @@ public interface IPlayerController {
void setHittingBlock(boolean hittingBlock);
default double getBlockReachDistance() {
- return this.getGameType().isCreative() ? 5.0F : 4.5F;
+ return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value;
}
}
diff --git a/src/api/java/baritone/api/accessor/IItemStack.java b/src/api/java/baritone/api/utils/accessor/IItemStack.java
similarity index 95%
rename from src/api/java/baritone/api/accessor/IItemStack.java
rename to src/api/java/baritone/api/utils/accessor/IItemStack.java
index 480c713f..22902779 100644
--- a/src/api/java/baritone/api/accessor/IItemStack.java
+++ b/src/api/java/baritone/api/utils/accessor/IItemStack.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package baritone.api.accessor;
+package baritone.api.utils.accessor;
public interface IItemStack {
diff --git a/src/launch/java/baritone/launch/mixins/MixinBitArray.java b/src/launch/java/baritone/launch/mixins/MixinBitArray.java
index 9383c9aa..bece3e3b 100644
--- a/src/launch/java/baritone/launch/mixins/MixinBitArray.java
+++ b/src/launch/java/baritone/launch/mixins/MixinBitArray.java
@@ -43,30 +43,6 @@ public abstract class MixinBitArray implements IBitArray {
@Final
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
@Unique
public int[] toArray() {
diff --git a/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java b/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java
index 8c08b03f..f1cc28b9 100644
--- a/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java
+++ b/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java
@@ -25,8 +25,6 @@ import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.world.chunk.IBlockStatePalette;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(BlockStateContainer.class)
public abstract class MixinBlockStateContainer implements IBlockStateContainer {
@@ -37,20 +35,6 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer {
@Shadow
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
public IBlockState getAtPalette(int index) {
return palette.getBlockState(index);
diff --git a/src/launch/java/baritone/launch/mixins/MixinChatTabCompleter.java b/src/launch/java/baritone/launch/mixins/MixinChatTabCompleter.java
index 797b6210..f8e4d789 100644
--- a/src/launch/java/baritone/launch/mixins/MixinChatTabCompleter.java
+++ b/src/launch/java/baritone/launch/mixins/MixinChatTabCompleter.java
@@ -26,14 +26,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiChat.ChatTabCompleter.class)
public abstract class MixinChatTabCompleter extends MixinTabCompleter {
- @Inject(
- method = "*",
- at = @At("RETURN")
- )
- private void onConstruction(CallbackInfo ci) {
- isChatCompleter = true;
- }
-
@Inject(
method = "complete",
at = @At("HEAD"),
diff --git a/src/launch/java/baritone/launch/mixins/MixinGuiChat.java b/src/launch/java/baritone/launch/mixins/MixinGuiChat.java
deleted file mode 100644
index 9883c176..00000000
--- a/src/launch/java/baritone/launch/mixins/MixinGuiChat.java
+++ /dev/null
@@ -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 .
- */
-
-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();
- }
- }
-}
diff --git a/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java b/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java
index 9f91beaa..39f78fd3 100644
--- a/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java
+++ b/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java
@@ -17,7 +17,7 @@
package baritone.launch.mixins;
-import baritone.api.accessor.IGuiScreen;
+import baritone.utils.accessor.IGuiScreen;
import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
diff --git a/src/launch/java/baritone/launch/mixins/MixinItemStack.java b/src/launch/java/baritone/launch/mixins/MixinItemStack.java
index 2ad4c187..32535977 100644
--- a/src/launch/java/baritone/launch/mixins/MixinItemStack.java
+++ b/src/launch/java/baritone/launch/mixins/MixinItemStack.java
@@ -17,7 +17,7 @@
package baritone.launch.mixins;
-import baritone.api.accessor.IItemStack;
+import baritone.api.utils.accessor.IItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Final;
diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
index 9dc835cd..3de4a0f5 100644
--- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
+++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
@@ -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.LocalCapture;
+import java.util.function.BiFunction;
+
/**
* @author Brady
* @since 7/31/2018
@@ -84,13 +86,15 @@ public class MixinMinecraft {
)
)
private void runTick(CallbackInfo ci) {
- for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
+ final BiFunction 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.OUT;
- ibaritone.getGameEventHandler().onTick(new TickEvent(EventState.PRE, type));
+ baritone.getGameEventHandler().onTick(tickProvider.apply(EventState.PRE, type));
}
}
diff --git a/src/launch/java/baritone/launch/mixins/MixinTabCompleter.java b/src/launch/java/baritone/launch/mixins/MixinTabCompleter.java
index cdbae3b4..7f9a66fb 100644
--- a/src/launch/java/baritone/launch/mixins/MixinTabCompleter.java
+++ b/src/launch/java/baritone/launch/mixins/MixinTabCompleter.java
@@ -20,7 +20,7 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
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.util.TabCompleter;
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;
@Mixin(TabCompleter.class)
-public abstract class MixinTabCompleter implements ITabCompleter {
+public abstract class MixinTabCompleter {
@Shadow
@Final
@@ -44,36 +44,22 @@ public abstract class MixinTabCompleter implements ITabCompleter {
@Shadow
public abstract void setCompletions(String... newCompl);
- @Unique
- protected boolean isChatCompleter = false;
-
@Unique
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(
method = "requestCompletions",
at = @At("HEAD"),
cancellable = true
)
private void onRequestCompletions(String prefix, CallbackInfo ci) {
- if (!isChatCompleter) {
+ if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
return;
}
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
- TabCompleteEvent.Pre event = new TabCompleteEvent.Pre(prefix);
+ TabCompleteEvent event = new TabCompleteEvent(prefix);
baritone.getGameEventHandler().onPreTabComplete(event);
if (event.isCancelled()) {
@@ -81,50 +67,17 @@ public abstract class MixinTabCompleter implements ITabCompleter {
return;
}
- if (event.prefix.wasModified()) {
- setPrefix(event.prefix.get());
- }
-
- if (event.completions.wasModified()) {
+ if (event.completions != null) {
ci.cancel();
- dontComplete = true;
+ this.dontComplete = true;
try {
- requestedCompletions = true;
- setCompletions(event.completions.get());
+ this.requestedCompletions = true;
+ setCompletions(event.completions);
} 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;
- }
}
diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json
index 82c1dd7f..eb31a2e7 100644
--- a/src/launch/resources/mixins.baritone.json
+++ b/src/launch/resources/mixins.baritone.json
@@ -19,7 +19,6 @@
"MixinEntityLivingBase",
"MixinEntityPlayerSP",
"MixinEntityRenderer",
- "MixinGuiChat",
"MixinGuiScreen",
"MixinItemStack",
"MixinMinecraft",
diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java
index e3dd6f67..1efc0b67 100644
--- a/src/main/java/baritone/BaritoneProvider.java
+++ b/src/main/java/baritone/BaritoneProvider.java
@@ -24,10 +24,12 @@ import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommandSystem;
import baritone.bot.UserManager;
-import baritone.cache.WorldScanner;
+import baritone.api.schematic.ISchematicSystem;
import baritone.command.BaritoneChatControl;
+import baritone.cache.WorldScanner;
import baritone.command.CommandSystem;
import baritone.utils.player.PrimaryPlayerContext;
+import baritone.utils.schematic.SchematicSystem;
import java.util.ArrayList;
import java.util.List;
@@ -76,4 +78,9 @@ public final class BaritoneProvider implements IBaritoneProvider {
public ICommandSystem getCommandSystem() {
return CommandSystem.INSTANCE;
}
+
+ @Override
+ public ISchematicSystem getSchematicSystem() {
+ return SchematicSystem.INSTANCE;
+ }
}
diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java
index 63e6c91e..b21cec03 100644
--- a/src/main/java/baritone/behavior/InventoryBehavior.java
+++ b/src/main/java/baritone/behavior/InventoryBehavior.java
@@ -151,7 +151,7 @@ public final class InventoryBehavior extends Behavior {
public boolean throwaway(boolean select, Predicate super ItemStack> desired) {
EntityPlayerSP p = ctx.player();
NonNullList inv = p.inventory.mainInventory;
- for (byte i = 0; i < 9; i++) {
+ for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
// this usage of settings() is okay because it's only called once during pathing
// (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
// 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
- for (byte i = 0; i < 9; i++) {
+ for (int i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
if (select) {
diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java
index d31c17ab..36250629 100644
--- a/src/main/java/baritone/cache/WorldScanner.java
+++ b/src/main/java/baritone/cache/WorldScanner.java
@@ -111,6 +111,41 @@ public enum WorldScanner implements IWorldScanner {
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 result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray();
boolean foundWithinY = false;
@@ -147,26 +182,4 @@ public enum WorldScanner implements IWorldScanner {
}
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;
- }
}
diff --git a/src/main/java/baritone/command/BaritoneChatControl.java b/src/main/java/baritone/command/BaritoneChatControl.java
index 2b81f284..15f15abe 100644
--- a/src/main/java/baritone/command/BaritoneChatControl.java
+++ b/src/main/java/baritone/command/BaritoneChatControl.java
@@ -20,7 +20,7 @@ package baritone.command;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
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.TabCompleteEvent;
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.exception.CommandNotEnoughArgumentsException;
import baritone.api.command.exception.CommandNotFoundException;
-import baritone.command.helpers.arguments.ArgConsumer;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.command.argument.ArgConsumer;
+import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager;
import baritone.command.argument.CommandArguments;
import baritone.command.manager.CommandManager;
@@ -146,11 +146,11 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
}
@Override
- public void onPreTabComplete(TabCompleteEvent.Pre event) {
+ public void onPreTabComplete(TabCompleteEvent event) {
if (!settings.prefixControl.value) {
return;
}
- String prefix = event.prefix.get();
+ String prefix = event.prefix;
String commandPrefix = settings.prefix.value;
if (!prefix.startsWith(commandPrefix)) {
return;
@@ -161,7 +161,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
if (args.size() == 1) {
stream = stream.map(x -> commandPrefix + x);
}
- event.completions.set(stream.toArray(String[]::new));
+ event.completions = stream.toArray(String[]::new);
}
public Stream tabComplete(String msg) {
diff --git a/src/main/java/baritone/command/helpers/arguments/ArgConsumer.java b/src/main/java/baritone/command/argument/ArgConsumer.java
similarity index 97%
rename from src/main/java/baritone/command/helpers/arguments/ArgConsumer.java
rename to src/main/java/baritone/command/argument/ArgConsumer.java
index c6a4fb0c..f4e7dd52 100644
--- a/src/main/java/baritone/command/helpers/arguments/ArgConsumer.java
+++ b/src/main/java/baritone/command/argument/ArgConsumer.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package baritone.command.helpers.arguments;
+package baritone.command.argument;
import baritone.api.IBaritone;
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.CommandNotEnoughArgumentsException;
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.command.argument.CommandArguments;
import java.util.ArrayList;
import java.util.Deque;
@@ -317,8 +316,7 @@ public class ArgConsumer implements IArgConsumer {
try {
return datatype.apply(this.context, original);
} catch (Exception e) {
- e.printStackTrace();
- throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
+ throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
}
}
@@ -347,7 +345,7 @@ public class ArgConsumer implements IArgConsumer {
try {
return datatype.get(this.context);
} catch (Exception e) {
- throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
+ throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
}
}
diff --git a/src/main/java/baritone/command/defaults/AxisCommand.java b/src/main/java/baritone/command/defaults/AxisCommand.java
index 09d00ae7..0a92ac6e 100644
--- a/src/main/java/baritone/command/defaults/AxisCommand.java
+++ b/src/main/java/baritone/command/defaults/AxisCommand.java
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalAxis;
import baritone.api.command.Command;
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.List;
diff --git a/src/main/java/baritone/command/defaults/BlacklistCommand.java b/src/main/java/baritone/command/defaults/BlacklistCommand.java
index 5069f434..a383e0a7 100644
--- a/src/main/java/baritone/command/defaults/BlacklistCommand.java
+++ b/src/main/java/baritone/command/defaults/BlacklistCommand.java
@@ -22,7 +22,7 @@ import baritone.api.process.IGetToBlockProcess;
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 baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java
index b2edbb24..3d549587 100644
--- a/src/main/java/baritone/command/defaults/BuildCommand.java
+++ b/src/main/java/baritone/command/defaults/BuildCommand.java
@@ -17,6 +17,7 @@
package baritone.command.defaults;
+import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
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.exception.CommandException;
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 org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.util.Arrays;
import java.util.List;
-import java.util.Locale;
import java.util.stream.Stream;
public class BuildCommand extends Command {
@@ -44,8 +45,8 @@ public class BuildCommand extends Command {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
- if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
- file = new File(file.getAbsolutePath() + ".schematic");
+ if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
+ file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension);
}
BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin;
diff --git a/src/main/java/baritone/command/defaults/CancelCommand.java b/src/main/java/baritone/command/defaults/CancelCommand.java
deleted file mode 100644
index aff839ae..00000000
--- a/src/main/java/baritone/command/defaults/CancelCommand.java
+++ /dev/null
@@ -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 .
- */
-
-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 tabComplete(String label, IArgConsumer args) {
- return Stream.empty();
- }
-
- @Override
- public String getShortDesc() {
- return "Cancel what Baritone is currently doing";
- }
-
- @Override
- public List getLongDesc() {
- return Arrays.asList(
- "The cancel command tells Baritone to stop whatever it's currently doing.",
- "",
- "Usage:",
- "> cancel"
- );
- }
-}
diff --git a/src/main/java/baritone/command/defaults/ChestsCommand.java b/src/main/java/baritone/command/defaults/ChestsCommand.java
index c3755b5a..fd084ad1 100644
--- a/src/main/java/baritone/command/defaults/ChestsCommand.java
+++ b/src/main/java/baritone/command/defaults/ChestsCommand.java
@@ -23,7 +23,7 @@ import baritone.api.utils.BetterBlockPos;
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 baritone.api.command.argument.IArgConsumer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
diff --git a/src/main/java/baritone/command/defaults/ClickCommand.java b/src/main/java/baritone/command/defaults/ClickCommand.java
index 95b04f52..b882c587 100644
--- a/src/main/java/baritone/command/defaults/ClickCommand.java
+++ b/src/main/java/baritone/command/defaults/ClickCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/ComeCommand.java b/src/main/java/baritone/command/defaults/ComeCommand.java
index 9b336a25..b8033c3f 100644
--- a/src/main/java/baritone/command/defaults/ComeCommand.java
+++ b/src/main/java/baritone/command/defaults/ComeCommand.java
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.GoalBlock;
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 baritone.api.command.argument.IArgConsumer;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
diff --git a/src/main/java/baritone/command/defaults/CommandAlias.java b/src/main/java/baritone/command/defaults/CommandAlias.java
index 08b1ca05..71c322fe 100644
--- a/src/main/java/baritone/command/defaults/CommandAlias.java
+++ b/src/main/java/baritone/command/defaults/CommandAlias.java
@@ -19,7 +19,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
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.List;
diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java
index dd1a3004..67555ed5 100644
--- a/src/main/java/baritone/command/defaults/DefaultCommands.java
+++ b/src/main/java/baritone/command/defaults/DefaultCommands.java
@@ -18,58 +18,59 @@
package baritone.command.defaults;
import baritone.api.IBaritone;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import java.util.*;
public final class DefaultCommands {
- private DefaultCommands() {}
+ private DefaultCommands() {
+ }
- public static List createAll(IBaritone baritone) {
+ public static List createAll(IBaritone baritone) {
Objects.requireNonNull(baritone);
- List commands = new ArrayList<>(Arrays.asList(
- new HelpCommand(baritone),
- new SetCommand(baritone),
- new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),
- new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"),
- new GoalCommand(baritone),
- new GotoCommand(baritone),
- new PathCommand(baritone),
- new ProcCommand(baritone),
- new VersionCommand(baritone),
- new RepackCommand(baritone),
- new BuildCommand(baritone),
- new SchematicaCommand(baritone),
- new ComeCommand(baritone),
- new AxisCommand(baritone),
- new CancelCommand(baritone),
- new ForceCancelCommand(baritone),
- new GcCommand(baritone),
- new InvertCommand(baritone),
- new TunnelCommand(baritone),
- new RenderCommand(baritone),
- new FarmCommand(baritone),
- new ChestsCommand(baritone),
- new FollowCommand(baritone),
- new ExploreFilterCommand(baritone),
- new ReloadAllCommand(baritone),
- new SaveAllCommand(baritone),
- new ExploreCommand(baritone),
- new BlacklistCommand(baritone),
- new FindCommand(baritone),
- new MineCommand(baritone),
- new ClickCommand(baritone),
- new ThisWayCommand(baritone),
- new WaypointsCommand(baritone),
- new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"),
- new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
- new SelCommand(baritone)
+ List commands = new ArrayList<>(Arrays.asList(
+ new HelpCommand(baritone),
+ new SetCommand(baritone),
+ new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),
+ new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"),
+ new GoalCommand(baritone),
+ new GotoCommand(baritone),
+ new PathCommand(baritone),
+ new ProcCommand(baritone),
+ new VersionCommand(baritone),
+ new RepackCommand(baritone),
+ new BuildCommand(baritone),
+ new SchematicaCommand(baritone),
+ new ComeCommand(baritone),
+ new AxisCommand(baritone),
+ new ForceCancelCommand(baritone),
+ new GcCommand(baritone),
+ new InvertCommand(baritone),
+ new TunnelCommand(baritone),
+ new RenderCommand(baritone),
+ new FarmCommand(baritone),
+ new ChestsCommand(baritone),
+ new FollowCommand(baritone),
+ new ExploreFilterCommand(baritone),
+ new ReloadAllCommand(baritone),
+ new SaveAllCommand(baritone),
+ new ExploreCommand(baritone),
+ new BlacklistCommand(baritone),
+ new FindCommand(baritone),
+ new MineCommand(baritone),
+ new ClickCommand(baritone),
+ new ThisWayCommand(baritone),
+ new WaypointsCommand(baritone),
+ new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"),
+ new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
+ new SelCommand(baritone)
));
- PauseResumeCommands prc = new PauseResumeCommands(baritone);
+ ExecutionControlCommands prc = new ExecutionControlCommands(baritone);
commands.add(prc.pauseCommand);
commands.add(prc.resumeCommand);
commands.add(prc.pausedCommand);
+ commands.add(prc.cancelCommand);
return Collections.unmodifiableList(commands);
}
}
diff --git a/src/main/java/baritone/command/defaults/PauseResumeCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java
similarity index 82%
rename from src/main/java/baritone/command/defaults/PauseResumeCommands.java
rename to src/main/java/baritone/command/defaults/ExecutionControlCommands.java
index 11e67882..4a04b9e0 100644
--- a/src/main/java/baritone/command/defaults/PauseResumeCommands.java
+++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java
@@ -18,13 +18,13 @@
package baritone.command.defaults;
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.PathingCommand;
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.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
* REQUEST_PAUSE} as needed.
*/
-public class PauseResumeCommands {
+public class ExecutionControlCommands {
Command pauseCommand;
Command resumeCommand;
Command pausedCommand;
+ Command cancelCommand;
- public PauseResumeCommands(IBaritone baritone) {
+ public ExecutionControlCommands(IBaritone baritone) {
// array for mutability, non-field so reflection can't touch it
final boolean[] paused = {false};
baritone.getPathingControlManager().registerProcess(
@@ -64,7 +65,8 @@ public class PauseResumeCommands {
}
@Override
- public void onLostControl() {}
+ public void onLostControl() {
+ }
@Override
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 tabComplete(String label, IArgConsumer args) {
+ return Stream.empty();
+ }
+
+ @Override
+ public String getShortDesc() {
+ return "Cancel what Baritone is currently doing";
+ }
+
+ @Override
+ public List getLongDesc() {
+ return Arrays.asList(
+ "The cancel command tells Baritone to stop whatever it's currently doing.",
+ "",
+ "Usage:",
+ "> cancel"
+ );
+ }
+ };
}
}
diff --git a/src/main/java/baritone/command/defaults/ExploreCommand.java b/src/main/java/baritone/command/defaults/ExploreCommand.java
index a2054cc7..9d27bbbe 100644
--- a/src/main/java/baritone/command/defaults/ExploreCommand.java
+++ b/src/main/java/baritone/command/defaults/ExploreCommand.java
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.GoalXZ;
import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeGoalXZ;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/ExploreFilterCommand.java b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
index a1c5074a..b4ee393a 100644
--- a/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
+++ b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
@@ -23,7 +23,7 @@ import baritone.api.command.datatypes.RelativeFile;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import com.google.gson.JsonSyntaxException;
import java.io.File;
diff --git a/src/main/java/baritone/command/defaults/FarmCommand.java b/src/main/java/baritone/command/defaults/FarmCommand.java
index 9151852c..786d0124 100644
--- a/src/main/java/baritone/command/defaults/FarmCommand.java
+++ b/src/main/java/baritone/command/defaults/FarmCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java
index 22a8fd87..3011d7f9 100644
--- a/src/main/java/baritone/command/defaults/FindCommand.java
+++ b/src/main/java/baritone/command/defaults/FindCommand.java
@@ -22,7 +22,7 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import net.minecraft.block.Block;
import java.util.ArrayList;
diff --git a/src/main/java/baritone/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java
index e9c80ab9..755fc535 100644
--- a/src/main/java/baritone/command/defaults/FollowCommand.java
+++ b/src/main/java/baritone/command/defaults/FollowCommand.java
@@ -23,8 +23,8 @@ import baritone.api.command.datatypes.EntityClassById;
import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.NearbyPlayer;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
diff --git a/src/main/java/baritone/command/defaults/ForceCancelCommand.java b/src/main/java/baritone/command/defaults/ForceCancelCommand.java
index f9213482..8344f4f9 100644
--- a/src/main/java/baritone/command/defaults/ForceCancelCommand.java
+++ b/src/main/java/baritone/command/defaults/ForceCancelCommand.java
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
import baritone.api.behavior.IPathingBehavior;
import baritone.api.command.Command;
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.List;
diff --git a/src/main/java/baritone/command/defaults/GcCommand.java b/src/main/java/baritone/command/defaults/GcCommand.java
index c64703e9..143da579 100644
--- a/src/main/java/baritone/command/defaults/GcCommand.java
+++ b/src/main/java/baritone/command/defaults/GcCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/GoalCommand.java b/src/main/java/baritone/command/defaults/GoalCommand.java
index 46b50695..a75af077 100644
--- a/src/main/java/baritone/command/defaults/GoalCommand.java
+++ b/src/main/java/baritone/command/defaults/GoalCommand.java
@@ -25,8 +25,8 @@ import baritone.api.command.Command;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.TabCompleteHelper;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java
index 9659fff8..28e76829 100644
--- a/src/main/java/baritone/command/defaults/GotoCommand.java
+++ b/src/main/java/baritone/command/defaults/GotoCommand.java
@@ -24,7 +24,7 @@ import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.Goal;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
@@ -41,9 +41,13 @@ public class GotoCommand extends Command {
@Override
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();
- Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin);
+ Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal);
return;
diff --git a/src/main/java/baritone/command/defaults/HelpCommand.java b/src/main/java/baritone/command/defaults/HelpCommand.java
index fe3c4808..4cb5f420 100644
--- a/src/main/java/baritone/command/defaults/HelpCommand.java
+++ b/src/main/java/baritone/command/defaults/HelpCommand.java
@@ -19,11 +19,12 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandNotFoundException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.pagination.Paginator;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.Paginator;
+import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
@@ -79,7 +80,7 @@ public class HelpCommand extends Command {
);
} else {
String commandName = args.getString().toLowerCase();
- Command command = this.baritone.getCommandManager().getCommand(commandName);
+ ICommand command = this.baritone.getCommandManager().getCommand(commandName);
if (command == null) {
throw new CommandNotFoundException(commandName);
}
diff --git a/src/main/java/baritone/command/defaults/InvertCommand.java b/src/main/java/baritone/command/defaults/InvertCommand.java
index ba79a4a9..9e3e859e 100644
--- a/src/main/java/baritone/command/defaults/InvertCommand.java
+++ b/src/main/java/baritone/command/defaults/InvertCommand.java
@@ -24,7 +24,7 @@ import baritone.api.process.ICustomGoalProcess;
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 baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/MineCommand.java b/src/main/java/baritone/command/defaults/MineCommand.java
index d2846e0a..2baf982a 100644
--- a/src/main/java/baritone/command/defaults/MineCommand.java
+++ b/src/main/java/baritone/command/defaults/MineCommand.java
@@ -23,7 +23,7 @@ import baritone.api.command.Command;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import baritone.cache.WorldScanner;
import java.util.ArrayList;
diff --git a/src/main/java/baritone/command/defaults/PathCommand.java b/src/main/java/baritone/command/defaults/PathCommand.java
index fff61a70..0add6408 100644
--- a/src/main/java/baritone/command/defaults/PathCommand.java
+++ b/src/main/java/baritone/command/defaults/PathCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import baritone.api.process.ICustomGoalProcess;
import baritone.cache.WorldScanner;
diff --git a/src/main/java/baritone/command/defaults/ProcCommand.java b/src/main/java/baritone/command/defaults/ProcCommand.java
index 794a4480..cf9371bc 100644
--- a/src/main/java/baritone/command/defaults/ProcCommand.java
+++ b/src/main/java/baritone/command/defaults/ProcCommand.java
@@ -24,7 +24,7 @@ import baritone.api.process.PathingCommand;
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 baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/ReloadAllCommand.java b/src/main/java/baritone/command/defaults/ReloadAllCommand.java
index 9f4ddd83..fa8d5117 100644
--- a/src/main/java/baritone/command/defaults/ReloadAllCommand.java
+++ b/src/main/java/baritone/command/defaults/ReloadAllCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/RenderCommand.java b/src/main/java/baritone/command/defaults/RenderCommand.java
index ea51edc8..90471432 100644
--- a/src/main/java/baritone/command/defaults/RenderCommand.java
+++ b/src/main/java/baritone/command/defaults/RenderCommand.java
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command;
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.List;
diff --git a/src/main/java/baritone/command/defaults/RepackCommand.java b/src/main/java/baritone/command/defaults/RepackCommand.java
index d42bd95a..6366fbc9 100644
--- a/src/main/java/baritone/command/defaults/RepackCommand.java
+++ b/src/main/java/baritone/command/defaults/RepackCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import baritone.cache.WorldScanner;
import java.util.Arrays;
diff --git a/src/main/java/baritone/command/defaults/SaveAllCommand.java b/src/main/java/baritone/command/defaults/SaveAllCommand.java
index 7df2e320..5f064a72 100644
--- a/src/main/java/baritone/command/defaults/SaveAllCommand.java
+++ b/src/main/java/baritone/command/defaults/SaveAllCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/SchematicaCommand.java b/src/main/java/baritone/command/defaults/SchematicaCommand.java
index 5f659d1f..8279b1dc 100644
--- a/src/main/java/baritone/command/defaults/SchematicaCommand.java
+++ b/src/main/java/baritone/command/defaults/SchematicaCommand.java
@@ -20,7 +20,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java
index 342d0a31..6f242f0b 100644
--- a/src/main/java/baritone/command/defaults/SelCommand.java
+++ b/src/main/java/baritone/command/defaults/SelCommand.java
@@ -27,7 +27,7 @@ import baritone.api.selection.ISelectionManager;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
-import baritone.api.utils.ISchematic;
+import baritone.api.schematic.ISchematic;
import baritone.api.command.Command;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.ForEnumFacing;
@@ -35,8 +35,8 @@ import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.TabCompleteHelper;
import baritone.utils.IRenderer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
diff --git a/src/main/java/baritone/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java
index 280f56ea..d5b4f5bf 100644
--- a/src/main/java/baritone/command/defaults/SetCommand.java
+++ b/src/main/java/baritone/command/defaults/SetCommand.java
@@ -24,9 +24,9 @@ import baritone.api.utils.SettingsUtil;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidTypeException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.pagination.Paginator;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.Paginator;
+import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
diff --git a/src/main/java/baritone/command/defaults/ThisWayCommand.java b/src/main/java/baritone/command/defaults/ThisWayCommand.java
index 9ff42f42..6073d82b 100644
--- a/src/main/java/baritone/command/defaults/ThisWayCommand.java
+++ b/src/main/java/baritone/command/defaults/ThisWayCommand.java
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.command.Command;
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.List;
diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java
index e7830c05..991a7ff8 100644
--- a/src/main/java/baritone/command/defaults/TunnelCommand.java
+++ b/src/main/java/baritone/command/defaults/TunnelCommand.java
@@ -22,7 +22,7 @@ import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalStrictDirection;
import baritone.api.command.Command;
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.List;
diff --git a/src/main/java/baritone/command/defaults/VersionCommand.java b/src/main/java/baritone/command/defaults/VersionCommand.java
index 6e063b0f..b7882d7d 100644
--- a/src/main/java/baritone/command/defaults/VersionCommand.java
+++ b/src/main/java/baritone/command/defaults/VersionCommand.java
@@ -21,7 +21,7 @@ import baritone.api.IBaritone;
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 baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/baritone/command/defaults/WaypointsCommand.java b/src/main/java/baritone/command/defaults/WaypointsCommand.java
index c61f6557..62c74212 100644
--- a/src/main/java/baritone/command/defaults/WaypointsCommand.java
+++ b/src/main/java/baritone/command/defaults/WaypointsCommand.java
@@ -29,9 +29,9 @@ import baritone.api.command.datatypes.RelativeBlockPos;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.exception.CommandInvalidTypeException;
-import baritone.api.command.helpers.arguments.IArgConsumer;
-import baritone.api.command.helpers.pagination.Paginator;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.helpers.Paginator;
+import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
diff --git a/src/main/java/baritone/command/manager/CommandManager.java b/src/main/java/baritone/command/manager/CommandManager.java
index 20f293b1..aba434e3 100644
--- a/src/main/java/baritone/command/manager/CommandManager.java
+++ b/src/main/java/baritone/command/manager/CommandManager.java
@@ -19,12 +19,12 @@ package baritone.command.manager;
import baritone.Baritone;
import baritone.api.IBaritone;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandUnhandledException;
import baritone.api.command.exception.ICommandException;
-import baritone.command.helpers.arguments.ArgConsumer;
-import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
+import baritone.command.argument.ArgConsumer;
+import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager;
import baritone.api.command.registry.Registry;
import baritone.command.argument.CommandArguments;
@@ -43,7 +43,7 @@ import java.util.stream.Stream;
*/
public class CommandManager implements ICommandManager {
- private final Registry registry = new Registry<>();
+ private final Registry registry = new Registry<>();
private final Baritone baritone;
public CommandManager(Baritone baritone) {
@@ -57,13 +57,13 @@ public class CommandManager implements ICommandManager {
}
@Override
- public Registry getRegistry() {
+ public Registry getRegistry() {
return this.registry;
}
@Override
- public Command getCommand(String name) {
- for (Command command : this.registry.entries) {
+ public ICommand getCommand(String name) {
+ for (ICommand command : this.registry.entries) {
if (command.getNames().contains(name.toLowerCase(Locale.US))) {
return command;
}
@@ -110,7 +110,7 @@ public class CommandManager implements ICommandManager {
String label = expanded.getFirst();
ArgConsumer args = new ArgConsumer(this, expanded.getSecond());
- Command command = this.getCommand(label);
+ ICommand command = this.getCommand(label);
return command == null ? null : new ExecutionWrapper(command, label, args);
}
@@ -125,11 +125,11 @@ public class CommandManager implements ICommandManager {
}
private static final class ExecutionWrapper {
- private Command command;
+ private ICommand command;
private String label;
private ArgConsumer args;
- private ExecutionWrapper(Command command, String label, ArgConsumer args) {
+ private ExecutionWrapper(ICommand command, String label, ArgConsumer args) {
this.command = command;
this.label = label;
this.args = args;
diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java
index be374f21..7027d2e2 100644
--- a/src/main/java/baritone/event/GameEventHandler.java
+++ b/src/main/java/baritone/event/GameEventHandler.java
@@ -75,15 +75,10 @@ public final class GameEventHandler implements IEventBus, Helper {
}
@Override
- public void onPreTabComplete(TabCompleteEvent.Pre event) {
+ public void onPreTabComplete(TabCompleteEvent event) {
listeners.forEach(l -> l.onPreTabComplete(event));
}
- @Override
- public void onPostTabComplete(TabCompleteEvent.Post event) {
- listeners.forEach(l -> l.onPostTabComplete(event));
- }
-
@Override
public final void onChunkEvent(ChunkEvent event) {
EventState state = event.getState();
diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java
index 725a0876..31a1de7a 100644
--- a/src/main/java/baritone/pathing/movement/MovementHelper.java
+++ b/src/main/java/baritone/pathing/movement/MovementHelper.java
@@ -35,6 +35,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
+import net.minecraft.world.IBlockAccess;
import java.util.Optional;
@@ -132,10 +133,8 @@ public interface MovementHelper extends ActionCosts, Helper {
}
return block == Blocks.WATER || block == Blocks.FLOWING_WATER;
}
- // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;"
- // has already been accounted for above
- // therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null
- return block.isPassable(null, BlockPos.ORIGIN);
+
+ return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z));
}
/**
@@ -149,10 +148,18 @@ public interface MovementHelper extends ActionCosts, Helper {
* @return Whether or not the block at the specified position
*/
static boolean fullyPassable(CalculationContext context, int x, int y, int z) {
- return fullyPassable(context.get(x, y, z));
+ return fullyPassable(
+ context.bsi.access,
+ context.bsi.isPassableBlockPos.setPos(x, y, z),
+ context.bsi.get0(x, y, z)
+ );
}
- static boolean fullyPassable(IBlockState state) {
+ static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) {
+ return fullyPassable(ctx.world(), pos, ctx.world().getBlockState(pos));
+ }
+
+ static boolean fullyPassable(IBlockAccess access, BlockPos pos, IBlockState state) {
Block block = state.getBlock();
if (block == Blocks.AIR) { // early return for most common case
return true;
@@ -174,7 +181,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
- return block.isPassable(null, null);
+ return block.isPassable(access, pos);
}
static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
index eb032210..3d3426da 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
@@ -114,7 +114,7 @@ public class MovementParkour extends Movement {
return;
}
IBlockState destInto = context.bsi.get0(destX, y, destZ);
- if (!MovementHelper.fullyPassable(destInto)) {
+ if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) {
if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) {
res.x = destX;
res.y = y + 1;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
index d28ff32c..f6f8fc0d 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
@@ -195,7 +195,7 @@ public class MovementPillar extends Movement {
if (ladder) {
BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
if (against == null) {
- logDebug("Unable to climb vines");
+ logDirect("Unable to climb vines. Consider disabling allowVines.");
return state.setStatus(MovementStatus.UNREACHABLE);
}
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
index 29ac1cec..9990ed74 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
@@ -261,6 +261,10 @@ public class MovementTraverse extends Movement {
BlockPos against = positionsToBreak[0];
if (feet.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.getValue(BlockLadder.FACING).getOpposite());
+ if (against == null) {
+ logDirect("Unable to climb vines. Consider disabling allowVines.");
+ return state.setStatus(MovementStatus.UNREACHABLE);
+ }
}
MovementHelper.moveTowards(ctx, state, against);
return state;
diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java
index 97bee424..7e4f76a3 100644
--- a/src/main/java/baritone/pathing/path/PathExecutor.java
+++ b/src/main/java/baritone/pathing/path/PathExecutor.java
@@ -466,7 +466,7 @@ public class PathExecutor implements IPathExecutor, Helper {
}
for (int y = next.getDest().y; y <= movement.getSrc().y + 1; y++) {
BlockPos chk = new BlockPos(next.getDest().x, y, next.getDest().z);
- if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) {
+ if (!MovementHelper.fullyPassable(ctx, chk)) {
break outer;
}
}
@@ -491,7 +491,7 @@ public class PathExecutor implements IPathExecutor, Helper {
}
// we are centered
BlockPos headBonk = current.getSrc().subtract(current.getDirection()).up(2);
- if (MovementHelper.fullyPassable(ctx.world().getBlockState(headBonk))) {
+ if (MovementHelper.fullyPassable(ctx, headBonk)) {
return true;
}
// wait 0.3
@@ -524,7 +524,7 @@ public class PathExecutor implements IPathExecutor, Helper {
if (x == 1) {
chk = chk.add(current.getDirection());
}
- if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) {
+ if (!MovementHelper.fullyPassable(ctx, chk)) {
return false;
}
}
diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java
index 687e6c98..4efa2c95 100644
--- a/src/main/java/baritone/process/BuilderProcess.java
+++ b/src/main/java/baritone/process/BuilderProcess.java
@@ -25,7 +25,14 @@ import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.process.IBuilderProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
-import baritone.api.utils.*;
+import baritone.api.schematic.FillSchematic;
+import baritone.api.schematic.ISchematic;
+import baritone.api.schematic.IStaticSchematic;
+import baritone.api.schematic.format.ISchematicFormat;
+import baritone.api.utils.BetterBlockPos;
+import baritone.api.utils.RayTraceUtils;
+import baritone.api.utils.Rotation;
+import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
@@ -33,9 +40,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.PathingCommandContext;
-import baritone.utils.schematic.FillSchematic;
import baritone.utils.schematic.MapArtSchematic;
-import baritone.utils.schematic.Schematic;
+import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.schematica.SchematicaHelper;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.block.BlockAir;
@@ -44,15 +50,12 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.CompressedStreamTools;
-import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.*;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.util.*;
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
@@ -68,6 +71,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private int ticks;
private boolean paused;
private int layer;
+ private int numRepeats;
private List approxPlaceable;
public BuilderProcess(Baritone baritone) {
@@ -94,6 +98,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
this.origin = new Vec3i(x, y, z);
this.paused = false;
this.layer = 0;
+ this.numRepeats = 0;
this.observedCompleted = new LongOpenHashSet();
}
@@ -112,27 +117,38 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
@Override
public boolean build(String name, File schematic, Vec3i origin) {
- NBTTagCompound tag;
- try (FileInputStream fileIn = new FileInputStream(schematic)) {
- tag = CompressedStreamTools.readCompressed(fileIn);
- } catch (IOException e) {
+ Optional format = SchematicSystem.INSTANCE.getByFile(schematic);
+ if (!format.isPresent()) {
+ return false;
+ }
+
+ ISchematic parsed;
+ try {
+ parsed = format.get().parse(new FileInputStream(schematic));
+ } catch (Exception e) {
e.printStackTrace();
return false;
}
- //noinspection ConstantConditions
- if (tag == null) {
- return false;
+
+ if (Baritone.settings().mapArtMode.value) {
+ parsed = new MapArtSchematic((IStaticSchematic) parsed);
}
- build(name, parse(tag), origin);
+
+ build(name, parsed, origin);
return true;
}
@Override
public void buildOpenSchematic() {
if (SchematicaHelper.isSchematicaPresent()) {
- Optional> schematic = SchematicaHelper.getOpenSchematic();
+ Optional> schematic = SchematicaHelper.getOpenSchematic();
if (schematic.isPresent()) {
- this.build(schematic.get().getFirst().toString(), schematic.get().getFirst(), schematic.get().getSecond());
+ IStaticSchematic s = schematic.get().getFirst();
+ this.build(
+ schematic.get().getFirst().toString(),
+ Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s,
+ schematic.get().getSecond()
+ );
} else {
logDirect("No schematic currently open");
}
@@ -154,10 +170,6 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return new ArrayList<>(approxPlaceable);
}
- private static ISchematic parse(NBTTagCompound schematic) {
- return Baritone.settings().mapArtMode.value ? new MapArtSchematic(schematic) : new Schematic(schematic);
- }
-
@Override
public boolean isActive() {
return schematic != null;
@@ -390,7 +402,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return onTick(calcFailed, isSafeToCancel);
}
Vec3i repeat = Baritone.settings().buildRepeat.value;
- if (repeat.equals(new Vec3i(0, 0, 0))) {
+ int max = Baritone.settings().buildRepeatCount.value;
+ numRepeats++;
+ if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
logDirect("Done building");
onLostControl();
return null;
@@ -730,6 +744,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
schematic = null;
realSchematic = null;
layer = 0;
+ numRepeats = 0;
paused = false;
observedCompleted = null;
}
@@ -755,11 +770,20 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
private boolean valid(IBlockState current, IBlockState desired) {
+ if (desired == null) {
+ return true;
+ }
// TODO more complicated comparison logic I guess
if (current.getBlock() instanceof BlockLiquid && Baritone.settings().okIfWater.value) {
return true;
}
- return desired == null || current.equals(desired);
+ if (desired.getBlock() instanceof BlockAir && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) {
+ return true;
+ }
+ if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value) {
+ return true;
+ }
+ return current.equals(desired);
}
public class BuilderCalculationContext extends CalculationContext {
diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java
index a723ebc5..7fe913ac 100644
--- a/src/main/java/baritone/utils/BaritoneAutoTest.java
+++ b/src/main/java/baritone/utils/BaritoneAutoTest.java
@@ -29,9 +29,7 @@ import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.tutorial.TutorialSteps;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.GameType;
-import net.minecraft.world.WorldSettings;
-import net.minecraft.world.WorldType;
+import net.minecraft.world.*;
/**
* Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific
@@ -85,15 +83,21 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
if (mc.currentScreen instanceof GuiMainMenu) {
System.out.println("Beginning Baritone automatic test routine");
mc.displayGuiScreen(null);
- WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.getByName("survival"), true, false, WorldType.DEFAULT);
+ WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.SURVIVAL, true, false, WorldType.DEFAULT);
mc.launchIntegratedServer("BaritoneAutoTest", "BaritoneAutoTest", worldsettings);
}
- // If the integrated server is launched and the world has initialized, set the spawn point
- // to our defined starting position
- if (mc.getIntegratedServer() != null && mc.getIntegratedServer().worlds[0] != null) {
- mc.getIntegratedServer().worlds[0].setSpawnPoint(STARTING_POSITION);
- mc.getIntegratedServer().worlds[0].getGameRules().setOrCreateGameRule("spawnRadius", "0");
+ // If the integrated server is running, set the difficulty to peaceful
+ if (mc.getIntegratedServer() != null) {
+ mc.getIntegratedServer().setDifficultyForAllWorlds(EnumDifficulty.PEACEFUL);
+
+ for (final WorldServer world : mc.getIntegratedServer().worlds) {
+ // If the world has initialized, set the spawn point to our defined starting position
+ if (world != null) {
+ world.setSpawnPoint(STARTING_POSITION);
+ world.getGameRules().setOrCreateGameRule("spawnRadius", "0");
+ }
+ }
}
if (event.getType() == TickEvent.Type.IN) { // If we're in-game
@@ -101,7 +105,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
// Force the integrated server to share the world to LAN so that
// the ingame pause menu gui doesn't actually pause our game
if (mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) {
- mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false);
+ mc.getIntegratedServer().shareToLAN(GameType.SURVIVAL, false);
}
// For the first 200 ticks, wait for the world to generate
diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java
index 84bdce5f..4f5f2689 100644
--- a/src/main/java/baritone/utils/BlockStateInterface.java
+++ b/src/main/java/baritone/utils/BlockStateInterface.java
@@ -30,6 +30,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
+import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
@@ -42,6 +43,9 @@ public class BlockStateInterface {
private final Long2ObjectMap loadedChunks;
private final WorldData worldData;
+ protected final IBlockAccess world;
+ public final BlockPos.MutableBlockPos isPassableBlockPos;
+ public final IBlockAccess access;
private Chunk prev = null;
private CachedRegion prevCached = null;
@@ -59,6 +63,7 @@ public class BlockStateInterface {
}
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
+ this.world = world;
this.worldData = worldData;
Long2ObjectMap worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
if (copyLoadedChunks) {
@@ -70,6 +75,8 @@ public class BlockStateInterface {
if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
throw new IllegalStateException();
}
+ this.isPassableBlockPos = new BlockPos.MutableBlockPos();
+ this.access = new BlockStateInterfaceAccessWrapper(this);
}
public boolean worldContainsLoadedChunk(int blockX, int blockZ) {
diff --git a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java
new file mode 100644
index 00000000..6ce70193
--- /dev/null
+++ b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java
@@ -0,0 +1,80 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.utils;
+
+import net.minecraft.block.material.Material;
+import net.minecraft.block.state.IBlockState;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.WorldType;
+import net.minecraft.world.biome.Biome;
+
+import javax.annotation.Nullable;
+
+/**
+ * @author Brady
+ * @since 11/5/2019
+ */
+@SuppressWarnings("NullableProblems")
+public final class BlockStateInterfaceAccessWrapper implements IBlockAccess {
+
+ private final BlockStateInterface bsi;
+
+ BlockStateInterfaceAccessWrapper(BlockStateInterface bsi) {
+ this.bsi = bsi;
+ }
+
+ @Nullable
+ @Override
+ public TileEntity getTileEntity(BlockPos pos) {
+ throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper");
+ }
+
+ @Override
+ public int getCombinedLight(BlockPos pos, int lightValue) {
+ throw new UnsupportedOperationException("getCombinedLight not supported by BlockStateInterfaceAccessWrapper");
+ }
+
+ @Override
+ public IBlockState getBlockState(BlockPos pos) {
+ // BlockStateInterface#get0(BlockPos) btfo!
+ return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ());
+ }
+
+ @Override
+ public boolean isAirBlock(BlockPos pos) {
+ return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ()).getMaterial() == Material.AIR;
+ }
+
+ @Override
+ public Biome getBiome(BlockPos pos) {
+ throw new UnsupportedOperationException("getBiome not supported by BlockStateInterfaceAccessWrapper");
+ }
+
+ @Override
+ public int getStrongPower(BlockPos pos, EnumFacing direction) {
+ throw new UnsupportedOperationException("getStrongPower not supported by BlockStateInterfaceAccessWrapper");
+ }
+
+ @Override
+ public WorldType getWorldType() {
+ return this.bsi.world.getWorldType();
+ }
+}
diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java
index 90f06bb0..b6446b30 100644
--- a/src/main/java/baritone/utils/ToolSet.java
+++ b/src/main/java/baritone/utils/ToolSet.java
@@ -99,15 +99,15 @@ public class ToolSet {
* Calculate which tool on the hotbar is best for mining
*
* @param b the blockstate to be mined
- * @return A byte containing the index in the tools array that worked best
+ * @return An int containing the index in the tools array that worked best
*/
- public byte getBestSlot(Block b, boolean preferSilkTouch) {
- byte best = 0;
+ public int getBestSlot(Block b, boolean preferSilkTouch) {
+ int best = 0;
double highestSpeed = Double.NEGATIVE_INFINITY;
int lowestCost = Integer.MIN_VALUE;
boolean bestSilkTouch = false;
IBlockState blockState = b.getDefaultState();
- for (byte i = 0; i < 9; i++) {
+ for (int i = 0; i < 9; i++) {
ItemStack itemStack = player.inventory.getStackInSlot(i);
double speed = calculateSpeedVsBlock(itemStack, blockState);
boolean silkTouch = hasSilkTouch(itemStack);
diff --git a/src/main/java/baritone/utils/accessor/IBitArray.java b/src/main/java/baritone/utils/accessor/IBitArray.java
index 81501036..baea5c1d 100644
--- a/src/main/java/baritone/utils/accessor/IBitArray.java
+++ b/src/main/java/baritone/utils/accessor/IBitArray.java
@@ -2,7 +2,5 @@ package baritone.utils.accessor;
public interface IBitArray {
- int getAtFast(int index);
-
int[] toArray();
}
diff --git a/src/main/java/baritone/utils/accessor/IBlockStateContainer.java b/src/main/java/baritone/utils/accessor/IBlockStateContainer.java
index 7c47a9b8..39572fc5 100644
--- a/src/main/java/baritone/utils/accessor/IBlockStateContainer.java
+++ b/src/main/java/baritone/utils/accessor/IBlockStateContainer.java
@@ -1,17 +1,9 @@
package baritone.utils.accessor;
import net.minecraft.block.state.IBlockState;
-import net.minecraft.util.BitArray;
-import net.minecraft.world.chunk.IBlockStatePalette;
public interface IBlockStateContainer {
- IBlockStatePalette getPalette();
-
- BitArray getStorage();
-
- IBlockState getFast(int index);
-
IBlockState getAtPalette(int index);
int[] storageArray();
diff --git a/src/api/java/baritone/api/accessor/IGuiScreen.java b/src/main/java/baritone/utils/accessor/IGuiScreen.java
similarity index 95%
rename from src/api/java/baritone/api/accessor/IGuiScreen.java
rename to src/main/java/baritone/utils/accessor/IGuiScreen.java
index ba01e275..beb5df31 100644
--- a/src/api/java/baritone/api/accessor/IGuiScreen.java
+++ b/src/main/java/baritone/utils/accessor/IGuiScreen.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package baritone.api.accessor;
+package baritone.utils.accessor;
import java.net.URI;
diff --git a/src/main/java/baritone/utils/accessor/ITabCompleter.java b/src/main/java/baritone/utils/accessor/ITabCompleter.java
deleted file mode 100644
index e187c3e6..00000000
--- a/src/main/java/baritone/utils/accessor/ITabCompleter.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package baritone.utils.accessor;
-
-public interface ITabCompleter {
-
- String getPrefix();
-
- void setPrefix(String prefix);
-
- boolean onGuiChatSetCompletions(String[] newCompl);
-}
diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java
index 32b3292c..31442261 100644
--- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java
+++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java
@@ -17,24 +17,34 @@
package baritone.utils.schematic;
+import baritone.api.schematic.IStaticSchematic;
+import baritone.api.schematic.MaskSchematic;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.IBlockState;
-import net.minecraft.nbt.NBTTagCompound;
import java.util.OptionalInt;
import java.util.function.Predicate;
-public class MapArtSchematic extends Schematic {
+public class MapArtSchematic extends MaskSchematic {
private final int[][] heightMap;
- public MapArtSchematic(NBTTagCompound schematic) {
+ public MapArtSchematic(IStaticSchematic schematic) {
super(schematic);
- heightMap = new int[widthX][lengthZ];
+ this.heightMap = generateHeightMap(schematic);
+ }
- for (int x = 0; x < widthX; x++) {
- for (int z = 0; z < lengthZ; z++) {
- IBlockState[] column = states[x][z];
+ @Override
+ protected boolean partOfMask(int x, int y, int z, IBlockState currentState) {
+ return y >= this.heightMap[x][z];
+ }
+
+ private static int[][] generateHeightMap(IStaticSchematic schematic) {
+ int[][] heightMap = new int[schematic.widthX()][schematic.lengthZ()];
+
+ for (int x = 0; x < schematic.widthX(); x++) {
+ for (int z = 0; z < schematic.lengthZ(); z++) {
+ IBlockState[] column = schematic.getColumn(x, z);
OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir));
if (lowestBlockY.isPresent()) {
@@ -44,9 +54,9 @@ public class MapArtSchematic extends Schematic {
System.out.println("Letting it be whatever");
heightMap[x][z] = 256;
}
-
}
}
+ return heightMap;
}
private static OptionalInt lastIndexMatching(T[] arr, Predicate super T> predicate) {
@@ -57,10 +67,4 @@ public class MapArtSchematic extends Schematic {
}
return OptionalInt.empty();
}
-
- @Override
- public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
- // in map art, we only care about coordinates in or above the art
- return super.inSchematic(x, y, z, currentState) && y >= heightMap[x][z];
- }
}
diff --git a/src/main/java/baritone/utils/schematic/SchematicSystem.java b/src/main/java/baritone/utils/schematic/SchematicSystem.java
new file mode 100644
index 00000000..8afafa8c
--- /dev/null
+++ b/src/main/java/baritone/utils/schematic/SchematicSystem.java
@@ -0,0 +1,51 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.utils.schematic;
+
+import baritone.api.command.registry.Registry;
+import baritone.api.schematic.ISchematicSystem;
+import baritone.api.schematic.format.ISchematicFormat;
+import baritone.utils.schematic.format.DefaultSchematicFormats;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Optional;
+
+/**
+ * @author Brady
+ * @since 12/24/2019
+ */
+public enum SchematicSystem implements ISchematicSystem {
+ INSTANCE;
+
+ private final Registry registry = new Registry<>();
+
+ SchematicSystem() {
+ Arrays.stream(DefaultSchematicFormats.values()).forEach(this.registry::register);
+ }
+
+ @Override
+ public Registry getRegistry() {
+ return this.registry;
+ }
+
+ @Override
+ public Optional getByFile(File file) {
+ return this.registry.stream().filter(format -> format.isFileType(file)).findFirst();
+ }
+}
diff --git a/src/main/java/baritone/utils/schematic/FillSchematic.java b/src/main/java/baritone/utils/schematic/StaticSchematic.java
similarity index 61%
rename from src/main/java/baritone/utils/schematic/FillSchematic.java
rename to src/main/java/baritone/utils/schematic/StaticSchematic.java
index 3216f59f..2251450a 100644
--- a/src/main/java/baritone/utils/schematic/FillSchematic.java
+++ b/src/main/java/baritone/utils/schematic/StaticSchematic.java
@@ -17,42 +17,34 @@
package baritone.utils.schematic;
-import baritone.api.utils.ISchematic;
+import baritone.api.schematic.AbstractSchematic;
+import baritone.api.schematic.IStaticSchematic;
import net.minecraft.block.state.IBlockState;
import java.util.List;
-public class FillSchematic implements ISchematic {
+/**
+ * Default implementation of {@link IStaticSchematic}
+ *
+ * @author Brady
+ * @since 12/23/2019
+ */
+public class StaticSchematic extends AbstractSchematic implements IStaticSchematic {
- private final int widthX;
- private final int heightY;
- private final int lengthZ;
- private final IBlockState state;
-
- public FillSchematic(int widthX, int heightY, int lengthZ, IBlockState state) {
- this.widthX = widthX;
- this.heightY = heightY;
- this.lengthZ = lengthZ;
- this.state = state;
- }
+ protected IBlockState[][][] states;
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) {
- return state;
+ return this.states[x][z][y];
}
@Override
- public int widthX() {
- return widthX;
+ public IBlockState getDirect(int x, int y, int z) {
+ return this.states[x][z][y];
}
@Override
- public int heightY() {
- return heightY;
- }
-
- @Override
- public int lengthZ() {
- return lengthZ;
+ public IBlockState[] getColumn(int x, int z) {
+ return this.states[x][z];
}
}
diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java
new file mode 100644
index 00000000..942bd72a
--- /dev/null
+++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java
@@ -0,0 +1,82 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.utils.schematic.format;
+
+import baritone.api.schematic.IStaticSchematic;
+import baritone.api.schematic.format.ISchematicFormat;
+import baritone.utils.schematic.format.defaults.MCEditSchematic;
+import baritone.utils.schematic.format.defaults.SpongeSchematic;
+import net.minecraft.nbt.CompressedStreamTools;
+import net.minecraft.nbt.NBTTagCompound;
+import org.apache.commons.io.FilenameUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Default implementations of {@link ISchematicFormat}
+ *
+ * @author Brady
+ * @since 12/13/2019
+ */
+public enum DefaultSchematicFormats implements ISchematicFormat {
+
+ /**
+ * The MCEdit schematic specification. Commonly denoted by the ".schematic" file extension.
+ */
+ MCEDIT("schematic") {
+
+ @Override
+ public IStaticSchematic parse(InputStream input) throws IOException {
+ return new MCEditSchematic(CompressedStreamTools.readCompressed(input));
+ }
+ },
+
+ /**
+ * The SpongePowered Schematic Specification. Commonly denoted by the ".schem" file extension.
+ *
+ * @see Sponge Schematic Specification
+ */
+ SPONGE("schem") {
+
+ @Override
+ public IStaticSchematic parse(InputStream input) throws IOException {
+ NBTTagCompound nbt = CompressedStreamTools.readCompressed(input);
+ int version = nbt.getInteger("Version");
+ switch (version) {
+ case 1:
+ case 2:
+ return new SpongeSchematic(nbt);
+ default:
+ throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic");
+ }
+ }
+ };
+
+ private final String extension;
+
+ DefaultSchematicFormats(String extension) {
+ this.extension = extension;
+ }
+
+ @Override
+ public boolean isFileType(File file) {
+ return this.extension.equalsIgnoreCase(FilenameUtils.getExtension(file.getAbsolutePath()));
+ }
+}
diff --git a/src/main/java/baritone/utils/schematic/Schematic.java b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java
similarity index 63%
rename from src/main/java/baritone/utils/schematic/Schematic.java
rename to src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java
index 47461e60..08e571c9 100644
--- a/src/main/java/baritone/utils/schematic/Schematic.java
+++ b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java
@@ -15,30 +15,27 @@
* along with Baritone. If not, see .
*/
-package baritone.utils.schematic;
+package baritone.utils.schematic.format.defaults;
-import baritone.api.utils.ISchematic;
+import baritone.utils.schematic.StaticSchematic;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
-import java.util.List;
+/**
+ * @author Brady
+ * @since 12/27/2019
+ */
+public final class MCEditSchematic extends StaticSchematic {
-public class Schematic implements ISchematic {
-
- public final int widthX;
- public final int heightY;
- public final int lengthZ;
- protected final IBlockState[][][] states;
-
- public Schematic(NBTTagCompound schematic) {
+ public MCEditSchematic(NBTTagCompound schematic) {
String type = schematic.getString("Materials");
if (!type.equals("Alpha")) {
throw new IllegalStateException("bad schematic " + type);
}
- widthX = schematic.getInteger("Width");
- heightY = schematic.getInteger("Height");
- lengthZ = schematic.getInteger("Length");
+ this.x = schematic.getInteger("Width");
+ this.y = schematic.getInteger("Height");
+ this.z = schematic.getInteger("Length");
byte[] blocks = schematic.getByteArray("Blocks");
byte[] metadata = schematic.getByteArray("Data");
@@ -51,11 +48,11 @@ public class Schematic implements ISchematic {
additional[i * 2 + 1] = (byte) ((addBlocks[i] >> 0) & 0xF); // upper nibble
}
}
- states = new IBlockState[widthX][lengthZ][heightY];
- for (int y = 0; y < heightY; y++) {
- for (int z = 0; z < lengthZ; z++) {
- for (int x = 0; x < widthX; x++) {
- int blockInd = (y * lengthZ + z) * widthX + x;
+ this.states = new IBlockState[this.x][this.z][this.y];
+ for (int y = 0; y < this.y; y++) {
+ for (int z = 0; z < this.z; z++) {
+ for (int x = 0; x < this.x; x++) {
+ int blockInd = (y * this.z + z) * this.x + x;
int blockID = blocks[blockInd] & 0xFF;
if (additional != null) {
@@ -64,29 +61,9 @@ public class Schematic implements ISchematic {
}
Block block = Block.REGISTRY.getObjectById(blockID);
int meta = metadata[blockInd] & 0xFF;
- states[x][z][y] = block.getStateFromMeta(meta);
+ this.states[x][z][y] = block.getStateFromMeta(meta);
}
}
}
}
-
- @Override
- public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) {
- return states[x][z][y];
- }
-
- @Override
- public int widthX() {
- return widthX;
- }
-
- @Override
- public int heightY() {
- return heightY;
- }
-
- @Override
- public int lengthZ() {
- return lengthZ;
- }
}
diff --git a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java
new file mode 100644
index 00000000..8de038f5
--- /dev/null
+++ b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java
@@ -0,0 +1,157 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.utils.schematic.format.defaults;
+
+import baritone.utils.schematic.StaticSchematic;
+import baritone.utils.type.VarInt;
+import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
+import net.minecraft.block.Block;
+import net.minecraft.block.properties.IProperty;
+import net.minecraft.block.state.IBlockState;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.ResourceLocation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Brady
+ * @since 12/27/2019
+ */
+public final class SpongeSchematic extends StaticSchematic {
+
+ public SpongeSchematic(NBTTagCompound nbt) {
+ this.x = nbt.getInteger("Width");
+ this.y = nbt.getInteger("Height");
+ this.z = nbt.getInteger("Length");
+ this.states = new IBlockState[this.x][this.z][this.y];
+
+ Int2ObjectArrayMap palette = new Int2ObjectArrayMap<>();
+ NBTTagCompound paletteTag = nbt.getCompoundTag("Palette");
+ for (String tag : paletteTag.getKeySet()) {
+ int index = paletteTag.getInteger(tag);
+
+ SerializedBlockState serializedState = SerializedBlockState.getFromString(tag);
+ if (serializedState == null) {
+ throw new IllegalArgumentException("Unable to parse palette tag");
+ }
+
+ IBlockState state = serializedState.deserialize();
+ if (state == null) {
+ throw new IllegalArgumentException("Unable to deserialize palette tag");
+ }
+
+ palette.put(index, state);
+ }
+
+ // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[]
+ byte[] rawBlockData = nbt.getByteArray("BlockData");
+ int[] blockData = new int[this.x * this.y * this.z];
+ int offset = 0;
+ for (int i = 0; i < blockData.length; i++) {
+ if (offset >= rawBlockData.length) {
+ throw new IllegalArgumentException("No remaining bytes in BlockData for complete schematic");
+ }
+
+ VarInt varInt = VarInt.read(rawBlockData, offset);
+ blockData[i] = varInt.getValue();
+ offset += varInt.getSize();
+ }
+
+ for (int y = 0; y < this.y; y++) {
+ for (int z = 0; z < this.z; z++) {
+ for (int x = 0; x < this.x; x++) {
+ int index = (y * this.z + z) * this.x + x;
+ IBlockState state = palette.get(blockData[index]);
+ if (state == null) {
+ throw new IllegalArgumentException("Invalid Palette Index " + index);
+ }
+
+ this.states[x][z][y] = state;
+ }
+ }
+ }
+ }
+
+ private static final class SerializedBlockState {
+
+ private static final Pattern REGEX = Pattern.compile("(?(\\w+:)?\\w+)(\\[(?(\\w+=\\w+,?)+)])?");
+
+ private final ResourceLocation resourceLocation;
+ private final Map properties;
+ private IBlockState blockState;
+
+ private SerializedBlockState(ResourceLocation resourceLocation, Map properties) {
+ this.resourceLocation = resourceLocation;
+ this.properties = properties;
+ }
+
+ private IBlockState deserialize() {
+ if (this.blockState == null) {
+ Block block = Block.REGISTRY.getObject(this.resourceLocation);
+ this.blockState = block.getDefaultState();
+
+ this.properties.keySet().stream().sorted(String::compareTo).forEachOrdered(key -> {
+ IProperty> property = block.getBlockState().getProperty(key);
+ if (property != null) {
+ this.blockState = setPropertyValue(this.blockState, property, this.properties.get(key));
+ }
+ });
+ }
+ return this.blockState;
+ }
+
+ private static SerializedBlockState getFromString(String s) {
+ Matcher m = REGEX.matcher(s);
+ if (!m.matches()) {
+ return null;
+ }
+
+ try {
+ String location = m.group("location");
+ String properties = m.group("properties");
+
+ ResourceLocation resourceLocation = new ResourceLocation(location);
+ Map propertiesMap = new HashMap<>();
+ if (properties != null) {
+ for (String property : properties.split(",")) {
+ String[] split = property.split("=");
+ propertiesMap.put(split[0], split[1]);
+ }
+ }
+
+ return new SerializedBlockState(resourceLocation, propertiesMap);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) {
+ Optional parsed = property.parseValue(value).toJavaUtil();
+ if (parsed.isPresent()) {
+ return state.withProperty(property, parsed.get());
+ } else {
+ throw new IllegalArgumentException("Invalid value for property " + property);
+ }
+ }
+ }
+}
diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java
index 38279031..0ae3edab 100644
--- a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java
+++ b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java
@@ -17,14 +17,14 @@
package baritone.utils.schematic.schematica;
-import baritone.api.utils.ISchematic;
+import baritone.api.schematic.IStaticSchematic;
import com.github.lunatrius.schematica.client.world.SchematicWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import java.util.List;
-public final class SchematicAdapter implements ISchematic {
+public final class SchematicAdapter implements IStaticSchematic {
private final SchematicWorld schematic;
@@ -34,7 +34,12 @@ public final class SchematicAdapter implements ISchematic {
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) {
- return schematic.getSchematic().getBlockState(new BlockPos(x, y, z));
+ return this.getDirect(x, y, z);
+ }
+
+ @Override
+ public IBlockState getDirect(int x, int y, int z) {
+ return this.schematic.getSchematic().getBlockState(new BlockPos(x, y, z));
}
@Override
diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java
index bacf1e9d..fab68845 100644
--- a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java
+++ b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java
@@ -17,7 +17,7 @@
package baritone.utils.schematic.schematica;
-import baritone.api.utils.ISchematic;
+import baritone.api.schematic.IStaticSchematic;
import com.github.lunatrius.schematica.Schematica;
import com.github.lunatrius.schematica.proxy.ClientProxy;
import net.minecraft.util.Tuple;
@@ -37,7 +37,7 @@ public enum SchematicaHelper {
}
}
- public static Optional> getOpenSchematic() {
+ public static Optional> getOpenSchematic() {
return Optional.ofNullable(ClientProxy.schematic)
.map(world -> new Tuple<>(new SchematicAdapter(world), world.position));
}
diff --git a/src/main/java/baritone/utils/type/VarInt.java b/src/main/java/baritone/utils/type/VarInt.java
new file mode 100644
index 00000000..7cc005bd
--- /dev/null
+++ b/src/main/java/baritone/utils/type/VarInt.java
@@ -0,0 +1,95 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.utils.type;
+
+import it.unimi.dsi.fastutil.bytes.ByteArrayList;
+import it.unimi.dsi.fastutil.bytes.ByteList;
+
+/**
+ * @author Brady
+ * @since 12/19/2019
+ */
+public final class VarInt {
+
+ private final int value;
+ private final byte[] serialized;
+ private final int size;
+
+ public VarInt(int value) {
+ this.value = value;
+ this.serialized = serialize0(this.value);
+ this.size = this.serialized.length;
+ }
+
+ /**
+ * @return The integer value that is represented by this {@link VarInt}.
+ */
+ public final int getValue() {
+ return this.value;
+ }
+
+ /**
+ * @return The size of this {@link VarInt}, in bytes, once serialized.
+ */
+ public final int getSize() {
+ return this.size;
+ }
+
+ public final byte[] serialize() {
+ return this.serialized;
+ }
+
+ private static byte[] serialize0(int valueIn) {
+ ByteList bytes = new ByteArrayList();
+
+ int value = valueIn;
+ while ((value & 0x80) != 0) {
+ bytes.add((byte) (value & 0x7F | 0x80));
+ value >>>= 7;
+ }
+ bytes.add((byte) (value & 0xFF));
+
+ return bytes.toByteArray();
+ }
+
+ public static VarInt read(byte[] bytes) {
+ return read(bytes, 0);
+ }
+
+ public static VarInt read(byte[] bytes, int start) {
+ int value = 0;
+ int size = 0;
+ int index = start;
+
+ while (true) {
+ byte b = bytes[index++];
+ value |= (b & 0x7F) << size++ * 7;
+
+ if (size > 5) {
+ throw new IllegalArgumentException("VarInt size cannot exceed 5 bytes");
+ }
+
+ // Most significant bit denotes another byte is to be read.
+ if ((b & 0x80) == 0) {
+ break;
+ }
+ }
+
+ return new VarInt(value);
+ }
+}