merge
This commit is contained in:
+2
-1
@@ -9,6 +9,7 @@
|
|||||||
- **Slabs and stairs**
|
- **Slabs and stairs**
|
||||||
- **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore).
|
- **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore).
|
||||||
- **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc.
|
- **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc.
|
||||||
|
- **Parkour** Sprint jumping over 1, 2, or 3 block gaps
|
||||||
|
|
||||||
# Pathing method
|
# Pathing method
|
||||||
Baritone uses a modified version of A*.
|
Baritone uses a modified version of A*.
|
||||||
@@ -42,7 +43,7 @@ Things it doesn't have yet
|
|||||||
See <a href="https://github.com/cabaletta/baritone/issues">issues</a> for more.
|
See <a href="https://github.com/cabaletta/baritone/issues">issues</a> for more.
|
||||||
|
|
||||||
Things it may not ever have, from most likely to least likely =(
|
Things it may not ever have, from most likely to least likely =(
|
||||||
- Boats
|
|
||||||
- Pigs
|
- Pigs
|
||||||
|
- Boats
|
||||||
- Horses (2x3 path instead of 1x2)
|
- Horses (2x3 path instead of 1x2)
|
||||||
- Elytra
|
- Elytra
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
Baritone will be in Impact 4.4 with nice integrations with its utility modules, but if you're impatient you can run Baritone on top of Impact 4.3 right now.
|
Baritone will be in Impact 4.4 with nice integrations with its utility modules, but if you're impatient you can run Baritone on top of Impact 4.3 right now.
|
||||||
|
|
||||||
You can either build Baritone yourself, or download the jar from September 4 from <a href="https://www.dropbox.com/s/imc6xwwpwsh3i0y/baritone-1.0.0.jar?dl=0">here</a>
|
You can either build Baritone yourself, or download the jar (as of commit <a href="https://github.com/cabaletta/baritone/commit/72eec135d02d09b773240c175edb3c8accab8654">72eec13</a>, built on September 10) from <a href="https://www.dropbox.com/s/imc6xwwpwsh3i0y/baritone-1.0.0.jar?dl=0">here</a>.
|
||||||
|
|
||||||
To build it yourself, clone and setup Baritone (instructions in main README.md). Then, build the jar. From the command line, it's `./gradlew build` (or `gradlew build` on Windows). In IntelliJ, you can just start the `build` task in the Gradle menu.
|
To build it yourself, clone and setup Baritone (instructions in main README.md). Then, build the jar. From the command line, it's `./gradlew build` (or `gradlew build` on Windows). In IntelliJ, you can just start the `build` task in the Gradle menu.
|
||||||
|
|
||||||
Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0.0/baritone-1.0.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0.0` in libraries first.
|
Copy the jar into place. If you built it yourself, it should be at `build/libs/baritone-1.0.0.jar` in baritone (otherwise, if you downloaded it, it's in your Downloads). Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0.0/baritone-1.0.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0.0` in libraries first.
|
||||||
|
|
||||||
Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json` or copy your existing installation and rename the version folder, json, and id in the json.
|
Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. Alternatively, copy your existing installation and rename the version folder, json, and id in the json if you want to be able to choose from the Minecraft launcher whether you want Impact or Impact+Baritone.
|
||||||
|
|
||||||
- Add the Baritone tweak class to line 7 "minecraftArguments" like so: `"minecraftArguments": " ... --tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine",`. You need the Optifine tweaker even though there is no Optifine involved, for reasons I don't quite understand.
|
- Add the Baritone tweak class to line 7 "minecraftArguments" like so: `"minecraftArguments": " ... --tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine",`. You need the Optifine tweaker even though there is no Optifine involved, for reasons I don't quite understand.
|
||||||
- Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0.0" },` between Impact and ClientAPI, which should be between lines 15 and 16.
|
- Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0.0" },` between Impact and ClientAPI, which should be between lines 15 and 16.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ PathingBehavior.INSTANCE.path();
|
|||||||
|
|
||||||
## Can I use Baritone as a library in my hacked client?
|
## Can I use Baritone as a library in my hacked client?
|
||||||
|
|
||||||
Sure!
|
Sure! (As long as usage is in compliance with the GPL 3 License)
|
||||||
|
|
||||||
## How is it so fast?
|
## How is it so fast?
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -87,5 +87,5 @@ mixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from sourceSets.launch.output
|
from sourceSets.launch.output, sourceSets.api.output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.event.events;
|
||||||
|
|
||||||
|
import baritone.api.event.events.type.EventState;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 8/21/2018
|
||||||
|
*/
|
||||||
|
public final class RotationMoveEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of event
|
||||||
|
*/
|
||||||
|
private final Type type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of the event
|
||||||
|
*/
|
||||||
|
private final EventState state;
|
||||||
|
|
||||||
|
public RotationMoveEvent(EventState state, Type type) {
|
||||||
|
this.state = state;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The state of the event
|
||||||
|
*/
|
||||||
|
public final EventState getState() {
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The type of the event
|
||||||
|
*/
|
||||||
|
public final Type getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the player's motion is updated.
|
||||||
|
*
|
||||||
|
* @see Entity#moveRelative(float, float, float, float)
|
||||||
|
*/
|
||||||
|
MOTION_UPDATE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the player jumps.
|
||||||
|
*
|
||||||
|
* @see EntityLivingBase#jump
|
||||||
|
*/
|
||||||
|
JUMP
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -75,7 +75,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
default void onReceivePacket(PacketEvent event) {}
|
default void onReceivePacket(PacketEvent event) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onPlayerRelativeMove(RelativeMoveEvent event) {}
|
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onBlockInteract(BlockInteractEvent event) {}
|
default void onBlockInteract(BlockInteractEvent event) {}
|
||||||
+4
-1
@@ -43,6 +43,7 @@ import net.minecraft.client.multiplayer.WorldClient;
|
|||||||
import net.minecraft.client.renderer.EntityRenderer;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.settings.GameSettings;
|
import net.minecraft.client.settings.GameSettings;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
@@ -120,10 +121,12 @@ public interface IGameEventListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Run once per game tick from before and after the player's moveRelative method is called
|
* Run once per game tick from before and after the player's moveRelative method is called
|
||||||
|
* and before and after the player jumps.
|
||||||
*
|
*
|
||||||
* @see Entity#moveRelative(float, float, float, float)
|
* @see Entity#moveRelative(float, float, float, float)
|
||||||
|
* @see EntityLivingBase#jump()
|
||||||
*/
|
*/
|
||||||
void onPlayerRelativeMove(RelativeMoveEvent event);
|
void onPlayerRotationMove(RotationMoveEvent event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the local player interacts with a block, whether it is breaking or opening/placing.
|
* Called when the local player interacts with a block, whether it is breaking or opening/placing.
|
||||||
@@ -39,9 +39,15 @@ public class BaritoneTweaker implements ITweaker {
|
|||||||
@Override
|
@Override
|
||||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||||
this.args = new ArrayList<>(args);
|
this.args = new ArrayList<>(args);
|
||||||
if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath());
|
if (gameDir != null) {
|
||||||
if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath());
|
addArg("gameDir", gameDir.getAbsolutePath());
|
||||||
if (profile != null) addArg("version", profile);
|
}
|
||||||
|
if (assetsDir != null) {
|
||||||
|
addArg("assetsDir", assetsDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
if (profile != null) {
|
||||||
|
addArg("version", profile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
package baritone.launch.mixins;
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.event.events.RelativeMoveEvent;
|
import baritone.api.event.events.RotationMoveEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@@ -41,7 +41,7 @@ public class MixinEntity {
|
|||||||
private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
||||||
Entity _this = (Entity) (Object) this;
|
Entity _this = (Entity) (Object) this;
|
||||||
if (_this == Minecraft.getMinecraft().player)
|
if (_this == Minecraft.getMinecraft().player)
|
||||||
Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.PRE));
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.MOTION_UPDATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
@@ -51,6 +51,6 @@ public class MixinEntity {
|
|||||||
private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
||||||
Entity _this = (Entity) (Object) this;
|
Entity _this = (Entity) (Object) this;
|
||||||
if (_this == Minecraft.getMinecraft().player)
|
if (_this == Minecraft.getMinecraft().player)
|
||||||
Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.POST));
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.MOTION_UPDATE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.event.events.RotationMoveEvent;
|
||||||
|
import baritone.api.event.events.type.EventState;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 9/10/2018
|
||||||
|
*/
|
||||||
|
@Mixin(EntityLivingBase.class)
|
||||||
|
public class MixinEntityLivingBase {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "jump",
|
||||||
|
at = @At("HEAD")
|
||||||
|
)
|
||||||
|
private void preJump(CallbackInfo ci) {
|
||||||
|
Entity _this = (Entity) (Object) this;
|
||||||
|
if (_this == Minecraft.getMinecraft().player)
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.JUMP));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "jump",
|
||||||
|
at = @At("RETURN")
|
||||||
|
)
|
||||||
|
private void postJump(CallbackInfo ci) {
|
||||||
|
Entity _this = (Entity) (Object) this;
|
||||||
|
if (_this == Minecraft.getMinecraft().player)
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.JUMP));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,8 +42,9 @@ public class MixinEntityPlayerSP {
|
|||||||
private void sendChatMessage(String msg, CallbackInfo ci) {
|
private void sendChatMessage(String msg, CallbackInfo ci) {
|
||||||
ChatEvent event = new ChatEvent(msg);
|
ChatEvent event = new ChatEvent(msg);
|
||||||
Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event);
|
Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event);
|
||||||
if (event.isCancelled())
|
if (event.isCancelled()) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public class MixinKeyBinding {
|
|||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
|
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this))
|
if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) {
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,13 +39,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
@Mixin(NetworkManager.class)
|
@Mixin(NetworkManager.class)
|
||||||
public class MixinNetworkManager {
|
public class MixinNetworkManager {
|
||||||
|
|
||||||
@Shadow private Channel channel;
|
@Shadow
|
||||||
|
private Channel channel;
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "dispatchPacket",
|
method = "dispatchPacket",
|
||||||
at = @At("HEAD")
|
at = @At("HEAD")
|
||||||
)
|
)
|
||||||
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void >>[] futureListeners, CallbackInfo ci) {
|
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
|
||||||
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.PRE, inPacket));
|
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.PRE, inPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ public class MixinNetworkManager {
|
|||||||
method = "dispatchPacket",
|
method = "dispatchPacket",
|
||||||
at = @At("RETURN")
|
at = @At("RETURN")
|
||||||
)
|
)
|
||||||
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void >>[] futureListeners, CallbackInfo ci) {
|
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
|
||||||
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.POST, inPacket));
|
Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.POST, inPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +74,8 @@ public class MixinNetworkManager {
|
|||||||
at = @At("RETURN")
|
at = @At("RETURN")
|
||||||
)
|
)
|
||||||
private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
|
private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
|
||||||
if (this.channel.isOpen())
|
if (this.channel.isOpen()) {
|
||||||
Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(EventState.POST, packet));
|
Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(EventState.POST, packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"MixinBlockPos",
|
"MixinBlockPos",
|
||||||
"MixinChunkProviderServer",
|
"MixinChunkProviderServer",
|
||||||
"MixinEntity",
|
"MixinEntity",
|
||||||
|
"MixinEntityLivingBase",
|
||||||
"MixinEntityPlayerSP",
|
"MixinEntityPlayerSP",
|
||||||
"MixinEntityRenderer",
|
"MixinEntityRenderer",
|
||||||
"MixinGameSettings",
|
"MixinGameSettings",
|
||||||
|
|||||||
@@ -17,9 +17,10 @@
|
|||||||
|
|
||||||
package baritone;
|
package baritone;
|
||||||
|
|
||||||
import baritone.api.event.GameEventHandler;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.behavior.impl.*;
|
import baritone.behavior.impl.*;
|
||||||
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ public enum Baritone {
|
|||||||
return this.initialized;
|
return this.initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final GameEventHandler getGameEventHandler() {
|
public final IGameEventListener getGameEventHandler() {
|
||||||
return this.gameEventHandler;
|
return this.gameEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public Setting<Boolean> allowWalkOnBottomSlab = new Setting<>(true);
|
public Setting<Boolean> allowWalkOnBottomSlab = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You know what it is
|
||||||
|
* <p>
|
||||||
|
* But it's very unreliable and falls off when cornering like all the time so.
|
||||||
|
*/
|
||||||
|
public Setting<Boolean> allowParkour = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly.
|
* For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Baritone.
|
|
||||||
*
|
|
||||||
* Baritone is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package baritone.api.event.events;
|
|
||||||
|
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called in some cases where a player's inventory has it's current slot queried.
|
|
||||||
* <p>
|
|
||||||
* @see IGameEventListener#onQueryItemSlotForBlocks()
|
|
||||||
*
|
|
||||||
* @author Brady
|
|
||||||
* @since 8/20/2018
|
|
||||||
*/
|
|
||||||
public final class ItemSlotEvent {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current slot index
|
|
||||||
*/
|
|
||||||
private int slot;
|
|
||||||
|
|
||||||
public ItemSlotEvent(int slot) {
|
|
||||||
this.slot = slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the new slot index that will be used
|
|
||||||
*
|
|
||||||
* @param slot The slot index
|
|
||||||
*/
|
|
||||||
public final void setSlot(int slot) {
|
|
||||||
this.slot = slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The current slot index
|
|
||||||
*/
|
|
||||||
public final int getSlot() {
|
|
||||||
return this.slot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -52,8 +52,9 @@ public class Behavior implements AbstractGameEventListener, Toggleable, Helper {
|
|||||||
@Override
|
@Override
|
||||||
public final boolean setEnabled(boolean enabled) {
|
public final boolean setEnabled(boolean enabled) {
|
||||||
boolean newState = getNewState(this.enabled, enabled);
|
boolean newState = getNewState(this.enabled, enabled);
|
||||||
if (newState == this.enabled)
|
if (newState == this.enabled) {
|
||||||
return this.enabled;
|
return this.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.enabled = newState) {
|
if (this.enabled = newState) {
|
||||||
onStart();
|
onStart();
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
package baritone.behavior.impl;
|
package baritone.behavior.impl;
|
||||||
|
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.chunk.Waypoint;
|
import baritone.cache.Waypoint;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.api.event.events.BlockInteractEvent;
|
import baritone.api.event.events.BlockInteractEvent;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.BlockBed;
|
import net.minecraft.block.BlockBed;
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ package baritone.behavior.impl;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.Settings;
|
import baritone.Settings;
|
||||||
import baritone.behavior.Behavior;
|
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
import baritone.api.event.events.PlayerUpdateEvent;
|
||||||
import baritone.api.event.events.RelativeMoveEvent;
|
import baritone.api.event.events.RotationMoveEvent;
|
||||||
|
import baritone.behavior.Behavior;
|
||||||
import baritone.utils.Rotation;
|
import baritone.utils.Rotation;
|
||||||
|
|
||||||
public class LookBehavior extends Behavior {
|
public class LookBehavior extends Behavior {
|
||||||
@@ -57,8 +57,9 @@ public class LookBehavior extends Behavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
if (this.target == null)
|
if (this.target == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Whether or not we're going to silently set our angles
|
// Whether or not we're going to silently set our angles
|
||||||
boolean silent = Baritone.settings().antiCheatCompatibility.get();
|
boolean silent = Baritone.settings().antiCheatCompatibility.get();
|
||||||
@@ -91,7 +92,7 @@ public class LookBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||||
if (this.target != null && !this.force) {
|
if (this.target != null && !this.force) {
|
||||||
switch (event.getState()) {
|
switch (event.getState()) {
|
||||||
case PRE:
|
case PRE:
|
||||||
@@ -102,8 +103,10 @@ public class LookBehavior extends Behavior {
|
|||||||
player().rotationYaw = this.lastYaw;
|
player().rotationYaw = this.lastYaw;
|
||||||
|
|
||||||
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
|
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
|
||||||
if (!Baritone.settings().antiCheatCompatibility.get())
|
// Also the type has to be MOTION_UPDATE because that is called after JUMP
|
||||||
|
if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE) {
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,10 @@ public final class LookBehaviorUtils implements Helper {
|
|||||||
return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f));
|
return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f));
|
||||||
}
|
}
|
||||||
Optional<Rotation> possibleRotation = reachableCenter(pos);
|
Optional<Rotation> possibleRotation = reachableCenter(pos);
|
||||||
System.out.println("center: " + possibleRotation);
|
//System.out.println("center: " + possibleRotation);
|
||||||
if (possibleRotation.isPresent())
|
if (possibleRotation.isPresent()) {
|
||||||
return possibleRotation;
|
return possibleRotation;
|
||||||
|
}
|
||||||
|
|
||||||
IBlockState state = BlockStateInterface.get(pos);
|
IBlockState state = BlockStateInterface.get(pos);
|
||||||
AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos);
|
AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos);
|
||||||
@@ -78,8 +79,9 @@ public final class LookBehaviorUtils implements Helper {
|
|||||||
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
|
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
|
||||||
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
|
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
|
||||||
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
|
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
|
||||||
if (possibleRotation.isPresent())
|
if (possibleRotation.isPresent()) {
|
||||||
return possibleRotation;
|
return possibleRotation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package baritone.behavior.impl;
|
package baritone.behavior.impl;
|
||||||
|
|
||||||
import baritone.behavior.Behavior;
|
|
||||||
import baritone.api.event.events.PacketEvent;
|
import baritone.api.event.events.PacketEvent;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
import baritone.api.event.events.PlayerUpdateEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
|
import baritone.behavior.Behavior;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.network.play.client.CPacketCloseWindow;
|
import net.minecraft.network.play.client.CPacketCloseWindow;
|
||||||
@@ -38,8 +38,9 @@ public class MemoryBehavior extends Behavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
if (event.getState() == EventState.PRE)
|
if (event.getState() == EventState.PRE) {
|
||||||
updateInventory();
|
updateInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,13 +87,13 @@ public class MemoryBehavior extends Behavior {
|
|||||||
this.futureInventories.stream()
|
this.futureInventories.stream()
|
||||||
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
|
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
|
||||||
.findFirst().ifPresent(matched -> {
|
.findFirst().ifPresent(matched -> {
|
||||||
// Remove the future inventory
|
// Remove the future inventory
|
||||||
this.futureInventories.remove(matched);
|
this.futureInventories.remove(matched);
|
||||||
|
|
||||||
// Setup the remembered inventory
|
// Setup the remembered inventory
|
||||||
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
|
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
|
||||||
inventory.windowId = packet.getWindowId();
|
inventory.windowId = packet.getWindowId();
|
||||||
inventory.size = packet.getSlotCount();
|
inventory.size = packet.getSlotCount();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ package baritone.behavior.impl;
|
|||||||
|
|
||||||
import baritone.api.event.events.PathEvent;
|
import baritone.api.event.events.PathEvent;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.chunk.CachedChunk;
|
import baritone.cache.CachedChunk;
|
||||||
import baritone.chunk.ChunkPacker;
|
import baritone.cache.ChunkPacker;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.chunk.WorldScanner;
|
import baritone.cache.WorldScanner;
|
||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.goals.GoalComposite;
|
import baritone.pathing.goals.GoalComposite;
|
||||||
import baritone.pathing.goals.GoalTwoBlocks;
|
import baritone.pathing.goals.GoalTwoBlocks;
|
||||||
@@ -60,7 +60,7 @@ public class MineBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
List<BlockPos> locs = scanFor(mining, 64);
|
List<BlockPos> locs = scanFor(mining, 64);
|
||||||
if (locs.isEmpty()) {
|
if (locs.isEmpty()) {
|
||||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
logDebug("No locations for " + mining + " known, cancelling");
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,14 +77,14 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (current.failed() || current.finished()) {
|
if (current.failed() || current.finished()) {
|
||||||
current = null;
|
current = null;
|
||||||
if (goal == null || goal.isInGoal(playerFeet())) {
|
if (goal == null || goal.isInGoal(playerFeet())) {
|
||||||
displayChatMessageRaw("All done. At " + goal);
|
logDebug("All done. At " + goal);
|
||||||
dispatchPathEvent(PathEvent.AT_GOAL);
|
dispatchPathEvent(PathEvent.AT_GOAL);
|
||||||
next = null;
|
next = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (next != null && !next.getPath().positions().contains(playerFeet())) {
|
if (next != null && !next.getPath().positions().contains(playerFeet())) {
|
||||||
// if the current path failed, we may not actually be on the next one, so make sure
|
// if the current path failed, we may not actually be on the next one, so make sure
|
||||||
displayChatMessageRaw("Discarding next path as it does not contain current position");
|
logDebug("Discarding next path as it does not contain current position");
|
||||||
// for example if we had a nicely planned ahead path that starts where current ends
|
// for example if we had a nicely planned ahead path that starts where current ends
|
||||||
// that's all fine and good
|
// that's all fine and good
|
||||||
// but if we fail in the middle of current
|
// but if we fail in the middle of current
|
||||||
@@ -94,7 +94,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
displayChatMessageRaw("Continuing on to planned next path");
|
logDebug("Continuing on to planned next path");
|
||||||
dispatchPathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
|
dispatchPathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
|
||||||
current = next;
|
current = next;
|
||||||
next = null;
|
next = null;
|
||||||
@@ -118,7 +118,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (next != null) {
|
if (next != null) {
|
||||||
if (next.getPath().positions().contains(playerFeet())) {
|
if (next.getPath().positions().contains(playerFeet())) {
|
||||||
// jump directly onto the next path
|
// jump directly onto the next path
|
||||||
displayChatMessageRaw("Splicing into planned next path early...");
|
logDebug("Splicing into planned next path early...");
|
||||||
dispatchPathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
|
dispatchPathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
|
||||||
current = next;
|
current = next;
|
||||||
next = null;
|
next = null;
|
||||||
@@ -141,7 +141,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
||||||
// and this path has 5 seconds or less left
|
// and this path has 5 seconds or less left
|
||||||
displayChatMessageRaw("Path almost over. Planning ahead...");
|
logDebug("Path almost over. Planning ahead...");
|
||||||
dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
|
dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
|
||||||
findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath()));
|
findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath()));
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
if (talkAboutIt) {
|
if (talkAboutIt) {
|
||||||
displayChatMessageRaw("Starting to search for path from " + start + " to " + goal);
|
logDebug("Starting to search for path from " + start + " to " + goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<IPath> path = findPath(start, previous);
|
Optional<IPath> path = findPath(start, previous);
|
||||||
@@ -280,9 +280,9 @@ public class PathingBehavior extends Behavior {
|
|||||||
|
|
||||||
if (talkAboutIt && current != null && current.getPath() != null) {
|
if (talkAboutIt && current != null && current.getPath() != null) {
|
||||||
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
||||||
displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
logDebug("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
||||||
} else {
|
} else {
|
||||||
displayChatMessageRaw("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
logDebug("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous) {
|
private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous) {
|
||||||
Goal goal = this.goal;
|
Goal goal = this.goal;
|
||||||
if (goal == null) {
|
if (goal == null) {
|
||||||
displayChatMessageRaw("no goal");
|
logDebug("no goal");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
if (Baritone.settings().simplifyUnloadedYCoord.get()) {
|
if (Baritone.settings().simplifyUnloadedYCoord.get()) {
|
||||||
@@ -320,7 +320,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
// TODO simplify each individual goal in a GoalComposite
|
// TODO simplify each individual goal in a GoalComposite
|
||||||
if (pos != null && world().getChunk(pos) instanceof EmptyChunk) {
|
if (pos != null && world().getChunk(pos) instanceof EmptyChunk) {
|
||||||
displayChatMessageRaw("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
|
logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
|
||||||
goal = new GoalXZ(pos.getX(), pos.getZ());
|
goal = new GoalXZ(pos.getX(), pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,7 +334,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions));
|
IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions));
|
||||||
return pf.calculate(timeout);
|
return pf.calculate(timeout);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
displayChatMessageRaw("Pathing exception: " + e);
|
logDebug("Pathing exception: " + e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@@ -389,8 +389,9 @@ public class PathingBehavior extends Behavior {
|
|||||||
});
|
});
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
//System.out.println((end - split) + " " + (split - start));
|
//System.out.println((end - split) + " " + (split - start));
|
||||||
// if (end - start > 0)
|
// if (end - start > 0) {
|
||||||
// System.out.println("Frame took " + (split - start) + " " + (end - split));
|
// System.out.println("Frame took " + (split - start) + " " + (end - split));
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-2
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.utils.pathing.IBlockTypeAccess;
|
import baritone.utils.pathing.IBlockTypeAccess;
|
||||||
import baritone.utils.pathing.PathingBlockType;
|
import baritone.utils.pathing.PathingBlockType;
|
||||||
@@ -199,7 +199,8 @@ public final class CachedChunk implements IBlockTypeAccess {
|
|||||||
* @throws IllegalArgumentException if the bitset size exceeds the maximum size
|
* @throws IllegalArgumentException if the bitset size exceeds the maximum size
|
||||||
*/
|
*/
|
||||||
private static void validateSize(BitSet data) {
|
private static void validateSize(BitSet data) {
|
||||||
if (data.size() > SIZE)
|
if (data.size() > SIZE) {
|
||||||
throw new IllegalArgumentException("BitSet of invalid length provided");
|
throw new IllegalArgumentException("BitSet of invalid length provided");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+9
-5
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.utils.pathing.IBlockTypeAccess;
|
import baritone.utils.pathing.IBlockTypeAccess;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -112,13 +112,15 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Path path = Paths.get(directory);
|
Path path = Paths.get(directory);
|
||||||
if (!Files.exists(path))
|
if (!Files.exists(path)) {
|
||||||
Files.createDirectories(path);
|
Files.createDirectories(path);
|
||||||
|
|
||||||
|
}
|
||||||
System.out.println("Saving region " + x + "," + z + " to disk " + path);
|
System.out.println("Saving region " + x + "," + z + " to disk " + path);
|
||||||
Path regionFile = getRegionFile(path, this.x, this.z);
|
Path regionFile = getRegionFile(path, this.x, this.z);
|
||||||
if (!Files.exists(regionFile))
|
if (!Files.exists(regionFile)) {
|
||||||
Files.createFile(regionFile);
|
Files.createFile(regionFile);
|
||||||
|
}
|
||||||
try (
|
try (
|
||||||
FileOutputStream fileOut = new FileOutputStream(regionFile.toFile());
|
FileOutputStream fileOut = new FileOutputStream(regionFile.toFile());
|
||||||
GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384);
|
GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384);
|
||||||
@@ -175,12 +177,14 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
public synchronized void load(String directory) {
|
public synchronized void load(String directory) {
|
||||||
try {
|
try {
|
||||||
Path path = Paths.get(directory);
|
Path path = Paths.get(directory);
|
||||||
if (!Files.exists(path))
|
if (!Files.exists(path)) {
|
||||||
Files.createDirectories(path);
|
Files.createDirectories(path);
|
||||||
|
}
|
||||||
|
|
||||||
Path regionFile = getRegionFile(path, this.x, this.z);
|
Path regionFile = getRegionFile(path, this.x, this.z);
|
||||||
if (!Files.exists(regionFile))
|
if (!Files.exists(regionFile)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Loading region " + x + "," + z + " from disk " + path);
|
System.out.println("Loading region " + x + "," + z + " from disk " + path);
|
||||||
long start = System.nanoTime() / 1000000L;
|
long start = System.nanoTime() / 1000000L;
|
||||||
Vendored
+22
-31
@@ -15,28 +15,28 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.utils.pathing.IBlockTypeAccess;
|
import baritone.utils.Helper;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/4/2018 12:02 AM
|
* @since 8/4/2018 12:02 AM
|
||||||
*/
|
*/
|
||||||
public final class CachedWorld implements IBlockTypeAccess {
|
public final class CachedWorld implements Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of regions in any direction from (0,0)
|
* The maximum number of regions in any direction from (0,0)
|
||||||
@@ -91,16 +91,6 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public final IBlockState getBlock(int x, int y, int z) {
|
|
||||||
// no point in doing getOrCreate region, if we don't have it we don't have it
|
|
||||||
CachedRegion region = getRegion(x >> 9, z >> 9);
|
|
||||||
if (region == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return region.getBlock(x & 511, y, z & 511);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isCached(BlockPos pos) {
|
public final boolean isCached(BlockPos pos) {
|
||||||
int x = pos.getX();
|
int x = pos.getX();
|
||||||
int z = pos.getZ();
|
int z = pos.getZ();
|
||||||
@@ -111,7 +101,6 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
return region.isCached(x & 511, z & 511);
|
return region.isCached(x & 511, z & 511);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
|
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
|
||||||
LinkedList<BlockPos> res = new LinkedList<>();
|
LinkedList<BlockPos> res = new LinkedList<>();
|
||||||
int playerRegionX = playerFeet().getX() >> 9;
|
int playerRegionX = playerFeet().getX() >> 9;
|
||||||
@@ -128,9 +117,11 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
int regionX = xoff + playerRegionX;
|
int regionX = xoff + playerRegionX;
|
||||||
int regionZ = zoff + playerRegionZ;
|
int regionZ = zoff + playerRegionZ;
|
||||||
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
||||||
if (region != null)
|
if (region != null) {
|
||||||
for (BlockPos pos : region.getLocationsOf(block))
|
for (BlockPos pos : region.getLocationsOf(block)) {
|
||||||
res.add(pos);
|
res.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res.size() >= minimum) {
|
if (res.size() >= minimum) {
|
||||||
@@ -152,19 +143,25 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long start = System.nanoTime() / 1000000L;
|
long start = System.nanoTime() / 1000000L;
|
||||||
this.cachedRegions.values().parallelStream().forEach(region -> {
|
allRegions().parallelStream().forEach(region -> {
|
||||||
if (region != null)
|
if (region != null) {
|
||||||
region.save(this.directory);
|
region.save(this.directory);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
long now = System.nanoTime() / 1000000L;
|
long now = System.nanoTime() / 1000000L;
|
||||||
System.out.println("World save took " + (now - start) + "ms");
|
System.out.println("World save took " + (now - start) + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized List<CachedRegion> allRegions() {
|
||||||
|
return new ArrayList<>(this.cachedRegions.values());
|
||||||
|
}
|
||||||
|
|
||||||
public final void reloadAllFromDisk() {
|
public final void reloadAllFromDisk() {
|
||||||
long start = System.nanoTime() / 1000000L;
|
long start = System.nanoTime() / 1000000L;
|
||||||
this.cachedRegions.values().forEach(region -> {
|
allRegions().forEach(region -> {
|
||||||
if (region != null)
|
if (region != null) {
|
||||||
region.load(this.directory);
|
region.load(this.directory);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
long now = System.nanoTime() / 1000000L;
|
long now = System.nanoTime() / 1000000L;
|
||||||
System.out.println("World load took " + (now - start) + "ms");
|
System.out.println("World load took " + (now - start) + "ms");
|
||||||
@@ -177,7 +174,7 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
* @param regionZ The region Z coordinate
|
* @param regionZ The region Z coordinate
|
||||||
* @return The region located at the specified coordinates
|
* @return The region located at the specified coordinates
|
||||||
*/
|
*/
|
||||||
public final CachedRegion getRegion(int regionX, int regionZ) {
|
public final synchronized CachedRegion getRegion(int regionX, int regionZ) {
|
||||||
return cachedRegions.get(getRegionID(regionX, regionZ));
|
return cachedRegions.get(getRegionID(regionX, regionZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,13 +194,6 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forEachRegion(Consumer<CachedRegion> consumer) {
|
|
||||||
this.cachedRegions.forEach((id, r) -> {
|
|
||||||
if (r != null)
|
|
||||||
consumer.accept(r);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the region ID based on the region coordinates. 0 will be
|
* Returns the region ID based on the region coordinates. 0 will be
|
||||||
* returned if the specified region coordinates are out of bounds.
|
* returned if the specified region coordinates are out of bounds.
|
||||||
@@ -213,8 +203,9 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
* @return The region ID
|
* @return The region ID
|
||||||
*/
|
*/
|
||||||
private long getRegionID(int regionX, int regionZ) {
|
private long getRegionID(int regionX, int regionZ) {
|
||||||
if (!isRegionInWorld(regionX, regionZ))
|
if (!isRegionInWorld(regionX, regionZ)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return (long) regionX & 0xFFFFFFFFL | ((long) regionZ & 0xFFFFFFFFL) << 32;
|
return (long) regionX & 0xFFFFFFFFL | ((long) regionZ & 0xFFFFFFFFL) << 32;
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
+3
-2
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@@ -61,8 +61,9 @@ public class Waypoints {
|
|||||||
waypoints.put(tag, new HashSet<>());
|
waypoints.put(tag, new HashSet<>());
|
||||||
|
|
||||||
Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4");
|
Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4");
|
||||||
if (!Files.exists(fileName))
|
if (!Files.exists(fileName)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try (
|
try (
|
||||||
FileInputStream fileIn = new FileInputStream(fileName.toFile());
|
FileInputStream fileIn = new FileInputStream(fileName.toFile());
|
||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
Vendored
+4
-3
@@ -15,12 +15,12 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||||
import baritone.utils.accessor.IChunkProviderServer;
|
import baritone.utils.accessor.IChunkProviderServer;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.client.multiplayer.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
import net.minecraft.server.integrated.IntegratedServer;
|
import net.minecraft.server.integrated.IntegratedServer;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
@@ -102,7 +102,8 @@ public enum WorldProvider implements Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
|
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
|
||||||
if (this.currentWorld != null)
|
if (this.currentWorld != null) {
|
||||||
currentWorldConsumer.accept(this.currentWorld);
|
currentWorldConsumer.accept(this.currentWorld);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+7
-7
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -47,13 +47,13 @@ public enum WorldScanner implements Helper {
|
|||||||
int playerChunkX = playerFeet().getX() >> 4;
|
int playerChunkX = playerFeet().getX() >> 4;
|
||||||
int playerChunkZ = playerFeet().getZ() >> 4;
|
int playerChunkZ = playerFeet().getZ() >> 4;
|
||||||
|
|
||||||
int searchRadius = 2;
|
int searchRadiusSq = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
boolean allUnloaded = true;
|
boolean allUnloaded = true;
|
||||||
for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) {
|
for (int xoff = -searchRadiusSq; xoff <= searchRadiusSq; xoff++) {
|
||||||
for (int zoff = -searchRadius; zoff <= searchRadius; zoff++) {
|
for (int zoff = -searchRadiusSq; zoff <= searchRadiusSq; zoff++) {
|
||||||
int distance = xoff * xoff + zoff * zoff;
|
int distance = xoff * xoff + zoff * zoff;
|
||||||
if (distance != searchRadius) {
|
if (distance != searchRadiusSq) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int chunkX = xoff + playerChunkX;
|
int chunkX = xoff + playerChunkX;
|
||||||
@@ -91,10 +91,10 @@ public enum WorldScanner implements Helper {
|
|||||||
if (allUnloaded) {
|
if (allUnloaded) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (res.size() >= max) {
|
if (res.size() >= max && searchRadiusSq > 26) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
searchRadius++;
|
searchRadiusSq++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+73
-48
@@ -15,30 +15,13 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
package baritone.event;
|
||||||
* This file is part of Baritone.
|
|
||||||
*
|
|
||||||
* Baritone is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package baritone.api.event;
|
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.event.events.*;
|
import baritone.api.event.events.*;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
@@ -48,8 +31,6 @@ import net.minecraft.world.chunk.Chunk;
|
|||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@@ -57,16 +38,24 @@ import java.util.function.Consumer;
|
|||||||
*/
|
*/
|
||||||
public final class GameEventHandler implements IGameEventListener, Helper {
|
public final class GameEventHandler implements IGameEventListener, Helper {
|
||||||
|
|
||||||
private final List<IGameEventListener> listeners = new ArrayList<>();
|
private final ArrayList<IGameEventListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick(TickEvent event) {
|
public final void onTick(TickEvent event) {
|
||||||
dispatch(listener -> listener.onTick(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onTick(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onPlayerUpdate(PlayerUpdateEvent event) {
|
public final void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
dispatch(listener -> listener.onPlayerUpdate(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerUpdate(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,17 +69,26 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
|
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
|
||||||
int keyCode = keyBinding.getKeyCode();
|
int keyCode = keyBinding.getKeyCode();
|
||||||
|
|
||||||
if (keyCode < Keyboard.KEYBOARD_SIZE)
|
if (keyCode < Keyboard.KEYBOARD_SIZE) {
|
||||||
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
|
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(IGameEventListener::onProcessKeyBinds);
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onProcessKeyBinds();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSendChatMessage(ChatEvent event) {
|
public final void onSendChatMessage(ChatEvent event) {
|
||||||
dispatch(listener -> listener.onSendChatMessage(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onSendChatMessage(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -116,18 +114,20 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dispatch(listener -> listener.onChunkEvent(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onChunkEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onRenderPass(RenderEvent event) {
|
public final void onRenderPass(RenderEvent event) {
|
||||||
/*
|
listeners.forEach(l -> {
|
||||||
WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> {
|
if (canDispatch(l)) {
|
||||||
drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks());
|
l.onRenderPass(event);
|
||||||
})));
|
}
|
||||||
*/
|
});
|
||||||
|
|
||||||
dispatch(listener -> listener.onRenderPass(event));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,52 +141,77 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
break;
|
break;
|
||||||
case POST:
|
case POST:
|
||||||
cache.closeWorld();
|
cache.closeWorld();
|
||||||
if (event.getWorld() != null)
|
if (event.getWorld() != null) {
|
||||||
cache.initWorld(event.getWorld());
|
cache.initWorld(event.getWorld());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(listener -> listener.onWorldEvent(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onWorldEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSendPacket(PacketEvent event) {
|
public final void onSendPacket(PacketEvent event) {
|
||||||
dispatch(listener -> listener.onSendPacket(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onSendPacket(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onReceivePacket(PacketEvent event) {
|
public final void onReceivePacket(PacketEvent event) {
|
||||||
dispatch(listener -> listener.onReceivePacket(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onReceivePacket(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||||
dispatch(listener -> listener.onPlayerRelativeMove(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerRotationMove(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
dispatch(listener -> listener.onBlockInteract(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onBlockInteract(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerDeath() {
|
public void onPlayerDeath() {
|
||||||
dispatch(IGameEventListener::onPlayerDeath);
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPlayerDeath();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPathEvent(PathEvent event) {
|
public void onPathEvent(PathEvent event) {
|
||||||
dispatch(listener -> listener.onPathEvent(event));
|
listeners.forEach(l -> {
|
||||||
|
if (canDispatch(l)) {
|
||||||
|
l.onPathEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void registerEventListener(IGameEventListener listener) {
|
public final void registerEventListener(IGameEventListener listener) {
|
||||||
this.listeners.add(listener);
|
this.listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dispatch(Consumer<IGameEventListener> dispatchFunction) {
|
|
||||||
this.listeners.stream().filter(this::canDispatch).forEach(dispatchFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canDispatch(IGameEventListener listener) {
|
private boolean canDispatch(IGameEventListener listener) {
|
||||||
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
package baritone.pathing.calc;
|
package baritone.pathing.calc;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.chunk.CachedWorld;
|
import baritone.cache.CachedWorld;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.ActionCosts;
|
import baritone.pathing.movement.ActionCosts;
|
||||||
@@ -70,10 +70,11 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
currentlyRunning = this;
|
currentlyRunning = this;
|
||||||
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
|
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
|
||||||
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
|
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
|
||||||
|
BlockStateInterface.clearCachedChunk();
|
||||||
long startTime = System.nanoTime() / 1000000L;
|
long startTime = System.nanoTime() / 1000000L;
|
||||||
boolean slowPath = Baritone.settings().slowPath.get();
|
boolean slowPath = Baritone.settings().slowPath.get();
|
||||||
if (slowPath) {
|
if (slowPath) {
|
||||||
displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + timeout + "ms");
|
logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + timeout + "ms");
|
||||||
}
|
}
|
||||||
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.<Long>get() : timeout);
|
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.<Long>get() : timeout);
|
||||||
//long lastPrintout = 0;
|
//long lastPrintout = 0;
|
||||||
@@ -125,7 +126,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
numNodes++;
|
numNodes++;
|
||||||
if (goal.isInGoal(currentNodePos)) {
|
if (goal.isInGoal(currentNodePos)) {
|
||||||
currentlyRunning = null;
|
currentlyRunning = null;
|
||||||
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||||
return Optional.of(new Path(startNode, currentNode, numNodes));
|
return Optional.of(new Path(startNode, currentNode, numNodes));
|
||||||
}
|
}
|
||||||
long constructStart = System.nanoTime();
|
long constructStart = System.nanoTime();
|
||||||
@@ -140,7 +141,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
if (movementToGetToNeighbor == null) {
|
if (movementToGetToNeighbor == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
|
BetterBlockPos dest = movementToGetToNeighbor.getDest();
|
||||||
long s = System.nanoTime();
|
long s = System.nanoTime();
|
||||||
int chunkX = currentNodePos.x >> 4;
|
int chunkX = currentNodePos.x >> 4;
|
||||||
int chunkZ = currentNodePos.z >> 4;
|
int chunkZ = currentNodePos.z >> 4;
|
||||||
@@ -256,7 +257,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
bestDist = dist;
|
bestDist = dist;
|
||||||
}
|
}
|
||||||
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
||||||
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
|
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
|
||||||
if (COEFFICIENTS[i] >= 3) {
|
if (COEFFICIENTS[i] >= 3) {
|
||||||
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
|
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
|
||||||
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
|
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
|
||||||
@@ -267,40 +268,51 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
return Optional.of(new Path(startNode, bestSoFar[i], numNodes));
|
return Optional.of(new Path(startNode, bestSoFar[i], numNodes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
||||||
displayChatMessageRaw("No path found =(");
|
logDebug("No path found =(");
|
||||||
currentlyRunning = null;
|
currentlyRunning = null;
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) {
|
public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) {
|
||||||
int x = pos.getX();
|
int x = pos.x;
|
||||||
int y = pos.getY();
|
int y = pos.y;
|
||||||
int z = pos.getZ();
|
int z = pos.z;
|
||||||
BetterBlockPos east = new BetterBlockPos(x + 1, y, z);
|
BetterBlockPos east = new BetterBlockPos(x + 1, y, z);
|
||||||
BetterBlockPos west = new BetterBlockPos(x - 1, y, z);
|
BetterBlockPos west = new BetterBlockPos(x - 1, y, z);
|
||||||
BetterBlockPos south = new BetterBlockPos(x, y, z + 1);
|
BetterBlockPos south = new BetterBlockPos(x, y, z + 1);
|
||||||
BetterBlockPos north = new BetterBlockPos(x, y, z - 1);
|
BetterBlockPos north = new BetterBlockPos(x, y, z - 1);
|
||||||
return new Movement[]{
|
return new Movement[]{
|
||||||
|
new MovementDownward(pos, new BetterBlockPos(x, y - 1, z)),
|
||||||
|
|
||||||
|
new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)),
|
||||||
|
|
||||||
new MovementTraverse(pos, east),
|
new MovementTraverse(pos, east),
|
||||||
new MovementTraverse(pos, west),
|
new MovementTraverse(pos, west),
|
||||||
new MovementTraverse(pos, north),
|
new MovementTraverse(pos, north),
|
||||||
new MovementTraverse(pos, south),
|
new MovementTraverse(pos, south),
|
||||||
|
|
||||||
new MovementAscend(pos, new BetterBlockPos(x + 1, y + 1, z)),
|
new MovementAscend(pos, new BetterBlockPos(x + 1, y + 1, z)),
|
||||||
new MovementAscend(pos, new BetterBlockPos(x - 1, y + 1, z)),
|
new MovementAscend(pos, new BetterBlockPos(x - 1, y + 1, z)),
|
||||||
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z + 1)),
|
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z + 1)),
|
||||||
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z - 1)),
|
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z - 1)),
|
||||||
|
|
||||||
MovementHelper.generateMovementFallOrDescend(pos, east, calcContext),
|
MovementHelper.generateMovementFallOrDescend(pos, east, calcContext),
|
||||||
MovementHelper.generateMovementFallOrDescend(pos, west, calcContext),
|
MovementHelper.generateMovementFallOrDescend(pos, west, calcContext),
|
||||||
MovementHelper.generateMovementFallOrDescend(pos, north, calcContext),
|
MovementHelper.generateMovementFallOrDescend(pos, north, calcContext),
|
||||||
MovementHelper.generateMovementFallOrDescend(pos, south, calcContext),
|
MovementHelper.generateMovementFallOrDescend(pos, south, calcContext),
|
||||||
new MovementDownward(pos, new BetterBlockPos(x, y - 1, z)),
|
|
||||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
|
|
||||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST),
|
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST),
|
||||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
|
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
|
||||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST),
|
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST),
|
||||||
new MovementPillar(pos, new BetterBlockPos(x, y + 1, z))
|
|
||||||
|
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
|
||||||
|
|
||||||
|
MovementParkour.generate(pos, EnumFacing.EAST),
|
||||||
|
MovementParkour.generate(pos, EnumFacing.WEST),
|
||||||
|
MovementParkour.generate(pos, EnumFacing.NORTH),
|
||||||
|
MovementParkour.generate(pos, EnumFacing.SOUTH),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
* @return The distance, squared
|
* @return The distance, squared
|
||||||
*/
|
*/
|
||||||
protected double getDistFromStartSq(PathNode n) {
|
protected double getDistFromStartSq(PathNode n) {
|
||||||
int xDiff = n.pos.getX() - start.getX();
|
int xDiff = n.pos.x - start.x;
|
||||||
int yDiff = n.pos.getY() - start.getY();
|
int yDiff = n.pos.y - start.y;
|
||||||
int zDiff = n.pos.getZ() - start.getZ();
|
int zDiff = n.pos.z - start.z;
|
||||||
return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff;
|
return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package baritone.pathing.calc;
|
package baritone.pathing.calc;
|
||||||
|
|
||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
|
import baritone.pathing.movement.ActionCosts;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ import baritone.utils.pathing.BetterBlockPos;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class PathNode {
|
public final class PathNode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The position of this node
|
* The position of this node
|
||||||
@@ -81,7 +82,7 @@ public class PathNode {
|
|||||||
public PathNode(BetterBlockPos pos, Goal goal) {
|
public PathNode(BetterBlockPos pos, Goal goal) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.previous = null;
|
this.previous = null;
|
||||||
this.cost = Short.MAX_VALUE;
|
this.cost = ActionCosts.COST_INF;
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
this.estimatedCostToGoal = goal.heuristic(pos);
|
this.estimatedCostToGoal = goal.heuristic(pos);
|
||||||
this.previousMovement = null;
|
this.previousMovement = null;
|
||||||
@@ -103,8 +104,9 @@ public class PathNode {
|
|||||||
// GOTTA GO FAST
|
// GOTTA GO FAST
|
||||||
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
|
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
|
||||||
// SKRT SKRT
|
// SKRT SKRT
|
||||||
//if (obj == null || !(obj instanceof PathNode))
|
//if (obj == null || !(obj instanceof PathNode)) {
|
||||||
// return false;
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
//final PathNode other = (PathNode) obj;
|
//final PathNode other = (PathNode) obj;
|
||||||
//return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);
|
//return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.goals;
|
package baritone.pathing.goals;
|
||||||
|
|
||||||
|
import baritone.utils.interfaces.IGoalRenderPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +25,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class GoalBlock implements Goal {
|
public class GoalBlock implements Goal, IGoalRenderPos {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The X block position of this goal
|
* The X block position of this goal
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.goals;
|
package baritone.pathing.goals;
|
||||||
|
|
||||||
|
import baritone.utils.interfaces.IGoalRenderPos;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*
|
*
|
||||||
* @author avecowa
|
* @author avecowa
|
||||||
*/
|
*/
|
||||||
public class GoalGetToBlock implements Goal {
|
public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
||||||
|
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
|
|||||||
@@ -17,9 +17,10 @@
|
|||||||
|
|
||||||
package baritone.pathing.goals;
|
package baritone.pathing.goals;
|
||||||
|
|
||||||
|
import baritone.utils.interfaces.IGoalRenderPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class GoalNear implements Goal {
|
public class GoalNear implements Goal, IGoalRenderPos {
|
||||||
final int x;
|
final int x;
|
||||||
final int y;
|
final int y;
|
||||||
final int z;
|
final int z;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.goals;
|
package baritone.pathing.goals;
|
||||||
|
|
||||||
|
import baritone.utils.interfaces.IGoalRenderPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +26,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class GoalTwoBlocks implements Goal {
|
public class GoalTwoBlocks implements Goal, IGoalRenderPos {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The X block position of this goal
|
* The X block position of this goal
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import baritone.behavior.impl.LookBehavior;
|
|||||||
import baritone.behavior.impl.LookBehaviorUtils;
|
import baritone.behavior.impl.LookBehaviorUtils;
|
||||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.utils.*;
|
import baritone.utils.*;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
@@ -39,9 +40,9 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
|
|
||||||
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||||
|
|
||||||
protected final BlockPos src;
|
protected final BetterBlockPos src;
|
||||||
|
|
||||||
protected final BlockPos dest;
|
protected final BetterBlockPos dest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The positions that need to be broken before this movement can ensue
|
* The positions that need to be broken before this movement can ensue
|
||||||
@@ -57,21 +58,22 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
|
|
||||||
private Double cost;
|
private Double cost;
|
||||||
|
|
||||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
|
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
|
||||||
this.src = src;
|
this.src = src;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
this.positionsToBreak = toBreak;
|
this.positionsToBreak = toBreak;
|
||||||
this.positionToPlace = toPlace;
|
this.positionToPlace = toPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) {
|
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) {
|
||||||
this(src, dest, toBreak, null);
|
this(src, dest, toBreak, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getCost(CalculationContext context) {
|
public double getCost(CalculationContext context) {
|
||||||
if (cost == null) {
|
if (cost == null) {
|
||||||
if (context == null)
|
if (context == null) {
|
||||||
context = new CalculationContext();
|
context = new CalculationContext();
|
||||||
|
}
|
||||||
cost = calculateCost(context);
|
cost = calculateCost(context);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
@@ -84,6 +86,10 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return getCost(null);
|
return getCost(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void override(double cost) {
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
public double calculateCostWithoutCaching() {
|
public double calculateCostWithoutCaching() {
|
||||||
return calculateCost(new CalculationContext());
|
return calculateCost(new CalculationContext());
|
||||||
}
|
}
|
||||||
@@ -128,13 +134,15 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
});
|
});
|
||||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
latestState.getInputStates().replaceAll((input, forced) -> false);
|
||||||
|
|
||||||
if (!this.didBreakLastTick)
|
if (!this.didBreakLastTick) {
|
||||||
BlockBreakHelper.stopBreakingBlock();
|
BlockBreakHelper.stopBreakingBlock();
|
||||||
|
}
|
||||||
|
|
||||||
currentState = latestState;
|
currentState = latestState;
|
||||||
|
|
||||||
if (isFinished())
|
if (isFinished()) {
|
||||||
onFinish(latestState);
|
onFinish(latestState);
|
||||||
|
}
|
||||||
|
|
||||||
return currentState.getStatus();
|
return currentState.getStatus();
|
||||||
}
|
}
|
||||||
@@ -178,11 +186,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
&& currentState.getStatus() != MovementStatus.WAITING);
|
&& currentState.getStatus() != MovementStatus.WAITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPos getSrc() {
|
public BetterBlockPos getSrc() {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPos getDest() {
|
public BetterBlockPos getDest() {
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,6 +278,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
} else if (state.getStatus() == MovementStatus.PREPPING) {
|
} else if (state.getStatus() == MovementStatus.PREPPING) {
|
||||||
state.setStatus(MovementStatus.WAITING);
|
state.setStatus(MovementStatus.WAITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state.getStatus() == MovementStatus.WAITING) {
|
||||||
|
state.setStatus(MovementStatus.RUNNING);
|
||||||
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementState.MovementTarget;
|
|||||||
import baritone.pathing.movement.movements.MovementDescend;
|
import baritone.pathing.movement.movements.MovementDescend;
|
||||||
import baritone.pathing.movement.movements.MovementFall;
|
import baritone.pathing.movement.movements.MovementFall;
|
||||||
import baritone.utils.*;
|
import baritone.utils.*;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.properties.PropertyBool;
|
import net.minecraft.block.properties.PropertyBool;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -48,14 +49,17 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
static boolean avoidBreaking(BlockPos pos, IBlockState state) {
|
static boolean avoidBreaking(BlockPos pos, IBlockState state) {
|
||||||
Block b = state.getBlock();
|
Block b = state.getBlock();
|
||||||
Block below = BlockStateInterface.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
int x = pos.getX();
|
||||||
return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path
|
int y = pos.getY();
|
||||||
|
int z = pos.getZ();
|
||||||
|
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||||
|| b instanceof BlockSilverfish // obvious reasons
|
|| b instanceof BlockSilverfish // obvious reasons
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
|
// call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()))
|
|| BlockStateInterface.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))
|
|| BlockStateInterface.get(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1))
|
|| BlockStateInterface.get(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1));
|
|| BlockStateInterface.get(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||||
|
|| BlockStateInterface.get(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,10 +74,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
|
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block instanceof BlockFire
|
if (block == Blocks.AIR) {
|
||||||
|| block instanceof BlockTripWire
|
return true;
|
||||||
|| block instanceof BlockWeb
|
}
|
||||||
|| block instanceof BlockEndPortal) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
|
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||||
@@ -106,6 +110,38 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return block.isPassable(mc.world, pos);
|
return block.isPassable(mc.world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click),
|
||||||
|
* not including water, and not including ladders or vines or cobwebs (they slow us down)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static boolean fullyPassable(BlockPos pos) {
|
||||||
|
return fullyPassable(pos, BlockStateInterface.get(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean fullyPassable(BlockPos pos, IBlockState state) {
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if (block == Blocks.AIR) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// exceptions - blocks that are isPassable true, but we can't actually jump through
|
||||||
|
if (block == Blocks.FIRE
|
||||||
|
|| block == Blocks.TRIPWIRE
|
||||||
|
|| block == Blocks.WEB
|
||||||
|
|| block == Blocks.VINE
|
||||||
|
|| block == Blocks.LADDER
|
||||||
|
|| block instanceof BlockDoor
|
||||||
|
|| block instanceof BlockFenceGate
|
||||||
|
|| block instanceof BlockSnow
|
||||||
|
|| block instanceof BlockLiquid
|
||||||
|
|| block instanceof BlockTrapDoor
|
||||||
|
|| block instanceof BlockEndPortal) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return block.isPassable(mc.world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
static boolean isReplacable(BlockPos pos, IBlockState state) {
|
static boolean isReplacable(BlockPos pos, IBlockState state) {
|
||||||
// for MovementTraverse and MovementAscend
|
// for MovementTraverse and MovementAscend
|
||||||
// block double plant defaults to true when the block doesn't match, so don't need to check that case
|
// block double plant defaults to true when the block doesn't match, so don't need to check that case
|
||||||
@@ -127,30 +163,35 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) {
|
static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) {
|
||||||
if (playerPos.equals(doorPos))
|
if (playerPos.equals(doorPos)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IBlockState state = BlockStateInterface.get(doorPos);
|
IBlockState state = BlockStateInterface.get(doorPos);
|
||||||
if (!(state.getBlock() instanceof BlockDoor))
|
if (!(state.getBlock() instanceof BlockDoor)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
|
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
|
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
|
||||||
if (playerPos.equals(gatePos))
|
if (playerPos.equals(gatePos)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IBlockState state = BlockStateInterface.get(gatePos);
|
IBlockState state = BlockStateInterface.get(gatePos);
|
||||||
if (!(state.getBlock() instanceof BlockFenceGate))
|
if (!(state.getBlock() instanceof BlockFenceGate)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN);
|
return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) {
|
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) {
|
||||||
if (playerPos.equals(blockPos))
|
if (playerPos.equals(blockPos)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis();
|
EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis();
|
||||||
boolean open = blockState.getValue(propertyOpen);
|
boolean open = blockState.getValue(propertyOpen);
|
||||||
@@ -169,10 +210,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
static boolean avoidWalkingInto(Block block) {
|
static boolean avoidWalkingInto(Block block) {
|
||||||
return BlockStateInterface.isLava(block)
|
return BlockStateInterface.isLava(block)
|
||||||
|| block instanceof BlockCactus
|
|| block == Blocks.MAGMA
|
||||||
|| block instanceof BlockFire
|
|| block == Blocks.CACTUS
|
||||||
|| block instanceof BlockEndPortal
|
|| block == Blocks.FIRE
|
||||||
|| block instanceof BlockWeb;
|
|| block == Blocks.END_PORTAL
|
||||||
|
|| block == Blocks.WEB;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,31 +226,22 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
*/
|
*/
|
||||||
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.AIR) {
|
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this
|
if (state.isBlockNormalCube()) {
|
||||||
return true;
|
if (BlockStateInterface.isLava(block) || BlockStateInterface.isWater(block)) {
|
||||||
}
|
throw new IllegalStateException();
|
||||||
if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Blocks.FARMLAND.equals(block) || Blocks.GRASS_PATH.equals(block)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Blocks.ENDER_CHEST.equals(block) || Blocks.CHEST.equals(block)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (block instanceof BlockSlab) {
|
|
||||||
if (!Baritone.settings().allowWalkOnBottomSlab.get()) {
|
|
||||||
if (((BlockSlab) block).isDouble()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockStairs) {
|
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.get())) { // TODO reconsider this
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (BlockStateInterface.isWater(block)) {
|
if (BlockStateInterface.isWater(block)) {
|
||||||
@@ -224,20 +257,28 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
// if assumeWalkOnWater is off, we can only walk on water if there is water above it
|
// if assumeWalkOnWater is off, we can only walk on water if there is water above it
|
||||||
return BlockStateInterface.isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
|
return BlockStateInterface.isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
|
||||||
}
|
}
|
||||||
if (Blocks.MAGMA.equals(block)) {
|
if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
if (block instanceof BlockSlab) {
|
||||||
|
if (!Baritone.settings().allowWalkOnBottomSlab.get()) {
|
||||||
|
if (((BlockSlab) block).isDouble()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (block instanceof BlockStairs) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canWalkOn(BlockPos pos) {
|
static boolean canWalkOn(BlockPos pos) {
|
||||||
return canWalkOn(pos, BlockStateInterface.get(pos));
|
return canWalkOn(pos, BlockStateInterface.get(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canFall(BlockPos pos) {
|
|
||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean canPlaceAgainst(BlockPos pos) {
|
static boolean canPlaceAgainst(BlockPos pos) {
|
||||||
IBlockState state = BlockStateInterface.get(pos);
|
IBlockState state = BlockStateInterface.get(pos);
|
||||||
// TODO isBlockNormalCube isn't the best check for whether or not we can place a block against it. e.g. glass isn't normalCube but we can place against it
|
// TODO isBlockNormalCube isn't the best check for whether or not we can place a block against it. e.g. glass isn't normalCube but we can place against it
|
||||||
@@ -251,7 +292,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) {
|
static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, state)) { // TODO is the air check really necessary? Isn't air canWalkThrough?
|
if (!canWalkThrough(position, state)) {
|
||||||
if (!context.allowBreak()) {
|
if (!context.allowBreak()) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
@@ -260,8 +301,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
}
|
}
|
||||||
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
|
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
|
||||||
double strVsBlock = context.getToolSet().getStrVsBlock(state);
|
double strVsBlock = context.getToolSet().getStrVsBlock(state);
|
||||||
if (strVsBlock < 0)
|
if (strVsBlock < 0) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
|
}
|
||||||
|
|
||||||
double result = m / strVsBlock;
|
double result = m / strVsBlock;
|
||||||
if (includeFalling) {
|
if (includeFalling) {
|
||||||
@@ -359,7 +401,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Movement generateMovementFallOrDescend(BlockPos pos, BlockPos dest, CalculationContext calcContext) {
|
static Movement generateMovementFallOrDescend(BetterBlockPos pos, BetterBlockPos dest, CalculationContext calcContext) {
|
||||||
// A
|
// A
|
||||||
//SA
|
//SA
|
||||||
// A
|
// A
|
||||||
@@ -376,12 +418,13 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
//this doesn't guarantee descend is possible, it just guarantees fall is impossible
|
//this doesn't guarantee descend is possible, it just guarantees fall is impossible
|
||||||
return new MovementDescend(pos, dest.down()); // standard move out by 1 and descend by 1
|
return new MovementDescend(pos, dest.down()); // standard move out by 1 and descend by 1
|
||||||
|
// we can't cost shortcut descend because !canWalkThrough doesn't mean canWalkOn
|
||||||
}
|
}
|
||||||
|
|
||||||
// we're clear for a fall 2
|
// we're clear for a fall 2
|
||||||
// let's see how far we can fall
|
// let's see how far we can fall
|
||||||
for (int fallHeight = 3; true; fallHeight++) {
|
for (int fallHeight = 3; true; fallHeight++) {
|
||||||
BlockPos onto = dest.down(fallHeight);
|
BetterBlockPos onto = dest.down(fallHeight);
|
||||||
if (onto.getY() < 0) {
|
if (onto.getY() < 0) {
|
||||||
// when pathing in the end, where you could plausibly fall into the void
|
// when pathing in the end, where you could plausibly fall into the void
|
||||||
// this check prevents it from getting the block at y=-1 and crashing
|
// this check prevents it from getting the block at y=-1 and crashing
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus;
|
|||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import baritone.utils.Utils;
|
import baritone.utils.Utils;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -41,7 +42,7 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
private int ticksWithoutPlacement = 0;
|
private int ticksWithoutPlacement = 0;
|
||||||
|
|
||||||
public MovementAscend(BlockPos src, BlockPos dest) {
|
public MovementAscend(BetterBlockPos src, BetterBlockPos dest) {
|
||||||
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
|
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ public class MovementAscend extends Movement {
|
|||||||
if (!context.hasThrowaway()) {
|
if (!context.hasThrowaway()) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
|
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
// TODO: add ability to place against .down() as well as the cardinal directions
|
// TODO: add ability to place against .down() as well as the cardinal directions
|
||||||
@@ -123,13 +124,8 @@ public class MovementAscend extends Movement {
|
|||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
|
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
|
||||||
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerFeet().equals(dest)) {
|
if (playerFeet().equals(dest)) {
|
||||||
@@ -160,8 +156,8 @@ public class MovementAscend extends Movement {
|
|||||||
if (player().isSneaking()) {
|
if (player().isSneaking()) {
|
||||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||||
}
|
}
|
||||||
if (ticksWithoutPlacement > 20) {
|
if (ticksWithoutPlacement > 10) {
|
||||||
// After 20 ticks without placement, we might be standing in the way, move back
|
// After 10 ticks without placement, we might be standing in the way, move back
|
||||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,13 +24,14 @@ import baritone.pathing.movement.MovementState;
|
|||||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class MovementDescend extends Movement {
|
public class MovementDescend extends Movement {
|
||||||
|
|
||||||
public MovementDescend(BlockPos start, BlockPos end) {
|
public MovementDescend(BetterBlockPos start, BetterBlockPos end) {
|
||||||
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down());
|
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +68,8 @@ public class MovementDescend extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockPos playerFeet = playerFeet();
|
BlockPos playerFeet = playerFeet();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockMagma;
|
import net.minecraft.block.BlockMagma;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -37,16 +38,16 @@ public class MovementDiagonal extends Movement {
|
|||||||
|
|
||||||
private static final double SQRT_2 = Math.sqrt(2);
|
private static final double SQRT_2 = Math.sqrt(2);
|
||||||
|
|
||||||
public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
public MovementDiagonal(BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
||||||
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
||||||
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) {
|
private MovementDiagonal(BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) {
|
||||||
this(start, dir1.offset(drr2), dir1, dir2);
|
this(start, dir1.offset(drr2), dir1, dir2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) {
|
||||||
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
|
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,13 +120,8 @@ public class MovementDiagonal extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementState.MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerFeet().equals(dest)) {
|
if (playerFeet().equals(dest)) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -31,7 +32,7 @@ public class MovementDownward extends Movement {
|
|||||||
|
|
||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
|
|
||||||
public MovementDownward(BlockPos start, BlockPos end) {
|
public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
|
||||||
super(start, end, new BlockPos[]{end});
|
super(start, end, new BlockPos[]{end});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +61,8 @@ public class MovementDownward extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementState.MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerFeet().equals(dest)) {
|
if (playerFeet().equals(dest)) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
|
|||||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||||
import baritone.utils.*;
|
import baritone.utils.*;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -41,7 +42,7 @@ public class MovementFall extends Movement {
|
|||||||
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
||||||
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
|
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
|
||||||
|
|
||||||
public MovementFall(BlockPos src, BlockPos dest) {
|
public MovementFall(BetterBlockPos src, BetterBlockPos dest) {
|
||||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
|
super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,13 +97,8 @@ public class MovementFall extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockPos playerFeet = playerFeet();
|
BlockPos playerFeet = playerFeet();
|
||||||
@@ -129,8 +125,7 @@ public class MovementFall extends Movement {
|
|||||||
} else {
|
} else {
|
||||||
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
||||||
}
|
}
|
||||||
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 // lilypads
|
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads
|
||||||
|| BlockStateInterface.isWater(dest))) {
|
|
||||||
if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
|
if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
|
||||||
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
|
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
|
||||||
if (player().motionY >= 0) {
|
if (player().motionY >= 0) {
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.pathing.movement.movements;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.pathing.movement.CalculationContext;
|
||||||
|
import baritone.pathing.movement.Movement;
|
||||||
|
import baritone.pathing.movement.MovementHelper;
|
||||||
|
import baritone.pathing.movement.MovementState;
|
||||||
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import baritone.utils.InputOverrideHandler;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class MovementParkour extends Movement {
|
||||||
|
|
||||||
|
final EnumFacing direction;
|
||||||
|
final int dist;
|
||||||
|
|
||||||
|
private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) {
|
||||||
|
super(src, src.offset(dir, dist), new BlockPos[]{});
|
||||||
|
this.direction = dir;
|
||||||
|
this.dist = dist;
|
||||||
|
super.override(costFromJumpDistance(dist));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MovementParkour generate(BetterBlockPos src, EnumFacing dir) {
|
||||||
|
if (!Baritone.settings().allowParkour.get()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
IBlockState standingOn = BlockStateInterface.get(src.down());
|
||||||
|
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockPos adjBlock = src.down().offset(dir);
|
||||||
|
IBlockState adj = BlockStateInterface.get(adjBlock);
|
||||||
|
if (MovementHelper.avoidWalkingInto(adj.getBlock())) { // magma sucks
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (MovementHelper.canWalkOn(adjBlock, adj)) { // don't parkour if we could just traverse (for now)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MovementHelper.fullyPassable(src.offset(dir))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!MovementHelper.fullyPassable(src.up().offset(dir))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!MovementHelper.fullyPassable(src.up(2).offset(dir))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!MovementHelper.fullyPassable(src.up(2))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (int i = 2; i <= 4; i++) {
|
||||||
|
BlockPos dest = src.offset(dir, i);
|
||||||
|
// TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly?
|
||||||
|
for (int y = 0; y < 4; y++) {
|
||||||
|
if (!MovementHelper.fullyPassable(dest.up(y))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (MovementHelper.canWalkOn(dest.down())) {
|
||||||
|
return new MovementParkour(src, i, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double costFromJumpDistance(int dist) {
|
||||||
|
switch (dist) {
|
||||||
|
case 2:
|
||||||
|
return WALK_ONE_BLOCK_COST * 2; // IDK LOL
|
||||||
|
case 3:
|
||||||
|
return WALK_ONE_BLOCK_COST * 3;
|
||||||
|
case 4:
|
||||||
|
return SPRINT_ONE_BLOCK_COST * 4;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("LOL");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double calculateCost(CalculationContext context) {
|
||||||
|
if (!MovementHelper.canWalkOn(dest.down())) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(src.down().offset(direction)).getBlock())) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= 4; i++) {
|
||||||
|
BlockPos d = src.offset(direction, i);
|
||||||
|
for (int y = 0; y < (i == 1 ? 3 : 4); y++) {
|
||||||
|
if (!MovementHelper.fullyPassable(d.up(y))) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d.equals(dest)) {
|
||||||
|
return costFromJumpDistance(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("invalid jump distance?");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MovementState updateState(MovementState state) {
|
||||||
|
super.updateState(state);
|
||||||
|
switch (state.getStatus()) {
|
||||||
|
case WAITING:
|
||||||
|
state.setStatus(MovementState.MovementStatus.RUNNING);
|
||||||
|
case RUNNING:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
if (dist >= 4) {
|
||||||
|
state.setInput(InputOverrideHandler.Input.SPRINT, true);
|
||||||
|
}
|
||||||
|
MovementHelper.moveTowards(state, dest);
|
||||||
|
if (playerFeet().equals(dest)) {
|
||||||
|
if (player().posY - playerFeet().getY() < 0.01) {
|
||||||
|
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
||||||
|
}
|
||||||
|
} else if (!playerFeet().equals(src)) {
|
||||||
|
if (playerFeet().equals(src.offset(direction)) || player().posY - playerFeet().getY() > 0.0001) {
|
||||||
|
state.setInput(InputOverrideHandler.Input.JUMP, true);
|
||||||
|
} else {
|
||||||
|
state.setInput(InputOverrideHandler.Input.SPRINT, false);
|
||||||
|
if (playerFeet().equals(src.offset(direction, -1))) {
|
||||||
|
MovementHelper.moveTowards(state, src);
|
||||||
|
} else {
|
||||||
|
MovementHelper.moveTowards(state, src.offset(direction, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ import baritone.utils.BlockStateInterface;
|
|||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import baritone.utils.Rotation;
|
import baritone.utils.Rotation;
|
||||||
import baritone.utils.Utils;
|
import baritone.utils.Utils;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -33,7 +34,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
public class MovementPillar extends Movement {
|
public class MovementPillar extends Movement {
|
||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
|
|
||||||
public MovementPillar(BlockPos start, BlockPos end) {
|
public MovementPillar(BetterBlockPos start, BetterBlockPos end) {
|
||||||
super(start, end, new BlockPos[]{start.up(2)}, start);
|
super(start, end, new BlockPos[]{start.up(2)}, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,13 +122,8 @@ public class MovementPillar extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementState.MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IBlockState fromDown = BlockStateInterface.get(src);
|
IBlockState fromDown = BlockStateInterface.get(src);
|
||||||
@@ -143,7 +139,7 @@ public class MovementPillar extends Movement {
|
|||||||
if (ladder) {
|
if (ladder) {
|
||||||
BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
|
BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
|
||||||
if (against == null) {
|
if (against == null) {
|
||||||
displayChatMessageRaw("Unable to climb vines");
|
logDebug("Unable to climb vines");
|
||||||
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +170,7 @@ public class MovementPillar extends Movement {
|
|||||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||||
|
|
||||||
// Otherwise jump
|
// Otherwise jump
|
||||||
if (numTicks > 40) {
|
if (numTicks > 20) {
|
||||||
double diffX = player().posX - (dest.getX() + 0.5);
|
double diffX = player().posX - (dest.getX() + 0.5);
|
||||||
double diffZ = player().posZ - (dest.getZ() + 0.5);
|
double diffZ = player().posZ - (dest.getZ() + 0.5);
|
||||||
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
|
|||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import baritone.utils.Utils;
|
import baritone.utils.Utils;
|
||||||
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -42,7 +43,7 @@ public class MovementTraverse extends Movement {
|
|||||||
*/
|
*/
|
||||||
private boolean wasTheBridgeBlockAlwaysThere = true;
|
private boolean wasTheBridgeBlockAlwaysThere = true;
|
||||||
|
|
||||||
public MovementTraverse(BlockPos from, BlockPos to) {
|
public MovementTraverse(BetterBlockPos from, BetterBlockPos to) {
|
||||||
super(from, to, new BlockPos[]{to.up(), to}, to.down());
|
super(from, to, new BlockPos[]{to.up(), to}, to.down());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,15 +126,9 @@ public class MovementTraverse extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
switch (state.getStatus()) {
|
if (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||||
case WAITING:
|
return state;
|
||||||
state.setStatus(MovementState.MovementStatus.RUNNING);
|
|
||||||
case RUNNING:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state.setInput(InputOverrideHandler.Input.SNEAK, false);
|
state.setInput(InputOverrideHandler.Input.SNEAK, false);
|
||||||
|
|
||||||
Block fd = BlockStateInterface.get(src.down()).getBlock();
|
Block fd = BlockStateInterface.get(src.down()).getBlock();
|
||||||
@@ -176,7 +171,7 @@ public class MovementTraverse extends Movement {
|
|||||||
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder;
|
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder;
|
||||||
BlockPos whereAmI = playerFeet();
|
BlockPos whereAmI = playerFeet();
|
||||||
if (whereAmI.getY() != dest.getY() && !ladder) {
|
if (whereAmI.getY() != dest.getY() && !ladder) {
|
||||||
displayChatMessageRaw("Wrong Y coordinate");
|
logDebug("Wrong Y coordinate");
|
||||||
if (whereAmI.getY() < dest.getY()) {
|
if (whereAmI.getY() < dest.getY()) {
|
||||||
state.setInput(InputOverrideHandler.Input.JUMP, true);
|
state.setInput(InputOverrideHandler.Input.JUMP, true);
|
||||||
}
|
}
|
||||||
@@ -208,7 +203,7 @@ public class MovementTraverse extends Movement {
|
|||||||
against1 = against1.down();
|
against1 = against1.down();
|
||||||
if (MovementHelper.canPlaceAgainst(against1)) {
|
if (MovementHelper.canPlaceAgainst(against1)) {
|
||||||
if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block
|
if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block
|
||||||
displayChatMessageRaw("bb pls get me some blocks. dirt or cobble");
|
logDebug("bb pls get me some blocks. dirt or cobble");
|
||||||
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||||
@@ -245,7 +240,7 @@ public class MovementTraverse extends Movement {
|
|||||||
// If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
|
// If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
|
||||||
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
||||||
if (!MovementHelper.throwaway(true)) {// get ready to place a throwaway block
|
if (!MovementHelper.throwaway(true)) {// get ready to place a throwaway block
|
||||||
displayChatMessageRaw("bb pls get me some blocks. dirt or cobble");
|
logDebug("bb pls get me some blocks. dirt or cobble");
|
||||||
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;
|
double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;
|
||||||
|
|||||||
@@ -128,12 +128,12 @@ public interface IPath extends Helper {
|
|||||||
for (int i = 0; i < positions().size(); i++) {
|
for (int i = 0; i < positions().size(); i++) {
|
||||||
BlockPos pos = positions().get(i);
|
BlockPos pos = positions().get(i);
|
||||||
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
||||||
displayChatMessageRaw("Cutting off path at edge of loaded chunks");
|
logDebug("Cutting off path at edge of loaded chunks");
|
||||||
displayChatMessageRaw("Length decreased by " + (positions().size() - i - 1));
|
logDebug("Length decreased by " + (positions().size() - i - 1));
|
||||||
return new CutoffPath(this, i);
|
return new CutoffPath(this, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
displayChatMessageRaw("Path ends within loaded chunks");
|
logDebug("Path ends within loaded chunks");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public interface IPath extends Helper {
|
|||||||
}
|
}
|
||||||
double factor = Baritone.settings().pathCutoffFactor.get();
|
double factor = Baritone.settings().pathCutoffFactor.get();
|
||||||
int newLength = (int) (length() * factor);
|
int newLength = (int) (length() * factor);
|
||||||
//displayChatMessageRaw("Static cutoff " + length() + " to " + newLength);
|
//logDebug("Static cutoff " + length() + " to " + newLength);
|
||||||
return new CutoffPath(this, newLength);
|
return new CutoffPath(this, newLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ public class PathExecutor implements Helper {
|
|||||||
if (!whereShouldIBe.equals(whereAmI)) {
|
if (!whereShouldIBe.equals(whereAmI)) {
|
||||||
//System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI);
|
//System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI);
|
||||||
if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
|
if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
|
||||||
for (int i = 0; i < pathPosition - 2 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
||||||
if (whereAmI.equals(path.positions().get(i))) {
|
if (whereAmI.equals(path.positions().get(i))) {
|
||||||
displayChatMessageRaw("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
||||||
int previousPos = pathPosition;
|
int previousPos = pathPosition;
|
||||||
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
|
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
|
||||||
for (int j = pathPosition; j <= previousPos; j++) {
|
for (int j = pathPosition; j <= previousPos; j++) {
|
||||||
@@ -105,7 +105,7 @@ public class PathExecutor implements Helper {
|
|||||||
for (int i = pathPosition + 2; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
|
for (int i = pathPosition + 2; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
|
||||||
if (whereAmI.equals(path.positions().get(i))) {
|
if (whereAmI.equals(path.positions().get(i))) {
|
||||||
if (i - pathPosition > 2) {
|
if (i - pathPosition > 2) {
|
||||||
displayChatMessageRaw("Skipping forward " + (i - pathPosition) + " steps, to " + i);
|
logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i);
|
||||||
}
|
}
|
||||||
System.out.println("Double skip sundae");
|
System.out.println("Double skip sundae");
|
||||||
pathPosition = i - 1;
|
pathPosition = i - 1;
|
||||||
@@ -121,7 +121,7 @@ public class PathExecutor implements Helper {
|
|||||||
ticksAway++;
|
ticksAway++;
|
||||||
System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DIST_FROM_PATH);
|
System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DIST_FROM_PATH);
|
||||||
if (ticksAway > MAX_TICKS_AWAY) {
|
if (ticksAway > MAX_TICKS_AWAY) {
|
||||||
displayChatMessageRaw("Too far away from path for too long, cancelling path");
|
logDebug("Too far away from path for too long, cancelling path");
|
||||||
System.out.println("Too many ticks");
|
System.out.println("Too many ticks");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
@@ -134,7 +134,7 @@ public class PathExecutor implements Helper {
|
|||||||
if (distanceFromPath > MAX_MAX_DIST_FROM_PATH) {
|
if (distanceFromPath > MAX_MAX_DIST_FROM_PATH) {
|
||||||
if (!(path.movements().get(pathPosition) instanceof MovementFall)) { // might be midair
|
if (!(path.movements().get(pathPosition) instanceof MovementFall)) { // might be midair
|
||||||
if (pathPosition == 0 || !(path.movements().get(pathPosition - 1) instanceof MovementFall)) { // might have overshot the landing
|
if (pathPosition == 0 || !(path.movements().get(pathPosition - 1) instanceof MovementFall)) { // might have overshot the landing
|
||||||
displayChatMessageRaw("too far from path");
|
logDebug("too far from path");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
failed = true;
|
failed = true;
|
||||||
@@ -211,7 +211,7 @@ public class PathExecutor implements Helper {
|
|||||||
}
|
}
|
||||||
long end = System.nanoTime() / 1000000L;
|
long end = System.nanoTime() / 1000000L;
|
||||||
if (end - start > 0) {
|
if (end - start > 0) {
|
||||||
//displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
|
//logDebug("Recalculating break and place took " + (end - start) + "ms");
|
||||||
}
|
}
|
||||||
Movement movement = path.movements().get(pathPosition);
|
Movement movement = path.movements().get(pathPosition);
|
||||||
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||||
@@ -220,7 +220,7 @@ public class PathExecutor implements Helper {
|
|||||||
currentMovementInitialCostEstimate = movement.getCost(null);
|
currentMovementInitialCostEstimate = movement.getCost(null);
|
||||||
for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) {
|
for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) {
|
||||||
if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) {
|
if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) {
|
||||||
displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling.");
|
logDebug("Something has changed in the world and a future movement has become impossible. Cancelling.");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
failed = true;
|
failed = true;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
@@ -230,7 +230,7 @@ public class PathExecutor implements Helper {
|
|||||||
}
|
}
|
||||||
double currentCost = movement.recalculateCost();
|
double currentCost = movement.recalculateCost();
|
||||||
if (currentCost >= ActionCosts.COST_INF) {
|
if (currentCost >= ActionCosts.COST_INF) {
|
||||||
displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling.");
|
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
failed = true;
|
failed = true;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
@@ -238,7 +238,7 @@ public class PathExecutor implements Helper {
|
|||||||
}
|
}
|
||||||
MovementState.MovementStatus movementStatus = movement.update();
|
MovementState.MovementStatus movementStatus = movement.update();
|
||||||
if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
|
if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
|
||||||
displayChatMessageRaw("Movement returns status " + movementStatus);
|
logDebug("Movement returns status " + movementStatus);
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
failed = true;
|
failed = true;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
@@ -259,7 +259,7 @@ public class PathExecutor implements Helper {
|
|||||||
// as you break the blocks required, the remaining cost goes down, to the point where
|
// as you break the blocks required, the remaining cost goes down, to the point where
|
||||||
// ticksOnCurrent is greater than recalculateCost + 100
|
// ticksOnCurrent is greater than recalculateCost + 100
|
||||||
// this is why we cache cost at the beginning, and don't recalculate for this comparison every tick
|
// this is why we cache cost at the beginning, and don't recalculate for this comparison every tick
|
||||||
displayChatMessageRaw("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling.");
|
logDebug("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling.");
|
||||||
movement.cancel();
|
movement.cancel();
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
@@ -318,7 +318,7 @@ public class PathExecutor implements Helper {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection()));
|
//logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection()));
|
||||||
}
|
}
|
||||||
player().setSprinting(false);
|
player().setSprinting(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,27 +18,44 @@
|
|||||||
package baritone.utils;
|
package baritone.utils;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.chunk.WorldData;
|
import baritone.cache.CachedRegion;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldData;
|
||||||
|
import baritone.cache.WorldProvider;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps get for chuck caching capability
|
||||||
|
*
|
||||||
|
* @author leijurv
|
||||||
|
*/
|
||||||
public class BlockStateInterface implements Helper {
|
public class BlockStateInterface implements Helper {
|
||||||
|
|
||||||
public static int numBlockStateLookups = 0;
|
public static int numBlockStateLookups = 0;
|
||||||
public static int numTimesChunkSucceeded = 0;
|
public static int numTimesChunkSucceeded = 0;
|
||||||
private static Chunk prev = null;
|
private static Chunk prev = null;
|
||||||
|
private static CachedRegion prevCached = null;
|
||||||
|
|
||||||
public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability
|
private static IBlockState AIR = Blocks.AIR.getDefaultState();
|
||||||
|
public static final Block waterFlowing = Blocks.FLOWING_WATER;
|
||||||
|
public static final Block waterStill = Blocks.WATER;
|
||||||
|
public static final Block lavaFlowing = Blocks.FLOWING_LAVA;
|
||||||
|
public static final Block lavaStill = Blocks.LAVA;
|
||||||
|
|
||||||
|
public static IBlockState get(BlockPos pos) {
|
||||||
|
return get(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IBlockState get(int x, int y, int z) {
|
||||||
numBlockStateLookups++;
|
numBlockStateLookups++;
|
||||||
// Invalid vertical position
|
// Invalid vertical position
|
||||||
if (pos.getY() < 0 || pos.getY() >= 256)
|
if (y < 0 || y >= 256) {
|
||||||
return Blocks.AIR.getDefaultState();
|
return AIR;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Baritone.settings().pathThroughCachedOnly.get()) {
|
if (!Baritone.settings().pathThroughCachedOnly.get()) {
|
||||||
Chunk cached = prev;
|
Chunk cached = prev;
|
||||||
@@ -47,40 +64,47 @@ public class BlockStateInterface implements Helper {
|
|||||||
// if it's the same chunk as last time
|
// if it's the same chunk as last time
|
||||||
// we can just skip the mc.world.getChunk lookup
|
// we can just skip the mc.world.getChunk lookup
|
||||||
// which is a Long2ObjectOpenHashMap.get
|
// which is a Long2ObjectOpenHashMap.get
|
||||||
if (cached != null && cached.x == pos.getX() >> 4 && cached.z == pos.getZ() >> 4) {
|
if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) {
|
||||||
numTimesChunkSucceeded++;
|
numTimesChunkSucceeded++;
|
||||||
return cached.getBlockState(pos);
|
return cached.getBlockState(x, y, z);
|
||||||
}
|
}
|
||||||
Chunk chunk = mc.world.getChunk(pos);
|
Chunk chunk = mc.world.getChunk(x >> 4, z >> 4);
|
||||||
if (chunk.isLoaded()) {
|
if (chunk.isLoaded()) {
|
||||||
prev = chunk;
|
prev = chunk;
|
||||||
return chunk.getBlockState(pos);
|
return chunk.getBlockState(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
|
// same idea here, skip the Long2ObjectOpenHashMap.get if at all possible
|
||||||
if (world != null) {
|
// except here, it's 512x512 tiles instead of 16x16, so even better repetition
|
||||||
IBlockState type = world.cache.getBlock(pos);
|
CachedRegion cached = prevCached;
|
||||||
if (type != null) {
|
if (cached == null || cached.getX() != x >> 9 || cached.getZ() != z >> 9) {
|
||||||
return type;
|
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
|
||||||
|
if (world == null) {
|
||||||
|
return AIR;
|
||||||
}
|
}
|
||||||
|
CachedRegion region = world.cache.getRegion(x >> 9, z >> 9);
|
||||||
|
if (region == null) {
|
||||||
|
return AIR;
|
||||||
|
}
|
||||||
|
prevCached = region;
|
||||||
|
cached = region;
|
||||||
}
|
}
|
||||||
|
IBlockState type = cached.getBlock(x & 511, y, z & 511);
|
||||||
|
if (type == null) {
|
||||||
return Blocks.AIR.getDefaultState();
|
return AIR;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearCachedChunk() {
|
public static void clearCachedChunk() {
|
||||||
prev = null;
|
prev = null;
|
||||||
|
prevCached = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getBlock(BlockPos pos) {
|
public static Block getBlock(BlockPos pos) {
|
||||||
return get(pos).getBlock();
|
return get(pos).getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Block waterFlowing = Blocks.FLOWING_WATER;
|
|
||||||
public static final Block waterStill = Blocks.WATER;
|
|
||||||
public static final Block lavaFlowing = Blocks.FLOWING_LAVA;
|
|
||||||
public static final Block lavaStill = Blocks.LAVA;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the specified block is
|
* Returns whether or not the specified block is
|
||||||
@@ -90,7 +114,7 @@ public class BlockStateInterface implements Helper {
|
|||||||
* @return Whether or not the block is water
|
* @return Whether or not the block is water
|
||||||
*/
|
*/
|
||||||
public static boolean isWater(Block b) {
|
public static boolean isWater(Block b) {
|
||||||
return waterFlowing.equals(b) || waterStill.equals(b);
|
return b == waterFlowing || b == waterStill;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +129,7 @@ public class BlockStateInterface implements Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLava(Block b) {
|
public static boolean isLava(Block b) {
|
||||||
return lavaFlowing.equals(b) || lavaStill.equals(b);
|
return b == lavaFlowing || b == lavaStill;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,18 +148,4 @@ public class BlockStateInterface implements Helper {
|
|||||||
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
|
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
|
||||||
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAir(BlockPos pos) {
|
|
||||||
return BlockStateInterface.getBlock(pos).equals(Blocks.AIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAir(IBlockState state) {
|
|
||||||
return state.getBlock().equals(Blocks.AIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean canFall(BlockPos pos) {
|
|
||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import baritone.behavior.Behavior;
|
|||||||
import baritone.behavior.impl.FollowBehavior;
|
import baritone.behavior.impl.FollowBehavior;
|
||||||
import baritone.behavior.impl.MineBehavior;
|
import baritone.behavior.impl.MineBehavior;
|
||||||
import baritone.behavior.impl.PathingBehavior;
|
import baritone.behavior.impl.PathingBehavior;
|
||||||
import baritone.chunk.ChunkPacker;
|
import baritone.cache.ChunkPacker;
|
||||||
import baritone.chunk.Waypoint;
|
import baritone.cache.Waypoint;
|
||||||
import baritone.chunk.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.pathing.calc.AStarPathFinder;
|
import baritone.pathing.calc.AStarPathFinder;
|
||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.goals.*;
|
import baritone.pathing.goals.*;
|
||||||
@@ -92,23 +92,27 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2])));
|
goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2])));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
displayChatMessageRaw("unable to understand lol");
|
logDirect("unable to understand lol");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
displayChatMessageRaw("unable to parse integer " + ex);
|
logDirect("unable to parse integer " + ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
displayChatMessageRaw("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.equals("path")) {
|
if (msg.equals("path")) {
|
||||||
if (!PathingBehavior.INSTANCE.path()) {
|
if (!PathingBehavior.INSTANCE.path()) {
|
||||||
if (PathingBehavior.INSTANCE.getGoal() == null) {
|
if (PathingBehavior.INSTANCE.getGoal() == null) {
|
||||||
displayChatMessageRaw("No goal.");
|
logDirect("No goal.");
|
||||||
} else {
|
} else {
|
||||||
displayChatMessageRaw("Currently executing a path. Please cancel it first.");
|
if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) {
|
||||||
|
logDirect("Already in goal");
|
||||||
|
} else {
|
||||||
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
@@ -119,13 +123,13 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
FollowBehavior.INSTANCE.cancel();
|
FollowBehavior.INSTANCE.cancel();
|
||||||
MineBehavior.INSTANCE.cancel();
|
MineBehavior.INSTANCE.cancel();
|
||||||
event.cancel();
|
event.cancel();
|
||||||
displayChatMessageRaw("ok canceled");
|
logDirect("ok canceled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("forcecancel")) {
|
if (msg.toLowerCase().equals("forcecancel")) {
|
||||||
AbstractNodeCostSearch.forceCancel();
|
AbstractNodeCostSearch.forceCancel();
|
||||||
event.cancel();
|
event.cancel();
|
||||||
displayChatMessageRaw("ok force canceled");
|
logDirect("ok force canceled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("invert")) {
|
if (msg.toLowerCase().equals("invert")) {
|
||||||
@@ -136,8 +140,8 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
} else if (goal instanceof GoalBlock) {
|
} else if (goal instanceof GoalBlock) {
|
||||||
runAwayFrom = ((GoalBlock) goal).getGoalPos();
|
runAwayFrom = ((GoalBlock) goal).getGoalPos();
|
||||||
} else {
|
} else {
|
||||||
displayChatMessageRaw("Goal must be GoalXZ or GoalBlock to invert");
|
logDirect("Goal must be GoalXZ or GoalBlock to invert");
|
||||||
displayChatMessageRaw("Inverting goal of player feet");
|
logDirect("Inverting goal of player feet");
|
||||||
runAwayFrom = playerFeet();
|
runAwayFrom = playerFeet();
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) {
|
PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) {
|
||||||
@@ -147,7 +151,7 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!PathingBehavior.INSTANCE.path()) {
|
if (!PathingBehavior.INSTANCE.path()) {
|
||||||
displayChatMessageRaw("Currently executing a path. Please cancel it first.");
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -155,31 +159,31 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
if (msg.toLowerCase().equals("follow")) {
|
if (msg.toLowerCase().equals("follow")) {
|
||||||
Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt();
|
Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt();
|
||||||
if (!entity.isPresent()) {
|
if (!entity.isPresent()) {
|
||||||
displayChatMessageRaw("You aren't looking at an entity bruh");
|
logDirect("You aren't looking at an entity bruh");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FollowBehavior.INSTANCE.follow(entity.get());
|
FollowBehavior.INSTANCE.follow(entity.get());
|
||||||
displayChatMessageRaw("Following " + entity.get());
|
logDirect("Following " + entity.get());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("reloadall")) {
|
if (msg.toLowerCase().equals("reloadall")) {
|
||||||
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
|
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
|
||||||
displayChatMessageRaw("ok");
|
logDirect("ok");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("saveall")) {
|
if (msg.toLowerCase().equals("saveall")) {
|
||||||
WorldProvider.INSTANCE.getCurrentWorld().cache.save();
|
WorldProvider.INSTANCE.getCurrentWorld().cache.save();
|
||||||
displayChatMessageRaw("ok");
|
logDirect("ok");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().startsWith("find")) {
|
if (msg.toLowerCase().startsWith("find")) {
|
||||||
String blockType = msg.toLowerCase().substring(4).trim();
|
String blockType = msg.toLowerCase().substring(4).trim();
|
||||||
LinkedList<BlockPos> locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4);
|
LinkedList<BlockPos> locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4);
|
||||||
displayChatMessageRaw("Have " + locs.size() + " locations");
|
logDirect("Have " + locs.size() + " locations");
|
||||||
for (BlockPos pos : locs) {
|
for (BlockPos pos : locs) {
|
||||||
Block actually = BlockStateInterface.get(pos).getBlock();
|
Block actually = BlockStateInterface.get(pos).getBlock();
|
||||||
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||||
@@ -193,20 +197,20 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" ");
|
String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" ");
|
||||||
for (String s : blockTypes) {
|
for (String s : blockTypes) {
|
||||||
if (ChunkPacker.stringToBlock(s) == null) {
|
if (ChunkPacker.stringToBlock(s) == null) {
|
||||||
displayChatMessageRaw(s + " isn't a valid block name");
|
logDirect(s + " isn't a valid block name");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MineBehavior.INSTANCE.mine(blockTypes);
|
MineBehavior.INSTANCE.mine(blockTypes);
|
||||||
displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes));
|
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().startsWith("thisway")) {
|
if (msg.toLowerCase().startsWith("thisway")) {
|
||||||
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
displayChatMessageRaw("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -218,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
}
|
}
|
||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -226,9 +230,9 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
// might as well show them from oldest to newest
|
// might as well show them from oldest to newest
|
||||||
List<Waypoint> sorted = new ArrayList<>(waypoints);
|
List<Waypoint> sorted = new ArrayList<>(waypoints);
|
||||||
sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp));
|
sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp));
|
||||||
displayChatMessageRaw("Waypoints under tag " + tag + ":");
|
logDirect("Waypoints under tag " + tag + ":");
|
||||||
for (Waypoint waypoint : sorted) {
|
for (Waypoint waypoint : sorted) {
|
||||||
displayChatMessageRaw(waypoint.toString());
|
logDirect(waypoint.toString());
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -242,15 +246,15 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
String mining = waypointType;
|
String mining = waypointType;
|
||||||
//displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
if (ChunkPacker.stringToBlock(mining) == null) {
|
if (ChunkPacker.stringToBlock(mining) == null) {
|
||||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
logDirect("No locations for " + mining + " known, cancelling");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
|
List<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
|
||||||
if (locs.isEmpty()) {
|
if (locs.isEmpty()) {
|
||||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
logDirect("No locations for " + mining + " known, cancelling");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
||||||
@@ -259,14 +263,16 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
}
|
}
|
||||||
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag);
|
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
displayChatMessageRaw("None saved for tag " + tag);
|
logDirect("None saved for tag " + tag);
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Goal goal = new GoalBlock(waypoint.location);
|
Goal goal = new GoalBlock(waypoint.location);
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
if (!PathingBehavior.INSTANCE.path()) {
|
if (!PathingBehavior.INSTANCE.path()) {
|
||||||
displayChatMessageRaw("Currently executing a path. Please cancel it first.");
|
if (!goal.isInGoal(playerFeet())) {
|
||||||
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -277,30 +283,30 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
BlockPos spawnPoint = player().getBedLocation();
|
BlockPos spawnPoint = player().getBedLocation();
|
||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
||||||
displayChatMessageRaw("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.location);
|
Goal goal = new GoalBlock(waypoint.location);
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
displayChatMessageRaw("Set goal to most recent bed " + goal);
|
logDirect("Set goal to most recent bed " + goal);
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("sethome")) {
|
if (msg.toLowerCase().equals("sethome")) {
|
||||||
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
|
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
|
||||||
displayChatMessageRaw("Saved. Say home to set goal.");
|
logDirect("Saved. Say home to set goal.");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("home")) {
|
if (msg.toLowerCase().equals("home")) {
|
||||||
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME);
|
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
displayChatMessageRaw("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.location);
|
Goal goal = new GoalBlock(waypoint.location);
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
displayChatMessageRaw("Set goal to saved home " + goal);
|
logDirect("Set goal to saved home " + goal);
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -308,6 +314,9 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
if (msg.toLowerCase().equals("costs")) {
|
if (msg.toLowerCase().equals("costs")) {
|
||||||
Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext());
|
Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext());
|
||||||
List<Movement> moves = new ArrayList<>(Arrays.asList(movements));
|
List<Movement> moves = new ArrayList<>(Arrays.asList(movements));
|
||||||
|
while (moves.contains(null)) {
|
||||||
|
moves.remove(null);
|
||||||
|
}
|
||||||
moves.sort(Comparator.comparingDouble(movement -> movement.getCost(new CalculationContext())));
|
moves.sort(Comparator.comparingDouble(movement -> movement.getCost(new CalculationContext())));
|
||||||
for (Movement move : moves) {
|
for (Movement move : moves) {
|
||||||
String[] parts = move.getClass().toString().split("\\.");
|
String[] parts = move.getClass().toString().split("\\.");
|
||||||
@@ -316,7 +325,7 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
if (cost >= ActionCosts.COST_INF) {
|
if (cost >= ActionCosts.COST_INF) {
|
||||||
strCost = "IMPOSSIBLE";
|
strCost = "IMPOSSIBLE";
|
||||||
}
|
}
|
||||||
displayChatMessageRaw(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -326,13 +335,13 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||||
setting.value ^= true;
|
setting.value ^= true;
|
||||||
event.cancel();
|
event.cancel();
|
||||||
displayChatMessageRaw("Toggled " + setting.getName() + " to " + setting.value);
|
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) {
|
if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) {
|
||||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
||||||
displayChatMessageRaw(setting.toString());
|
logDirect(setting.toString());
|
||||||
}
|
}
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@@ -353,11 +362,11 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
setting.value = Double.parseDouble(data[1]);
|
setting.value = Double.parseDouble(data[1]);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
displayChatMessageRaw("Unable to parse " + data[1]);
|
logDirect("Unable to parse " + data[1]);
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
displayChatMessageRaw(setting.toString());
|
logDirect(setting.toString());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -365,7 +374,7 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
}
|
}
|
||||||
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
|
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
|
||||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
|
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
|
||||||
displayChatMessageRaw(setting.toString());
|
logDirect(setting.toString());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,13 +73,24 @@ public interface Helper {
|
|||||||
return new Rotation(player().rotationYaw, player().rotationPitch);
|
return new Rotation(player().rotationYaw, player().rotationPitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void displayChatMessageRaw(String message) {
|
/**
|
||||||
|
* Send a message to chat only if chatDebug is on
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
default void logDebug(String message) {
|
||||||
if (!Baritone.settings().chatDebug.get()) {
|
if (!Baritone.settings().chatDebug.get()) {
|
||||||
System.out.println("Suppressed debug message:");
|
System.out.println("Suppressed debug message:");
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
logDirect(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command)
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
default void logDirect(String message) {
|
||||||
ITextComponent component = MESSAGE_PREFIX.createCopy();
|
ITextComponent component = MESSAGE_PREFIX.createCopy();
|
||||||
component.getStyle().setColor(TextFormatting.GRAY);
|
component.getStyle().setColor(TextFormatting.GRAY);
|
||||||
component.appendSibling(new TextComponentString(" " + message));
|
component.appendSibling(new TextComponentString(" " + message));
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ package baritone.utils;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.goals.GoalBlock;
|
import baritone.pathing.goals.GoalComposite;
|
||||||
|
import baritone.pathing.goals.GoalTwoBlocks;
|
||||||
import baritone.pathing.goals.GoalXZ;
|
import baritone.pathing.goals.GoalXZ;
|
||||||
import baritone.pathing.path.IPath;
|
import baritone.pathing.path.IPath;
|
||||||
|
import baritone.utils.interfaces.IGoalRenderPos;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -183,17 +185,25 @@ public final class PathRenderer implements Helper {
|
|||||||
double maxY;
|
double maxY;
|
||||||
double y1;
|
double y1;
|
||||||
double y2;
|
double y2;
|
||||||
if (goal instanceof GoalBlock) {
|
if (goal instanceof IGoalRenderPos) {
|
||||||
BlockPos goalPos = ((GoalBlock) goal).getGoalPos();
|
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
|
||||||
minX = goalPos.getX() + 0.002 - renderPosX;
|
minX = goalPos.getX() + 0.002 - renderPosX;
|
||||||
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
||||||
minZ = goalPos.getZ() + 0.002 - renderPosZ;
|
minZ = goalPos.getZ() + 0.002 - renderPosZ;
|
||||||
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
|
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
|
||||||
double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2));
|
double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2));
|
||||||
|
if (goal instanceof GoalTwoBlocks) {
|
||||||
|
y /= 2;
|
||||||
|
}
|
||||||
y1 = 1 + y + goalPos.getY() - renderPosY;
|
y1 = 1 + y + goalPos.getY() - renderPosY;
|
||||||
y2 = 1 - y + goalPos.getY() - renderPosY;
|
y2 = 1 - y + goalPos.getY() - renderPosY;
|
||||||
minY = goalPos.getY() - renderPosY;
|
minY = goalPos.getY() - renderPosY;
|
||||||
maxY = minY + 2;
|
maxY = minY + 2;
|
||||||
|
if (goal instanceof GoalTwoBlocks) {
|
||||||
|
y1 -= 0.5;
|
||||||
|
y2 -= 0.5;
|
||||||
|
maxY--;
|
||||||
|
}
|
||||||
} else if (goal instanceof GoalXZ) {
|
} else if (goal instanceof GoalXZ) {
|
||||||
GoalXZ goalPos = (GoalXZ) goal;
|
GoalXZ goalPos = (GoalXZ) goal;
|
||||||
|
|
||||||
@@ -206,8 +216,12 @@ public final class PathRenderer implements Helper {
|
|||||||
y2 = 0;
|
y2 = 0;
|
||||||
minY = 0 - renderPosY;
|
minY = 0 - renderPosY;
|
||||||
maxY = 256 - renderPosY;
|
maxY = 256 - renderPosY;
|
||||||
|
} else if (goal instanceof GoalComposite) {
|
||||||
|
for (Goal g : ((GoalComposite) goal).goals()) {
|
||||||
|
drawLitDankGoalBox(player, g, partialTicks, color);
|
||||||
|
}
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
// TODO GoalComposite
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,9 @@ public class ToolSet implements Helper {
|
|||||||
ItemStack contents = player().inventory.getStackInSlot(slot);
|
ItemStack contents = player().inventory.getStackInSlot(slot);
|
||||||
|
|
||||||
float blockHard = state.getBlockHardness(null, null);
|
float blockHard = state.getBlockHardness(null, null);
|
||||||
if (blockHard < 0)
|
if (blockHard < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
float speed = contents.getDestroySpeed(state);
|
float speed = contents.getDestroySpeed(state);
|
||||||
if (speed > 1) {
|
if (speed > 1) {
|
||||||
|
|||||||
+4
-23
@@ -15,29 +15,10 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.api.event.events;
|
package baritone.utils.interfaces;
|
||||||
|
|
||||||
import baritone.api.event.events.type.EventState;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
public interface IGoalRenderPos {
|
||||||
* @author Brady
|
BlockPos getGoalPos();
|
||||||
* @since 8/21/2018
|
|
||||||
*/
|
|
||||||
public final class RelativeMoveEvent {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The state of the event
|
|
||||||
*/
|
|
||||||
private final EventState state;
|
|
||||||
|
|
||||||
public RelativeMoveEvent(EventState state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The state of the event
|
|
||||||
*/
|
|
||||||
public final EventState getState() {
|
|
||||||
return this.state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,10 @@ import net.minecraft.util.math.Vec3i;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A better BlockPos that has fewer hash collisions (and slightly more performant offsets)
|
* A better BlockPos that has fewer hash collisions (and slightly more performant offsets)
|
||||||
|
* <p>
|
||||||
|
* Is it really faster to subclass BlockPos and calculate a hash in the constructor like this, taking everything into account?
|
||||||
|
* Yes. 20% faster actually. It's called BETTER BlockPos for a reason. Source:
|
||||||
|
* <a href="https://docs.google.com/spreadsheets/d/1GWjOjOZINkg_0MkRgKRPH1kUzxjsnEROD9u3UFh_DJc">Benchmark Spreadsheet</a>
|
||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
@@ -60,12 +64,12 @@ public final class BetterBlockPos extends BlockPos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public int hashCode() {
|
||||||
return (int) hashCode;
|
return (int) hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -83,7 +87,7 @@ public final class BetterBlockPos extends BlockPos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos up() {
|
public BetterBlockPos up() {
|
||||||
// this is unimaginably faster than blockpos.up
|
// this is unimaginably faster than blockpos.up
|
||||||
// that literally calls
|
// that literally calls
|
||||||
// this.up(1)
|
// this.up(1)
|
||||||
@@ -97,26 +101,32 @@ public final class BetterBlockPos extends BlockPos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos up(int amt) {
|
public BetterBlockPos up(int amt) {
|
||||||
// see comment in up()
|
// see comment in up()
|
||||||
return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
|
return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos down() {
|
public BetterBlockPos down() {
|
||||||
// see comment in up()
|
// see comment in up()
|
||||||
return new BetterBlockPos(x, y - 1, z);
|
return new BetterBlockPos(x, y - 1, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos down(int amt) {
|
public BetterBlockPos down(int amt) {
|
||||||
// see comment in up()
|
// see comment in up()
|
||||||
return new BetterBlockPos(x, y - amt, z);
|
return new BetterBlockPos(x, y - amt, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos offset(EnumFacing dir) {
|
public BetterBlockPos offset(EnumFacing dir) {
|
||||||
Vec3i vec = dir.getDirectionVec();
|
Vec3i vec = dir.getDirectionVec();
|
||||||
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
|
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BetterBlockPos offset(EnumFacing dir, int dist) {
|
||||||
|
Vec3i vec = dir.getDirectionVec();
|
||||||
|
return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.chunk;
|
package baritone.cache;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
Reference in New Issue
Block a user