diff --git a/README.md b/README.md
index e2c83ddec..c6a90ff93 100644
--- a/README.md
+++ b/README.md
@@ -4,13 +4,16 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -33,7 +36,7 @@
-
+
@@ -48,21 +51,26 @@
A Minecraft pathfinder bot.
-[**Baritone Discord Server**](http://discord.gg/s6fRBAUpmr)
-
-Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do.
+Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do.
-[Tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa)
+[**Baritone Discord Server**](http://discord.gg/s6fRBAUpmr)
-The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to
-install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click
-[here](https://github.com/cabaletta/baritone/releases/download/v1.2.17/baritone-api-forge-1.2.17.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it.
+**Quick download links:**
-For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. If you need Forge or Fabric 1.16.5, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.6.3) and get the `api-forge` or `api-fabric` jar. **For 1.16.5 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.6.3/baritone-api-fabric-1.6.3.jar)**.
+| Forge | Fabric |
+|---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
+| [1.12.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.2.17/baritone-api-forge-1.2.17.jar) | |
+| [1.16.5 Forge](https://github.com/cabaletta/baritone/releases/download/v1.6.4/baritone-api-forge-1.6.4.jar) | [1.16.5 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.6.4/baritone-api-fabric-1.6.4.jar) |
+| [1.17.1 Forge](https://github.com/cabaletta/baritone/releases/download/v1.7.3/baritone-api-forge-1.7.3.jar) | [1.17.1 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.7.3/baritone-api-fabric-1.7.3.jar) |
+| [1.18.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.8.4/baritone-api-forge-1.8.4.jar) | [1.18.2 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.8.4/baritone-api-fabric-1.8.4.jar) |
+| [1.19.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.4/baritone-api-forge-1.9.4.jar) | [1.19.2 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.4/baritone-api-fabric-1.9.4.jar) |
+| [1.19.3 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-forge-1.9.1.jar) | [1.19.3 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-fabric-1.9.1.jar) |
+| [1.19.4 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-forge-1.9.3.jar) | [1.19.4 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-fabric-1.9.3.jar) |
+| [1.20.1 Forge](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-forge-1.10.1.jar) | [1.20.1 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-fabric-1.10.1.jar) |
-If you need Forge or Fabric 1.17.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.7.2) and get the `api-forge` or `api-fabric` jar. **For 1.17.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.7.2/baritone-api-fabric-1.7.2.jar)**.
+**How to immediately get started:** Type `#goto 1000 500` in chat to go to x=1000 z=500. Type `#mine diamond_ore` to mine diamond ore. Type `#stop` to stop. For more, read [the usage page](USAGE.md) and/or watch this [tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa)
-If you need Forge or Fabric 1.18.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.8.3) and get the `api-forge` or `api-fabric` jar. **For 1.18.2 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.3/baritone-api-fabric-1.8.3.jar)**. **For 1.18.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.3/baritone-api-forge-1.8.3.jar)**.
+For other versions of Minecraft or more complicated situations or for development, see [Installation & setup](SETUP.md). Also consider just installing [Impact](https://impactclient.net/), which comes with Baritone and is easier to install than wrangling with version JSONs and zips. For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#6313 on Baritone which I recommend.
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 onwards. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
diff --git a/SETUP.md b/SETUP.md
index 57866b192..1daeb9f89 100644
--- a/SETUP.md
+++ b/SETUP.md
@@ -43,13 +43,13 @@ If another one of your Forge mods has a Baritone integration, you want `baritone
## Command Line
On Mac OSX and Linux, use `./gradlew` instead of `gradlew`.
-If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8 for 1.12.2-1.16.5, JDK 16 for 1.17.1, and JDK 17 for 1.18.1.
+If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8 for 1.12.2-1.16.5, JDK 16+ for 1.17.1, and JDK 17+ for 1.18.1.
To check which java you are using do
`java -version` in a command prompt or terminal.
If you are using anything above OpenJDK 8 for 1.12.2-1.16.5, it might not work because the Java distributions above JDK 8 using may not have the needed javax classes.
-Open JDK download: https://openjdk.java.net/install/
+Download java: https://adoptium.net/
#### macOS guide
In order to get JDK 8, Try running the following command:
`% /usr/libexec/java_home -V`
@@ -66,68 +66,13 @@ In order to get JDK 8 running in the **current terminal window** you will have t
To add OpenJDK 8 to your PATH add the export line to the end of your `.zshrc / .bashrc` if you want it to apply to each new terminal. If you're using bash change the .bachrc and if you're using zsh change the .zshrc
-Setting up the Environment:
+### Building Baritone
-```
-$ gradlew setupDecompWorkspace
-$ gradlew --refresh-dependencies
-```
+These tasks depend on the minecraft version, but are (for the most part) standard for building mods.
-Building Baritone:
-
-```
-$ gradlew build
-```
-
-For minecraft 1.15.2+, run the following instead to include the Forge jars:
-
-```
-$ gradlew build -Pbaritone.forge_build
-```
-
-Do this instead for Fabric jars:
-
-```
-$ gradlew build -Pbaritone.fabric_build
-```
-
-Running Baritone:
-
-```
-$ gradlew runClient
-```
-
-For information on how to build baritone, see [Building Baritone](#building-baritone)
+for more details, see [the build ci action](/.github/workflows/gradle_build.yml)
## IntelliJ
- Open the project in IntelliJ as a Gradle project
-
- ![Image](https://i.imgur.com/jw7Q6vY.png)
-
-- Run the Gradle tasks `setupDecompWorkspace` then `genIntellijRuns`
-
- ![Image](https://i.imgur.com/QEfVvWP.png)
-
- Refresh the Gradle project (or, to be safe, just restart IntelliJ)
-
- ![Image](https://i.imgur.com/3V7EdWr.png)
-
-- Select the "Minecraft Client" launch config
-
- ![Image](https://i.imgur.com/1qz2QGV.png)
-
-- Click on ``Edit Configurations...`` from the same dropdown and select the "Minecraft Client" config
-
- ![Image](https://i.imgur.com/s4ly0ZF.png)
-
-- In `Edit Configurations...` you need to select `baritone_launch` for `Use classpath of module:`.
-
- ![Image](https://i.imgur.com/hrLhG9u.png)
-
-## IntelliJ
-
-- Navigate to the gradle tasks on the right tab as follows
-
- ![Image](https://i.imgur.com/PE6r9iN.png)
-
-- Double click on **build** to run it
+- depending on the minecraft version, you may need to run `setupDecompWorkspace` or `genIntellijRuns` in order to get everything working
\ No newline at end of file
diff --git a/scripts/proguard.pro b/scripts/proguard.pro
index 86d31247e..34b76170f 100644
--- a/scripts/proguard.pro
+++ b/scripts/proguard.pro
@@ -19,6 +19,8 @@
-dontwarn module-info
# we dont have forge
-dontwarn baritone.launch.BaritoneForgeModXD
+# progard doesn't like signature polymorphism
+-dontwarn java.lang.invoke.MethodHandle
# please do not change the comment below
-keep class baritone.api.** { *; } # this is the keep api
diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java
index 4a87449cd..fa98525bf 100644
--- a/src/api/java/baritone/api/BaritoneAPI.java
+++ b/src/api/java/baritone/api/BaritoneAPI.java
@@ -32,7 +32,7 @@ public final class BaritoneAPI {
static {
settings = new Settings();
- SettingsUtil.readAndApply(settings);
+ SettingsUtil.readAndApply(settings, SettingsUtil.SETTINGS_DEFAULT_NAME);
try {
provider = (IBaritoneProvider) Class.forName("baritone.BaritoneProvider").newInstance();
diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java
index 7fa97d168..5eb0ba86a 100644
--- a/src/api/java/baritone/api/IBaritoneProvider.java
+++ b/src/api/java/baritone/api/IBaritoneProvider.java
@@ -21,9 +21,11 @@
import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.player.LocalPlayer;
+
import java.util.List;
import java.util.Objects;
-import net.minecraft.client.player.LocalPlayer;
/**
* Provides the present {@link IBaritone} instances, as well as non-baritone instance related APIs.
@@ -51,15 +53,13 @@ public interface IBaritoneProvider {
List getAllBaritones();
/**
- * Provides the {@link IBaritone} instance for a given {@link LocalPlayer}. This will likely be
- * replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when
- * {@code bot-system} is merged into {@code master}.
+ * Provides the {@link IBaritone} instance for a given {@link LocalPlayer}.
*
* @param player The player
* @return The {@link IBaritone} instance.
*/
default IBaritone getBaritoneForPlayer(LocalPlayer player) {
- for (IBaritone baritone : getAllBaritones()) {
+ for (IBaritone baritone : this.getAllBaritones()) {
if (Objects.equals(player, baritone.getPlayerContext().player())) {
return baritone;
}
@@ -67,6 +67,39 @@ default IBaritone getBaritoneForPlayer(LocalPlayer player) {
return null;
}
+ /**
+ * Provides the {@link IBaritone} instance for a given {@link Minecraft}.
+ *
+ * @param minecraft The minecraft
+ * @return The {@link IBaritone} instance.
+ */
+ default IBaritone getBaritoneForMinecraft(Minecraft minecraft) {
+ for (IBaritone baritone : this.getAllBaritones()) {
+ if (Objects.equals(minecraft, baritone.getPlayerContext().minecraft())) {
+ return baritone;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Creates and registers a new {@link IBaritone} instance using the specified {@link Minecraft}. The existing
+ * instance is returned if already registered.
+ *
+ * @param minecraft The minecraft
+ * @return The {@link IBaritone} instance
+ */
+ IBaritone createBaritone(Minecraft minecraft);
+
+ /**
+ * Destroys and removes the specified {@link IBaritone} instance. If the specified instance is the
+ * {@link #getPrimaryBaritone() primary baritone}, this operation has no effect and will return {@code false}.
+ *
+ * @param baritone The baritone instance to remove
+ * @return Whether the baritone instance was removed
+ */
+ boolean destroyBaritone(IBaritone baritone);
+
/**
* Returns the {@link IWorldScanner} instance. This is not a type returned by
* {@link IBaritone} implementation, because it is not linked with {@link IBaritone}.
diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java
index 2b7ebc288..26600a51a 100644
--- a/src/api/java/baritone/api/Settings.java
+++ b/src/api/java/baritone/api/Settings.java
@@ -30,6 +30,10 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import java.awt.*;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -70,6 +74,16 @@ public final class Settings {
*/
public final Setting allowInventory = new Setting<>(false);
+ /**
+ * Wait this many ticks between InventoryBehavior moving inventory items
+ */
+ public final Setting ticksBetweenInventoryMoves = new Setting<>(1);
+
+ /**
+ * Come to a halt before doing any inventory moves. Intended for anticheat such as 2b2t
+ */
+ public final Setting inventoryMoveOnlyIfStationary = new Setting<>(false);
+
/**
* Disable baritone's auto-tool at runtime, but still assume that another mod will provide auto tool functionality
*
@@ -611,6 +625,13 @@ public final class Settings {
*/
public final Setting pruneRegionsFromRAM = new Setting<>(true);
+ /**
+ * The chunk packer queue can never grow to larger than this, if it does, the oldest chunks are discarded
+ *
+ * The newest chunks are kept, so that if you're moving in a straight line quickly then stop, your immediate render distance is still included
+ */
+ public final Setting chunkPackerQueueMaxSize = new Setting<>(2000);
+
/**
* Fill in blocks behind you
*/
@@ -712,6 +733,17 @@ public final class Settings {
*/
public final Setting freeLook = new Setting<>(true);
+ /**
+ * Break and place blocks without having to force the client-sided rotations. Requires {@link #freeLook}.
+ */
+ public final Setting blockFreeLook = new Setting<>(false);
+
+ /**
+ * When true, the player will remain with its existing look direction as often as possible.
+ * Although, in some cases this can get it stuck, hence this setting to disable that behavior.
+ */
+ public final Setting remainWithExistingLookDirection = new Setting<>(true);
+
/**
* Will cause some minor behavioral differences to ensure that Baritone works on anticheats.
*
@@ -852,6 +884,11 @@ public final class Settings {
*/
public final Setting minYLevelWhileMining = new Setting<>(0);
+ /**
+ * Sets the maximum y level to mine ores at.
+ */
+ public final Setting maxYLevelWhileMining = new Setting<>(2031);
+
/**
* This will only allow baritone to mine exposed ores, can be used to stop ore obfuscators on servers that use them.
*/
@@ -1148,9 +1185,10 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value};
*/
+ @JavaOnly
public final Setting> logger = new Setting<>((msg) -> {
- final GuiMessageTag tag = useMessageTag.value ? Helper.MESSAGE_TAG : null;
- Minecraft.getInstance().gui.getChat().addMessage(msg, null, tag);
+ final GuiMessageTag tag = useMessageTag.value ? Helper.MESSAGE_TAG : null;
+ Minecraft.getInstance().gui.getChat().addMessage(msg, null, tag);
});
/**
@@ -1158,6 +1196,7 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value};
*/
+ @JavaOnly
public final Setting> notifier = new Setting<>(NotificationHelper::notify);
/**
@@ -1165,6 +1204,7 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value};
*/
+ @JavaOnly
public final Setting> toaster = new Setting<>(BaritoneToast::addOrUpdate);
/**
@@ -1314,6 +1354,7 @@ public final class Setting {
public T value;
public final T defaultValue;
private String name;
+ private boolean javaOnly;
@SuppressWarnings("unchecked")
private Setting(T value) {
@@ -1322,6 +1363,7 @@ private Setting(T value) {
}
this.value = value;
this.defaultValue = value;
+ this.javaOnly = false;
}
/**
@@ -1358,8 +1400,25 @@ public void reset() {
public final Type getType() {
return settingTypes.get(this);
}
+
+ /**
+ * This should always be the same as whether the setting can be parsed from or serialized to a string; in other
+ * words, the only way to modify it is by writing to {@link #value} programatically.
+ *
+ * @return {@code true} if the setting can not be set or read by the user
+ */
+ public boolean isJavaOnly() {
+ return javaOnly;
+ }
}
+ /**
+ * Marks a {@link Setting} field as being {@link Setting#isJavaOnly() Java-only}
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.FIELD)
+ private @interface JavaOnly {}
+
// here be dragons
Settings() {
@@ -1375,6 +1434,7 @@ public final Type getType() {
Setting> setting = (Setting>) field.get(this);
String name = field.getName();
setting.name = name;
+ setting.javaOnly = field.isAnnotationPresent(JavaOnly.class);
name = name.toLowerCase();
if (tmpByName.containsKey(name)) {
throw new IllegalStateException("Duplicate setting name");
diff --git a/src/api/java/baritone/api/behavior/ILookBehavior.java b/src/api/java/baritone/api/behavior/ILookBehavior.java
index 058a5dd88..d78e7f8b3 100644
--- a/src/api/java/baritone/api/behavior/ILookBehavior.java
+++ b/src/api/java/baritone/api/behavior/ILookBehavior.java
@@ -17,6 +17,8 @@
package baritone.api.behavior;
+import baritone.api.Settings;
+import baritone.api.behavior.look.IAimProcessor;
import baritone.api.utils.Rotation;
/**
@@ -26,14 +28,23 @@
public interface ILookBehavior extends IBehavior {
/**
- * Updates the current {@link ILookBehavior} target to target
- * the specified rotations on the next tick. If force is {@code true},
- * then freeLook will be overriden and angles will be set regardless.
- * If any sort of block interaction is required, force should be {@code true},
- * otherwise, it should be {@code false};
+ * Updates the current {@link ILookBehavior} target to target the specified rotations on the next tick. If any sort
+ * of block interaction is required, {@code blockInteract} should be {@code true}. It is not guaranteed that the
+ * rotations set by the caller will be the exact rotations expressed by the client (This is due to settings like
+ * {@link Settings#randomLooking}). If the rotations produced by this behavior are required, then the
+ * {@link #getAimProcessor() aim processor} should be used.
*
- * @param rotation The target rotations
- * @param force Whether or not to "force" the rotations
+ * @param rotation The target rotations
+ * @param blockInteract Whether the target rotations are needed for a block interaction
*/
- void updateTarget(Rotation rotation, boolean force);
+ void updateTarget(Rotation rotation, boolean blockInteract);
+
+ /**
+ * The aim processor instance for this {@link ILookBehavior}, which is responsible for applying additional,
+ * deterministic transformations to the target rotation set by {@link #updateTarget}.
+ *
+ * @return The aim processor
+ * @see IAimProcessor#fork
+ */
+ IAimProcessor getAimProcessor();
}
diff --git a/src/api/java/baritone/api/behavior/look/IAimProcessor.java b/src/api/java/baritone/api/behavior/look/IAimProcessor.java
new file mode 100644
index 000000000..c7c60f413
--- /dev/null
+++ b/src/api/java/baritone/api/behavior/look/IAimProcessor.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.behavior.look;
+
+import baritone.api.utils.Rotation;
+
+/**
+ * @author Brady
+ */
+public interface IAimProcessor {
+
+ /**
+ * Returns the actual rotation that will be used when the desired rotation is requested. The returned rotation
+ * always reflects what would happen in the upcoming tick. In other words, it is a pure function, and no internal
+ * state changes. If simulation of the rotation states beyond the next tick is required, then a
+ * {@link IAimProcessor#fork fork} should be created.
+ *
+ * @param desired The desired rotation to set
+ * @return The actual rotation
+ */
+ Rotation peekRotation(Rotation desired);
+
+ /**
+ * Returns a copy of this {@link IAimProcessor} which has its own internal state and is manually tickable.
+ *
+ * @return The forked processor
+ * @see ITickableAimProcessor
+ */
+ ITickableAimProcessor fork();
+}
diff --git a/src/api/java/baritone/api/behavior/look/ITickableAimProcessor.java b/src/api/java/baritone/api/behavior/look/ITickableAimProcessor.java
new file mode 100644
index 000000000..e0a07ae57
--- /dev/null
+++ b/src/api/java/baritone/api/behavior/look/ITickableAimProcessor.java
@@ -0,0 +1,47 @@
+/*
+ * 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.behavior.look;
+
+import baritone.api.utils.Rotation;
+
+/**
+ * @author Brady
+ */
+public interface ITickableAimProcessor extends IAimProcessor {
+
+ /**
+ * Advances the internal state of this aim processor by a single tick.
+ */
+ void tick();
+
+ /**
+ * Calls {@link #tick()} the specified number of times.
+ *
+ * @param ticks The number of calls
+ */
+ void advance(int ticks);
+
+ /**
+ * Returns the actual rotation as provided by {@link #peekRotation(Rotation)}, and then automatically advances the
+ * internal state by one {@link #tick() tick}.
+ *
+ * @param rotation The desired rotation to set
+ * @return The actual rotation
+ */
+ Rotation nextRotation(Rotation rotation);
+}
diff --git a/src/api/java/baritone/api/cache/IWorldProvider.java b/src/api/java/baritone/api/cache/IWorldProvider.java
index 0e54ef469..b9ca149c7 100644
--- a/src/api/java/baritone/api/cache/IWorldProvider.java
+++ b/src/api/java/baritone/api/cache/IWorldProvider.java
@@ -17,6 +17,8 @@
package baritone.api.cache;
+import java.util.function.Consumer;
+
/**
* @author Brady
* @since 9/24/2018
@@ -29,4 +31,11 @@ public interface IWorldProvider {
* @return The current world data
*/
IWorldData getCurrentWorld();
+
+ default void ifWorldLoaded(Consumer callback) {
+ final IWorldData currentWorld = this.getCurrentWorld();
+ if (currentWorld != null) {
+ callback.accept(currentWorld);
+ }
+ }
}
diff --git a/src/api/java/baritone/api/command/datatypes/BlockById.java b/src/api/java/baritone/api/command/datatypes/BlockById.java
index 5e63fcf25..7862b9edf 100644
--- a/src/api/java/baritone/api/command/datatypes/BlockById.java
+++ b/src/api/java/baritone/api/command/datatypes/BlockById.java
@@ -19,14 +19,21 @@
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper;
-import java.util.stream.Stream;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
public enum BlockById implements IDatatypeFor {
INSTANCE;
+ /**
+ * Matches (domain:)?name? where domain and name are [a-z0-9_.-]+ and [a-z0-9/_.-]+ respectively.
+ */
+ private static Pattern PATTERN = Pattern.compile("(?:[a-z0-9_.-]+:)?[a-z0-9/_.-]*");
+
@Override
public Block get(IDatatypeContext ctx) throws CommandException {
ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString());
@@ -39,13 +46,19 @@ public Block get(IDatatypeContext ctx) throws CommandException {
@Override
public Stream tabComplete(IDatatypeContext ctx) throws CommandException {
+ String arg = ctx.getConsumer().getString();
+
+ if (!PATTERN.matcher(arg).matches()) {
+ return Stream.empty();
+ }
+
return new TabCompleteHelper()
.append(
Registry.BLOCK.keySet()
.stream()
.map(Object::toString)
)
- .filterPrefixNamespaced(ctx.getConsumer().getString())
+ .filterPrefixNamespaced(arg)
.sortAlphabetically()
.stream();
}
diff --git a/src/api/java/baritone/api/command/datatypes/ForAxis.java b/src/api/java/baritone/api/command/datatypes/ForAxis.java
new file mode 100644
index 000000000..369697dcb
--- /dev/null
+++ b/src/api/java/baritone/api/command/datatypes/ForAxis.java
@@ -0,0 +1,43 @@
+/*
+ * 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.datatypes;
+
+import baritone.api.command.exception.CommandException;
+import baritone.api.command.helpers.TabCompleteHelper;
+import net.minecraft.core.Direction;
+
+import java.util.Locale;
+import java.util.stream.Stream;
+
+public enum ForAxis implements IDatatypeFor {
+ INSTANCE;
+
+ @Override
+ public Direction.Axis get(IDatatypeContext ctx) throws CommandException {
+ return Direction.Axis.valueOf(ctx.getConsumer().getString().toUpperCase(Locale.US));
+ }
+
+ @Override
+ public Stream tabComplete(IDatatypeContext ctx) throws CommandException {
+ return new TabCompleteHelper()
+ .append(Stream.of(Direction.Axis.values())
+ .map(Direction.Axis::getName).map(String::toLowerCase))
+ .filterPrefix(ctx.getConsumer().getString())
+ .stream();
+ }
+}
diff --git a/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java
index 978450a23..74a5a0d7c 100644
--- a/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java
+++ b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java
@@ -18,20 +18,137 @@
package baritone.api.command.datatypes;
import baritone.api.command.exception.CommandException;
+import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.utils.BlockOptionalMeta;
+import net.minecraft.core.Registry;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.properties.Property;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
public enum ForBlockOptionalMeta implements IDatatypeFor {
INSTANCE;
+ /**
+ * Matches (domain:)?name([(property=value)*])? but the input can be truncated at any position.
+ * domain and name are [a-z0-9_.-]+ and [a-z0-9/_.-]+ because that's what mc 1.13+ accepts.
+ * property and value use the same format as domain.
+ */
+ // Good luck reading this.
+ private static Pattern PATTERN = Pattern.compile("(?:[a-z0-9_.-]+:)?(?:[a-z0-9/_.-]+(?:\\[(?:(?:[a-z0-9_.-]+=[a-z0-9_.-]+,)*(?:[a-z0-9_.-]+(?:=(?:[a-z0-9_.-]+(?:\\])?)?)?)?|\\])?)?)?");
+
@Override
public BlockOptionalMeta get(IDatatypeContext ctx) throws CommandException {
return new BlockOptionalMeta(ctx.getConsumer().getString());
}
@Override
- public Stream tabComplete(IDatatypeContext ctx) {
- return ctx.getConsumer().tabCompleteDatatype(BlockById.INSTANCE);
+ public Stream tabComplete(IDatatypeContext ctx) throws CommandException {
+ String arg = ctx.getConsumer().peekString();
+
+ if (!PATTERN.matcher(arg).matches()) {
+ // Invalid format; we can't complete this.
+ ctx.getConsumer().getString();
+ return Stream.empty();
+ }
+
+ if (arg.endsWith("]")) {
+ // We are already done.
+ ctx.getConsumer().getString();
+ return Stream.empty();
+ }
+
+ if (!arg.contains("[")) {
+ // no properties so we are completing the block id
+ return ctx.getConsumer().tabCompleteDatatype(BlockById.INSTANCE);
+ }
+
+ ctx.getConsumer().getString();
+
+ // destructuring assignment? Please?
+ String blockId, properties;
+ {
+ String[] parts = splitLast(arg, '[');
+ blockId = parts[0];
+ properties = parts[1];
+ }
+
+ Block block = Registry.BLOCK.getOptional(new ResourceLocation(blockId)).orElse(null);
+ if (block == null) {
+ // This block doesn't exist so there's no properties to complete.
+ return Stream.empty();
+ }
+
+ String leadingProperties, lastProperty;
+ {
+ String[] parts = splitLast(properties, ',');
+ leadingProperties = parts[0];
+ lastProperty = parts[1];
+ }
+
+ if (!lastProperty.contains("=")) {
+ // The last property-value pair doesn't have a value yet so we are completing its name
+ Set usedProps = Stream.of(leadingProperties.split(","))
+ .map(pair -> pair.split("=")[0])
+ .collect(Collectors.toSet());
+
+ String prefix = arg.substring(0, arg.length() - lastProperty.length());
+ return new TabCompleteHelper()
+ .append(
+ block.getStateDefinition()
+ .getProperties()
+ .stream()
+ .map(Property::getName)
+ )
+ .filter(prop -> !usedProps.contains(prop))
+ .filterPrefix(lastProperty)
+ .sortAlphabetically()
+ .map(prop -> prefix + prop)
+ .stream();
+ }
+
+ String lastName, lastValue;
+ {
+ String[] parts = splitLast(lastProperty, '=');
+ lastName = parts[0];
+ lastValue = parts[1];
+ }
+
+ // We are completing the value of a property
+ String prefix = arg.substring(0, arg.length() - lastValue.length());
+
+ Property> property = block.getStateDefinition().getProperty(lastName);
+ if (property == null) {
+ // The property does not exist so there's no values to complete
+ return Stream.empty();
+ }
+
+ return new TabCompleteHelper()
+ .append(getValues(property))
+ .filterPrefix(lastValue)
+ .sortAlphabetically()
+ .map(val -> prefix + val)
+ .stream();
+ }
+
+ /**
+ * Always returns exactly two strings.
+ * If the separator is not found the FIRST returned string is empty.
+ */
+ private static String[] splitLast(String string, char chr) {
+ int idx = string.lastIndexOf(chr);
+ if (idx == -1) {
+ return new String[]{"", string};
+ }
+ return new String[]{string.substring(0, idx), string.substring(idx + 1)};
+ }
+
+ // this shouldn't need to be a separate method?
+ private static > Stream getValues(Property property) {
+ return property.getPossibleValues().stream().map(property::getName);
}
}
diff --git a/src/api/java/baritone/api/command/datatypes/RelativeFile.java b/src/api/java/baritone/api/command/datatypes/RelativeFile.java
index 7d7e6899b..e85f12971 100644
--- a/src/api/java/baritone/api/command/datatypes/RelativeFile.java
+++ b/src/api/java/baritone/api/command/datatypes/RelativeFile.java
@@ -19,6 +19,8 @@
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
+import baritone.api.utils.Helper;
+import net.minecraft.client.Minecraft;
import java.io.File;
import java.io.IOException;
@@ -30,8 +32,6 @@
import java.util.Objects;
import java.util.stream.Stream;
-import static baritone.api.utils.Helper.HELPER;
-
public enum RelativeFile implements IDatatypePost {
INSTANCE;
@@ -93,8 +93,13 @@ public static Stream tabComplete(IArgConsumer consumer, File base0) thro
.filter(s -> !s.contains(" "));
}
+ @Deprecated
public static File gameDir() {
- File gameDir = HELPER.mc.gameDirectory.getAbsoluteFile();
+ return gameDir(Helper.mc);
+ }
+
+ public static File gameDir(Minecraft mc) {
+ File gameDir = mc.gameDirectory.getAbsoluteFile();
if (gameDir.getName().equals(".")) {
return gameDir.getParentFile();
}
diff --git a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
index a7dfb7f8a..4f822352a 100644
--- a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
+++ b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java
@@ -252,7 +252,7 @@ public TabCompleteHelper addCommands(ICommandManager manager) {
public TabCompleteHelper addSettings() {
return append(
BaritoneAPI.getSettings().allSettings.stream()
- .filter(s -> !SettingsUtil.javaOnlySetting(s))
+ .filter(s -> !s.isJavaOnly())
.map(Settings.Setting::getName)
.sorted(String.CASE_INSENSITIVE_ORDER)
);
diff --git a/src/api/java/baritone/api/event/events/RotationMoveEvent.java b/src/api/java/baritone/api/event/events/RotationMoveEvent.java
index bae83c0fa..c5a9ea9f9 100644
--- a/src/api/java/baritone/api/event/events/RotationMoveEvent.java
+++ b/src/api/java/baritone/api/event/events/RotationMoveEvent.java
@@ -17,6 +17,7 @@
package baritone.api.event.events;
+import baritone.api.utils.Rotation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
@@ -32,14 +33,27 @@ public final class RotationMoveEvent {
*/
private final Type type;
+ private final Rotation original;
+
/**
* The yaw rotation
*/
private float yaw;
- public RotationMoveEvent(Type type, float yaw) {
+ /**
+ * The pitch rotation
+ */
+ private float pitch;
+
+ public RotationMoveEvent(Type type, float yaw, float pitch) {
this.type = type;
+ this.original = new Rotation(yaw, pitch);
this.yaw = yaw;
+ this.pitch = pitch;
+ }
+
+ public Rotation getOriginal() {
+ return this.original;
}
/**
@@ -47,21 +61,37 @@ public RotationMoveEvent(Type type, float yaw) {
*
* @param yaw Yaw rotation
*/
- public final void setYaw(float yaw) {
+ public void setYaw(float yaw) {
this.yaw = yaw;
}
/**
* @return The yaw rotation
*/
- public final float getYaw() {
+ public float getYaw() {
return this.yaw;
}
+ /**
+ * Set the pitch movement rotation
+ *
+ * @param pitch Pitch rotation
+ */
+ public void setPitch(float pitch) {
+ this.pitch = pitch;
+ }
+
+ /**
+ * @return The pitch rotation
+ */
+ public float getPitch() {
+ return pitch;
+ }
+
/**
* @return The type of the event
*/
- public final Type getType() {
+ public Type getType() {
return this.type;
}
diff --git a/src/api/java/baritone/api/pathing/goals/GoalAxis.java b/src/api/java/baritone/api/pathing/goals/GoalAxis.java
index 7c9b26705..6e2f84e7a 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalAxis.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalAxis.java
@@ -42,6 +42,16 @@ public double heuristic(int x0, int y, int z0) {
return flatAxisDistance * BaritoneAPI.getSettings().costHeuristic.value + GoalYLevel.calculate(BaritoneAPI.getSettings().axisHeight.value, y);
}
+ @Override
+ public boolean equals(Object o) {
+ return o.getClass() == GoalAxis.class;
+ }
+
+ @Override
+ public int hashCode() {
+ return 201385781;
+ }
+
@Override
public String toString() {
return "GoalAxis";
diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java
index 7cb9da14a..4bebe07a3 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java
@@ -17,6 +17,7 @@
package baritone.api.pathing.goals;
+import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.core.BlockPos;
@@ -66,6 +67,26 @@ public double heuristic(int x, int y, int z) {
return calculate(xDiff, yDiff, zDiff);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalBlock goal = (GoalBlock) o;
+ return x == goal.x
+ && y == goal.y
+ && z == goal.z;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) BetterBlockPos.longHash(x, y, z) * 905165533;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalComposite.java b/src/api/java/baritone/api/pathing/goals/GoalComposite.java
index 47522492b..8e13a86e4 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalComposite.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalComposite.java
@@ -67,6 +67,24 @@ public double heuristic() {
return min;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalComposite goal = (GoalComposite) o;
+ return Arrays.equals(goals, goal.goals);
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(goals);
+ }
+
@Override
public String toString() {
return "GoalComposite" + Arrays.toString(goals);
diff --git a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java
index 8d15e4bc9..1c04f7c6d 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java
@@ -17,6 +17,7 @@
package baritone.api.pathing.goals;
+import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.core.BlockPos;
@@ -60,6 +61,26 @@ public double heuristic(int x, int y, int z) {
return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalGetToBlock goal = (GoalGetToBlock) o;
+ return x == goal.x
+ && y == goal.y
+ && z == goal.z;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) BetterBlockPos.longHash(x, y, z) * -49639096;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalInverted.java b/src/api/java/baritone/api/pathing/goals/GoalInverted.java
index 354e2ce39..4a3f75315 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalInverted.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalInverted.java
@@ -17,6 +17,8 @@
package baritone.api.pathing.goals;
+import java.util.Objects;
+
/**
* Invert any goal.
*
@@ -50,6 +52,24 @@ public double heuristic() {
return Double.NEGATIVE_INFINITY;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalInverted goal = (GoalInverted) o;
+ return Objects.equals(origin, goal.origin);
+ }
+
+ @Override
+ public int hashCode() {
+ return origin.hashCode() * 495796690;
+ }
+
@Override
public String toString() {
return String.format("GoalInverted{%s}", origin.toString());
diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java
index 6ee35ad7b..351c08021 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalNear.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java
@@ -17,6 +17,7 @@
package baritone.api.pathing.goals;
+import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import it.unimi.dsi.fastutil.doubles.DoubleIterator;
@@ -86,6 +87,27 @@ public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalNear goal = (GoalNear) o;
+ return x == goal.x
+ && y == goal.y
+ && z == goal.z
+ && rangeSq == goal.rangeSq;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) BetterBlockPos.longHash(x, y, z) + rangeSq;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java
index 3906713f2..49b6f708d 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java
@@ -23,6 +23,7 @@
import net.minecraft.core.BlockPos;
import java.util.Arrays;
+import java.util.Objects;
/**
* Useful for automated combat (retreating specifically)
@@ -124,6 +125,29 @@ public double heuristic() {// TODO less hacky solution
return maxInside;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalRunAway goal = (GoalRunAway) o;
+ return distanceSq == goal.distanceSq
+ && Arrays.equals(from, goal.from)
+ && Objects.equals(maintainY, goal.maintainY);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = Arrays.hashCode(from);
+ hash = hash * 1196803141 + distanceSq;
+ hash = hash * -2053788840 + maintainY;
+ return hash;
+ }
+
@Override
public String toString() {
if (maintainY != null) {
diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java
index c4a8a6272..6facfbd79 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java
@@ -17,6 +17,7 @@
package baritone.api.pathing.goals;
+import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@@ -69,6 +70,31 @@ public double heuristic() {
return Double.NEGATIVE_INFINITY;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalStrictDirection goal = (GoalStrictDirection) o;
+ return x == goal.x
+ && y == goal.y
+ && z == goal.z
+ && dx == goal.dx
+ && dz == goal.dz;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = (int) BetterBlockPos.longHash(x, y, z);
+ hash = hash * 630627507 + dx;
+ hash = hash * -283028380 + dz;
+ return hash;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java
index 1b7213471..c9325e3ad 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java
@@ -17,6 +17,7 @@
package baritone.api.pathing.goals;
+import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.interfaces.IGoalRenderPos;
import net.minecraft.core.BlockPos;
@@ -72,6 +73,26 @@ public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalTwoBlocks goal = (GoalTwoBlocks) o;
+ return x == goal.x
+ && y == goal.y
+ && z == goal.z;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) BetterBlockPos.longHash(x, y, z) * 516508351;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalXZ.java b/src/api/java/baritone/api/pathing/goals/GoalXZ.java
index f70f6c4f7..b72711283 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalXZ.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalXZ.java
@@ -64,6 +64,27 @@ public double heuristic(int x, int y, int z) {//mostly copied from GoalBlock
return calculate(xDiff, zDiff);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalXZ goal = (GoalXZ) o;
+ return x == goal.x && z == goal.z;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 1791873246;
+ hash = hash * 222601791 + x;
+ hash = hash * -1331679453 + z;
+ return hash;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java
index 603ef9bd1..442906ad1 100644
--- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java
+++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java
@@ -58,6 +58,24 @@ public static double calculate(int goalY, int currentY) {
return 0;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ GoalYLevel goal = (GoalYLevel) o;
+ return level == goal.level;
+ }
+
+ @Override
+ public int hashCode() {
+ return level * 1271009915;
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java
index 9f0ab1032..77250ce73 100644
--- a/src/api/java/baritone/api/process/IBuilderProcess.java
+++ b/src/api/java/baritone/api/process/IBuilderProcess.java
@@ -50,6 +50,7 @@ public interface IBuilderProcess extends IBaritoneProcess {
*/
boolean build(String name, File schematic, Vec3i origin);
+ @Deprecated
default boolean build(String schematicFile, BlockPos origin) {
File file = new File(new File(Minecraft.getInstance().gameDirectory, "schematics"), schematicFile);
return build(schematicFile, file, origin);
diff --git a/src/api/java/baritone/api/schematic/MaskSchematic.java b/src/api/java/baritone/api/schematic/MaskSchematic.java
index ee56f3425..a5749ff57 100644
--- a/src/api/java/baritone/api/schematic/MaskSchematic.java
+++ b/src/api/java/baritone/api/schematic/MaskSchematic.java
@@ -17,9 +17,11 @@
package baritone.api.schematic;
-import java.util.List;
+import baritone.api.schematic.mask.Mask;
import net.minecraft.world.level.block.state.BlockState;
+import java.util.List;
+
public abstract class MaskSchematic extends AbstractSchematic {
private final ISchematic schematic;
@@ -40,4 +42,14 @@ public boolean inSchematic(int x, int y, int z, BlockState currentState) {
public BlockState desiredState(int x, int y, int z, BlockState current, List approxPlaceable) {
return schematic.desiredState(x, y, z, current, approxPlaceable);
}
+
+ public static MaskSchematic create(ISchematic schematic, Mask function) {
+ return new MaskSchematic(schematic) {
+
+ @Override
+ protected boolean partOfMask(int x, int y, int z, BlockState currentState) {
+ return function.partOfMask(x, y, z, currentState);
+ }
+ };
+ }
}
diff --git a/src/api/java/baritone/api/schematic/mask/AbstractMask.java b/src/api/java/baritone/api/schematic/mask/AbstractMask.java
new file mode 100644
index 000000000..ce92af0ec
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/AbstractMask.java
@@ -0,0 +1,49 @@
+/*
+ * 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.mask;
+
+/**
+ * @author Brady
+ */
+public abstract class AbstractMask implements Mask {
+
+ private final int widthX;
+ private final int heightY;
+ private final int lengthZ;
+
+ public AbstractMask(int widthX, int heightY, int lengthZ) {
+ this.widthX = widthX;
+ this.heightY = heightY;
+ this.lengthZ = lengthZ;
+ }
+
+ @Override
+ public int widthX() {
+ return this.widthX;
+ }
+
+ @Override
+ public int heightY() {
+ return this.heightY;
+ }
+
+ @Override
+ public int lengthZ() {
+ return this.lengthZ;
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/Mask.java b/src/api/java/baritone/api/schematic/mask/Mask.java
new file mode 100644
index 000000000..c8b1f15a1
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/Mask.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.mask;
+
+import baritone.api.schematic.mask.operator.BinaryOperatorMask;
+import baritone.api.schematic.mask.operator.NotMask;
+import baritone.api.utils.BooleanBinaryOperators;
+import net.minecraft.world.level.block.state.BlockState;
+
+/**
+ * @author Brady
+ */
+public interface Mask {
+
+ /**
+ * @param x The relative x position of the block
+ * @param y The relative y position of the block
+ * @param z The relative z position of the block
+ * @param currentState The current state of that block in the world, may be {@code null}
+ * @return Whether the given position is included in this mask
+ */
+ boolean partOfMask(int x, int y, int z, BlockState currentState);
+
+ int widthX();
+
+ int heightY();
+
+ int lengthZ();
+
+ default Mask not() {
+ return new NotMask(this);
+ }
+
+ default Mask union(Mask other) {
+ return new BinaryOperatorMask(this, other, BooleanBinaryOperators.OR);
+ }
+
+ default Mask intersection(Mask other) {
+ return new BinaryOperatorMask(this, other, BooleanBinaryOperators.AND);
+ }
+
+ default Mask xor(Mask other) {
+ return new BinaryOperatorMask(this, other, BooleanBinaryOperators.XOR);
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/PreComputedMask.java b/src/api/java/baritone/api/schematic/mask/PreComputedMask.java
new file mode 100644
index 000000000..aed26cc94
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/PreComputedMask.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.mask;
+
+/**
+ * @author Brady
+ */
+final class PreComputedMask extends AbstractMask implements StaticMask {
+
+ private final boolean[][][] mask;
+
+ public PreComputedMask(StaticMask mask) {
+ super(mask.widthX(), mask.heightY(), mask.lengthZ());
+
+ this.mask = new boolean[this.heightY()][this.lengthZ()][this.widthX()];
+ for (int y = 0; y < this.heightY(); y++) {
+ for (int z = 0; z < this.lengthZ(); z++) {
+ for (int x = 0; x < this.widthX(); x++) {
+ this.mask[y][z][x] = mask.partOfMask(x, y, z);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z) {
+ return this.mask[y][z][x];
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/StaticMask.java b/src/api/java/baritone/api/schematic/mask/StaticMask.java
new file mode 100644
index 000000000..9925ffca2
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/StaticMask.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.api.schematic.mask;
+
+import baritone.api.schematic.mask.operator.BinaryOperatorMask;
+import baritone.api.schematic.mask.operator.NotMask;
+import baritone.api.utils.BooleanBinaryOperators;
+import net.minecraft.world.level.block.state.BlockState;
+
+/**
+ * A mask that is context-free. In other words, it doesn't require the current block state to determine if a relative
+ * position is a part of the mask.
+ *
+ * @author Brady
+ */
+public interface StaticMask extends Mask {
+
+ /**
+ * Determines if a given relative coordinate is included in this mask, without the need for the current block state.
+ *
+ * @param x The relative x position of the block
+ * @param y The relative y position of the block
+ * @param z The relative z position of the block
+ * @return Whether the given position is included in this mask
+ */
+ boolean partOfMask(int x, int y, int z);
+
+ /**
+ * Implements the parent {@link Mask#partOfMask partOfMask function} by calling the static function
+ * provided in this functional interface without needing the {@link BlockState} argument. This {@code default}
+ * implementation should NOT be overriden.
+ *
+ * @param x The relative x position of the block
+ * @param y The relative y position of the block
+ * @param z The relative z position of the block
+ * @param currentState The current state of that block in the world, may be {@code null}
+ * @return Whether the given position is included in this mask
+ */
+ @Override
+ default boolean partOfMask(int x, int y, int z, BlockState currentState) {
+ return this.partOfMask(x, y, z);
+ }
+
+ @Override
+ default StaticMask not() {
+ return new NotMask.Static(this);
+ }
+
+ default StaticMask union(StaticMask other) {
+ return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.OR);
+ }
+
+ default StaticMask intersection(StaticMask other) {
+ return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.AND);
+ }
+
+ default StaticMask xor(StaticMask other) {
+ return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.XOR);
+ }
+
+ /**
+ * Returns a pre-computed mask using {@code this} function, with the specified size parameters.
+ */
+ default StaticMask compute() {
+ return new PreComputedMask(this);
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java b/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java
new file mode 100644
index 000000000..08975e521
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java
@@ -0,0 +1,79 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.api.schematic.mask.operator;
+
+import baritone.api.schematic.mask.AbstractMask;
+import baritone.api.schematic.mask.Mask;
+import baritone.api.schematic.mask.StaticMask;
+import baritone.api.utils.BooleanBinaryOperator;
+import net.minecraft.world.level.block.state.BlockState;
+
+/**
+ * @author Brady
+ */
+public final class BinaryOperatorMask extends AbstractMask {
+
+ private final Mask a;
+ private final Mask b;
+ private final BooleanBinaryOperator operator;
+
+ public BinaryOperatorMask(Mask a, Mask b, BooleanBinaryOperator operator) {
+ super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ()));
+ this.a = a;
+ this.b = b;
+ this.operator = operator;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z, BlockState currentState) {
+ return this.operator.applyAsBoolean(
+ partOfMask(a, x, y, z, currentState),
+ partOfMask(b, x, y, z, currentState)
+ );
+ }
+
+ private static boolean partOfMask(Mask mask, int x, int y, int z, BlockState currentState) {
+ return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z, currentState);
+ }
+
+ public static final class Static extends AbstractMask implements StaticMask {
+
+ private final StaticMask a;
+ private final StaticMask b;
+ private final BooleanBinaryOperator operator;
+
+ public Static(StaticMask a, StaticMask b, BooleanBinaryOperator operator) {
+ super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ()));
+ this.a = a;
+ this.b = b;
+ this.operator = operator;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z) {
+ return this.operator.applyAsBoolean(
+ partOfMask(a, x, y, z),
+ partOfMask(b, x, y, z)
+ );
+ }
+
+ private static boolean partOfMask(StaticMask mask, int x, int y, int z) {
+ return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z);
+ }
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/operator/NotMask.java b/src/api/java/baritone/api/schematic/mask/operator/NotMask.java
new file mode 100644
index 000000000..9d0dfcd6d
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/operator/NotMask.java
@@ -0,0 +1,56 @@
+/*
+ * 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.mask.operator;
+
+import baritone.api.schematic.mask.AbstractMask;
+import baritone.api.schematic.mask.Mask;
+import baritone.api.schematic.mask.StaticMask;
+import net.minecraft.world.level.block.state.BlockState;
+
+/**
+ * @author Brady
+ */
+public final class NotMask extends AbstractMask {
+
+ private final Mask source;
+
+ public NotMask(Mask source) {
+ super(source.widthX(), source.heightY(), source.lengthZ());
+ this.source = source;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z, BlockState currentState) {
+ return !this.source.partOfMask(x, y, z, currentState);
+ }
+
+ public static final class Static extends AbstractMask implements StaticMask {
+
+ private final StaticMask source;
+
+ public Static(StaticMask source) {
+ super(source.widthX(), source.heightY(), source.lengthZ());
+ this.source = source;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z) {
+ return !this.source.partOfMask(x, y, z);
+ }
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java b/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java
new file mode 100644
index 000000000..093a27e38
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mask.shape;
+
+import baritone.api.schematic.mask.AbstractMask;
+import baritone.api.schematic.mask.StaticMask;
+import net.minecraft.core.Direction;
+
+/**
+ * @author Brady
+ */
+public final class CylinderMask extends AbstractMask implements StaticMask {
+
+ private final double centerA;
+ private final double centerB;
+ private final double radiusSqA;
+ private final double radiusSqB;
+ private final boolean filled;
+ private final Direction.Axis alignment;
+
+ public CylinderMask(int widthX, int heightY, int lengthZ, boolean filled, Direction.Axis alignment) {
+ super(widthX, heightY, lengthZ);
+ this.centerA = this.getA(widthX, heightY, alignment) / 2.0;
+ this.centerB = this.getB(heightY, lengthZ, alignment) / 2.0;
+ this.radiusSqA = (this.centerA - 1) * (this.centerA - 1);
+ this.radiusSqB = (this.centerB - 1) * (this.centerB - 1);
+ this.filled = filled;
+ this.alignment = alignment;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z) {
+ double da = Math.abs((this.getA(x, y, this.alignment) + 0.5) - this.centerA);
+ double db = Math.abs((this.getB(y, z, this.alignment) + 0.5) - this.centerB);
+ if (this.outside(da, db)) {
+ return false;
+ }
+ return this.filled
+ || this.outside(da + 1, db)
+ || this.outside(da, db + 1);
+ }
+
+ private boolean outside(double da, double db) {
+ return da * da / this.radiusSqA + db * db / this.radiusSqB > 1;
+ }
+
+ private static int getA(int x, int y, Direction.Axis alignment) {
+ return alignment == Direction.Axis.X ? y : x;
+ }
+
+ private static int getB(int y, int z, Direction.Axis alignment) {
+ return alignment == Direction.Axis.Z ? y : z;
+ }
+}
diff --git a/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java b/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java
new file mode 100644
index 000000000..d805c98a8
--- /dev/null
+++ b/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java
@@ -0,0 +1,64 @@
+/*
+ * 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.mask.shape;
+
+import baritone.api.schematic.mask.AbstractMask;
+import baritone.api.schematic.mask.StaticMask;
+
+/**
+ * @author Brady
+ */
+public final class SphereMask extends AbstractMask implements StaticMask {
+
+ private final double centerX;
+ private final double centerY;
+ private final double centerZ;
+ private final double radiusSqX;
+ private final double radiusSqY;
+ private final double radiusSqZ;
+ private final boolean filled;
+
+ public SphereMask(int widthX, int heightY, int lengthZ, boolean filled) {
+ super(widthX, heightY, lengthZ);
+ this.centerX = widthX / 2.0;
+ this.centerY = heightY / 2.0;
+ this.centerZ = lengthZ / 2.0;
+ this.radiusSqX = this.centerX * this.centerX;
+ this.radiusSqY = this.centerY * this.centerY;
+ this.radiusSqZ = this.centerZ * this.centerZ;
+ this.filled = filled;
+ }
+
+ @Override
+ public boolean partOfMask(int x, int y, int z) {
+ double dx = Math.abs((x + 0.5) - this.centerX);
+ double dy = Math.abs((y + 0.5) - this.centerY);
+ double dz = Math.abs((z + 0.5) - this.centerZ);
+ if (this.outside(dx, dy, dz)) {
+ return false;
+ }
+ return this.filled
+ || this.outside(dx + 1, dy, dz)
+ || this.outside(dx, dy + 1, dz)
+ || this.outside(dx, dy, dz + 1);
+ }
+
+ private boolean outside(double dx, double dy, double dz) {
+ return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1;
+ }
+}
diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java
index 13fe102ac..3b2432d08 100644
--- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java
+++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java
@@ -18,6 +18,7 @@
package baritone.api.utils;
import baritone.api.utils.accessor.IItemStack;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.netty.util.concurrent.ThreadPerTaskExecutor;
import net.minecraft.core.BlockPos;
@@ -30,6 +31,7 @@
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Unit;
+import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
@@ -42,47 +44,88 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nonnull;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
import java.util.concurrent.CompletableFuture;
-import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
public final class BlockOptionalMeta {
+ // id or id[] or id[properties] where id and properties are any text with at least one character
+ private static final Pattern PATTERN = Pattern.compile("^(?.+?)(?:\\[(?.+?)?\\])?$");
private final Block block;
+ private final String propertiesDescription; // exists so toString() can return something more useful than a list of all blockstates
private final Set blockstates;
- private final ImmutableSet stateHashes;
- private final ImmutableSet stackHashes;
- private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
+ private final Set stateHashes;
+ private final Set stackHashes;
private static LootTables manager;
private static PredicateManager predicate = new PredicateManager();
private static Map> drops = new HashMap<>();
public BlockOptionalMeta(@Nonnull Block block) {
this.block = block;
- this.blockstates = getStates(block);
+ this.propertiesDescription = "{}";
+ this.blockstates = getStates(block, Collections.emptyMap());
this.stateHashes = getStateHashes(blockstates);
this.stackHashes = getStackHashes(blockstates);
}
public BlockOptionalMeta(@Nonnull String selector) {
- Matcher matcher = pattern.matcher(selector);
+ Matcher matcher = PATTERN.matcher(selector);
if (!matcher.find()) {
throw new IllegalArgumentException("invalid block selector");
}
- MatchResult matchResult = matcher.toMatchResult();
+ block = BlockUtils.stringToBlockRequired(matcher.group("id"));
- block = BlockUtils.stringToBlockRequired(matchResult.group(1));
- blockstates = getStates(block);
+ String props = matcher.group("properties");
+ Map, ?> properties = props == null || props.equals("") ? Collections.emptyMap() : parseProperties(block, props);
+
+ propertiesDescription = props == null ? "{}" : "{" + props.replace("=", ":") + "}";
+ blockstates = getStates(block, properties);
stateHashes = getStateHashes(blockstates);
stackHashes = getStackHashes(blockstates);
}
- private static Set getStates(@Nonnull Block block) {
- return new HashSet<>(block.getStateDefinition().getPossibleStates());
+ private static , P extends Property> P castToIProperty(Object value) {
+ //noinspection unchecked
+ return (P) value;
+ }
+
+ private static Map, ?> parseProperties(Block block, String raw) {
+ ImmutableMap.Builder, Object> builder = ImmutableMap.builder();
+ for (String pair : raw.split(",")) {
+ String[] parts = pair.split("=");
+ if (parts.length != 2) {
+ throw new IllegalArgumentException(String.format("\"%s\" is not a valid property-value pair", pair));
+ }
+ String rawKey = parts[0];
+ String rawValue = parts[1];
+ Property> key = block.getStateDefinition().getProperty(rawKey);
+ Comparable> value = castToIProperty(key).getValue(rawValue)
+ .orElseThrow(() -> new IllegalArgumentException(String.format(
+ "\"%s\" is not a valid value for %s on %s",
+ rawValue, key, block
+ )));
+ builder.put(key, value);
+ }
+ return builder.build();
+ }
+
+ private static Set getStates(@Nonnull Block block, @Nonnull Map, ?> properties) {
+ return block.getStateDefinition().getPossibleStates().stream()
+ .filter(blockstate -> properties.entrySet().stream().allMatch(entry ->
+ blockstate.getValue(entry.getKey()) == entry.getValue()
+ ))
+ .collect(Collectors.toSet());
}
private static ImmutableSet getStateHashes(Set blockstates) {
@@ -130,7 +173,7 @@ public boolean matches(ItemStack stack) {
@Override
public String toString() {
- return String.format("BlockOptionalMeta{block=%s}", block);
+ return String.format("BlockOptionalMeta{block=%s,properties=%s}", block, propertiesDescription);
}
public BlockState getAnyBlockState() {
@@ -141,6 +184,14 @@ public BlockState getAnyBlockState() {
return null;
}
+ public Set getAllBlockStates() {
+ return blockstates;
+ }
+
+ public Set stackHashes() {
+ return stackHashes;
+ }
+
public static LootTables getManager() {
if (manager == null) {
PackRepository rpl = new PackRepository(PackType.SERVER_DATA, new ServerPacksSource());
diff --git a/src/api/java/baritone/api/utils/BlockOptionalMetaLookup.java b/src/api/java/baritone/api/utils/BlockOptionalMetaLookup.java
index 7c1070a84..7ab01cc87 100644
--- a/src/api/java/baritone/api/utils/BlockOptionalMetaLookup.java
+++ b/src/api/java/baritone/api/utils/BlockOptionalMetaLookup.java
@@ -17,67 +17,70 @@
package baritone.api.utils;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Stream;
+import baritone.api.utils.accessor.IItemStack;
+import com.google.common.collect.ImmutableSet;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
-public class BlockOptionalMetaLookup {
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+public class BlockOptionalMetaLookup {
+ private final ImmutableSet blockSet;
+ private final ImmutableSet blockStateSet;
+ private final ImmutableSet stackHashes;
private final BlockOptionalMeta[] boms;
public BlockOptionalMetaLookup(BlockOptionalMeta... boms) {
this.boms = boms;
+ Set blocks = new HashSet<>();
+ Set blockStates = new HashSet<>();
+ Set stacks = new HashSet<>();
+ for (BlockOptionalMeta bom : boms) {
+ blocks.add(bom.getBlock());
+ blockStates.addAll(bom.getAllBlockStates());
+ stacks.addAll(bom.stackHashes());
+ }
+ this.blockSet = ImmutableSet.copyOf(blocks);
+ this.blockStateSet = ImmutableSet.copyOf(blockStates);
+ this.stackHashes = ImmutableSet.copyOf(stacks);
}
public BlockOptionalMetaLookup(Block... blocks) {
- this.boms = Stream.of(blocks)
+ this(Stream.of(blocks)
.map(BlockOptionalMeta::new)
- .toArray(BlockOptionalMeta[]::new);
+ .toArray(BlockOptionalMeta[]::new));
+
}
public BlockOptionalMetaLookup(List blocks) {
- this.boms = blocks.stream()
+ this(blocks.stream()
.map(BlockOptionalMeta::new)
- .toArray(BlockOptionalMeta[]::new);
+ .toArray(BlockOptionalMeta[]::new));
}
public BlockOptionalMetaLookup(String... blocks) {
- this.boms = Stream.of(blocks)
+ this(Stream.of(blocks)
.map(BlockOptionalMeta::new)
- .toArray(BlockOptionalMeta[]::new);
+ .toArray(BlockOptionalMeta[]::new));
}
public boolean has(Block block) {
- for (BlockOptionalMeta bom : boms) {
- if (bom.getBlock() == block) {
- return true;
- }
- }
-
- return false;
+ return blockSet.contains(block);
}
public boolean has(BlockState state) {
- for (BlockOptionalMeta bom : boms) {
- if (bom.matches(state)) {
- return true;
- }
- }
-
- return false;
+ return blockStateSet.contains(state);
}
public boolean has(ItemStack stack) {
- for (BlockOptionalMeta bom : boms) {
- if (bom.matches(stack)) {
- return true;
- }
- }
-
- return false;
+ int hash = ((IItemStack) (Object) stack).getBaritoneHash();
+ hash -= stack.getDamageValue();
+ return stackHashes.contains(hash);
}
public List blocks() {
diff --git a/src/api/java/baritone/api/utils/BooleanBinaryOperator.java b/src/api/java/baritone/api/utils/BooleanBinaryOperator.java
new file mode 100644
index 000000000..cfb85e644
--- /dev/null
+++ b/src/api/java/baritone/api/utils/BooleanBinaryOperator.java
@@ -0,0 +1,27 @@
+/*
+ * 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.utils;
+
+/**
+ * @author Brady
+ */
+@FunctionalInterface
+public interface BooleanBinaryOperator {
+
+ boolean applyAsBoolean(boolean a, boolean b);
+}
diff --git a/src/api/java/baritone/api/utils/BooleanBinaryOperators.java b/src/api/java/baritone/api/utils/BooleanBinaryOperators.java
new file mode 100644
index 000000000..11605c965
--- /dev/null
+++ b/src/api/java/baritone/api/utils/BooleanBinaryOperators.java
@@ -0,0 +1,38 @@
+/*
+ * 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.utils;
+
+/**
+ * @author Brady
+ */
+public enum BooleanBinaryOperators implements BooleanBinaryOperator {
+ OR((a, b) -> a || b),
+ AND((a, b) -> a && b),
+ XOR((a, b) -> a ^ b);
+
+ private final BooleanBinaryOperator op;
+
+ BooleanBinaryOperators(BooleanBinaryOperator op) {
+ this.op = op;
+ }
+
+ @Override
+ public boolean applyAsBoolean(boolean a, boolean b) {
+ return this.op.applyAsBoolean(a, b);
+ }
+}
diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java
index 63ced2496..d66d035f2 100755
--- a/src/api/java/baritone/api/utils/Helper.java
+++ b/src/api/java/baritone/api/utils/Helper.java
@@ -46,8 +46,10 @@ public interface Helper {
Helper HELPER = new Helper() {};
/**
- * Instance of the game
+ * The main game instance returned by {@link Minecraft#getInstance()}.
+ * Deprecated since {@link IPlayerContext#minecraft()} should be used instead (In the majority of cases).
*/
+ @Deprecated
Minecraft mc = Minecraft.getInstance();
/**
@@ -79,7 +81,7 @@ static Component getPrefix() {
* @param message The message to display in the popup
*/
default void logToast(Component title, Component message) {
- mc.execute(() -> BaritoneAPI.getSettings().toaster.value.accept(title, message));
+ Minecraft.getInstance().execute(() -> BaritoneAPI.getSettings().toaster.value.accept(title, message));
}
/**
@@ -140,7 +142,7 @@ default void logNotificationDirect(String message) {
* @param error Whether to log as an error
*/
default void logNotificationDirect(String message, boolean error) {
- mc.execute(() -> BaritoneAPI.getSettings().notifier.value.accept(message, error));
+ Minecraft.getInstance().execute(() -> BaritoneAPI.getSettings().notifier.value.accept(message, error));
}
/**
@@ -175,7 +177,7 @@ default void logDirect(boolean logAsToast, Component... components) {
if (logAsToast) {
logToast(getPrefix(), component);
} else {
- mc.execute(() -> BaritoneAPI.getSettings().logger.value.accept(component));
+ Minecraft.getInstance().execute(() -> BaritoneAPI.getSettings().logger.value.accept(component));
}
}
diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java
index 4e29b1459..1829bb757 100644
--- a/src/api/java/baritone/api/utils/IPlayerContext.java
+++ b/src/api/java/baritone/api/utils/IPlayerContext.java
@@ -18,9 +18,7 @@
package baritone.api.utils;
import baritone.api.cache.IWorldData;
-import java.util.Optional;
-import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
@@ -31,12 +29,18 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
+import java.util.Optional;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
/**
* @author Brady
* @since 11/12/2018
*/
public interface IPlayerContext {
+ Minecraft minecraft();
+
LocalPlayer player();
IPlayerController playerController();
@@ -85,6 +89,8 @@ default Vec3 playerHead() {
return new Vec3(player().position().x, player().position().y + player().getEyeHeight(), player().position().z);
}
+ BetterBlockPos viewerPos();
+
default Rotation playerRotations() {
return new Rotation(player().getYRot(), player().getXRot());
}
diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java
index 36beea7bc..c75a9a559 100644
--- a/src/api/java/baritone/api/utils/Rotation.java
+++ b/src/api/java/baritone/api/utils/Rotation.java
@@ -26,12 +26,12 @@ public class Rotation {
/**
* The yaw angle of this Rotation
*/
- private float yaw;
+ private final float yaw;
/**
* The pitch angle of this Rotation
*/
- private float pitch;
+ private final float pitch;
public Rotation(float yaw, float pitch) {
this.yaw = yaw;
@@ -113,6 +113,10 @@ public Rotation normalizeAndClamp() {
);
}
+ public Rotation withPitch(float pitch) {
+ return new Rotation(this.yaw, pitch);
+ }
+
/**
* Is really close to
*
diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java
index a6156354e..5db577839 100644
--- a/src/api/java/baritone/api/utils/RotationUtils.java
+++ b/src/api/java/baritone/api/utils/RotationUtils.java
@@ -140,14 +140,14 @@ public static Vec3 calcVector3dFromRotation(Rotation rotation) {
* @param ctx Context for the viewing entity
* @param pos The target block position
* @return The optional rotation
- * @see #reachable(LocalPlayer, BlockPos, double)
+ * @see #reachable(IPlayerContext, BlockPos, double)
*/
public static Optional reachable(IPlayerContext ctx, BlockPos pos) {
- return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
+ return reachable(ctx, pos, false);
}
public static Optional reachable(IPlayerContext ctx, BlockPos pos, boolean wouldSneak) {
- return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance(), wouldSneak);
+ return reachable(ctx, pos, ctx.playerController().getBlockReachDistance(), wouldSneak);
}
/**
@@ -157,18 +157,17 @@ public static Optional reachable(IPlayerContext ctx, BlockPos pos, boo
* side that is reachable. The return type will be {@link Optional#empty()} if the entity is
* unable to reach any of the sides of the block.
*
- * @param entity The viewing entity
+ * @param ctx Context for the viewing entity
* @param pos The target block position
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
- public static Optional reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance) {
- return reachable(entity, pos, blockReachDistance, false);
+ public static Optional reachable(IPlayerContext ctx, BlockPos pos, double blockReachDistance) {
+ return reachable(ctx, pos, blockReachDistance, false);
}
- public static Optional reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
- IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
- if (baritone.getPlayerContext().isLookingAt(pos)) {
+ public static Optional reachable(IPlayerContext ctx, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
+ if (BaritoneAPI.getSettings().remainWithExistingLookDirection.value && ctx.isLookingAt(pos)) {
/*
* why add 0.0001?
* to indicate that we actually have a desired pitch
@@ -179,10 +178,10 @@ public static Optional reachable(LocalPlayer entity, BlockPos pos, dou
*
* or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level
*/
- Rotation hypothetical = new Rotation(entity.getYRot(), entity.getXRot() + 0.0001F);
+ Rotation hypothetical = ctx.playerRotations().add(new Rotation(0, 0.0001F));
if (wouldSneak) {
// the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are
- HitResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true);
+ HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), hypothetical, blockReachDistance, true);
if (result != null && result.getType() == HitResult.Type.BLOCK && ((BlockHitResult) result).getBlockPos().equals(pos)) {
return Optional.of(hypothetical); // yes, if we sneaked we would still be looking at the block
}
@@ -190,14 +189,14 @@ public static Optional reachable(LocalPlayer entity, BlockPos pos, dou
return Optional.of(hypothetical);
}
}
- Optional possibleRotation = reachableCenter(entity, pos, blockReachDistance, wouldSneak);
+ Optional possibleRotation = reachableCenter(ctx, pos, blockReachDistance, wouldSneak);
//System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
- BlockState state = entity.level.getBlockState(pos);
- VoxelShape shape = state.getShape(entity.level, pos);
+ BlockState state = ctx.world().getBlockState(pos);
+ VoxelShape shape = state.getShape(ctx.world(), pos);
if (shape.isEmpty()) {
shape = Shapes.block();
}
@@ -205,7 +204,7 @@ public static Optional reachable(LocalPlayer entity, BlockPos pos, dou
double xDiff = shape.min(Direction.Axis.X) * sideOffset.x + shape.max(Direction.Axis.X) * (1 - sideOffset.x);
double yDiff = shape.min(Direction.Axis.Y) * sideOffset.y + shape.max(Direction.Axis.Y) * (1 - sideOffset.y);
double zDiff = shape.min(Direction.Axis.Z) * sideOffset.z + shape.max(Direction.Axis.Z) * (1 - sideOffset.z);
- possibleRotation = reachableOffset(entity, pos, new Vec3(pos.getX(), pos.getY(), pos.getZ()).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak);
+ possibleRotation = reachableOffset(ctx, pos, new Vec3(pos.getX(), pos.getY(), pos.getZ()).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
@@ -218,22 +217,23 @@ public static Optional reachable(LocalPlayer entity, BlockPos pos, dou
* the given offsetted position. The return type will be {@link Optional#empty()} if
* the entity is unable to reach the block with the offset applied.
*
- * @param entity The viewing entity
+ * @param ctx Context for the viewing entity
* @param pos The target block position
* @param offsetPos The position of the block with the offset applied.
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
- public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3 offsetPos, double blockReachDistance, boolean wouldSneak) {
- Vec3 eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getEyePosition(1.0F);
- Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.getYRot(), entity.getXRot()));
- HitResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak);
+ public static Optional reachableOffset(IPlayerContext ctx, BlockPos pos, Vec3 offsetPos, double blockReachDistance, boolean wouldSneak) {
+ Vec3 eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.player().getEyePosition(1.0F);
+ Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, ctx.playerRotations());
+ Rotation actualRotation = BaritoneAPI.getProvider().getBaritoneForPlayer(ctx.player()).getLookBehavior().getAimProcessor().peekRotation(rotation);
+ HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), actualRotation, blockReachDistance, wouldSneak);
//System.out.println(result);
if (result != null && result.getType() == HitResult.Type.BLOCK) {
if (((BlockHitResult) result).getBlockPos().equals(pos)) {
return Optional.of(rotation);
}
- if (entity.level.getBlockState(pos).getBlock() instanceof BaseFireBlock && ((BlockHitResult) result).getBlockPos().equals(pos.below())) {
+ if (ctx.world().getBlockState(pos).getBlock() instanceof BaseFireBlock && ((BlockHitResult) result).getBlockPos().equals(pos.below())) {
return Optional.of(rotation);
}
}
@@ -244,11 +244,45 @@ public static Optional reachableOffset(Entity entity, BlockPos pos, Ve
* Determines if the specified entity is able to reach the specified block where it is
* looking at the direct center of it's hitbox.
*
- * @param entity The viewing entity
+ * @param ctx Context for the viewing entity
* @param pos The target block position
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
+ public static Optional reachableCenter(IPlayerContext ctx, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
+ return reachableOffset(ctx, pos, VecUtils.calculateBlockCenter(ctx.world(), pos), blockReachDistance, wouldSneak);
+ }
+
+ @Deprecated
+ public static Optional reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance) {
+ return reachable(entity, pos, blockReachDistance, false);
+ }
+
+ @Deprecated
+ public static Optional reachable(LocalPlayer entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
+ IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
+ IPlayerContext ctx = baritone.getPlayerContext();
+ return reachable(ctx, pos, blockReachDistance, wouldSneak);
+ }
+
+ @Deprecated
+ public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3 offsetPos, double blockReachDistance, boolean wouldSneak) {
+ Vec3 eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getEyePosition(1.0F);
+ Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.getYRot(), entity.getXRot()));
+ HitResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak);
+ //System.out.println(result);
+ if (result != null && result.getType() == HitResult.Type.BLOCK) {
+ if (((BlockHitResult) result).getBlockPos().equals(pos)) {
+ return Optional.of(rotation);
+ }
+ if (entity.level.getBlockState(pos).getBlock() instanceof BaseFireBlock && ((BlockHitResult) result).getBlockPos().equals(pos.below())) {
+ return Optional.of(rotation);
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Deprecated
public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.level, pos), blockReachDistance, wouldSneak);
}
diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java
index 5b9358a21..6d00fd598 100644
--- a/src/api/java/baritone/api/utils/SettingsUtil.java
+++ b/src/api/java/baritone/api/utils/SettingsUtil.java
@@ -46,12 +46,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
public class SettingsUtil {
- private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDirectory.toPath().resolve("baritone").resolve("settings.txt");
+ public static final String SETTINGS_DEFAULT_NAME = "settings.txt";
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?[^ ]+) +(?.+)"); // key and value split by the first space
- private static final String[] JAVA_ONLY_SETTINGS = {"logger", "notifier", "toaster"};
private static boolean isComment(String line) {
@@ -70,12 +68,12 @@ private static void forEachLine(Path file, Consumer consumer) throws IOE
}
}
- public static void readAndApply(Settings settings) {
+ public static void readAndApply(Settings settings, String settingsName) {
try {
- forEachLine(SETTINGS_PATH, line -> {
+ forEachLine(settingsByName(settingsName), line -> {
Matcher matcher = SETTING_PATTERN.matcher(line);
if (!matcher.matches()) {
- System.out.println("Invalid syntax in setting file: " + line);
+ Helper.HELPER.logDirect("Invalid syntax in setting file: " + line);
return;
}
@@ -84,29 +82,33 @@ public static void readAndApply(Settings settings) {
try {
parseAndApply(settings, settingName, settingValue);
} catch (Exception ex) {
- System.out.println("Unable to parse line " + line);
+ Helper.HELPER.logDirect("Unable to parse line " + line);
ex.printStackTrace();
}
});
} catch (NoSuchFileException ignored) {
- System.out.println("Baritone settings file not found, resetting.");
+ Helper.HELPER.logDirect("Baritone settings file not found, resetting.");
} catch (Exception ex) {
- System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
+ Helper.HELPER.logDirect("Exception while reading Baritone settings, some settings may be reset to default values!");
ex.printStackTrace();
}
}
public static synchronized void save(Settings settings) {
- try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) {
+ try (BufferedWriter out = Files.newBufferedWriter(settingsByName(SETTINGS_DEFAULT_NAME))) {
for (Settings.Setting setting : modifiedSettings(settings)) {
out.write(settingToString(setting) + "\n");
}
} catch (Exception ex) {
- System.out.println("Exception thrown while saving Baritone settings!");
+ Helper.HELPER.logDirect("Exception thrown while saving Baritone settings!");
ex.printStackTrace();
}
}
+ private static Path settingsByName(String name) {
+ return Minecraft.getInstance().gameDirectory.toPath().resolve("baritone").resolve(name);
+ }
+
public static List modifiedSettings(Settings settings) {
List modified = new ArrayList<>();
for (Settings.Setting setting : settings.allSettings) {
@@ -114,7 +116,7 @@ public static List modifiedSettings(Settings settings) {
System.out.println("NULL SETTING?" + setting.getName());
continue;
}
- if (javaOnlySetting(setting)) {
+ if (setting.isJavaOnly()) {
continue; // NO
}
if (setting.value == setting.defaultValue) {
@@ -168,7 +170,7 @@ public static String maybeCensor(int coord) {
}
public static String settingToString(Settings.Setting setting) throws IllegalStateException {
- if (javaOnlySetting(setting)) {
+ if (setting.isJavaOnly()) {
return setting.getName();
}
@@ -176,18 +178,14 @@ public static String settingToString(Settings.Setting setting) throws IllegalSta
}
/**
- * This should always be the same as whether the setting can be parsed from or serialized to a string
+ * Deprecated. Use {@link Settings.Setting#isJavaOnly()} instead.
*
* @param setting The Setting
* @return true if the setting can not be set or read by the user
*/
+ @Deprecated
public static boolean javaOnlySetting(Settings.Setting setting) {
- for (String name : JAVA_ONLY_SETTINGS) { // no JAVA_ONLY_SETTINGS.contains(...) because that would be case sensitive
- if (setting.getName().equalsIgnoreCase(name)) {
- return true;
- }
- }
- return false;
+ return setting.isJavaOnly();
}
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
diff --git a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java
index e5f3e0375..29f9c003b 100644
--- a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java
+++ b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java
@@ -62,9 +62,8 @@ private void sendChatMessage(String string, Component component, CallbackInfo ci
method = "tick",
at = @At(
value = "INVOKE",
- target = "net/minecraft/client/player/LocalPlayer.isPassenger()Z",
- shift = At.Shift.BY,
- by = -3
+ target = "net/minecraft/client/player/AbstractClientPlayer.tick()V",
+ shift = At.Shift.AFTER
)
)
private void onPreUpdate(CallbackInfo ci) {
@@ -74,22 +73,6 @@ private void onPreUpdate(CallbackInfo ci) {
}
}
- @Inject(
- method = "tick",
- at = @At(
- value = "INVOKE",
- target = "net/minecraft/client/player/LocalPlayer.sendPosition()V",
- shift = At.Shift.BY,
- by = 2
- )
- )
- private void onPostUpdate(CallbackInfo ci) {
- IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
- if (baritone != null) {
- baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
- }
- }
-
@Redirect(
method = "aiStep",
at = @At(
diff --git a/src/launch/java/baritone/launch/mixins/MixinCommandSuggestionHelper.java b/src/launch/java/baritone/launch/mixins/MixinCommandSuggestionHelper.java
index 63331502f..2bcdb2d78 100644
--- a/src/launch/java/baritone/launch/mixins/MixinCommandSuggestionHelper.java
+++ b/src/launch/java/baritone/launch/mixins/MixinCommandSuggestionHelper.java
@@ -19,9 +19,12 @@
import baritone.api.BaritoneAPI;
import baritone.api.event.events.TabCompleteEvent;
+import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
+import net.minecraft.client.gui.components.CommandSuggestions;
+import net.minecraft.client.gui.components.EditBox;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -33,8 +36,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import net.minecraft.client.gui.components.CommandSuggestions;
-import net.minecraft.client.gui.components.EditBox;
/**
* @author Brady
@@ -51,9 +52,18 @@ public class MixinCommandSuggestionHelper {
@Final
private List commandUsage;
+ @Shadow
+ private ParseResults currentParse;
+
@Shadow
private CompletableFuture pendingSuggestions;
+ @Shadow
+ private CommandSuggestions.SuggestionsList suggestions;
+
+ @Shadow
+ boolean keepSuggestions;
+
@Inject(
method = "updateCommandInfo",
at = @At("HEAD"),
@@ -74,27 +84,32 @@ private void preUpdateSuggestion(CallbackInfo ci) {
if (event.completions != null) {
ci.cancel();
+ this.currentParse = null; // stop coloring
+
+ if (this.keepSuggestions) { // Supress suggestions update when cycling suggestions.
+ return;
+ }
+
+ this.input.setSuggestion(null); // clear old suggestions
+ this.suggestions = null;
// TODO: Support populating the command usage
this.commandUsage.clear();
if (event.completions.length == 0) {
this.pendingSuggestions = Suggestions.empty();
} else {
- int offset = this.input.getValue().endsWith(" ")
- ? this.input.getCursorPosition()
- : this.input.getValue().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes
+ StringRange range = StringRange.between(prefix.lastIndexOf(" ") + 1, prefix.length()); // if there is no space this starts at 0
List suggestionList = Stream.of(event.completions)
- .map(s -> new Suggestion(StringRange.between(offset, offset + s.length()), s))
+ .map(s -> new Suggestion(range, s))
.collect(Collectors.toList());
- Suggestions suggestions = new Suggestions(
- StringRange.between(offset, offset + suggestionList.stream().mapToInt(s -> s.getText().length()).max().orElse(0)),
- suggestionList);
+ Suggestions suggestions = new Suggestions(range, suggestionList);
this.pendingSuggestions = new CompletableFuture<>();
this.pendingSuggestions.complete(suggestions);
}
+ ((CommandSuggestions) (Object) this).showSuggestions(true); // actually populate the suggestions list from the suggestions future
}
}
}
diff --git a/src/launch/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java
index b48e919f2..748095351 100644
--- a/src/launch/java/baritone/launch/mixins/MixinEntity.java
+++ b/src/launch/java/baritone/launch/mixins/MixinEntity.java
@@ -23,6 +23,7 @@
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -33,21 +34,25 @@ public class MixinEntity {
@Shadow
private float yRot;
- float yawRestore;
+ @Shadow
+ private float xRot;
+
+ @Unique
+ private RotationMoveEvent motionUpdateRotationEvent;
@Inject(
method = "moveRelative",
at = @At("HEAD")
)
private void moveRelativeHead(CallbackInfo info) {
- this.yawRestore = this.yRot;
// noinspection ConstantConditions
if (!LocalPlayer.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this) == null) {
return;
}
- RotationMoveEvent motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.yRot);
+ this.motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.yRot, this.xRot);
BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
- this.yRot = motionUpdateRotationEvent.getYaw();
+ this.yRot = this.motionUpdateRotationEvent.getYaw();
+ this.xRot = this.motionUpdateRotationEvent.getPitch();
}
@Inject(
@@ -55,6 +60,10 @@ private void moveRelativeHead(CallbackInfo info) {
at = @At("RETURN")
)
private void moveRelativeReturn(CallbackInfo info) {
- this.yRot = this.yawRestore;
+ if (this.motionUpdateRotationEvent != null) {
+ this.yRot = this.motionUpdateRotationEvent.getOriginal().getYaw();
+ this.xRot = this.motionUpdateRotationEvent.getOriginal().getPitch();
+ this.motionUpdateRotationEvent = null;
+ }
}
}
diff --git a/src/launch/java/baritone/launch/mixins/MixinLivingEntity.java b/src/launch/java/baritone/launch/mixins/MixinLivingEntity.java
index 44a5c1e32..6858a61aa 100644
--- a/src/launch/java/baritone/launch/mixins/MixinLivingEntity.java
+++ b/src/launch/java/baritone/launch/mixins/MixinLivingEntity.java
@@ -25,12 +25,16 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
+import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import java.util.Optional;
+
import static org.objectweb.asm.Opcodes.GETFIELD;
/**
@@ -43,8 +47,12 @@ public abstract class MixinLivingEntity extends Entity {
/**
* Event called to override the movement direction when jumping
*/
+ @Unique
private RotationMoveEvent jumpRotationEvent;
+ @Unique
+ private RotationMoveEvent elytraRotationEvent;
+
public MixinLivingEntity(EntityType> entityTypeIn, Level worldIn) {
super(entityTypeIn, worldIn);
}
@@ -54,14 +62,10 @@ public MixinLivingEntity(EntityType> entityTypeIn, Level worldIn) {
at = @At("HEAD")
)
private void preMoveRelative(CallbackInfo ci) {
- // noinspection ConstantConditions
- if (LocalPlayer.class.isInstance(this)) {
- IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this);
- if (baritone != null) {
- this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.getYRot());
- baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
- }
- }
+ this.getBaritone().ifPresent(baritone -> {
+ this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.getYRot(), this.getXRot());
+ baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
+ });
}
@Redirect(
@@ -78,5 +82,45 @@ private float overrideYaw(LivingEntity self) {
return self.getYRot();
}
+ @Inject(
+ method = "travel",
+ at = @At(
+ value = "INVOKE",
+ target = "net/minecraft/world/entity/LivingEntity.getLookAngle()Lnet/minecraft/world/phys/Vec3;"
+ )
+ )
+ private void onPreElytraMove(Vec3 direction, CallbackInfo ci) {
+ this.getBaritone().ifPresent(baritone -> {
+ this.elytraRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.getYRot(), this.getXRot());
+ baritone.getGameEventHandler().onPlayerRotationMove(this.elytraRotationEvent);
+ this.setYRot(this.elytraRotationEvent.getYaw());
+ this.setXRot(this.elytraRotationEvent.getPitch());
+ });
+ }
+ @Inject(
+ method = "travel",
+ at = @At(
+ value = "INVOKE",
+ target = "net/minecraft/world/entity/LivingEntity.move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V",
+ shift = At.Shift.AFTER
+ )
+ )
+ private void onPostElytraMove(Vec3 direction, CallbackInfo ci) {
+ if (this.elytraRotationEvent != null) {
+ this.setYRot(this.elytraRotationEvent.getOriginal().getYaw());
+ this.setXRot(this.elytraRotationEvent.getOriginal().getPitch());
+ this.elytraRotationEvent = null;
+ }
+ }
+
+ @Unique
+ private Optional getBaritone() {
+ // noinspection ConstantConditions
+ if (LocalPlayer.class.isInstance(this)) {
+ return Optional.ofNullable(BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this));
+ } else {
+ return Optional.empty();
+ }
+ }
}
diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
index ae6996d0a..686e22d25 100644
--- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
+++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java
@@ -19,6 +19,7 @@
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
+import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.TickEvent;
import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState;
@@ -79,7 +80,21 @@ private void runTick(CallbackInfo ci) {
baritone.getGameEventHandler().onTick(tickProvider.apply(EventState.PRE, type));
}
+ }
+ @Inject(
+ method = "tick",
+ at = @At(
+ value = "INVOKE",
+ target = "net/minecraft/client/multiplayer/ClientLevel.tickEntities()V",
+ shift = At.Shift.AFTER
+ )
+ )
+ private void postUpdateEntities(CallbackInfo ci) {
+ IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(this.player);
+ if (baritone != null) {
+ baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
+ }
}
@Inject(
diff --git a/src/launch/java/baritone/launch/mixins/MixinPalettedContainer$Data.java b/src/launch/java/baritone/launch/mixins/MixinPalettedContainer$Data.java
new file mode 100644
index 000000000..e4c3cc61d
--- /dev/null
+++ b/src/launch/java/baritone/launch/mixins/MixinPalettedContainer$Data.java
@@ -0,0 +1,34 @@
+/*
+ * 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.IPalettedContainer.IData;
+import net.minecraft.util.BitStorage;
+import net.minecraft.world.level.chunk.Palette;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(targets = "net/minecraft/world/level/chunk/PalettedContainer$Data")
+public abstract class MixinPalettedContainer$Data implements IData {
+
+ @Accessor
+ public abstract Palette getPalette();
+
+ @Accessor
+ public abstract BitStorage getStorage();
+}
diff --git a/src/launch/java/baritone/launch/mixins/MixinPalettedContainer.java b/src/launch/java/baritone/launch/mixins/MixinPalettedContainer.java
new file mode 100644
index 000000000..a1b409a09
--- /dev/null
+++ b/src/launch/java/baritone/launch/mixins/MixinPalettedContainer.java
@@ -0,0 +1,100 @@
+/*
+ * 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.IPalettedContainer;
+import baritone.utils.accessor.IPalettedContainer.IData;
+import net.minecraft.util.BitStorage;
+import net.minecraft.world.level.chunk.Palette;
+import net.minecraft.world.level.chunk.PalettedContainer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+@Mixin(PalettedContainer.class)
+public abstract class MixinPalettedContainer implements IPalettedContainer {
+
+ private static final MethodHandle DATA_GETTER;
+
+ // Mixin has no way of referring to the data field and we can't use inheritance
+ // tricks to determine its name, so we use this ugly workaround instead.
+ // Classloading is hell here and causes accessor mixins (@Mixin interfaces with
+ // only @Accessor and @Invoker methods) to break on use and proguard hates method
+ // handles and on top of that mojang decided that error messages during world
+ // load are not needed so if you want to debug this you'll probably need an extra
+ // mixin just to display the error and hard quit the game before follow up errors
+ // blow up your log file.
+ // Mumphrey, please add the shadow classes you promised 5 years ago.
+ static {
+ Field dataField = null;
+ for (Field field : PalettedContainer.class.getDeclaredFields()) {
+ Class> fieldType = field.getType();
+ if (IData.class.isAssignableFrom(fieldType)) {
+ if ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) != 0 || field.isSynthetic()) {
+ continue;
+ }
+ if (dataField != null) {
+ throw new IllegalStateException("PalettedContainer has more than one Data field.");
+ }
+ dataField = field;
+ }
+ }
+ if (dataField == null) {
+ throw new IllegalStateException("PalettedContainer has no Data field.");
+ }
+ MethodHandle rawGetter;
+ try {
+ rawGetter = MethodHandles.lookup().unreflectGetter(dataField);
+ } catch (IllegalAccessException impossible) {
+ // we literally are the owning class, wtf?
+ throw new IllegalStateException("PalettedContainer may not access its own field?!", impossible);
+ }
+ MethodType getterType = MethodType.methodType(IData.class, PalettedContainer.class);
+ DATA_GETTER = MethodHandles.explicitCastArguments(rawGetter, getterType);
+ }
+
+ @Override
+ public Palette getPalette() {
+ return data().getPalette();
+ }
+
+ @Override
+ public BitStorage getStorage() {
+ return data().getStorage();
+ }
+
+ @Unique
+ private IData data() {
+ try {
+ // cast to Object first so the method handle doesn't hide the interface usage from proguard
+ return (IData) (Object) DATA_GETTER.invoke((PalettedContainer) (Object) this);
+ } catch (Throwable t) {
+ throw sneaky(t, RuntimeException.class);
+ }
+ }
+
+ @Unique
+ private static T sneaky(Throwable t, Class as) throws T {
+ throw (T) t;
+ }
+}
diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json
index 4b9ea4c91..b00c7a2a6 100644
--- a/src/launch/resources/mixins.baritone.json
+++ b/src/launch/resources/mixins.baritone.json
@@ -20,6 +20,8 @@
"MixinLootContext",
"MixinMinecraft",
"MixinNetworkManager",
+ "MixinPalettedContainer",
+ "MixinPalettedContainer$Data",
"MixinPlayerController",
"MixinScreen",
"MixinWorldRenderer"
diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java
index 7174a1228..667e5c901 100755
--- a/src/main/java/baritone/Baritone.java
+++ b/src/main/java/baritone/Baritone.java
@@ -20,8 +20,9 @@
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.Settings;
+import baritone.api.behavior.IBehavior;
import baritone.api.event.listener.IEventBus;
-import baritone.api.utils.Helper;
+import baritone.api.process.IBaritoneProcess;
import baritone.api.utils.IPlayerContext;
import baritone.behavior.*;
import baritone.cache.WorldProvider;
@@ -33,16 +34,17 @@
import baritone.utils.GuiClick;
import baritone.utils.InputOverrideHandler;
import baritone.utils.PathingControlManager;
-import baritone.utils.player.PrimaryPlayerContext;
+import baritone.utils.player.BaritonePlayerContext;
import net.minecraft.client.Minecraft;
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
/**
* @author Brady
@@ -50,87 +52,101 @@
*/
public class Baritone implements IBaritone {
- private static ThreadPoolExecutor threadPool;
- private static File dir;
+ private static final ThreadPoolExecutor threadPool;
static {
threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
-
- dir = new File(Minecraft.getInstance().gameDirectory, "baritone");
- if (!Files.exists(dir.toPath())) {
- try {
- Files.createDirectories(dir.toPath());
- } catch (IOException ignored) {}
- }
}
- private GameEventHandler gameEventHandler;
+ private final Minecraft mc;
+ private final Path directory;
- private PathingBehavior pathingBehavior;
- private LookBehavior lookBehavior;
- private InventoryBehavior inventoryBehavior;
- private WaypointBehavior waypointBehavior;
- private InputOverrideHandler inputOverrideHandler;
+ private final GameEventHandler gameEventHandler;
- private FollowProcess followProcess;
- private MineProcess mineProcess;
- private GetToBlockProcess getToBlockProcess;
- private CustomGoalProcess customGoalProcess;
- private BuilderProcess builderProcess;
- private ExploreProcess exploreProcess;
- private BackfillProcess backfillProcess;
- private FarmProcess farmProcess;
+ private final PathingBehavior pathingBehavior;
+ private final LookBehavior lookBehavior;
+ private final InventoryBehavior inventoryBehavior;
+ private final InputOverrideHandler inputOverrideHandler;
- private PathingControlManager pathingControlManager;
- private SelectionManager selectionManager;
- private CommandManager commandManager;
+ private final FollowProcess followProcess;
+ private final MineProcess mineProcess;
+ private final GetToBlockProcess getToBlockProcess;
+ private final CustomGoalProcess customGoalProcess;
+ private final BuilderProcess builderProcess;
+ private final ExploreProcess exploreProcess;
+ private final FarmProcess farmProcess;
+ private final InventoryPauserProcess inventoryPauserProcess;
- private IPlayerContext playerContext;
- private WorldProvider worldProvider;
+ private final PathingControlManager pathingControlManager;
+ private final SelectionManager selectionManager;
+ private final CommandManager commandManager;
+
+ private final IPlayerContext playerContext;
+ private final WorldProvider worldProvider;
public BlockStateInterface bsi;
- Baritone() {
+ Baritone(Minecraft mc) {
+ this.mc = mc;
this.gameEventHandler = new GameEventHandler(this);
+ this.directory = mc.gameDirectory.toPath().resolve("baritone");
+ if (!Files.exists(this.directory)) {
+ try {
+ Files.createDirectories(this.directory);
+ } catch (IOException ignored) {}
+ }
+
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
- this.playerContext = PrimaryPlayerContext.INSTANCE;
+ this.playerContext = new BaritonePlayerContext(this, mc);
{
- // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
- pathingBehavior = new PathingBehavior(this);
- lookBehavior = new LookBehavior(this);
- inventoryBehavior = new InventoryBehavior(this);
- inputOverrideHandler = new InputOverrideHandler(this);
- waypointBehavior = new WaypointBehavior(this);
+ this.lookBehavior = this.registerBehavior(LookBehavior::new);
+ this.pathingBehavior = this.registerBehavior(PathingBehavior::new);
+ this.inventoryBehavior = this.registerBehavior(InventoryBehavior::new);
+ this.inputOverrideHandler = this.registerBehavior(InputOverrideHandler::new);
+ this.registerBehavior(WaypointBehavior::new);
}
this.pathingControlManager = new PathingControlManager(this);
{
- this.pathingControlManager.registerProcess(followProcess = new FollowProcess(this));
- this.pathingControlManager.registerProcess(mineProcess = new MineProcess(this));
- this.pathingControlManager.registerProcess(customGoalProcess = new CustomGoalProcess(this)); // very high iq
- this.pathingControlManager.registerProcess(getToBlockProcess = new GetToBlockProcess(this));
- this.pathingControlManager.registerProcess(builderProcess = new BuilderProcess(this));
- this.pathingControlManager.registerProcess(exploreProcess = new ExploreProcess(this));
- this.pathingControlManager.registerProcess(backfillProcess = new BackfillProcess(this));
- this.pathingControlManager.registerProcess(farmProcess = new FarmProcess(this));
+ this.followProcess = this.registerProcess(FollowProcess::new);
+ this.mineProcess = this.registerProcess(MineProcess::new);
+ this.customGoalProcess = this.registerProcess(CustomGoalProcess::new); // very high iq
+ this.getToBlockProcess = this.registerProcess(GetToBlockProcess::new);
+ this.builderProcess = this.registerProcess(BuilderProcess::new);
+ this.exploreProcess = this.registerProcess(ExploreProcess::new);
+ this.farmProcess = this.registerProcess(FarmProcess::new);
+ this.inventoryPauserProcess = this.registerProcess(InventoryPauserProcess::new);
+ this.registerProcess(BackfillProcess::new);
}
- this.worldProvider = new WorldProvider();
+ this.worldProvider = new WorldProvider(this);
this.selectionManager = new SelectionManager(this);
this.commandManager = new CommandManager(this);
}
+ public void registerBehavior(IBehavior behavior) {
+ this.gameEventHandler.registerEventListener(behavior);
+ }
+
+ public T registerBehavior(Function constructor) {
+ final T behavior = constructor.apply(this);
+ this.registerBehavior(behavior);
+ return behavior;
+ }
+
+ public T registerProcess(Function constructor) {
+ final T behavior = constructor.apply(this);
+ this.pathingControlManager.registerProcess(behavior);
+ return behavior;
+ }
+
@Override
public PathingControlManager getPathingControlManager() {
return this.pathingControlManager;
}
- public void registerBehavior(Behavior behavior) {
- this.gameEventHandler.registerEventListener(behavior);
- }
-
@Override
public InputOverrideHandler getInputOverrideHandler() {
return this.inputOverrideHandler;
@@ -170,6 +186,7 @@ public LookBehavior getLookBehavior() {
return this.lookBehavior;
}
+ @Override
public ExploreProcess getExploreProcess() {
return this.exploreProcess;
}
@@ -179,10 +196,15 @@ public MineProcess getMineProcess() {
return this.mineProcess;
}
+ @Override
public FarmProcess getFarmProcess() {
return this.farmProcess;
}
+ public InventoryPauserProcess getInventoryPauserProcess() {
+ return this.inventoryPauserProcess;
+ }
+
@Override
public PathingBehavior getPathingBehavior() {
return this.pathingBehavior;
@@ -213,17 +235,17 @@ public void openClick() {
new Thread(() -> {
try {
Thread.sleep(100);
- Helper.mc.execute(() -> Helper.mc.setScreen(new GuiClick()));
+ mc.execute(() -> mc.setScreen(new GuiClick()));
} catch (Exception ignored) {}
}).start();
}
- public static Settings settings() {
- return BaritoneAPI.getSettings();
+ public Path getDirectory() {
+ return this.directory;
}
- public static File getDir() {
- return dir;
+ public static Settings settings() {
+ return BaritoneAPI.getSettings();
}
public static Executor getExecutor() {
diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java
index d5457cf85..f34d9bcb9 100644
--- a/src/main/java/baritone/BaritoneProvider.java
+++ b/src/main/java/baritone/BaritoneProvider.java
@@ -22,13 +22,15 @@
import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
-import baritone.cache.WorldScanner;
+import baritone.cache.FasterWorldScanner;
import baritone.command.CommandSystem;
import baritone.command.ExampleBaritoneControl;
import baritone.utils.schematic.SchematicSystem;
+import net.minecraft.client.Minecraft;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* @author Brady
@@ -36,30 +38,45 @@
*/
public final class BaritoneProvider implements IBaritoneProvider {
- private final Baritone primary;
private final List all;
+ private final List allView;
- {
- this.primary = new Baritone();
- this.all = Collections.singletonList(this.primary);
+ public BaritoneProvider() {
+ this.all = new CopyOnWriteArrayList<>();
+ this.allView = Collections.unmodifiableList(this.all);
// Setup chat control, just for the primary instance
- new ExampleBaritoneControl(this.primary);
+ final Baritone primary = (Baritone) this.createBaritone(Minecraft.getInstance());
+ primary.registerBehavior(ExampleBaritoneControl::new);
}
@Override
public IBaritone getPrimaryBaritone() {
- return primary;
+ return this.all.get(0);
}
@Override
public List getAllBaritones() {
- return all;
+ return this.allView;
+ }
+
+ @Override
+ public synchronized IBaritone createBaritone(Minecraft minecraft) {
+ IBaritone baritone = this.getBaritoneForMinecraft(minecraft);
+ if (baritone == null) {
+ this.all.add(baritone = new Baritone(minecraft));
+ }
+ return baritone;
+ }
+
+ @Override
+ public synchronized boolean destroyBaritone(IBaritone baritone) {
+ return baritone != this.getPrimaryBaritone() && this.all.remove(baritone);
}
@Override
public IWorldScanner getWorldScanner() {
- return WorldScanner.INSTANCE;
+ return FasterWorldScanner.INSTANCE;
}
@Override
diff --git a/src/main/java/baritone/behavior/Behavior.java b/src/main/java/baritone/behavior/Behavior.java
index 36273c026..848beb298 100644
--- a/src/main/java/baritone/behavior/Behavior.java
+++ b/src/main/java/baritone/behavior/Behavior.java
@@ -35,6 +35,5 @@ public class Behavior implements IBehavior {
protected Behavior(Baritone baritone) {
this.baritone = baritone;
this.ctx = baritone.getPlayerContext();
- baritone.registerBehavior(this);
}
}
diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java
index 570a3e1c8..43a553d4d 100644
--- a/src/main/java/baritone/behavior/InventoryBehavior.java
+++ b/src/main/java/baritone/behavior/InventoryBehavior.java
@@ -19,6 +19,7 @@
import baritone.Baritone;
import baritone.api.event.events.TickEvent;
+import baritone.api.utils.Helper;
import baritone.utils.ToolSet;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Direction;
@@ -42,7 +43,10 @@
import java.util.Random;
import java.util.function.Predicate;
-public final class InventoryBehavior extends Behavior {
+public final class InventoryBehavior extends Behavior implements Helper {
+
+ int ticksSinceLastInventoryMove;
+ int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt
public InventoryBehavior(Baritone baritone) {
super(baritone);
@@ -60,20 +64,28 @@ public void onTick(TickEvent event) {
// we have a crafting table or a chest or something open
return;
}
+ ticksSinceLastInventoryMove++;
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
- swapWithHotBar(firstValidThrowaway(), 8);
+ requestSwapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class);
if (pick >= 9) {
- swapWithHotBar(pick, 0);
+ requestSwapWithHotBar(pick, 0);
+ }
+ if (lastTickRequestedMove != null) {
+ logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick");
+ requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]);
}
}
- public void attemptToPutOnHotbar(int inMainInvy, Predicate disallowedHotbar) {
+ public boolean attemptToPutOnHotbar(int inMainInvy, Predicate disallowedHotbar) {
OptionalInt destination = getTempHotbarSlot(disallowedHotbar);
if (destination.isPresent()) {
- swapWithHotBar(inMainInvy, destination.getAsInt());
+ if (!requestSwapWithHotBar(inMainInvy, destination.getAsInt())) {
+ return false;
+ }
}
+ return true;
}
public OptionalInt getTempHotbarSlot(Predicate disallowedHotbar) {
@@ -97,8 +109,20 @@ public OptionalInt getTempHotbarSlot(Predicate disallowedHotbar) {
return OptionalInt.of(candidates.get(new Random().nextInt(candidates.size())));
}
- private void swapWithHotBar(int inInventory, int inHotbar) {
+ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) {
+ lastTickRequestedMove = new int[]{inInventory, inHotbar};
+ if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) {
+ logDebug("Inventory move requested but delaying " + ticksSinceLastInventoryMove + " " + Baritone.settings().ticksBetweenInventoryMoves.value);
+ return false;
+ }
+ if (Baritone.settings().inventoryMoveOnlyIfStationary.value && !baritone.getInventoryPauserProcess().stationaryForInventoryMove()) {
+ logDebug("Inventory move requested but delaying until stationary");
+ return false;
+ }
ctx.playerController().windowClick(ctx.player().inventoryMenu.containerId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
+ ticksSinceLastInventoryMove = 0;
+ lastTickRequestedMove = null;
+ return true;
}
private int firstValidThrowaway() { // TODO offhand idk
@@ -200,8 +224,8 @@ public boolean throwaway(boolean select, Predicate super ItemStack> desired, b
if (allowInventory) {
for (int i = 9; i < 36; i++) {
if (desired.test(inv.get(i))) {
- swapWithHotBar(i, 7);
if (select) {
+ requestSwapWithHotBar(i, 7);
p.getInventory().selected = 7;
}
return true;
diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java
index e9b0ca661..722258148 100644
--- a/src/main/java/baritone/behavior/LookBehavior.java
+++ b/src/main/java/baritone/behavior/LookBehavior.java
@@ -20,44 +20,57 @@
import baritone.Baritone;
import baritone.api.Settings;
import baritone.api.behavior.ILookBehavior;
-import baritone.api.event.events.PlayerUpdateEvent;
-import baritone.api.event.events.RotationMoveEvent;
+import baritone.api.behavior.look.IAimProcessor;
+import baritone.api.behavior.look.ITickableAimProcessor;
+import baritone.api.event.events.*;
+import baritone.api.utils.IPlayerContext;
import baritone.api.utils.Rotation;
+import baritone.behavior.look.ForkableRandom;
+import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
+
+import java.util.Optional;
public final class LookBehavior extends Behavior implements ILookBehavior {
/**
- * Target's values are as follows:
+ * The current look target, may be {@code null}.
*/
- private Rotation target;
+ private Target target;
/**
- * Whether or not rotations are currently being forced
+ * The rotation known to the server. Returned by {@link #getEffectiveRotation()} for use in {@link IPlayerContext}.
*/
- private boolean force;
+ private Rotation serverRotation;
/**
- * The last player yaw angle. Used when free looking
+ * The last player rotation. Used to restore the player's angle when using free look.
*
* @see Settings#freeLook
*/
- private float lastYaw;
+ private Rotation prevRotation;
+
+ private final AimProcessor processor;
public LookBehavior(Baritone baritone) {
super(baritone);
+ this.processor = new AimProcessor(baritone.getPlayerContext());
}
@Override
- public void updateTarget(Rotation target, boolean force) {
- this.target = target;
- if (!force) {
- double rand = Math.random() - 0.5;
- if (Math.abs(rand) < 0.1) {
- rand *= 4;
- }
- this.target = new Rotation(this.target.getYaw() + (float) (rand * Baritone.settings().randomLooking113.value), this.target.getPitch());
+ public void updateTarget(Rotation rotation, boolean blockInteract) {
+ this.target = new Target(rotation, blockInteract);
+ }
+
+ @Override
+ public IAimProcessor getAimProcessor() {
+ return this.processor;
+ }
+
+ @Override
+ public void onTick(TickEvent event) {
+ if (event.getType() == TickEvent.Type.IN) {
+ this.processor.tick();
}
- this.force = force || !Baritone.settings().freeLook.value;
}
@Override
@@ -65,35 +78,30 @@ public void onPlayerUpdate(PlayerUpdateEvent event) {
if (this.target == null) {
return;
}
-
- // Whether or not we're going to silently set our angles
- boolean silent = Baritone.settings().antiCheatCompatibility.value && !this.force;
-
switch (event.getState()) {
case PRE: {
- if (this.force) {
- ctx.player().setYRot(this.target.getYaw());
- float oldPitch = ctx.player().getXRot();
- float desiredPitch = this.target.getPitch();
- ctx.player().setXRot(desiredPitch);
- ctx.player().setYRot((float) (ctx.player().getYRot() + (Math.random() - 0.5) * Baritone.settings().randomLooking.value));
- ctx.player().setXRot((float) (ctx.player().getXRot() + (Math.random() - 0.5) * Baritone.settings().randomLooking.value));
- if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) {
- nudgeToLevel();
- }
- this.target = null;
+ if (this.target.mode == Target.Mode.NONE) {
+ // Just return for PRE, we still want to set target to null on POST
+ return;
}
- if (silent) {
- this.lastYaw = ctx.player().getYRot();
- ctx.player().setYRot(this.target.getYaw());
+ if (this.target.mode == Target.Mode.SERVER) {
+ this.prevRotation = new Rotation(ctx.player().getYRot(), ctx.player().getXRot());
}
+
+ final Rotation actual = this.processor.peekRotation(this.target.rotation);
+ ctx.player().setYRot(actual.getYaw());
+ ctx.player().setXRot(actual.getPitch());
break;
}
case POST: {
- if (silent) {
- ctx.player().setYRot(this.lastYaw);
- this.target = null;
+ // Reset the player's rotations back to their original values
+ if (this.prevRotation != null) {
+ ctx.player().setYRot(this.prevRotation.getYaw());
+ ctx.player().setXRot(this.prevRotation.getPitch());
+ this.prevRotation = null;
}
+ // The target is done being used for this game tick, so it can be invalidated
+ this.target = null;
break;
}
default:
@@ -101,34 +109,223 @@ public void onPlayerUpdate(PlayerUpdateEvent event) {
}
}
+ @Override
+ public void onSendPacket(PacketEvent event) {
+ if (!(event.getPacket() instanceof ServerboundMovePlayerPacket)) {
+ return;
+ }
+
+ final ServerboundMovePlayerPacket packet = (ServerboundMovePlayerPacket) event.getPacket();
+ if (packet instanceof ServerboundMovePlayerPacket.Rot || packet instanceof ServerboundMovePlayerPacket.PosRot) {
+ this.serverRotation = new Rotation(packet.getYRot(0.0f), packet.getXRot(0.0f));
+ }
+ }
+
+ @Override
+ public void onWorldEvent(WorldEvent event) {
+ this.serverRotation = null;
+ this.target = null;
+ }
+
public void pig() {
if (this.target != null) {
- ctx.player().setYRot(this.target.getYaw());
+ final Rotation actual = this.processor.peekRotation(this.target.rotation);
+ ctx.player().setYRot(actual.getYaw());
+ }
+ }
+
+ public Optional getEffectiveRotation() {
+ if (Baritone.settings().freeLook.value) {
+ return Optional.ofNullable(this.serverRotation);
}
+ // If freeLook isn't on, just defer to the player's actual rotations
+ return Optional.empty();
}
@Override
public void onPlayerRotationMove(RotationMoveEvent event) {
if (this.target != null) {
+ final Rotation actual = this.processor.peekRotation(this.target.rotation);
+ event.setYaw(actual.getYaw());
+ event.setPitch(actual.getPitch());
+ }
+ }
- event.setYaw(this.target.getYaw());
+ private static final class AimProcessor extends AbstractAimProcessor {
- // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
- // Also the type has to be MOTION_UPDATE because that is called after JUMP
- if (!Baritone.settings().antiCheatCompatibility.value && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE && !this.force) {
- this.target = null;
+ public AimProcessor(final IPlayerContext ctx) {
+ super(ctx);
+ }
+
+ @Override
+ protected Rotation getPrevRotation() {
+ // Implementation will use LookBehavior.serverRotation
+ return ctx.playerRotations();
+ }
+ }
+
+ private static abstract class AbstractAimProcessor implements ITickableAimProcessor {
+
+ protected final IPlayerContext ctx;
+ private final ForkableRandom rand;
+ private double randomYawOffset;
+ private double randomPitchOffset;
+
+ public AbstractAimProcessor(IPlayerContext ctx) {
+ this.ctx = ctx;
+ this.rand = new ForkableRandom();
+ }
+
+ private AbstractAimProcessor(final AbstractAimProcessor source) {
+ this.ctx = source.ctx;
+ this.rand = source.rand.fork();
+ this.randomYawOffset = source.randomYawOffset;
+ this.randomPitchOffset = source.randomPitchOffset;
+ }
+
+ @Override
+ public final Rotation peekRotation(final Rotation rotation) {
+ final Rotation prev = this.getPrevRotation();
+
+ float desiredYaw = rotation.getYaw();
+ float desiredPitch = rotation.getPitch();
+
+ // In other words, the target doesn't care about the pitch, so it used playerRotations().getPitch()
+ // and it's safe to adjust it to a normal level
+ if (desiredPitch == prev.getPitch()) {
+ desiredPitch = nudgeToLevel(desiredPitch);
}
+
+ desiredYaw += this.randomYawOffset;
+ desiredPitch += this.randomPitchOffset;
+
+ return new Rotation(
+ this.calculateMouseMove(prev.getYaw(), desiredYaw),
+ this.calculateMouseMove(prev.getPitch(), desiredPitch)
+ ).clamp();
+ }
+
+ @Override
+ public final void tick() {
+ // randomLooking
+ this.randomYawOffset = (this.rand.nextDouble() - 0.5) * Baritone.settings().randomLooking.value;
+ this.randomPitchOffset = (this.rand.nextDouble() - 0.5) * Baritone.settings().randomLooking.value;
+
+ // randomLooking113
+ double random = this.rand.nextDouble() - 0.5;
+ if (Math.abs(random) < 0.1) {
+ random *= 4;
+ }
+ this.randomYawOffset += random * Baritone.settings().randomLooking113.value;
+ }
+
+ @Override
+ public final void advance(int ticks) {
+ for (int i = 0; i < ticks; i++) {
+ this.tick();
+ }
+ }
+
+ @Override
+ public Rotation nextRotation(final Rotation rotation) {
+ final Rotation actual = this.peekRotation(rotation);
+ this.tick();
+ return actual;
+ }
+
+ @Override
+ public final ITickableAimProcessor fork() {
+ return new AbstractAimProcessor(this) {
+
+ private Rotation prev = AbstractAimProcessor.this.getPrevRotation();
+
+ @Override
+ public Rotation nextRotation(final Rotation rotation) {
+ return (this.prev = super.nextRotation(rotation));
+ }
+
+ @Override
+ protected Rotation getPrevRotation() {
+ return this.prev;
+ }
+ };
+ }
+
+ protected abstract Rotation getPrevRotation();
+
+ /**
+ * Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1})
+ */
+ private float nudgeToLevel(float pitch) {
+ if (pitch < -20) {
+ return pitch + 1;
+ } else if (pitch > 10) {
+ return pitch - 1;
+ }
+ return pitch;
+ }
+
+ private float calculateMouseMove(float current, float target) {
+ final float delta = target - current;
+ final double deltaPx = angleToMouse(delta); // yes, even the mouse movements use double
+ return current + mouseToAngle(deltaPx);
+ }
+
+ private double angleToMouse(float angleDelta) {
+ final float minAngleChange = mouseToAngle(1);
+ return Math.round(angleDelta / minAngleChange);
+ }
+
+ private float mouseToAngle(double mouseDelta) {
+ // casting float literals to double gets us the precise values used by mc
+ final double f = ctx.minecraft().options.sensitivity().get() * (double) 0.6f + (double) 0.2f;
+ return (float) (mouseDelta * f * f * f * 8.0d) * 0.15f; // yes, one double and one float scaling factor
}
}
- /**
- * Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1})
- */
- private void nudgeToLevel() {
- if (ctx.player().getXRot() < -20) {
- ctx.player().setXRot(ctx.player().getXRot() + 1);
- } else if (ctx.player().getXRot() > 10) {
- ctx.player().setXRot(ctx.player().getXRot() - 1);
+ private static class Target {
+
+ public final Rotation rotation;
+ public final Mode mode;
+
+ public Target(Rotation rotation, boolean blockInteract) {
+ this.rotation = rotation;
+ this.mode = Mode.resolve(blockInteract);
+ }
+
+ enum Mode {
+ /**
+ * Rotation will be set client-side and is visual to the player
+ */
+ CLIENT,
+
+ /**
+ * Rotation will be set server-side and is silent to the player
+ */
+ SERVER,
+
+ /**
+ * Rotation will remain unaffected on both the client and server
+ */
+ NONE;
+
+ static Mode resolve(boolean blockInteract) {
+ final Settings settings = Baritone.settings();
+ final boolean antiCheat = settings.antiCheatCompatibility.value;
+ final boolean blockFreeLook = settings.blockFreeLook.value;
+ final boolean freeLook = settings.freeLook.value;
+
+ if (!freeLook) return CLIENT;
+ if (!blockFreeLook && blockInteract) return CLIENT;
+
+ // Regardless of if antiCheatCompatibility is enabled, if a blockInteract is requested then the player
+ // rotation needs to be set somehow, otherwise Baritone will halt since objectMouseOver() will just be
+ // whatever the player is mousing over visually. Let's just settle for setting it silently.
+ if (antiCheat || blockInteract) return SERVER;
+
+ // Pathing regularly without antiCheatCompatibility, don't set the player rotation
+ return NONE;
+ }
}
}
}
diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java
index c307e673b..b9d2f9cd9 100644
--- a/src/main/java/baritone/behavior/PathingBehavior.java
+++ b/src/main/java/baritone/behavior/PathingBehavior.java
@@ -238,11 +238,11 @@ public void onPlayerUpdate(PlayerUpdateEvent event) {
if (current != null) {
switch (event.getState()) {
case PRE:
- lastAutoJump = mc.options.autoJump().get();
- mc.options.autoJump().set(false);
+ lastAutoJump = ctx.minecraft().options.autoJump().get();
+ ctx.minecraft().options.autoJump().set(false);
break;
case POST:
- mc.options.autoJump().set(lastAutoJump);
+ ctx.minecraft().options.autoJump().set(lastAutoJump);
break;
default:
break;
diff --git a/src/main/java/baritone/behavior/look/ForkableRandom.java b/src/main/java/baritone/behavior/look/ForkableRandom.java
new file mode 100644
index 000000000..5f5f942d2
--- /dev/null
+++ b/src/main/java/baritone/behavior/look/ForkableRandom.java
@@ -0,0 +1,85 @@
+/*
+ * 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.behavior.look;
+
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.LongSupplier;
+
+/**
+ * Implementation of Xoroshiro256++
+ *
+ * Extended to produce random double-precision floating point numbers, and allow copies to be spawned via {@link #fork},
+ * which share the same internal state as the source object.
+ *
+ * @author Brady
+ */
+public final class ForkableRandom {
+
+ private static final double DOUBLE_UNIT = 0x1.0p-53;
+
+ private final long[] s;
+
+ public ForkableRandom() {
+ this(System.nanoTime() ^ System.currentTimeMillis());
+ }
+
+ public ForkableRandom(long seedIn) {
+ final AtomicLong seed = new AtomicLong(seedIn);
+ final LongSupplier splitmix64 = () -> {
+ long z = seed.addAndGet(0x9e3779b97f4a7c15L);
+ z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L;
+ z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL;
+ return z ^ (z >>> 31);
+ };
+ this.s = new long[] {
+ splitmix64.getAsLong(),
+ splitmix64.getAsLong(),
+ splitmix64.getAsLong(),
+ splitmix64.getAsLong()
+ };
+ }
+
+ private ForkableRandom(long[] s) {
+ this.s = s;
+ }
+
+ public double nextDouble() {
+ return (this.next() >>> 11) * DOUBLE_UNIT;
+ }
+
+ public long next() {
+ final long result = rotl(this.s[0] + this.s[3], 23) + this.s[0];
+ final long t = this.s[1] << 17;
+ this.s[2] ^= this.s[0];
+ this.s[3] ^= this.s[1];
+ this.s[1] ^= this.s[2];
+ this.s[0] ^= this.s[3];
+ this.s[2] ^= t;
+ this.s[3] = rotl(this.s[3], 45);
+ return result;
+ }
+
+ public ForkableRandom fork() {
+ return new ForkableRandom(Arrays.copyOf(this.s, 4));
+ }
+
+ private static long rotl(long x, int k) {
+ return (x << k) | (x >>> (64 - k));
+ }
+}
diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java
index bbc713af7..3109d9293 100644
--- a/src/main/java/baritone/cache/CachedChunk.java
+++ b/src/main/java/baritone/cache/CachedChunk.java
@@ -21,16 +21,17 @@
import baritone.utils.pathing.PathingBlockType;
import com.google.common.collect.ImmutableSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.List;
-import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.dimension.DimensionType;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map;
+
/**
* @author Brady
* @since 8/3/2018
diff --git a/src/main/java/baritone/cache/CachedRegion.java b/src/main/java/baritone/cache/CachedRegion.java
index 9bcebcaad..8aa992d79 100644
--- a/src/main/java/baritone/cache/CachedRegion.java
+++ b/src/main/java/baritone/cache/CachedRegion.java
@@ -20,6 +20,10 @@
import baritone.Baritone;
import baritone.api.cache.ICachedRegion;
import baritone.api.utils.BlockUtils;
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.dimension.DimensionType;
+
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -27,9 +31,6 @@
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
-import net.minecraft.core.BlockPos;
-import net.minecraft.world.level.block.state.BlockState;
-import net.minecraft.world.level.dimension.DimensionType;
/**
* @author Brady
diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java
index 4e323097c..fe8119993 100644
--- a/src/main/java/baritone/cache/CachedWorld.java
+++ b/src/main/java/baritone/cache/CachedWorld.java
@@ -25,6 +25,13 @@
import baritone.api.utils.Helper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
+import net.minecraft.core.BlockPos;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.chunk.LevelChunk;
+import net.minecraft.world.level.dimension.DimensionType;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -33,12 +40,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
-import net.minecraft.core.BlockPos;
-import net.minecraft.resources.ResourceKey;
-import net.minecraft.world.level.ChunkPos;
-import net.minecraft.world.level.Level;
-import net.minecraft.world.level.chunk.LevelChunk;
-import net.minecraft.world.level.dimension.DimensionType;
/**
* @author Brady
@@ -309,6 +310,9 @@ public void run() {
try {
ChunkPos pos = toPackQueue.take();
LevelChunk chunk = toPackMap.remove(pos);
+ if (toPackQueue.size() > Baritone.settings().chunkPackerQueueMaxSize.value) {
+ continue;
+ }
CachedChunk cached = ChunkPacker.pack(chunk);
CachedWorld.this.updateCachedChunk(cached);
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);
diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java
index d544ac74d..5d619543d 100644
--- a/src/main/java/baritone/cache/ChunkPacker.java
+++ b/src/main/java/baritone/cache/ChunkPacker.java
@@ -34,6 +34,7 @@
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.phys.Vec3;
+
import java.util.*;
import static baritone.utils.BlockStateInterface.getFromChunk;
diff --git a/src/main/java/baritone/cache/FasterWorldScanner.java b/src/main/java/baritone/cache/FasterWorldScanner.java
new file mode 100644
index 000000000..b001fef30
--- /dev/null
+++ b/src/main/java/baritone/cache/FasterWorldScanner.java
@@ -0,0 +1,262 @@
+/*
+ * 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.cache;
+
+import baritone.api.cache.ICachedWorld;
+import baritone.api.cache.IWorldScanner;
+import baritone.api.utils.BetterBlockPos;
+import baritone.api.utils.BlockOptionalMetaLookup;
+import baritone.api.utils.IPlayerContext;
+import baritone.utils.accessor.IPalettedContainer;
+import io.netty.buffer.Unpooled;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.IdMapper;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.util.BitStorage;
+import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.chunk.GlobalPalette;
+import net.minecraft.world.level.chunk.ChunkSource;
+import net.minecraft.world.level.chunk.LevelChunk;
+import net.minecraft.world.level.chunk.LevelChunkSection;
+import net.minecraft.world.level.chunk.Palette;
+import net.minecraft.world.level.chunk.PalettedContainer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum FasterWorldScanner implements IWorldScanner {
+ INSTANCE;
+ @Override
+ public List scanChunkRadius(IPlayerContext ctx, BlockOptionalMetaLookup filter, int max, int yLevelThreshold, int maxSearchRadius) {
+ assert ctx.world() != null;
+ if (maxSearchRadius < 0) {
+ throw new IllegalArgumentException("chunkRange must be >= 0");
+ }
+ return scanChunksInternal(ctx, filter, getChunkRange(ctx.playerFeet().x >> 4, ctx.playerFeet().z >> 4, maxSearchRadius), max);
+ }
+
+ @Override
+ public List scanChunk(IPlayerContext ctx, BlockOptionalMetaLookup filter, ChunkPos pos, int max, int yLevelThreshold) {
+ Stream stream = scanChunkInternal(ctx, filter, pos);
+ if (max >= 0) {
+ stream = stream.limit(max);
+ }
+ return stream.collect(Collectors.toList());
+ }
+
+ @Override
+ public int repack(IPlayerContext ctx) {
+ return this.repack(ctx, 40);
+ }
+
+ @Override
+ public int repack(IPlayerContext ctx, int range) {
+ ChunkSource chunkProvider = ctx.world().getChunkSource();
+ 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++) {
+ LevelChunk chunk = chunkProvider.getChunk(x, z, false);
+
+ if (chunk != null && !chunk.isEmpty()) {
+ queued++;
+ cachedWorld.queueForPacking(chunk);
+ }
+ }
+ }
+
+ return queued;
+ }
+
+ // ordered in a way that the closest blocks are generally first
+ public static List getChunkRange(int centerX, int centerZ, int chunkRadius) {
+ List chunks = new ArrayList<>();
+ // spiral out
+ chunks.add(new ChunkPos(centerX, centerZ));
+ for (int i = 1; i < chunkRadius; i++) {
+ for (int j = 0; j <= i; j++) {
+ chunks.add(new ChunkPos(centerX - j, centerZ - i));
+ if (j != 0) {
+ chunks.add(new ChunkPos(centerX + j, centerZ - i));
+ chunks.add(new ChunkPos(centerX - j, centerZ + i));
+ }
+ chunks.add(new ChunkPos(centerX + j, centerZ + i));
+ if (j != i) {
+ chunks.add(new ChunkPos(centerX - i, centerZ - j));
+ chunks.add(new ChunkPos(centerX + i, centerZ - j));
+ if (j != 0) {
+ chunks.add(new ChunkPos(centerX - i, centerZ + j));
+ chunks.add(new ChunkPos(centerX + i, centerZ + j));
+ }
+ }
+ }
+ }
+ return chunks;
+ }
+
+ private List scanChunksInternal(IPlayerContext ctx, BlockOptionalMetaLookup lookup, List chunkPositions, int maxBlocks) {
+ assert ctx.world() != null;
+ try {
+ // p -> scanChunkInternal(ctx, lookup, p)
+ Stream posStream = chunkPositions.parallelStream().flatMap(p -> scanChunkInternal(ctx, lookup, p));
+ if (maxBlocks >= 0) {
+ // WARNING: this can be expensive if maxBlocks is large...
+ // see limit's javadoc
+ posStream = posStream.limit(maxBlocks);
+ }
+ return posStream.collect(Collectors.toList());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ private Stream scanChunkInternal(IPlayerContext ctx, BlockOptionalMetaLookup lookup, ChunkPos pos) {
+ ChunkSource chunkProvider = ctx.world().getChunkSource();
+ // if chunk is not loaded, return empty stream
+ if (!chunkProvider.hasChunk(pos.x, pos.z)) {
+ return Stream.empty();
+ }
+
+ long chunkX = (long) pos.x << 4;
+ long chunkZ = (long) pos.z << 4;
+
+ int playerSectionY = ctx.playerFeet().y >> 4;
+
+ return collectChunkSections(lookup, chunkProvider.getChunk(pos.x, pos.z, false), chunkX, chunkZ, playerSectionY).stream();
+ }
+
+
+
+ private List collectChunkSections(BlockOptionalMetaLookup lookup, LevelChunk chunk, long chunkX, long chunkZ, int playerSection) {
+ // iterate over sections relative to player
+ List blocks = new ArrayList<>();
+ LevelChunkSection[] sections = chunk.getSections();
+ int l = sections.length;
+ int i = playerSection - 1;
+ int j = playerSection;
+ for (; i >= 0 || j < l; ++j, --i) {
+ if (j < l) {
+ visitSection(lookup, sections[j], blocks, chunkX, chunkZ);
+ }
+ if (i >= 0) {
+ visitSection(lookup, sections[i], blocks, chunkX, chunkZ);
+ }
+ }
+ return blocks;
+ }
+
+ private void visitSection(BlockOptionalMetaLookup lookup, LevelChunkSection section, List blocks, long chunkX, long chunkZ) {
+ if (section == null || section.hasOnlyAir()) {
+ return;
+ }
+
+ PalettedContainer sectionContainer = section.getStates();
+ //this won't work if the PaletteStorage is of the type EmptyPaletteStorage
+ if (((IPalettedContainer) sectionContainer).getStorage() == null) {
+ return;
+ }
+
+ boolean[] isInFilter = getIncludedFilterIndices(lookup, ((IPalettedContainer) sectionContainer).getPalette());
+ if (isInFilter.length == 0) {
+ return;
+ }
+
+ BitStorage array = ((IPalettedContainer) section.getStates()).getStorage();
+ long[] longArray = array.getRaw();
+ int arraySize = array.getSize();
+ int bitsPerEntry = array.getBits();
+ long maxEntryValue = (1L << bitsPerEntry) - 1L;
+
+
+ int yOffset = section.bottomBlockY();
+
+ for (int i = 0, idx = 0; i < longArray.length && idx < arraySize; ++i) {
+ long l = longArray[i];
+ for (int offset = 0; offset <= (64 - bitsPerEntry) && idx < arraySize; offset += bitsPerEntry, ++idx) {
+ int value = (int) ((l >> offset) & maxEntryValue);
+ if (isInFilter[value]) {
+ //noinspection DuplicateExpressions
+ blocks.add(new BlockPos(
+ chunkX + ((idx & 255) & 15),
+ yOffset + (idx >> 8),
+ chunkZ + ((idx & 255) >> 4)
+ ));
+ }
+ }
+ }
+ }
+
+ private boolean[] getIncludedFilterIndices(BlockOptionalMetaLookup lookup, Palette palette) {
+ boolean commonBlockFound = false;
+ IdMapper paletteMap = getPalette(palette);
+ int size = paletteMap.size();
+
+ boolean[] isInFilter = new boolean[size];
+
+ for (int i = 0; i < size; i++) {
+ BlockState state = paletteMap.byId(i);
+ if (lookup.has(state)) {
+ isInFilter[i] = true;
+ commonBlockFound = true;
+ } else {
+ isInFilter[i] = false;
+ }
+ }
+
+ if (!commonBlockFound) {
+ return new boolean[0];
+ }
+ return isInFilter;
+ }
+
+ /**
+ * cheats to get the actual map of id -> blockstate from the various palette implementations
+ */
+ private static IdMapper getPalette(Palette palette) {
+ if (palette instanceof GlobalPalette) {
+ return Block.BLOCK_STATE_REGISTRY;
+ } else {
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
+ palette.write(buf);
+ int size = buf.readVarInt();
+ IdMapper states = new IdMapper<>();
+ for (int i = 0; i < size; i++) {
+ BlockState state = Block.BLOCK_STATE_REGISTRY.byId(buf.readVarInt());
+ assert state != null;
+ states.addMapping(state, i);
+ }
+ return states;
+ }
+ }
+}
diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java
index f3d96a0db..035b50b98 100644
--- a/src/main/java/baritone/cache/WorldProvider.java
+++ b/src/main/java/baritone/cache/WorldProvider.java
@@ -19,136 +19,163 @@
import baritone.Baritone;
import baritone.api.cache.IWorldProvider;
-import baritone.api.utils.Helper;
+import baritone.api.utils.IPlayerContext;
+import net.minecraft.client.multiplayer.ServerData;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.util.Tuple;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.dimension.DimensionType;
+import net.minecraft.world.level.storage.LevelResource;
import org.apache.commons.lang3.SystemUtils;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Consumer;
-import net.minecraft.client.server.IntegratedServer;
-import net.minecraft.resources.ResourceKey;
-import net.minecraft.world.level.Level;
-import net.minecraft.world.level.dimension.DimensionType;
-import net.minecraft.world.level.storage.LevelResource;
+import java.util.Optional;
/**
* @author Brady
* @since 8/4/2018
*/
-public class WorldProvider implements IWorldProvider, Helper {
+public class WorldProvider implements IWorldProvider {
- private static final Map worldCache = new HashMap<>(); // this is how the bots have the same cached world
+ private static final Map worldCache = new HashMap<>();
+ private final Baritone baritone;
+ private final IPlayerContext ctx;
private WorldData currentWorld;
- private Level mcWorld; // this let's us detect a broken load/unload hook
+
+ /**
+ * This lets us detect a broken load/unload hook.
+ * @see #detectAndHandleBrokenLoading()
+ */
+ private Level mcWorld;
+
+ public WorldProvider(Baritone baritone) {
+ this.baritone = baritone;
+ this.ctx = baritone.getPlayerContext();
+ }
@Override
public final WorldData getCurrentWorld() {
- detectAndHandleBrokenLoading();
+ this.detectAndHandleBrokenLoading();
return this.currentWorld;
}
/**
* Called when a new world is initialized to discover the
*
- * @param world The world's Registry Data
+ * @param world The new world
*/
- public final void initWorld(ResourceKey worldKey, DimensionType world) {
- Path directory;
- Path readme;
+ public final void initWorld(Level world) {
+ this.getSaveDirectories(world).ifPresent(dirs -> {
+ final Path worldDir = dirs.getA();
+ final Path readmeDir = dirs.getB();
- IntegratedServer integratedServer = mc.getSingleplayerServer();
+ try {
+ // lol wtf is this baritone folder in my minecraft save?
+ // good thing we have a readme
+ Files.createDirectories(readmeDir);
+ Files.write(
+ readmeDir.resolve("readme.txt"),
+ "https://github.com/cabaletta/baritone\n".getBytes(StandardCharsets.US_ASCII)
+ );
+ } catch (IOException ignored) {}
+
+ // We will actually store the world data in a subfolder: "DIM"
+ final Path worldDataDir = this.getWorldDataDirectory(worldDir, world);
+ try {
+ Files.createDirectories(worldDataDir);
+ } catch (IOException ignored) {}
+
+ System.out.println("Baritone world data dir: " + worldDataDir);
+ synchronized (worldCache) {
+ this.currentWorld = worldCache.computeIfAbsent(worldDataDir, d -> new WorldData(d, world.dimensionType()));
+ }
+ this.mcWorld = ctx.world();
+ });
+ }
+
+ public final void closeWorld() {
+ WorldData world = this.currentWorld;
+ this.currentWorld = null;
+ this.mcWorld = null;
+ if (world == null) {
+ return;
+ }
+ world.onClose();
+ }
+
+ private Path getWorldDataDirectory(Path parent, Level world) {
+ ResourceLocation dimId = world.dimension().location();
+ int height = world.dimensionType().logicalHeight();
+ return parent.resolve(dimId.getNamespace()).resolve(dimId.getPath() + "_" + height);
+ }
+
+ /**
+ * @param world The world
+ * @return An {@link Optional} containing the world's baritone dir and readme dir, or {@link Optional#empty()} if
+ * the world isn't valid for caching.
+ */
+ private Optional> getSaveDirectories(Level world) {
+ Path worldDir;
+ Path readmeDir;
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
- if (mc.hasSingleplayerServer()) {
- directory = DimensionType.getStorageFolder(worldKey, integratedServer.getWorldPath(LevelResource.ROOT));
+ if (ctx.minecraft().hasSingleplayerServer()) {
+ worldDir = ctx.minecraft().getSingleplayerServer().getWorldPath(LevelResource.ROOT);
- // Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
- if (directory.relativize(mc.gameDirectory.toPath()).getNameCount() != 2) {
+ // Gets the "depth" of this directory relative to the game's run directory, 2 is the location of the world
+ if (worldDir.relativize(ctx.minecraft().gameDirectory.toPath()).getNameCount() != 2) {
// subdirectory of the main save directory for this world
- directory = directory.getParent();
+ worldDir = worldDir.getParent();
}
- directory = directory.resolve("baritone");
- readme = directory;
+ worldDir = worldDir.resolve("baritone");
+ readmeDir = worldDir;
} else { // Otherwise, the server must be remote...
String folderName;
- if (mc.getCurrentServer() != null) {
- folderName = mc.isConnectedToRealms() ? "realms" : mc.getCurrentServer().ip;
+ final ServerData serverData = ctx.minecraft().getCurrentServer();
+ if (serverData != null) {
+ folderName = ctx.minecraft().isConnectedToRealms() ? "realms" : serverData.ip;
} else {
//replaymod causes null currentServer and false singleplayer.
System.out.println("World seems to be a replay. Not loading Baritone cache.");
currentWorld = null;
- mcWorld = mc.level;
- return;
+ mcWorld = ctx.world();
+ return Optional.empty();
}
if (SystemUtils.IS_OS_WINDOWS) {
folderName = folderName.replace(":", "_");
}
- directory = Baritone.getDir().toPath().resolve(folderName);
- readme = Baritone.getDir().toPath();
- }
-
- // lol wtf is this baritone folder in my minecraft save?
- try (FileOutputStream out = new FileOutputStream(readme.resolve("readme.txt").toFile())) {
- // good thing we have a readme
- out.write("https://github.com/cabaletta/baritone\n".getBytes());
- } catch (IOException ignored) {}
-
- // We will actually store the world data in a subfolder: "DIM"
- Path dir = getDimDir(worldKey, world.logicalHeight(), directory);
- if (!Files.exists(dir)) {
- try {
- Files.createDirectories(dir);
- } catch (IOException ignored) {}
- }
-
- System.out.println("Baritone world data dir: " + dir);
- synchronized (worldCache) {
- this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, world));
- }
- this.mcWorld = mc.level;
- }
-
- public final Path getDimDir(ResourceKey level, int height, Path directory) {
- return directory.resolve(level.location().getNamespace()).resolve(level.location().getPath() + "_" + height);
- }
-
- public final void closeWorld() {
- WorldData world = this.currentWorld;
- this.currentWorld = null;
- this.mcWorld = null;
- if (world == null) {
- return;
+ // TODO: This should probably be in "baritone/servers"
+ worldDir = baritone.getDirectory().resolve(folderName);
+ // Just write the readme to the baritone directory instead of each server save in it
+ readmeDir = baritone.getDirectory();
}
- world.onClose();
- }
- public final void ifWorldLoaded(Consumer currentWorldConsumer) {
- detectAndHandleBrokenLoading();
- if (this.currentWorld != null) {
- currentWorldConsumer.accept(this.currentWorld);
- }
+ return Optional.of(new Tuple<>(worldDir, readmeDir));
}
- private final void detectAndHandleBrokenLoading() {
- if (this.mcWorld != mc.level) {
+ /**
+ * Why does this exist instead of fixing the event? Some mods break the event. Lol.
+ */
+ private void detectAndHandleBrokenLoading() {
+ if (this.mcWorld != ctx.world()) {
if (this.currentWorld != null) {
System.out.println("mc.world unloaded unnoticed! Unloading Baritone cache now.");
closeWorld();
}
- if (mc.level != null) {
+ if (ctx.world() != null) {
System.out.println("mc.world loaded unnoticed! Loading Baritone cache now.");
- initWorld(mc.level.dimension(), mc.level.dimensionType());
+ initWorld(ctx.world());
}
- } else if (currentWorld == null && mc.level != null && (mc.hasSingleplayerServer() || mc.getCurrentServer() != null)) {
+ } else if (this.currentWorld == null && ctx.world() != null && (ctx.minecraft().hasSingleplayerServer() || ctx.minecraft().getCurrentServer() != null)) {
System.out.println("Retrying to load Baritone cache");
- initWorld(mc.level.dimension(), mc.level.dimensionType());
+ initWorld(ctx.world());
}
}
}
diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java
index 2ce865a8d..35e46ba23 100644
--- a/src/main/java/baritone/cache/WorldScanner.java
+++ b/src/main/java/baritone/cache/WorldScanner.java
@@ -22,8 +22,6 @@
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.IPlayerContext;
-import java.util.*;
-import java.util.stream.IntStream;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
@@ -33,6 +31,9 @@
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.PalettedContainer;
+import java.util.*;
+import java.util.stream.IntStream;
+
public enum WorldScanner implements IWorldScanner {
INSTANCE;
diff --git a/src/main/java/baritone/command/ExampleBaritoneControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java
index c3c6648fe..943b8afa6 100644
--- a/src/main/java/baritone/command/ExampleBaritoneControl.java
+++ b/src/main/java/baritone/command/ExampleBaritoneControl.java
@@ -17,8 +17,8 @@
package baritone.command;
+import baritone.Baritone;
import baritone.api.BaritoneAPI;
-import baritone.api.IBaritone;
import baritone.api.Settings;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
@@ -27,9 +27,9 @@
import baritone.api.command.manager.ICommandManager;
import baritone.api.event.events.ChatEvent;
import baritone.api.event.events.TabCompleteEvent;
-import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.utils.Helper;
import baritone.api.utils.SettingsUtil;
+import baritone.behavior.Behavior;
import baritone.command.argument.ArgConsumer;
import baritone.command.argument.CommandArguments;
import baritone.command.manager.CommandManager;
@@ -46,14 +46,14 @@
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
-public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
+public class ExampleBaritoneControl extends Behavior implements Helper {
private static final Settings settings = BaritoneAPI.getSettings();
private final ICommandManager manager;
- public ExampleBaritoneControl(IBaritone baritone) {
+ public ExampleBaritoneControl(Baritone baritone) {
+ super(baritone);
this.manager = baritone.getCommandManager();
- baritone.getGameEventHandler().registerEventListener(this);
}
@Override
@@ -97,7 +97,7 @@ public boolean runCommand(String msg) {
return false;
} else if (msg.trim().equalsIgnoreCase("orderpizza")) {
try {
- ((IGuiScreen) mc.screen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/"));
+ ((IGuiScreen) ctx.minecraft().screen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/"));
} catch (NullPointerException | URISyntaxException ignored) {}
return false;
}
@@ -121,7 +121,7 @@ public boolean runCommand(String msg) {
}
} else if (argc.hasExactlyOne()) {
for (Settings.Setting setting : settings.allSettings) {
- if (SettingsUtil.javaOnlySetting(setting)) {
+ if (setting.isJavaOnly()) {
continue;
}
if (setting.getName().equalsIgnoreCase(pair.getA())) {
@@ -174,7 +174,7 @@ public Stream tabComplete(String msg) {
.stream();
}
Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
- if (setting != null && !SettingsUtil.javaOnlySetting(setting)) {
+ if (setting != null && !setting.isJavaOnly()) {
if (setting.getValueClass() == Boolean.class) {
TabCompleteHelper helper = new TabCompleteHelper();
if ((Boolean) setting.value) {
diff --git a/src/main/java/baritone/command/argument/ArgConsumer.java b/src/main/java/baritone/command/argument/ArgConsumer.java
index c4a6df002..99f30ce96 100644
--- a/src/main/java/baritone/command/argument/ArgConsumer.java
+++ b/src/main/java/baritone/command/argument/ArgConsumer.java
@@ -380,6 +380,8 @@ public > T getDatatypeForOrNull(D datatype) {
public Stream tabCompleteDatatype(T datatype) {
try {
return datatype.tabComplete(this.context);
+ } catch (CommandException ignored) {
+ // NOP
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java
index 622aef4f8..bb34254ae 100644
--- a/src/main/java/baritone/command/defaults/BuildCommand.java
+++ b/src/main/java/baritone/command/defaults/BuildCommand.java
@@ -35,10 +35,11 @@
public class BuildCommand extends Command {
- private static final File schematicsDir = new File(mc.gameDirectory, "schematics");
+ private final File schematicsDir;
public BuildCommand(IBaritone baritone) {
super(baritone, "build");
+ this.schematicsDir = new File(baritone.getPlayerContext().minecraft().gameDirectory, "schematics");
}
@Override
diff --git a/src/main/java/baritone/command/defaults/ComeCommand.java b/src/main/java/baritone/command/defaults/ComeCommand.java
index 5cbed55bc..b111ee1de 100644
--- a/src/main/java/baritone/command/defaults/ComeCommand.java
+++ b/src/main/java/baritone/command/defaults/ComeCommand.java
@@ -21,12 +21,11 @@
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.pathing.goals.GoalBlock;
+
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
-import net.minecraft.world.entity.Entity;
public class ComeCommand extends Command {
@@ -37,11 +36,7 @@ public ComeCommand(IBaritone baritone) {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
- Entity entity = mc.getCameraEntity();
- if (entity == null) {
- throw new CommandInvalidStateException("render view entity is null");
- }
- baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(entity.blockPosition()));
+ baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(ctx.viewerPos()));
logDirect("Coming");
}
diff --git a/src/main/java/baritone/command/defaults/ExploreFilterCommand.java b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
index 504f7c146..ecb5f8376 100644
--- a/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
+++ b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java
@@ -41,7 +41,7 @@ public ExploreFilterCommand(IBaritone baritone) {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(2);
- File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDirectory.getAbsoluteFile().getParentFile());
+ File file = args.getDatatypePost(RelativeFile.INSTANCE, ctx.minecraft().gameDirectory.getAbsoluteFile().getParentFile());
boolean invert = false;
if (args.hasAny()) {
if (args.getString().equalsIgnoreCase("invert")) {
@@ -65,7 +65,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
@Override
public Stream tabComplete(String label, IArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) {
- return RelativeFile.tabComplete(args, RelativeFile.gameDir());
+ return RelativeFile.tabComplete(args, RelativeFile.gameDir(ctx.minecraft()));
}
return Stream.empty();
}
diff --git a/src/main/java/baritone/command/defaults/GoalCommand.java b/src/main/java/baritone/command/defaults/GoalCommand.java
index 40822e057..a174ecad9 100644
--- a/src/main/java/baritone/command/defaults/GoalCommand.java
+++ b/src/main/java/baritone/command/defaults/GoalCommand.java
@@ -51,7 +51,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
}
} else {
args.requireMax(3);
- BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
+ BetterBlockPos origin = ctx.playerFeet();
Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
goalProcess.setGoal(goal);
logDirect(String.format("Goal: %s", goal.toString()));
diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java
index 896e3f5f8..c64d7fa00 100644
--- a/src/main/java/baritone/command/defaults/GotoCommand.java
+++ b/src/main/java/baritone/command/defaults/GotoCommand.java
@@ -20,7 +20,6 @@
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
-import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
@@ -46,7 +45,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
// is no need to handle the case of empty arguments.
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
args.requireMax(3);
- BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
+ BetterBlockPos origin = ctx.playerFeet();
Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal);
@@ -61,7 +60,8 @@ public void execute(String label, IArgConsumer args) throws CommandException {
public Stream tabComplete(String label, IArgConsumer args) throws CommandException {
// since it's either a goal or a block, I don't think we can tab complete properly?
// so just tab complete for the block variant
- return args.tabCompleteDatatype(BlockById.INSTANCE);
+ args.requireMax(1);
+ return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
}
@Override
diff --git a/src/main/java/baritone/command/defaults/MineCommand.java b/src/main/java/baritone/command/defaults/MineCommand.java
index 98a2e264d..eb2c22c6d 100644
--- a/src/main/java/baritone/command/defaults/MineCommand.java
+++ b/src/main/java/baritone/command/defaults/MineCommand.java
@@ -17,14 +17,13 @@
package baritone.command.defaults;
+import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
-import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.exception.CommandException;
import baritone.api.utils.BlockOptionalMeta;
-import baritone.cache.WorldScanner;
import java.util.ArrayList;
import java.util.Arrays;
@@ -45,14 +44,18 @@ public void execute(String label, IArgConsumer args) throws CommandException {
while (args.hasAny()) {
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
}
- WorldScanner.INSTANCE.repack(ctx);
+ BaritoneAPI.getProvider().getWorldScanner().repack(ctx);
logDirect(String.format("Mining %s", boms.toString()));
baritone.getMineProcess().mine(quantity, boms.toArray(new BlockOptionalMeta[0]));
}
@Override
- public Stream tabComplete(String label, IArgConsumer args) {
- return args.tabCompleteDatatype(BlockById.INSTANCE);
+ public Stream tabComplete(String label, IArgConsumer args) throws CommandException {
+ args.getAsOrDefault(Integer.class, 0);
+ while (args.has(2)) {
+ args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
+ }
+ return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
}
@Override
diff --git a/src/main/java/baritone/command/defaults/PathCommand.java b/src/main/java/baritone/command/defaults/PathCommand.java
index 182a1e5bc..b2021adf6 100644
--- a/src/main/java/baritone/command/defaults/PathCommand.java
+++ b/src/main/java/baritone/command/defaults/PathCommand.java
@@ -17,12 +17,12 @@
package baritone.command.defaults;
+import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.process.ICustomGoalProcess;
-import baritone.cache.WorldScanner;
import java.util.Arrays;
import java.util.List;
@@ -38,7 +38,7 @@ public PathCommand(IBaritone baritone) {
public void execute(String label, IArgConsumer args) throws CommandException {
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
args.requireMax(0);
- WorldScanner.INSTANCE.repack(ctx);
+ BaritoneAPI.getProvider().getWorldScanner().repack(ctx);
customGoalProcess.path();
logDirect("Now pathing");
}
diff --git a/src/main/java/baritone/command/defaults/RenderCommand.java b/src/main/java/baritone/command/defaults/RenderCommand.java
index 39dc6ea7c..543c3387c 100644
--- a/src/main/java/baritone/command/defaults/RenderCommand.java
+++ b/src/main/java/baritone/command/defaults/RenderCommand.java
@@ -37,8 +37,8 @@ public RenderCommand(IBaritone baritone) {
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
BetterBlockPos origin = ctx.playerFeet();
- int renderDistance = (mc.options.renderDistance().get() + 1) * 16;
- mc.levelRenderer.setBlocksDirty(
+ int renderDistance = (ctx.minecraft().options.renderDistance().get() + 1) * 16;
+ ctx.minecraft().levelRenderer.setBlocksDirty(
origin.x - renderDistance,
0,
origin.z - renderDistance,
diff --git a/src/main/java/baritone/command/defaults/RepackCommand.java b/src/main/java/baritone/command/defaults/RepackCommand.java
index cafbea524..9f972561d 100644
--- a/src/main/java/baritone/command/defaults/RepackCommand.java
+++ b/src/main/java/baritone/command/defaults/RepackCommand.java
@@ -17,11 +17,11 @@
package baritone.command.defaults;
+import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
-import baritone.cache.WorldScanner;
import java.util.Arrays;
import java.util.List;
@@ -36,7 +36,7 @@ public RepackCommand(IBaritone baritone) {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
- logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
+ logDirect(String.format("Queued %d chunks for repacking", BaritoneAPI.getProvider().getWorldScanner().repack(ctx)));
}
@Override
diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java
index c5b82932d..14d22b0b4 100644
--- a/src/main/java/baritone/command/defaults/SelCommand.java
+++ b/src/main/java/baritone/command/defaults/SelCommand.java
@@ -21,6 +21,7 @@
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
+import baritone.api.command.datatypes.ForAxis;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.ForDirection;
import baritone.api.command.datatypes.RelativeBlockPos;
@@ -31,6 +32,8 @@
import baritone.api.event.events.RenderEvent;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.schematic.*;
+import baritone.api.schematic.mask.shape.CylinderMask;
+import baritone.api.schematic.mask.shape.SphereMask;
import baritone.api.selection.ISelection;
import baritone.api.selection.ISelectionManager;
import baritone.api.utils.BetterBlockPos;
@@ -50,6 +53,7 @@
import java.util.*;
import java.util.List;
import java.util.function.Function;
+import java.util.function.UnaryOperator;
import java.util.stream.Stream;
public class SelCommand extends Command {
@@ -72,7 +76,7 @@ public void onRenderPass(RenderEvent event) {
float lineWidth = Baritone.settings().selectionLineWidth.value;
boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value;
IRenderer.startLines(color, opacity, lineWidth, ignoreDepth);
- IRenderer.drawAABB(event.getModelViewStack(), new AABB(pos1, pos1.offset(1, 1, 1)));
+ IRenderer.emitAABB(event.getModelViewStack(), new AABB(pos1, pos1.offset(1, 1, 1)));
IRenderer.endLines(ignoreDepth);
}
});
@@ -88,7 +92,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
if (action == Action.POS2 && pos1 == null) {
throw new CommandInvalidStateException("Set pos1 first before using pos2");
}
- BetterBlockPos playerPos = mc.getCameraEntity() != null ? BetterBlockPos.from(mc.getCameraEntity().blockPosition()) : ctx.playerFeet();
+ BetterBlockPos playerPos = ctx.viewerPos();
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
args.requireMax(0);
if (action == Action.POS1) {
@@ -117,11 +121,13 @@ public void execute(String label, IArgConsumer args) throws CommandException {
logDirect("Undid pos2");
}
}
- } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
+ } else if (action.isFillAction()) {
BlockOptionalMeta type = action == Action.CLEARAREA
? new BlockOptionalMeta(Blocks.AIR)
: args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
- BlockOptionalMetaLookup replaces = null;
+
+ final BlockOptionalMetaLookup replaces; // Action.REPLACE
+ final Direction.Axis alignment; // Action.(H)CYLINDER
if (action == Action.REPLACE) {
args.requireMin(1);
List replacesList = new ArrayList<>();
@@ -131,8 +137,15 @@ public void execute(String label, IArgConsumer args) throws CommandException {
}
type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
+ alignment = null;
+ } else if (action == Action.CYLINDER || action == Action.HCYLINDER) {
+ args.requireMax(1);
+ alignment = args.hasAny() ? args.getDatatypeFor(ForAxis.INSTANCE) : Direction.Axis.Y;
+ replaces = null;
} else {
args.requireMax(0);
+ replaces = null;
+ alignment = null;
}
ISelection[] selections = manager.getSelections();
if (selections.length == 0) {
@@ -151,20 +164,41 @@ public void execute(String label, IArgConsumer args) throws CommandException {
for (ISelection selection : selections) {
Vec3i size = selection.size();
BetterBlockPos min = selection.min();
- ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
- if (action == Action.WALLS) {
- schematic = new WallsSchematic(schematic);
- } else if (action == Action.SHELL) {
- schematic = new ShellSchematic(schematic);
- } else if (action == Action.REPLACE) {
- schematic = new ReplaceSchematic(schematic, replaces);
- }
+
+ // Java 8 so no switch expressions 😿
+ UnaryOperator create = fill -> {
+ final int w = fill.widthX();
+ final int h = fill.heightY();
+ final int l = fill.lengthZ();
+
+ switch (action) {
+ case WALLS:
+ return new WallsSchematic(fill);
+ case SHELL:
+ return new ShellSchematic(fill);
+ case REPLACE:
+ return new ReplaceSchematic(fill, replaces);
+ case SPHERE:
+ return MaskSchematic.create(fill, new SphereMask(w, h, l, true).compute());
+ case HSPHERE:
+ return MaskSchematic.create(fill, new SphereMask(w, h, l, false).compute());
+ case CYLINDER:
+ return MaskSchematic.create(fill, new CylinderMask(w, h, l, true, alignment).compute());
+ case HCYLINDER:
+ return MaskSchematic.create(fill, new CylinderMask(w, h, l, false, alignment).compute());
+ default:
+ // Silent fail
+ return fill;
+ }
+ };
+
+ ISchematic schematic = create.apply(new FillSchematic(size.getX(), size.getY(), size.getZ(), type));
composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
}
baritone.getBuilderProcess().build("Fill", composite, origin);
logDirect("Filling now");
} else if (action == Action.COPY) {
- BetterBlockPos playerPos = mc.getCameraEntity() != null ? BetterBlockPos.from(mc.getCameraEntity().blockPosition()) : ctx.playerFeet();
+ BetterBlockPos playerPos = ctx.viewerPos();
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
args.requireMax(0);
ISelection[] selections = manager.getSelections();
@@ -205,7 +239,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
clipboardOffset = origin.subtract(pos);
logDirect("Selection copied");
} else if (action == Action.PASTE) {
- BetterBlockPos playerPos = mc.getCameraEntity() != null ? BetterBlockPos.from(mc.getCameraEntity().blockPosition()) : ctx.playerFeet();
+ BetterBlockPos playerPos = ctx.viewerPos();
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
args.requireMax(0);
if (clipboard == null) {
@@ -254,12 +288,15 @@ public Stream tabComplete(String label, IArgConsumer args) throws Comman
if (args.hasAtMost(3)) {
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
}
- } else if (action == Action.SET || action == Action.WALLS || action == Action.CLEARAREA || action == Action.REPLACE) {
+ } else if (action.isFillAction()) {
if (args.hasExactlyOne() || action == Action.REPLACE) {
while (args.has(2)) {
args.get();
}
return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
+ } else if (args.hasExactly(2) && (action == Action.CYLINDER || action == Action.HCYLINDER)) {
+ args.get();
+ return args.tabCompleteDatatype(ForAxis.INSTANCE);
}
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
if (args.hasExactlyOne()) {
@@ -305,6 +342,10 @@ public List getLongDesc() {
"> sel set/fill/s/f [block] - Completely fill all selections with a block.",
"> sel walls/w [block] - Fill in the walls of the selection with a specified block.",
"> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.",
+ "> sel sphere/sph [block] - Fills the selection with a sphere bounded by the sides.",
+ "> sel hsphere/hsph [block] - The same as sphere, but hollow.",
+ "> sel cylinder/cyl [block] - Fills the selection with a cylinder bounded by the sides, oriented about the given axis. (default=y)",
+ "> sel hcylinder/hcyl [block] - The same as cylinder, but hollow.",
"> sel cleararea/ca - Basically 'set air'.",
"> sel replace/r - Replaces blocks with another block.",
"> sel copy/cp - Copy the selected area relative to the specified or your position.",
@@ -324,6 +365,10 @@ enum Action {
SET("set", "fill", "s", "f"),
WALLS("walls", "w"),
SHELL("shell", "shl"),
+ SPHERE("sphere", "sph"),
+ HSPHERE("hsphere", "hsph"),
+ CYLINDER("cylinder", "cyl"),
+ HCYLINDER("hcylinder", "hcyl"),
CLEARAREA("cleararea", "ca"),
REPLACE("replace", "r"),
EXPAND("expand", "ex"),
@@ -355,6 +400,18 @@ public static String[] getAllNames() {
}
return names.toArray(new String[0]);
}
+
+ public final boolean isFillAction() {
+ return this == SET
+ || this == WALLS
+ || this == SHELL
+ || this == SPHERE
+ || this == HSPHERE
+ || this == CYLINDER
+ || this == HCYLINDER
+ || this == CLEARAREA
+ || this == REPLACE;
+ }
}
enum TransformTarget {
diff --git a/src/main/java/baritone/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java
index 3d70c16b9..0f4439cef 100644
--- a/src/main/java/baritone/command/defaults/SetCommand.java
+++ b/src/main/java/baritone/command/defaults/SetCommand.java
@@ -22,23 +22,25 @@
import baritone.api.Settings;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
+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.Paginator;
import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.utils.SettingsUtil;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.Minecraft;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.ClickEvent;
+import net.minecraft.network.chat.HoverEvent;
+import net.minecraft.network.chat.MutableComponent;
-import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import net.minecraft.ChatFormatting;
-import net.minecraft.network.chat.*;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static baritone.api.utils.SettingsUtil.*;
@@ -57,6 +59,18 @@ public void execute(String label, IArgConsumer args) throws CommandException {
logDirect("Settings saved");
return;
}
+ if (Arrays.asList("load", "ld").contains(arg)) {
+ String file = SETTINGS_DEFAULT_NAME;
+ if (args.hasAny()) {
+ file = args.getString();
+ }
+ // reset to defaults
+ SettingsUtil.modifiedSettings(Baritone.settings()).forEach(Settings.Setting::reset);
+ // then load from disk
+ SettingsUtil.readAndApply(Baritone.settings(), file);
+ logDirect("Settings reloaded from " + file);
+ return;
+ }
boolean viewModified = Arrays.asList("m", "mod", "modified").contains(arg);
boolean viewAll = Arrays.asList("all", "l", "list").contains(arg);
boolean paginate = viewModified || viewAll;
@@ -65,7 +79,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(1);
List extends Settings.Setting> toPaginate =
(viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream()
- .filter(s -> !javaOnlySetting(s))
+ .filter(s -> !s.isJavaOnly())
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
.collect(Collectors.toList());
@@ -129,7 +143,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
if (setting == null) {
throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
}
- if (javaOnlySetting(setting)) {
+ if (setting.isJavaOnly()) {
// ideally it would act as if the setting didn't exist
// but users will see it in Settings.java or its javadoc
// so at some point we have to tell them or they will see it as a bug
@@ -209,6 +223,9 @@ public Stream tabComplete(String label, IArgConsumer args) throws Comman
.addToggleableSettings()
.filterPrefix(args.getString())
.stream();
+ } else if (Arrays.asList("ld", "load").contains(arg.toLowerCase(Locale.US))) {
+ // settings always use the directory of the main Minecraft instance
+ return RelativeFile.tabComplete(args, Minecraft.getInstance().gameDirectory.toPath().resolve("baritone").toFile());
}
Settings.Setting setting = Baritone.settings().byLowerName.get(arg.toLowerCase(Locale.US));
if (setting != null) {
@@ -228,7 +245,7 @@ public Stream tabComplete(String label, IArgConsumer args) throws Comman
return new TabCompleteHelper()
.addSettings()
.sortAlphabetically()
- .prepend("list", "modified", "reset", "toggle", "save")
+ .prepend("list", "modified", "reset", "toggle", "save", "load")
.filterPrefix(arg)
.stream();
}
@@ -255,7 +272,9 @@ public List getLongDesc() {
"> set reset all - Reset ALL SETTINGS to their defaults",
"> set reset - Reset a setting to its default",
"> set toggle - Toggle a boolean setting",
- "> set save - Save all settings (this is automatic tho)"
+ "> set save - Save all settings (this is automatic tho)",
+ "> set load - Load settings from settings.txt",
+ "> set load [filename] - Load settings from another file in your minecraft/baritone"
);
}
}
diff --git a/src/main/java/baritone/command/defaults/SurfaceCommand.java b/src/main/java/baritone/command/defaults/SurfaceCommand.java
index 3bbd4d738..a9c981cc3 100644
--- a/src/main/java/baritone/command/defaults/SurfaceCommand.java
+++ b/src/main/java/baritone/command/defaults/SurfaceCommand.java
@@ -37,13 +37,13 @@ protected SurfaceCommand(IBaritone baritone) {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
- final BetterBlockPos playerPos = baritone.getPlayerContext().playerFeet();
- final int surfaceLevel = baritone.getPlayerContext().world().getSeaLevel();
- final int worldHeight = baritone.getPlayerContext().world().getHeight();
+ final BetterBlockPos playerPos = ctx.playerFeet();
+ final int surfaceLevel = ctx.world().getSeaLevel();
+ final int worldHeight = ctx.world().getHeight();
// Ensure this command will not run if you are above the surface level and the block above you is air
// As this would imply that your are already on the open surface
- if (playerPos.getY() > surfaceLevel && mc.level.getBlockState(playerPos.above()).getBlock() instanceof AirBlock) {
+ if (playerPos.getY() > surfaceLevel && ctx.world().getBlockState(playerPos.above()).getBlock() instanceof AirBlock) {
logDirect("Already at surface");
return;
}
@@ -53,7 +53,7 @@ public void execute(String label, IArgConsumer args) throws CommandException {
for (int currentIteratedY = startingYPos; currentIteratedY < worldHeight; currentIteratedY++) {
final BetterBlockPos newPos = new BetterBlockPos(playerPos.getX(), currentIteratedY, playerPos.getZ());
- if (!(mc.level.getBlockState(newPos).getBlock() instanceof AirBlock) && newPos.getY() > playerPos.getY()) {
+ if (!(ctx.world().getBlockState(newPos).getBlock() instanceof AirBlock) && newPos.getY() > playerPos.getY()) {
Goal goal = new GoalBlock(newPos.above());
logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal);
diff --git a/src/main/java/baritone/command/defaults/WaypointsCommand.java b/src/main/java/baritone/command/defaults/WaypointsCommand.java
index 56a833517..6e7f0a1e5 100644
--- a/src/main/java/baritone/command/defaults/WaypointsCommand.java
+++ b/src/main/java/baritone/command/defaults/WaypointsCommand.java
@@ -149,7 +149,11 @@ public void execute(String label, IArgConsumer args) throws CommandException {
logDirect(component);
} else if (action == Action.CLEAR) {
args.requireMax(1);
- IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
+ String name = args.getString();
+ IWaypoint.Tag tag = IWaypoint.Tag.getByName(name);
+ if (tag == null) {
+ throw new CommandInvalidStateException("Invalid tag, \"" + name + "\"");
+ }
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(this.baritone, tag);
for (IWaypoint waypoint : waypoints) {
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
diff --git a/src/main/java/baritone/command/manager/CommandManager.java b/src/main/java/baritone/command/manager/CommandManager.java
index 4c33226d3..8712165f1 100644
--- a/src/main/java/baritone/command/manager/CommandManager.java
+++ b/src/main/java/baritone/command/manager/CommandManager.java
@@ -21,6 +21,7 @@
import baritone.api.IBaritone;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
+import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandUnhandledException;
import baritone.api.command.exception.ICommandException;
import baritone.api.command.helpers.TabCompleteHelper;
@@ -153,9 +154,12 @@ private void execute() {
private Stream tabComplete() {
try {
return this.command.tabComplete(this.label, this.args);
+ } catch (CommandException ignored) {
+ // NOP
} catch (Throwable t) {
- return Stream.empty();
+ t.printStackTrace();
}
+ return Stream.empty();
}
}
}
diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java
index b7853e360..16331ea89 100644
--- a/src/main/java/baritone/event/GameEventHandler.java
+++ b/src/main/java/baritone/event/GameEventHandler.java
@@ -25,11 +25,12 @@
import baritone.api.utils.Helper;
import baritone.cache.WorldProvider;
import baritone.utils.BlockStateInterface;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
/**
* @author Brady
* @since 7/31/2018
@@ -114,7 +115,7 @@ public final void onWorldEvent(WorldEvent event) {
if (event.getState() == EventState.POST) {
cache.closeWorld();
if (event.getWorld() != null) {
- cache.initWorld(event.getWorld().dimension(), event.getWorld().dimensionType());
+ cache.initWorld(event.getWorld());
}
}
diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java
index c1cc0daf5..bd70d263e 100644
--- a/src/main/java/baritone/pathing/movement/CalculationContext.java
+++ b/src/main/java/baritone/pathing/movement/CalculationContext.java
@@ -91,8 +91,8 @@ public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
this.baritone = baritone;
LocalPlayer player = baritone.getPlayerContext().player();
this.world = baritone.getPlayerContext().world();
- this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
- this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
+ this.worldData = (WorldData) baritone.getPlayerContext().worldData();
+ this.bsi = new BlockStateInterface(baritone.getPlayerContext(), forUseOnAnotherThread);
this.toolSet = new ToolSet(player);
this.hasThrowaway = Baritone.settings().allowPlace.value && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway();
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && Inventory.isHotbarSlot(player.getInventory().findSlotMatchingItem(STACK_BUCKET_WATER)) && world.dimension() != Level.NETHER;
diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java
index d319cea62..739c8ee89 100644
--- a/src/main/java/baritone/pathing/movement/Movement.java
+++ b/src/main/java/baritone/pathing/movement/Movement.java
@@ -162,7 +162,7 @@ protected boolean prepared(MovementState state) {
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try
somethingInTheWay = true;
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
- Optional reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
+ Optional reachable = RotationUtils.reachable(ctx, blockPos, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
Rotation rotTowardsBlock = reachable.get();
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java
index 128fa5e16..80391c0bd 100644
--- a/src/main/java/baritone/pathing/movement/MovementHelper.java
+++ b/src/main/java/baritone/pathing/movement/MovementHelper.java
@@ -651,9 +651,9 @@ static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts, bo
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
state.setTarget(new MovementTarget(
- new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
+ RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
VecUtils.getBlockPosCenter(pos),
- ctx.playerRotations()).getYaw(), ctx.player().getXRot()),
+ ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
false
)).setInput(Input.MOVE_FORWARD, true);
}
@@ -760,7 +760,8 @@ static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone,
double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vec3(faceX, faceY, faceZ), ctx.playerRotations());
- HitResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak);
+ Rotation actual = baritone.getLookBehavior().getAimProcessor().peekRotation(place);
+ HitResult res = RayTraceUtils.rayTraceTowards(ctx.player(), actual, ctx.playerController().getBlockReachDistance(), wouldSneak);
if (res != null && res.getType() == HitResult.Type.BLOCK && ((BlockHitResult) res).getBlockPos().equals(against1) && ((BlockHitResult) res).getBlockPos().relative(((BlockHitResult) res).getDirection()).equals(placeAt)) {
state.setTarget(new MovementTarget(place, true));
found = true;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java
index ec069ae4f..a982b7415 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java
@@ -20,7 +20,6 @@
import baritone.api.IBaritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
-import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
@@ -30,8 +29,6 @@
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import com.google.common.collect.ImmutableSet;
-import java.util.Set;
-import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -39,6 +36,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
+import java.util.Set;
+
public class MovementDescend extends Movement {
private int numTicks = 0;
@@ -233,11 +232,10 @@ public MovementState updateState(MovementState state) {
if (safeMode()) {
double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
- LocalPlayer player = ctx.player();
state.setTarget(new MovementState.MovementTarget(
- new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
+ RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
new Vec3(destX, dest.getY(), destZ),
- new Rotation(player.getYRot(), player.getXRot())).getYaw(), player.getXRot()),
+ ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
false
)).setInput(Input.MOVE_FORWARD, true);
return state;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
index cf084093c..a11086d5b 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
@@ -196,9 +196,9 @@ public MovementState updateState(MovementState state) {
boolean vine = fromDown.getBlock() == Blocks.VINE;
Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
VecUtils.getBlockPosCenter(positionToPlace),
- new Rotation(ctx.player().getYRot(), ctx.player().getXRot()));
+ ctx.playerRotations());
if (!ladder) {
- state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().getYRot(), rotation.getPitch()), true));
+ state.setTarget(new MovementState.MovementTarget(ctx.playerRotations().withPitch(rotation.getPitch()), true));
}
boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
@@ -257,7 +257,7 @@ public MovementState updateState(MovementState state) {
Block fr = frState.getBlock();
// TODO: Evaluate usage of getMaterial().isReplaceable()
if (!(fr instanceof AirBlock || frState.getMaterial().isReplaceable())) {
- RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance())
+ RotationUtils.reachable(ctx, src, ctx.playerController().getBlockReachDistance())
.map(rot -> new MovementState.MovementTarget(rot, true))
.ifPresent(state::setTarget);
state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping
diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java
index 01eac45c1..86378bbbc 100644
--- a/src/main/java/baritone/process/BuilderProcess.java
+++ b/src/main/java/baritone/process/BuilderProcess.java
@@ -30,10 +30,7 @@
import baritone.api.schematic.IStaticSchematic;
import baritone.api.schematic.SubstituteSchematic;
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.*;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
@@ -60,7 +57,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
-import net.minecraft.world.level.block.*;
+import net.minecraft.world.level.block.AirBlock;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.HorizontalDirectionalBlock;
+import net.minecraft.world.level.block.LiquidBlock;
+import net.minecraft.world.level.block.PipeBlock;
+import net.minecraft.world.level.block.RotatedPillarBlock;
+import net.minecraft.world.level.block.StairBlock;
+import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.AABB;
@@ -164,7 +168,6 @@ public boolean build(String name, File schematic, Vec3i origin) {
if (!format.isPresent()) {
return false;
}
-
ISchematic parsed;
try {
parsed = format.get().parse(new FileInputStream(schematic));
@@ -172,18 +175,20 @@ public boolean build(String name, File schematic, Vec3i origin) {
e.printStackTrace();
return false;
}
+ parsed = applyMapArtAndSelection(origin, (IStaticSchematic) parsed);
+ build(name, parsed, origin);
+ return true;
+ }
+ private ISchematic applyMapArtAndSelection(Vec3i origin, IStaticSchematic parsed) {
+ ISchematic schematic = parsed;
if (Baritone.settings().mapArtMode.value) {
- parsed = new MapArtSchematic((IStaticSchematic) parsed);
+ schematic = new MapArtSchematic(parsed);
}
-
if (Baritone.settings().buildOnlySelection.value) {
- parsed = new SelectionSchematic(parsed, origin, baritone.getSelectionManager().getSelections());
+ schematic = new SelectionSchematic(schematic, origin, baritone.getSelectionManager().getSelections());
}
-
-
- build(name, parsed, origin);
- return true;
+ return schematic;
}
@Override
@@ -219,7 +224,8 @@ public void buildOpenLitematic(int i) {
try {
LitematicaSchematic schematic1 = new LitematicaSchematic(NbtIo.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())), false);
Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i);
- LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i);
+ ISchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i);
+ schematic2 = applyMapArtAndSelection(origin, (IStaticSchematic) schematic2);
build(name, schematic2, correctedOrigin);
} catch (Exception e) {
logDirect("Schematic File could not be loaded.");
@@ -283,7 +289,7 @@ private Optional> toBreakNearPlayer(BuilderCalcu
BlockState curr = bcc.bsi.get0(x, y, z);
if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired, false)) {
BetterBlockPos pos = new BetterBlockPos(x, y, z);
- Optional rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
+ Optional rot = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance());
if (rot.isPresent()) {
return Optional.of(new Tuple<>(pos, rot.get()));
}
@@ -362,9 +368,10 @@ private Optional possibleToPlace(BlockState toPlace, int x, int y, in
double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3(placeX, placeY, placeZ), ctx.playerRotations());
- HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true);
+ Rotation actualRot = baritone.getLookBehavior().getAimProcessor().peekRotation(rot);
+ HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), actualRot, ctx.playerController().getBlockReachDistance(), true);
if (result != null && result.getType() == HitResult.Type.BLOCK && ((BlockHitResult) result).getBlockPos().equals(placeAgainstPos) && ((BlockHitResult) result).getDirection() == against.getOpposite()) {
- OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
+ OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, actualRot);
if (hotbar.isPresent()) {
return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
}
@@ -574,7 +581,10 @@ public int lengthZ() {
for (int i = 9; i < 36; i++) {
for (BlockState desired : noValidHotbarOption) {
if (valid(approxPlaceable.get(i), desired, true)) {
- baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
+ if (!baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains)) {
+ // awaiting inventory move, so pause
+ return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
+ }
break outer;
}
}
@@ -700,7 +710,7 @@ private Goal assemble(BuilderCalculationContext bcc, List approxPlac
incorrectPositions.forEach(pos -> {
BlockState state = bcc.bsi.get0(pos);
if (state.getBlock() instanceof AirBlock) {
- if (approxPlaceable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
+ if (containsBlockState(approxPlaceable, bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
placeable.add(pos);
} else {
BlockState desired = bcc.getSchematic(pos.x, pos.y, pos.z, state);
@@ -773,6 +783,28 @@ public double heuristic(int x, int y, int z) {
return primary.heuristic(x, y, z);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ JankyGoalComposite goal = (JankyGoalComposite) o;
+ return Objects.equals(primary, goal.primary)
+ && Objects.equals(fallback, goal.fallback);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = -1701079641;
+ hash = hash * 1196141026 + primary.hashCode();
+ hash = hash * -80327868 + fallback.hashCode();
+ return hash;
+ }
+
@Override
public String toString() {
return "JankyComposite Primary: " + primary + " Fallback: " + fallback;
@@ -794,6 +826,21 @@ public boolean isInGoal(int x, int y, int z) {
// but any other adjacent works for breaking, including inside or below
return super.isInGoal(x, y, z);
}
+
+ @Override
+ public String toString() {
+ return String.format(
+ "GoalBreak{x=%s,y=%s,z=%s}",
+ SettingsUtil.maybeCensor(x),
+ SettingsUtil.maybeCensor(y),
+ SettingsUtil.maybeCensor(z)
+ );
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() * 1636324008;
+ }
}
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
@@ -837,6 +884,7 @@ public GoalAdjacent(BlockPos pos, BlockPos no, boolean allowSameLevel) {
this.allowSameLevel = allowSameLevel;
}
+ @Override
public boolean isInGoal(int x, int y, int z) {
if (x == this.x && y == this.y && z == this.z) {
return false;
@@ -853,10 +901,41 @@ public boolean isInGoal(int x, int y, int z) {
return super.isInGoal(x, y, z);
}
+ @Override
public double heuristic(int x, int y, int z) {
// prioritize lower y coordinates
return this.y * 100 + super.heuristic(x, y, z);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (!super.equals(o)) {
+ return false;
+ }
+
+ GoalAdjacent goal = (GoalAdjacent) o;
+ return allowSameLevel == goal.allowSameLevel
+ && Objects.equals(no, goal.no);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 806368046;
+ hash = hash * 1412661222 + super.hashCode();
+ hash = hash * 1730799370 + (int) BetterBlockPos.longHash(no.getX(), no.getY(), no.getZ());
+ hash = hash * 260592149 + (allowSameLevel ? -1314802005 : 1565710265);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "GoalAdjacent{x=%s,y=%s,z=%s}",
+ SettingsUtil.maybeCensor(x),
+ SettingsUtil.maybeCensor(y),
+ SettingsUtil.maybeCensor(z)
+ );
+ }
}
public static class GoalPlace extends GoalBlock {
@@ -865,10 +944,26 @@ public GoalPlace(BlockPos placeAt) {
super(placeAt.above());
}
+ @Override
public double heuristic(int x, int y, int z) {
// prioritize lower y coordinates
return this.y * 100 + super.heuristic(x, y, z);
}
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() * 1910811835;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "GoalPlace{x=%s,y=%s,z=%s}",
+ SettingsUtil.maybeCensor(x),
+ SettingsUtil.maybeCensor(y),
+ SettingsUtil.maybeCensor(z)
+ );
+ }
}
@Override
@@ -943,6 +1038,15 @@ private boolean sameBlockstate(BlockState first, BlockState second) {
return true;
}
+ private boolean containsBlockState(Collection states, BlockState state) {
+ for (BlockState testee : states) {
+ if (sameBlockstate(testee, state)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private boolean valid(BlockState current, BlockState desired, boolean itemVerify) {
if (desired == null) {
return true;
diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java
index 13112ca68..f15c5f6db 100644
--- a/src/main/java/baritone/process/FarmProcess.java
+++ b/src/main/java/baritone/process/FarmProcess.java
@@ -18,8 +18,10 @@
package baritone.process;
import baritone.Baritone;
+import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
+import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.process.IFarmProcess;
import baritone.api.process.PathingCommand;
@@ -28,7 +30,6 @@
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
-import baritone.cache.WorldScanner;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.core.BlockPos;
@@ -44,6 +45,7 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.CactusBlock;
+import net.minecraft.world.level.block.CocoaBlock;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.NetherWartBlock;
import net.minecraft.world.level.block.SugarCaneBlock;
@@ -51,6 +53,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -89,6 +92,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
Items.POTATO,
Items.CARROT,
Items.NETHER_WART,
+ Items.COCOA_BEANS,
Blocks.SUGAR_CANE.asItem(),
Blocks.CACTUS.asItem()
);
@@ -122,6 +126,7 @@ private enum Harvest {
PUMPKIN(Blocks.PUMPKIN, state -> true),
MELON(Blocks.MELON, state -> true),
NETHERWART(Blocks.NETHER_WART, state -> state.getValue(NetherWartBlock.AGE) >= 3),
+ COCOA(Blocks.COCOA, state -> state.getValue(CocoaBlock.AGE) >= 2),
SUGARCANE(Blocks.SUGAR_CANE, null) {
@Override
public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) {
@@ -179,6 +184,10 @@ private boolean isNetherWart(ItemStack stack) {
return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART);
}
+ private boolean isCocoa(ItemStack stack) {
+ return !stack.isEmpty() && stack.getItem().equals(Items.COCOA_BEANS);
+ }
+
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
ArrayList scan = new ArrayList<>();
@@ -187,13 +196,14 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
if (Baritone.settings().replantCrops.value) {
scan.add(Blocks.FARMLAND);
+ scan.add(Blocks.JUNGLE_LOG);
if (Baritone.settings().replantNetherWart.value) {
scan.add(Blocks.SOUL_SAND);
}
}
if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
- Baritone.getExecutor().execute(() -> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 10));
+ Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10));
}
if (locations == null) {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
@@ -202,6 +212,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
List openFarmland = new ArrayList<>();
List bonemealable = new ArrayList<>();
List openSoulsand = new ArrayList<>();
+ List openLog = new ArrayList<>();
for (BlockPos pos : locations) {
//check if the target block is out of range.
if (range != 0 && pos.distSqr(center) > range * range) {
@@ -222,6 +233,15 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
continue;
}
+ if (state.getBlock() == Blocks.JUNGLE_LOG) {
+ for (Direction direction : Direction.Plane.HORIZONTAL) {
+ if (ctx.world().getBlockState(pos.relative(direction)).getBlock() instanceof AirBlock) {
+ openLog.add(pos);
+ break;
+ }
+ }
+ continue;
+ }
if (readyForHarvest(ctx.world(), pos, state)) {
toBreak.add(pos);
continue;
@@ -250,7 +270,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
both.addAll(openSoulsand);
for (BlockPos pos : both) {
boolean soulsand = openSoulsand.contains(pos);
- Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
+ Optional rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == Direction.UP) {
@@ -262,6 +282,25 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
}
}
+ for (BlockPos pos : openLog) {
+ for (Direction dir : Direction.Plane.HORIZONTAL) {
+ if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) {
+ continue;
+ }
+ Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5));
+ Optional rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false);
+ if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
+ HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
+ if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == dir) {
+ baritone.getLookBehavior().updateTarget(rot.get(), true);
+ if (ctx.isLookingAt(pos)) {
+ baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
+ }
+ return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
+ }
+ }
+ }
+ }
for (BlockPos pos : bonemealable) {
Optional rot = RotationUtils.reachable(ctx, pos);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
@@ -296,6 +335,15 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
goalz.add(new GoalBlock(pos.above()));
}
}
+ if (baritone.getInventoryBehavior().throwaway(false, this::isCocoa)) {
+ for (BlockPos pos : openLog) {
+ for (Direction direction : Direction.Plane.HORIZONTAL) {
+ if (ctx.world().getBlockState(pos.relative(direction)).getBlock() instanceof AirBlock) {
+ goalz.add(new GoalGetToBlock(pos.relative(direction)));
+ }
+ }
+ }
+ }
if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
for (BlockPos pos : bonemealable) {
goalz.add(new GoalBlock(pos));
diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java
index 88cc5bfa2..1352232d4 100644
--- a/src/main/java/baritone/process/GetToBlockProcess.java
+++ b/src/main/java/baritone/process/GetToBlockProcess.java
@@ -211,7 +211,7 @@ private Goal createGoal(BlockPos pos) {
private boolean rightClick() {
for (BlockPos pos : knownLocations) {
- Optional reachable = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
+ Optional reachable = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
baritone.getLookBehavior().updateTarget(reachable.get(), true);
if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) {
diff --git a/src/main/java/baritone/process/InventoryPauserProcess.java b/src/main/java/baritone/process/InventoryPauserProcess.java
new file mode 100644
index 000000000..fc9f4735a
--- /dev/null
+++ b/src/main/java/baritone/process/InventoryPauserProcess.java
@@ -0,0 +1,90 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.process;
+
+import baritone.Baritone;
+import baritone.api.process.PathingCommand;
+import baritone.api.process.PathingCommandType;
+import baritone.utils.BaritoneProcessHelper;
+
+public class InventoryPauserProcess extends BaritoneProcessHelper {
+
+ boolean pauseRequestedLastTick;
+ boolean safeToCancelLastTick;
+ int ticksOfStationary;
+
+ public InventoryPauserProcess(Baritone baritone) {
+ super(baritone);
+ }
+
+ @Override
+ public boolean isActive() {
+ if (ctx.player() == null || ctx.world() == null) {
+ return false;
+ }
+ return true;
+ }
+
+ private double motion() {
+ return ctx.player().getDeltaMovement().multiply(1, 0, 1).length();
+ }
+
+ private boolean stationaryNow() {
+ return motion() < 0.00001;
+ }
+
+ public boolean stationaryForInventoryMove() {
+ pauseRequestedLastTick = true;
+ return safeToCancelLastTick && ticksOfStationary > 1;
+ }
+
+ @Override
+ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
+ //logDebug(pauseRequestedLastTick + " " + safeToCancelLastTick + " " + ticksOfStationary);
+ safeToCancelLastTick = isSafeToCancel;
+ if (pauseRequestedLastTick) {
+ pauseRequestedLastTick = false;
+ if (stationaryNow()) {
+ ticksOfStationary++;
+ }
+ return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
+ }
+ ticksOfStationary = 0;
+ return new PathingCommand(null, PathingCommandType.DEFER);
+ }
+
+ @Override
+ public void onLostControl() {
+
+ }
+
+ @Override
+ public String displayName0() {
+ return "inventory pauser";
+ }
+
+ @Override
+ public double priority() {
+ return 5.1; // slightly higher than backfill
+ }
+
+ @Override
+ public boolean isTemporary() {
+ return true;
+ }
+}
diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java
index c7bbec752..b6f2be526 100644
--- a/src/main/java/baritone/process/MineProcess.java
+++ b/src/main/java/baritone/process/MineProcess.java
@@ -18,6 +18,7 @@
package baritone.process;
import baritone.Baritone;
+import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.*;
import baritone.api.process.IMineProcess;
import baritone.api.process.PathingCommand;
@@ -25,7 +26,6 @@
import baritone.api.utils.*;
import baritone.api.utils.input.Input;
import baritone.cache.CachedChunk;
-import baritone.cache.WorldScanner;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
@@ -320,6 +320,26 @@ public double heuristic(int x, int y, int z) {
int zDiff = z - this.z;
return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff);
}
+
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() * 393857768;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "GoalThreeBlocks{x=%s,y=%s,z=%s}",
+ SettingsUtil.maybeCensor(x),
+ SettingsUtil.maybeCensor(y),
+ SettingsUtil.maybeCensor(z)
+ );
+ }
}
public List droppedItemsScan() {
@@ -363,7 +383,7 @@ public static List searchWorld(CalculationContext ctx, BlockOptionalMe
locs = prune(ctx, locs, filter, max, blacklist, dropped);
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
- locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
+ locs.addAll(BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(
ctx.getBaritone().getPlayerContext(),
filter,
max,
@@ -398,7 +418,7 @@ private boolean addNearby() {
// is an x-ray and it'll get caught
if (filter.has(bsi.get0(x, y, z))) {
BlockPos pos = new BlockPos(x, y, z);
- if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distSqr(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
+ if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distSqr(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx, pos, fakedBlockReachDistance).isPresent()) {
knownOreLocations.add(pos);
}
}
@@ -438,6 +458,8 @@ private static List prune(CalculationContext ctx, List locs2
.filter(pos -> pos.getY() >= Baritone.settings().minYLevelWhileMining.value + ctx.world.dimensionType().minY())
+ .filter(pos -> pos.getY() <= Baritone.settings().maxYLevelWhileMining.value)
+
.filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player().blockPosition()::distSqr))
diff --git a/src/main/java/baritone/selection/SelectionRenderer.java b/src/main/java/baritone/selection/SelectionRenderer.java
index 90c4bca10..94cbb2d90 100644
--- a/src/main/java/baritone/selection/SelectionRenderer.java
+++ b/src/main/java/baritone/selection/SelectionRenderer.java
@@ -24,27 +24,27 @@ public static void renderSelections(PoseStack stack, ISelection[] selections) {
boolean ignoreDepth = settings.renderSelectionIgnoreDepth.value;
float lineWidth = settings.selectionLineWidth.value;
- if (!settings.renderSelection.value) {
+ if (!settings.renderSelection.value || selections.length == 0) {
return;
}
IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth);
for (ISelection selection : selections) {
- IRenderer.drawAABB(stack, selection.aabb(), SELECTION_BOX_EXPANSION);
+ IRenderer.emitAABB(stack, selection.aabb(), SELECTION_BOX_EXPANSION);
}
if (settings.renderSelectionCorners.value) {
IRenderer.glColor(settings.colorSelectionPos1.value, opacity);
for (ISelection selection : selections) {
- IRenderer.drawAABB(stack, new AABB(selection.pos1(), selection.pos1().offset(1, 1, 1)));
+ IRenderer.emitAABB(stack, new AABB(selection.pos1(), selection.pos1().offset(1, 1, 1)));
}
IRenderer.glColor(settings.colorSelectionPos2.value, opacity);
for (ISelection selection : selections) {
- IRenderer.drawAABB(stack, new AABB(selection.pos2(), selection.pos2().offset(1, 1, 1)));
+ IRenderer.emitAABB(stack, new AABB(selection.pos2(), selection.pos2().offset(1, 1, 1)));
}
}
diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java
index 5edc1439b..2d209c721 100644
--- a/src/main/java/baritone/utils/BlockBreakHelper.java
+++ b/src/main/java/baritone/utils/BlockBreakHelper.java
@@ -17,7 +17,6 @@
package baritone.utils;
-import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.phys.BlockHitResult;
@@ -27,7 +26,7 @@
* @author Brady
* @since 8/25/2018
*/
-public final class BlockBreakHelper implements Helper {
+public final class BlockBreakHelper {
private final IPlayerContext ctx;
private boolean didBreakLastTick;
diff --git a/src/main/java/baritone/utils/BlockPlaceHelper.java b/src/main/java/baritone/utils/BlockPlaceHelper.java
index fb8cba397..93b0c4408 100644
--- a/src/main/java/baritone/utils/BlockPlaceHelper.java
+++ b/src/main/java/baritone/utils/BlockPlaceHelper.java
@@ -18,14 +18,13 @@
package baritone.utils;
import baritone.Baritone;
-import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
-public class BlockPlaceHelper implements Helper {
+public class BlockPlaceHelper {
private final IPlayerContext ctx;
private int rightClickTimer;
diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java
index 3f018ff89..2931b9392 100644
--- a/src/main/java/baritone/utils/BlockStateInterface.java
+++ b/src/main/java/baritone/utils/BlockStateInterface.java
@@ -23,7 +23,6 @@
import baritone.cache.WorldData;
import baritone.utils.accessor.IClientChunkProvider;
import baritone.utils.pathing.BetterWorldBorder;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
@@ -61,20 +60,16 @@ public BlockStateInterface(IPlayerContext ctx) {
}
public BlockStateInterface(IPlayerContext ctx, boolean copyLoadedChunks) {
- this(ctx.world(), (WorldData) ctx.worldData(), copyLoadedChunks);
- }
-
- public BlockStateInterface(Level world, WorldData worldData, boolean copyLoadedChunks) {
- this.world = world;
+ this.world = ctx.world();
this.worldBorder = new BetterWorldBorder(world.getWorldBorder());
- this.worldData = worldData;
+ this.worldData = (WorldData) ctx.worldData();
if (copyLoadedChunks) {
this.provider = ((IClientChunkProvider) world.getChunkSource()).createThreadSafeCopy();
} else {
this.provider = (ClientChunkCache) world.getChunkSource();
}
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
- if (!Minecraft.getInstance().isSameThread()) {
+ if (!ctx.minecraft().isSameThread()) {
throw new IllegalStateException();
}
this.isPassableBlockPos = new BlockPos.MutableBlockPos();
diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java
index d0a435e1f..3c40651a8 100644
--- a/src/main/java/baritone/utils/GuiClick.java
+++ b/src/main/java/baritone/utils/GuiClick.java
@@ -22,7 +22,6 @@
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper;
-import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector4f;
@@ -44,7 +43,6 @@
import java.util.Collections;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
-import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends Screen implements Helper {
@@ -127,22 +125,11 @@ public void onRender(PoseStack modelViewStack, Matrix4f projectionMatrix) {
// drawSingleSelectionBox WHEN?
PathRenderer.drawManySelectionBoxes(modelViewStack, e, Collections.singletonList(currentMouseOver), Color.CYAN);
if (clickStart != null && !clickStart.equals(currentMouseOver)) {
- RenderSystem.enableBlend();
- RenderSystem.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
- //TODO: check
- IRenderer.glColor(Color.RED, 0.4F);
- RenderSystem.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
- RenderSystem.disableTexture();
- RenderSystem.depthMask(false);
- RenderSystem.disableDepthTest();
+ IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value, true);
BetterBlockPos a = new BetterBlockPos(currentMouseOver);
BetterBlockPos b = new BetterBlockPos(clickStart);
- IRenderer.drawAABB(modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));
- RenderSystem.enableDepthTest();
-
- RenderSystem.depthMask(true);
- RenderSystem.enableTexture();
- RenderSystem.disableBlend();
+ IRenderer.emitAABB(modelViewStack, new AABB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));
+ IRenderer.endLines(true);
}
}
}
diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java
index d07bf44fa..010346bd9 100644
--- a/src/main/java/baritone/utils/IRenderer.java
+++ b/src/main/java/baritone/utils/IRenderer.java
@@ -19,21 +19,25 @@
import baritone.api.BaritoneAPI;
import baritone.api.Settings;
-import baritone.api.utils.Helper;
import baritone.utils.accessor.IEntityRenderManager;
+import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.math.Matrix3f;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.GameRenderer;
+import net.minecraft.client.renderer.texture.TextureManager;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
-import java.awt.*;
import net.minecraft.world.phys.AABB;
-import static org.lwjgl.opengl.GL11.*;
+import java.awt.*;
public interface IRenderer {
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder buffer = tessellator.getBuilder();
- IEntityRenderManager renderManager = (IEntityRenderManager) Helper.mc.getEntityRenderDispatcher();
+ IEntityRenderManager renderManager = (IEntityRenderManager) Minecraft.getInstance().getEntityRenderDispatcher();
+ TextureManager textureManager = Minecraft.getInstance().getTextureManager();
Settings settings = BaritoneAPI.getSettings();
float[] color = new float[] {1.0F, 1.0F, 1.0F, 255.0F};
@@ -48,15 +52,23 @@ static void glColor(Color color, float alpha) {
static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
RenderSystem.enableBlend();
- RenderSystem.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
+ RenderSystem.blendFuncSeparate(
+ GlStateManager.SourceFactor.SRC_ALPHA,
+ GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
+ GlStateManager.SourceFactor.ONE,
+ GlStateManager.DestFactor.ZERO
+ );
glColor(color, alpha);
RenderSystem.lineWidth(lineWidth);
RenderSystem.disableTexture();
RenderSystem.depthMask(false);
+ RenderSystem.disableCull();
if (ignoreDepth) {
RenderSystem.disableDepthTest();
}
+ RenderSystem.setShader(GameRenderer::getRendertypeLinesShader);
+ buffer.begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
}
static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
@@ -64,52 +76,73 @@ static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
}
static void endLines(boolean ignoredDepth) {
+ tessellator.end();
if (ignoredDepth) {
RenderSystem.enableDepthTest();
}
+ RenderSystem.enableCull();
RenderSystem.depthMask(true);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
- static void drawAABB(PoseStack stack, AABB aabb) {
+ static void emitLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
+ final double dx = x2 - x1;
+ final double dy = y2 - y1;
+ final double dz = z2 - z1;
+
+ final double invMag = 1.0 / Math.sqrt(dx * dx + dy * dy + dz * dz);
+ final float nx = (float) (dx * invMag);
+ final float ny = (float) (dy * invMag);
+ final float nz = (float) (dz * invMag);
+
+ emitLine(stack, x1, y1, z1, x2, y2, z2, nx, ny, nz);
+ }
+
+ static void emitLine(PoseStack stack,
+ double x1, double y1, double z1,
+ double x2, double y2, double z2,
+ double nx, double ny, double nz) {
+ emitLine(stack,
+ (float) x1, (float) y1, (float) z1,
+ (float) x2, (float) y2, (float) z2,
+ (float) nx, (float) ny, (float) nz
+ );
+ }
+
+ static void emitLine(PoseStack stack,
+ float x1, float y1, float z1,
+ float x2, float y2, float z2,
+ float nx, float ny, float nz) {
+ final Matrix4f matrix4f = stack.last().pose();
+ final Matrix3f normal = stack.last().normal();
+
+ buffer.vertex(matrix4f, x1, y1, z1).color(color[0], color[1], color[2], color[3]).normal(normal, nx, ny, nz).endVertex();
+ buffer.vertex(matrix4f, x2, y2, z2).color(color[0], color[1], color[2], color[3]).normal(normal, nx, ny, nz).endVertex();
+ }
+
+ static void emitAABB(PoseStack stack, AABB aabb) {
AABB toDraw = aabb.move(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ());
- Matrix4f matrix4f = stack.last().pose();
- //TODO: check
- buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
// bottom
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
+ emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.minZ, 1.0, 0.0, 0.0);
+ emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.minY, toDraw.maxZ, 0.0, 0.0, 1.0);
+ emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.maxZ, -1.0, 0.0, 0.0);
+ emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.minY, toDraw.minZ, 0.0, 0.0, -1.0);
// top
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
+ emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 1.0, 0.0, 0.0);
+ emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 0.0, 1.0);
+ emitLine(stack, toDraw.maxX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, -1.0, 0.0, 0.0);
+ emitLine(stack, toDraw.minX, toDraw.maxY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 0.0, -1.0);
// corners
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- tessellator.end();
+ emitLine(stack, toDraw.minX, toDraw.minY, toDraw.minZ, toDraw.minX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0);
+ emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.minZ, toDraw.maxX, toDraw.maxY, toDraw.minZ, 0.0, 1.0, 0.0);
+ emitLine(stack, toDraw.maxX, toDraw.minY, toDraw.maxZ, toDraw.maxX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0);
+ emitLine(stack, toDraw.minX, toDraw.minY, toDraw.maxZ, toDraw.minX, toDraw.maxY, toDraw.maxZ, 0.0, 1.0, 0.0);
}
- static void drawAABB(PoseStack stack, AABB aabb, double expand) {
- drawAABB(stack, aabb.inflate(expand, expand, expand));
+ static void emitAABB(PoseStack stack, AABB aabb, double expand) {
+ emitAABB(stack, aabb.inflate(expand, expand, expand));
}
}
diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java
index d91123108..6e3d60dc9 100755
--- a/src/main/java/baritone/utils/InputOverrideHandler.java
+++ b/src/main/java/baritone/utils/InputOverrideHandler.java
@@ -23,8 +23,8 @@
import baritone.api.utils.IInputOverrideHandler;
import baritone.api.utils.input.Input;
import baritone.behavior.Behavior;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.player.KeyboardInput;
+
import java.util.HashMap;
import java.util.Map;
@@ -99,7 +99,7 @@ public final void onTick(TickEvent event) {
}
} else {
if (ctx.player().input.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam
- ctx.player().input = new KeyboardInput(Minecraft.getInstance().options);
+ ctx.player().input = new KeyboardInput(ctx.minecraft().options);
}
}
// only set it if it was previously incorrect
diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java
index 5f50962e7..88c56bc96 100644
--- a/src/main/java/baritone/utils/PathRenderer.java
+++ b/src/main/java/baritone/utils/PathRenderer.java
@@ -22,19 +22,14 @@
import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.goals.*;
import baritone.api.utils.BetterBlockPos;
-import baritone.api.utils.Helper;
+import baritone.api.utils.IPlayerContext;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import com.mojang.blaze3d.systems.RenderSystem;
-import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
-import com.mojang.blaze3d.vertex.VertexFormat;
+import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
-import java.awt.*;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
@@ -46,13 +41,17 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
-import static org.lwjgl.opengl.GL11.*;
+import java.awt.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
/**
* @author Brady
* @since 8/9/2018
*/
-public final class PathRenderer implements IRenderer, Helper {
+public final class PathRenderer implements IRenderer {
private static final ResourceLocation TEXTURE_BEACON_BEAM = new ResourceLocation("textures/entity/beacon_beam.png");
@@ -72,31 +71,27 @@ public static double posZ() {
}
public static void render(RenderEvent event, PathingBehavior behavior) {
- float partialTicks = event.getPartialTicks();
- Goal goal = behavior.getGoal();
- if (Helper.mc.screen instanceof GuiClick) {
- ((GuiClick) Helper.mc.screen).onRender(event.getModelViewStack(), event.getProjectionMatrix());
+ final IPlayerContext ctx = behavior.ctx;
+ if (ctx.world() == null) {
+ return;
}
+ if (ctx.minecraft().screen instanceof GuiClick) {
+ ((GuiClick) ctx.minecraft().screen).onRender(event.getModelViewStack(), event.getProjectionMatrix());
+ }
+
+ final float partialTicks = event.getPartialTicks();
+ final Goal goal = behavior.getGoal();
- DimensionType thisPlayerDimension = behavior.baritone.getPlayerContext().world().dimensionType();
- DimensionType currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().dimensionType();
+ final DimensionType thisPlayerDimension = ctx.world().dimensionType();
+ final DimensionType currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().dimensionType();
if (thisPlayerDimension != currentRenderViewDimension) {
// this is a path for a bot in a different dimension, don't render it
return;
}
- Entity renderView = Helper.mc.getCameraEntity();
-
- if (renderView.level != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world()) {
- System.out.println("I have no idea what's going on");
- System.out.println("The primary baritone is in a different world than the render view entity");
- System.out.println("Not rendering the path");
- return;
- }
-
if (goal != null && settings.renderGoal.value) {
- drawDankLitGoalBox(event.getModelViewStack(), renderView, goal, partialTicks, settings.colorGoalBox.value);
+ drawGoal(event.getModelViewStack(), ctx, goal, partialTicks, settings.colorGoalBox.value);
}
if (!settings.renderPath.value) {
@@ -106,9 +101,9 @@ public static void render(RenderEvent event, PathingBehavior behavior) {
PathExecutor current = behavior.getCurrent(); // this should prevent most race conditions?
PathExecutor next = behavior.getNext(); // like, now it's not possible for current!=null to be true, then suddenly false because of another thread
if (current != null && settings.renderSelectionBoxes.value) {
- drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toBreak(), settings.colorBlocksToBreak.value);
- drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toPlace(), settings.colorBlocksToPlace.value);
- drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toWalkInto(), settings.colorBlocksToWalkInto.value);
+ drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toBreak(), settings.colorBlocksToBreak.value);
+ drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toPlace(), settings.colorBlocksToPlace.value);
+ drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toWalkInto(), settings.colorBlocksToWalkInto.value);
}
//drawManySelectionBoxes(player, Collections.singletonList(behavior.pathStart()), partialTicks, Color.WHITE);
@@ -131,12 +126,12 @@ public static void render(RenderEvent event, PathingBehavior behavior) {
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
drawPath(event.getModelViewStack(), mr, 0, settings.colorMostRecentConsidered.value, settings.fadePath.value, 10, 20);
- drawManySelectionBoxes(event.getModelViewStack(), renderView, Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.value);
+ drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.value);
});
});
}
- public static void drawPath(PoseStack stack, IPath path, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
+ private static void drawPath(PoseStack stack, IPath path, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
int fadeStart = fadeStart0 + startIndex;
@@ -172,32 +167,35 @@ public static void drawPath(PoseStack stack, IPath path, int startIndex, Color c
IRenderer.glColor(color, alpha);
}
- drawLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
-
- tessellator.end();
+ emitPathLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
}
IRenderer.endLines(settings.renderPathIgnoreDepth.value);
}
-
- public static void drawLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
- Matrix4f matrix4f = stack.last().pose();
-
+ private static void emitPathLine(PoseStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
double vpX = posX();
double vpY = posY();
double vpZ = posZ();
boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value;
- //TODO: check
- buffer.begin(renderPathAsFrickinThingy ? VertexFormat.Mode.DEBUG_LINE_STRIP : VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
- buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
-
+ IRenderer.emitLine(stack,
+ x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ,
+ x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ
+ );
if (renderPathAsFrickinThingy) {
- buffer.vertex(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
+ IRenderer.emitLine(stack,
+ x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ,
+ x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ
+ );
+ IRenderer.emitLine(stack,
+ x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ,
+ x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ
+ );
+ IRenderer.emitLine(stack,
+ x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ,
+ x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ
+ );
}
}
@@ -212,13 +210,17 @@ public static void drawManySelectionBoxes(PoseStack stack, Entity player, Collec
VoxelShape shape = state.getShape(player.level, pos);
AABB toDraw = shape.isEmpty() ? Shapes.block().bounds() : shape.bounds();
toDraw = toDraw.move(pos);
- IRenderer.drawAABB(stack, toDraw, .002D);
+ IRenderer.emitAABB(stack, toDraw, .002D);
});
IRenderer.endLines(settings.renderSelectionBoxesIgnoreDepth.value);
}
- public static void drawDankLitGoalBox(PoseStack stack, Entity player, Goal goal, float partialTicks, Color color) {
+ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color) {
+ drawGoal(stack, ctx, goal, partialTicks, color, true);
+ }
+
+ private static void drawGoal(PoseStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color, boolean setupRender) {
double renderPosX = posX();
double renderPosY = posY();
double renderPosZ = posZ();
@@ -250,14 +252,15 @@ public static void drawDankLitGoalBox(PoseStack stack, Entity player, Goal goal,
y2 -= 0.5;
maxY--;
}
+ drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
} else if (goal instanceof GoalXZ) {
GoalXZ goalPos = (GoalXZ) goal;
+ minY = ctx.world().getMinBuildHeight();
+ maxY = ctx.world().getMaxBuildHeight();
if (settings.renderGoalXZBeacon.value) {
- glPushAttrib(GL_LIGHTING_BIT);
-
//TODO: check
- Helper.mc.getTextureManager().bindForSetup(TEXTURE_BEACON_BEAM);
+ textureManager.bindForSetup(TEXTURE_BEACON_BEAM);
if (settings.renderGoalIgnoreDepth.value) {
RenderSystem.disableDepthTest();
}
@@ -268,13 +271,13 @@ public static void drawDankLitGoalBox(PoseStack stack, Entity player, Goal goal,
//TODO: check
BeaconRenderer.renderBeaconBeam(
stack,
- mc.renderBuffers().bufferSource(),
+ ctx.minecraft().renderBuffers().bufferSource(),
TEXTURE_BEACON_BEAM,
settings.renderGoalAnimated.value ? partialTicks : 0,
1.0F,
- settings.renderGoalAnimated.value ? player.level.getGameTime() : 0,
- 0,
- 256,
+ settings.renderGoalAnimated.value ? ctx.world().getGameTime() : 0,
+ (int) minY,
+ (int) maxY,
color.getColorComponents(null),
// Arguments filled by the private method lol
@@ -287,8 +290,6 @@ public static void drawDankLitGoalBox(PoseStack stack, Entity player, Goal goal,
if (settings.renderGoalIgnoreDepth.value) {
RenderSystem.enableDepthTest();
}
-
- glPopAttrib();
return;
}
@@ -299,61 +300,65 @@ public static void drawDankLitGoalBox(PoseStack stack, Entity player, Goal goal,
y1 = 0;
y2 = 0;
- minY = 0 - renderPosY;
- maxY = 256 - renderPosY;
+ minY -= renderPosY;
+ maxY -= renderPosY;
+ drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
} else if (goal instanceof GoalComposite) {
+ // Simple way to determine if goals can be batched, without having some sort of GoalRenderer
+ boolean batch = Arrays.stream(((GoalComposite) goal).goals()).allMatch(IGoalRenderPos.class::isInstance);
+
+ if (batch) {
+ IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
+ }
for (Goal g : ((GoalComposite) goal).goals()) {
- drawDankLitGoalBox(stack, player, g, partialTicks, color);
+ drawGoal(stack, ctx, g, partialTicks, color, !batch);
+ }
+ if (batch) {
+ IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
}
- return;
} else if (goal instanceof GoalInverted) {
- drawDankLitGoalBox(stack, player, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value);
- return;
+ drawGoal(stack, ctx, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value);
} else if (goal instanceof GoalYLevel) {
GoalYLevel goalpos = (GoalYLevel) goal;
- minX = player.position().x - settings.yLevelBoxSize.value - renderPosX;
- minZ = player.position().z - settings.yLevelBoxSize.value - renderPosZ;
- maxX = player.position().x + settings.yLevelBoxSize.value - renderPosX;
- maxZ = player.position().z + settings.yLevelBoxSize.value - renderPosZ;
+ minX = ctx.player().position().x - settings.yLevelBoxSize.value - renderPosX;
+ minZ = ctx.player().position().z - settings.yLevelBoxSize.value - renderPosZ;
+ maxX = ctx.player().position().x + settings.yLevelBoxSize.value - renderPosX;
+ maxZ = ctx.player().position().z + settings.yLevelBoxSize.value - renderPosZ;
minY = ((GoalYLevel) goal).level - renderPosY;
maxY = minY + 2;
y1 = 1 + y + goalpos.level - renderPosY;
y2 = 1 - y + goalpos.level - renderPosY;
- } else {
- return;
+ drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
}
+ }
- IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
+ private static void drawDankLitGoalBox(PoseStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) {
+ if (setupRender) {
+ IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
+ }
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1);
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2);
- Matrix4f matrix4f = stack.last().pose();
- buffer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR);
- buffer.vertex(matrix4f, (float) minX, (float) minY, (float) minZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) minX, (float) maxY, (float) minZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) minY, (float) minZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) maxY, (float) minZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) minY, (float) maxZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) maxY, (float) maxZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) minX, (float) minY, (float) maxZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- buffer.vertex(matrix4f, (float) minX, (float) maxY, (float) maxZ).color(IRenderer.color[0], IRenderer.color[1], IRenderer.color[2], IRenderer.color[3]).endVertex();
- tessellator.end();
-
- IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
+ for (double y = minY; y < maxY; y += 16) {
+ double max = Math.min(maxY, y + 16);
+ IRenderer.emitLine(stack, minX, y, minZ, minX, max, minZ, 0.0, 1.0, 0.0);
+ IRenderer.emitLine(stack, maxX, y, minZ, maxX, max, minZ, 0.0, 1.0, 0.0);
+ IRenderer.emitLine(stack, maxX, y, maxZ, maxX, max, maxZ, 0.0, 1.0, 0.0);
+ IRenderer.emitLine(stack, minX, y, maxZ, minX, max, maxZ, 0.0, 1.0, 0.0);
+ }
+
+ if (setupRender) {
+ IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
+ }
}
private static void renderHorizontalQuad(PoseStack stack, double minX, double maxX, double minZ, double maxZ, double y) {
if (y != 0) {
- Matrix4f matrix4f = stack.last().pose();
- //TODO: check
- buffer.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR);
- buffer.vertex(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) maxX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) minX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
- buffer.vertex(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
- tessellator.end();
+ IRenderer.emitLine(stack, minX, y, minZ, maxX, y, minZ, 1.0, 0.0, 0.0);
+ IRenderer.emitLine(stack, maxX, y, minZ, maxX, y, maxZ, 0.0, 0.0, 1.0);
+ IRenderer.emitLine(stack, maxX, y, maxZ, minX, y, maxZ, -1.0, 0.0, 0.0);
+ IRenderer.emitLine(stack, minX, y, maxZ, minX, y, minZ, 0.0, 0.0, -1.0);
}
}
}
diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java
index d841cf3a1..86350ff0b 100644
--- a/src/main/java/baritone/utils/PathingControlManager.java
+++ b/src/main/java/baritone/utils/PathingControlManager.java
@@ -159,7 +159,7 @@ public boolean forceRevalidate(Goal newGoal) {
if (newGoal.isInGoal(current.getPath().getDest())) {
return false;
}
- return !newGoal.toString().equals(current.getPath().getGoal().toString());
+ return !newGoal.equals(current.getPath().getGoal());
}
return false;
}
diff --git a/src/main/java/baritone/utils/accessor/IPalettedContainer.java b/src/main/java/baritone/utils/accessor/IPalettedContainer.java
new file mode 100644
index 000000000..c7281080d
--- /dev/null
+++ b/src/main/java/baritone/utils/accessor/IPalettedContainer.java
@@ -0,0 +1,36 @@
+/*
+ * 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.accessor;
+
+import net.minecraft.util.BitStorage;
+import net.minecraft.world.level.chunk.Palette;
+
+public interface IPalettedContainer {
+
+ Palette getPalette();
+
+ BitStorage getStorage();
+
+
+ public interface IData {
+
+ Palette getPalette();
+
+ BitStorage getStorage();
+ }
+}
diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/BaritonePlayerContext.java
similarity index 55%
rename from src/main/java/baritone/utils/player/PrimaryPlayerContext.java
rename to src/main/java/baritone/utils/player/BaritonePlayerContext.java
index 0e9060379..4ae89945f 100644
--- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java
+++ b/src/main/java/baritone/utils/player/BaritonePlayerContext.java
@@ -17,13 +17,12 @@
package baritone.utils.player;
-import baritone.api.BaritoneAPI;
+import baritone.Baritone;
import baritone.api.cache.IWorldData;
-import baritone.api.utils.Helper;
-import baritone.api.utils.IPlayerContext;
-import baritone.api.utils.IPlayerController;
-import baritone.api.utils.RayTraceUtils;
+import baritone.api.utils.*;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
+import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.HitResult;
@@ -33,28 +32,52 @@
* @author Brady
* @since 11/12/2018
*/
-public enum PrimaryPlayerContext implements IPlayerContext, Helper {
+public final class BaritonePlayerContext implements IPlayerContext {
- INSTANCE;
+ private final Baritone baritone;
+ private final Minecraft mc;
+ private final IPlayerController playerController;
+
+ public BaritonePlayerContext(Baritone baritone, Minecraft mc) {
+ this.baritone = baritone;
+ this.mc = mc;
+ this.playerController = new BaritonePlayerController(mc);
+ }
+
+ @Override
+ public Minecraft minecraft() {
+ return this.mc;
+ }
@Override
public LocalPlayer player() {
- return mc.player;
+ return this.mc.player;
}
@Override
public IPlayerController playerController() {
- return PrimaryPlayerController.INSTANCE;
+ return this.playerController;
}
@Override
public Level world() {
- return mc.level;
+ return this.mc.level;
}
@Override
public IWorldData worldData() {
- return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
+ return this.baritone.getWorldProvider().getCurrentWorld();
+ }
+
+ @Override
+ public BetterBlockPos viewerPos() {
+ final Entity entity = this.mc.getCameraEntity();
+ return entity == null ? this.playerFeet() : BetterBlockPos.from(entity.blockPosition());
+ }
+
+ @Override
+ public Rotation playerRotations() {
+ return this.baritone.getLookBehavior().getEffectiveRotation().orElseGet(IPlayerContext.super::playerRotations);
}
@Override
diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/BaritonePlayerController.java
similarity index 93%
rename from src/main/java/baritone/utils/player/PrimaryPlayerController.java
rename to src/main/java/baritone/utils/player/BaritonePlayerController.java
index 4aee8c567..42ba49052 100644
--- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java
+++ b/src/main/java/baritone/utils/player/BaritonePlayerController.java
@@ -17,9 +17,9 @@
package baritone.utils.player;
-import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerController;
import baritone.utils.accessor.IPlayerControllerMP;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
@@ -39,9 +39,13 @@
* @author Brady
* @since 12/14/2018
*/
-public enum PrimaryPlayerController implements IPlayerController, Helper {
+public final class BaritonePlayerController implements IPlayerController {
- INSTANCE;
+ private final Minecraft mc;
+
+ public BaritonePlayerController(Minecraft mc) {
+ this.mc = mc;
+ }
@Override
public void syncHeldItem() {