merge
This commit is contained in:
+2
-1
@@ -9,6 +9,7 @@
|
||||
- **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).
|
||||
- **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
|
||||
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.
|
||||
|
||||
Things it may not ever have, from most likely to least likely =(
|
||||
- Boats
|
||||
- Pigs
|
||||
- Boats
|
||||
- Horses (2x3 path instead of 1x2)
|
||||
- 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.
|
||||
|
||||
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.
|
||||
|
||||
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 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?
|
||||
|
||||
Sure!
|
||||
Sure! (As long as usage is in compliance with the GPL 3 License)
|
||||
|
||||
## How is it so fast?
|
||||
|
||||
|
||||
+1
-1
@@ -87,5 +87,5 @@ mixin {
|
||||
}
|
||||
|
||||
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) {}
|
||||
|
||||
@Override
|
||||
default void onPlayerRelativeMove(RelativeMoveEvent event) {}
|
||||
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
||||
|
||||
@Override
|
||||
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.settings.GameSettings;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
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
|
||||
* and before and after the player jumps.
|
||||
*
|
||||
* @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.
|
||||
@@ -39,9 +39,15 @@ public class BaritoneTweaker implements ITweaker {
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
this.args = new ArrayList<>(args);
|
||||
if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath());
|
||||
if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath());
|
||||
if (profile != null) addArg("version", profile);
|
||||
if (gameDir != null) {
|
||||
addArg("gameDir", gameDir.getAbsolutePath());
|
||||
}
|
||||
if (assetsDir != null) {
|
||||
addArg("assetsDir", assetsDir.getAbsolutePath());
|
||||
}
|
||||
if (profile != null) {
|
||||
addArg("version", profile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.RelativeMoveEvent;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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) {
|
||||
Entity _this = (Entity) (Object) this;
|
||||
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(
|
||||
@@ -51,6 +51,6 @@ public class MixinEntity {
|
||||
private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
||||
Entity _this = (Entity) (Object) this;
|
||||
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) {
|
||||
ChatEvent event = new ChatEvent(msg);
|
||||
Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event);
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
|
||||
@@ -37,7 +37,8 @@ public class MixinKeyBinding {
|
||||
cancellable = true
|
||||
)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(NetworkManager.class)
|
||||
public class MixinNetworkManager {
|
||||
|
||||
@Shadow private Channel channel;
|
||||
@Shadow
|
||||
private Channel channel;
|
||||
|
||||
@Inject(
|
||||
method = "dispatchPacket",
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ public class MixinNetworkManager {
|
||||
method = "dispatchPacket",
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -73,7 +74,8 @@ public class MixinNetworkManager {
|
||||
at = @At("RETURN")
|
||||
)
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"MixinBlockPos",
|
||||
"MixinChunkProviderServer",
|
||||
"MixinEntity",
|
||||
"MixinEntityLivingBase",
|
||||
"MixinEntityPlayerSP",
|
||||
"MixinEntityRenderer",
|
||||
"MixinGameSettings",
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
|
||||
package baritone;
|
||||
|
||||
import baritone.api.event.GameEventHandler;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.behavior.impl.*;
|
||||
import baritone.event.GameEventHandler;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -99,7 +100,7 @@ public enum Baritone {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
public final GameEventHandler getGameEventHandler() {
|
||||
public final IGameEventListener getGameEventHandler() {
|
||||
return this.gameEventHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,13 @@ public class Settings {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
public final boolean setEnabled(boolean enabled) {
|
||||
boolean newState = getNewState(this.enabled, enabled);
|
||||
if (newState == this.enabled)
|
||||
if (newState == this.enabled) {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
if (this.enabled = newState) {
|
||||
onStart();
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
package baritone.behavior.impl;
|
||||
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.chunk.Waypoint;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.api.event.events.BlockInteractEvent;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.BlockBed;
|
||||
|
||||
@@ -19,9 +19,9 @@ package baritone.behavior.impl;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.Settings;
|
||||
import baritone.behavior.Behavior;
|
||||
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;
|
||||
|
||||
public class LookBehavior extends Behavior {
|
||||
@@ -57,8 +57,9 @@ public class LookBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||
if (this.target == null)
|
||||
if (this.target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Whether or not we're going to silently set our angles
|
||||
boolean silent = Baritone.settings().antiCheatCompatibility.get();
|
||||
@@ -91,7 +92,7 @@ public class LookBehavior extends Behavior {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
||||
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||
if (this.target != null && !this.force) {
|
||||
switch (event.getState()) {
|
||||
case PRE:
|
||||
@@ -102,8 +103,10 @@ public class LookBehavior extends Behavior {
|
||||
player().rotationYaw = this.lastYaw;
|
||||
|
||||
// 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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +67,10 @@ public final class LookBehaviorUtils implements Helper {
|
||||
return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f));
|
||||
}
|
||||
Optional<Rotation> possibleRotation = reachableCenter(pos);
|
||||
System.out.println("center: " + possibleRotation);
|
||||
if (possibleRotation.isPresent())
|
||||
//System.out.println("center: " + possibleRotation);
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(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 zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
|
||||
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
|
||||
if (possibleRotation.isPresent())
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package baritone.behavior.impl;
|
||||
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.event.events.PacketEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.behavior.Behavior;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.CPacketCloseWindow;
|
||||
@@ -38,8 +38,9 @@ public class MemoryBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||
if (event.getState() == EventState.PRE)
|
||||
if (event.getState() == EventState.PRE) {
|
||||
updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,13 +87,13 @@ public class MemoryBehavior extends Behavior {
|
||||
this.futureInventories.stream()
|
||||
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
|
||||
.findFirst().ifPresent(matched -> {
|
||||
// Remove the future inventory
|
||||
this.futureInventories.remove(matched);
|
||||
// Remove the future inventory
|
||||
this.futureInventories.remove(matched);
|
||||
|
||||
// Setup the remembered inventory
|
||||
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
|
||||
inventory.windowId = packet.getWindowId();
|
||||
inventory.size = packet.getSlotCount();
|
||||
// Setup the remembered inventory
|
||||
RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory());
|
||||
inventory.windowId = packet.getWindowId();
|
||||
inventory.size = packet.getSlotCount();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ package baritone.behavior.impl;
|
||||
|
||||
import baritone.api.event.events.PathEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.chunk.CachedChunk;
|
||||
import baritone.chunk.ChunkPacker;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.chunk.WorldScanner;
|
||||
import baritone.cache.CachedChunk;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.goals.GoalComposite;
|
||||
import baritone.pathing.goals.GoalTwoBlocks;
|
||||
@@ -60,7 +60,7 @@ public class MineBehavior extends Behavior {
|
||||
}
|
||||
List<BlockPos> locs = scanFor(mining, 64);
|
||||
if (locs.isEmpty()) {
|
||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
||||
logDebug("No locations for " + mining + " known, cancelling");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ public class PathingBehavior extends Behavior {
|
||||
if (current.failed() || current.finished()) {
|
||||
current = null;
|
||||
if (goal == null || goal.isInGoal(playerFeet())) {
|
||||
displayChatMessageRaw("All done. At " + goal);
|
||||
logDebug("All done. At " + goal);
|
||||
dispatchPathEvent(PathEvent.AT_GOAL);
|
||||
next = null;
|
||||
return;
|
||||
}
|
||||
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
|
||||
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
|
||||
// that's all fine and good
|
||||
// but if we fail in the middle of current
|
||||
@@ -94,7 +94,7 @@ public class PathingBehavior extends Behavior {
|
||||
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);
|
||||
current = next;
|
||||
next = null;
|
||||
@@ -118,7 +118,7 @@ public class PathingBehavior extends Behavior {
|
||||
if (next != null) {
|
||||
if (next.getPath().positions().contains(playerFeet())) {
|
||||
// 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);
|
||||
current = next;
|
||||
next = null;
|
||||
@@ -141,7 +141,7 @@ public class PathingBehavior extends Behavior {
|
||||
}
|
||||
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
||||
// 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);
|
||||
findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath()));
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class PathingBehavior extends Behavior {
|
||||
}
|
||||
new Thread(() -> {
|
||||
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);
|
||||
@@ -280,9 +280,9 @@ public class PathingBehavior extends Behavior {
|
||||
|
||||
if (talkAboutIt && current != null && current.getPath() != null) {
|
||||
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 {
|
||||
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) {
|
||||
Goal goal = this.goal;
|
||||
if (goal == null) {
|
||||
displayChatMessageRaw("no goal");
|
||||
logDebug("no goal");
|
||||
return Optional.empty();
|
||||
}
|
||||
if (Baritone.settings().simplifyUnloadedYCoord.get()) {
|
||||
@@ -320,7 +320,7 @@ public class PathingBehavior extends Behavior {
|
||||
}
|
||||
// TODO simplify each individual goal in a GoalComposite
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public class PathingBehavior extends Behavior {
|
||||
IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions));
|
||||
return pf.calculate(timeout);
|
||||
} catch (Exception e) {
|
||||
displayChatMessageRaw("Pathing exception: " + e);
|
||||
logDebug("Pathing exception: " + e);
|
||||
e.printStackTrace();
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -389,8 +389,9 @@ public class PathingBehavior extends Behavior {
|
||||
});
|
||||
long end = System.nanoTime();
|
||||
//System.out.println((end - split) + " " + (split - start));
|
||||
// if (end - start > 0)
|
||||
// if (end - start > 0) {
|
||||
// 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/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.utils.pathing.IBlockTypeAccess;
|
||||
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
|
||||
*/
|
||||
private static void validateSize(BitSet data) {
|
||||
if (data.size() > SIZE)
|
||||
if (data.size() > SIZE) {
|
||||
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/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.utils.pathing.IBlockTypeAccess;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -112,13 +112,15 @@ public final class CachedRegion implements IBlockTypeAccess {
|
||||
}
|
||||
try {
|
||||
Path path = Paths.get(directory);
|
||||
if (!Files.exists(path))
|
||||
if (!Files.exists(path)) {
|
||||
Files.createDirectories(path);
|
||||
|
||||
}
|
||||
System.out.println("Saving region " + x + "," + z + " to disk " + path);
|
||||
Path regionFile = getRegionFile(path, this.x, this.z);
|
||||
if (!Files.exists(regionFile))
|
||||
if (!Files.exists(regionFile)) {
|
||||
Files.createFile(regionFile);
|
||||
}
|
||||
try (
|
||||
FileOutputStream fileOut = new FileOutputStream(regionFile.toFile());
|
||||
GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384);
|
||||
@@ -175,12 +177,14 @@ public final class CachedRegion implements IBlockTypeAccess {
|
||||
public synchronized void load(String directory) {
|
||||
try {
|
||||
Path path = Paths.get(directory);
|
||||
if (!Files.exists(path))
|
||||
if (!Files.exists(path)) {
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
|
||||
Path regionFile = getRegionFile(path, this.x, this.z);
|
||||
if (!Files.exists(regionFile))
|
||||
if (!Files.exists(regionFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Loading region " + x + "," + z + " from disk " + path);
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
Vendored
+22
-31
@@ -15,28 +15,28 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
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.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @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)
|
||||
@@ -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) {
|
||||
int x = pos.getX();
|
||||
int z = pos.getZ();
|
||||
@@ -111,7 +101,6 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
return region.isCached(x & 511, z & 511);
|
||||
}
|
||||
|
||||
|
||||
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
int playerRegionX = playerFeet().getX() >> 9;
|
||||
@@ -128,9 +117,11 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
int regionX = xoff + playerRegionX;
|
||||
int regionZ = zoff + playerRegionZ;
|
||||
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
||||
if (region != null)
|
||||
for (BlockPos pos : region.getLocationsOf(block))
|
||||
if (region != null) {
|
||||
for (BlockPos pos : region.getLocationsOf(block)) {
|
||||
res.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res.size() >= minimum) {
|
||||
@@ -152,19 +143,25 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
return;
|
||||
}
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
this.cachedRegions.values().parallelStream().forEach(region -> {
|
||||
if (region != null)
|
||||
allRegions().parallelStream().forEach(region -> {
|
||||
if (region != null) {
|
||||
region.save(this.directory);
|
||||
}
|
||||
});
|
||||
long now = System.nanoTime() / 1000000L;
|
||||
System.out.println("World save took " + (now - start) + "ms");
|
||||
}
|
||||
|
||||
private synchronized List<CachedRegion> allRegions() {
|
||||
return new ArrayList<>(this.cachedRegions.values());
|
||||
}
|
||||
|
||||
public final void reloadAllFromDisk() {
|
||||
long start = System.nanoTime() / 1000000L;
|
||||
this.cachedRegions.values().forEach(region -> {
|
||||
if (region != null)
|
||||
allRegions().forEach(region -> {
|
||||
if (region != null) {
|
||||
region.load(this.directory);
|
||||
}
|
||||
});
|
||||
long now = System.nanoTime() / 1000000L;
|
||||
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
|
||||
* @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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* returned if the specified region coordinates are out of bounds.
|
||||
@@ -213,8 +203,9 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
* @return The region ID
|
||||
*/
|
||||
private long getRegionID(int regionX, int regionZ) {
|
||||
if (!isRegionInWorld(regionX, regionZ))
|
||||
if (!isRegionInWorld(regionX, regionZ)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.Helper;
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
+3
-2
@@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -61,8 +61,9 @@ public class Waypoints {
|
||||
waypoints.put(tag, new HashSet<>());
|
||||
|
||||
Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4");
|
||||
if (!Files.exists(fileName))
|
||||
if (!Files.exists(fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (
|
||||
FileInputStream fileIn = new FileInputStream(fileName.toFile());
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
Vendored
+5
-4
@@ -15,12 +15,12 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||
import baritone.utils.accessor.IChunkProviderServer;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
@@ -69,7 +69,7 @@ public enum WorldProvider implements Helper {
|
||||
|
||||
directory = new File(directory, "baritone");
|
||||
readme = directory;
|
||||
|
||||
|
||||
} else {
|
||||
//remote
|
||||
directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP);
|
||||
@@ -102,7 +102,8 @@ public enum WorldProvider implements Helper {
|
||||
}
|
||||
|
||||
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
|
||||
if (this.currentWorld != null)
|
||||
if (this.currentWorld != null) {
|
||||
currentWorldConsumer.accept(this.currentWorld);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+7
-7
@@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -47,13 +47,13 @@ public enum WorldScanner implements Helper {
|
||||
int playerChunkX = playerFeet().getX() >> 4;
|
||||
int playerChunkZ = playerFeet().getZ() >> 4;
|
||||
|
||||
int searchRadius = 2;
|
||||
int searchRadiusSq = 0;
|
||||
while (true) {
|
||||
boolean allUnloaded = true;
|
||||
for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) {
|
||||
for (int zoff = -searchRadius; zoff <= searchRadius; zoff++) {
|
||||
for (int xoff = -searchRadiusSq; xoff <= searchRadiusSq; xoff++) {
|
||||
for (int zoff = -searchRadiusSq; zoff <= searchRadiusSq; zoff++) {
|
||||
int distance = xoff * xoff + zoff * zoff;
|
||||
if (distance != searchRadius) {
|
||||
if (distance != searchRadiusSq) {
|
||||
continue;
|
||||
}
|
||||
int chunkX = xoff + playerChunkX;
|
||||
@@ -91,10 +91,10 @@ public enum WorldScanner implements Helper {
|
||||
if (allUnloaded) {
|
||||
return res;
|
||||
}
|
||||
if (res.size() >= max) {
|
||||
if (res.size() >= max && searchRadiusSq > 26) {
|
||||
return res;
|
||||
}
|
||||
searchRadius++;
|
||||
searchRadiusSq++;
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
-48
@@ -15,30 +15,13 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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;
|
||||
package baritone.event;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.*;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
@@ -48,8 +31,6 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@@ -57,16 +38,24 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
|
||||
private final List<IGameEventListener> listeners = new ArrayList<>();
|
||||
private final ArrayList<IGameEventListener> listeners = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public final void onTick(TickEvent event) {
|
||||
dispatch(listener -> listener.onTick(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onTick(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||
dispatch(listener -> listener.onPlayerUpdate(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onPlayerUpdate(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,17 +69,26 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
|
||||
if (keyCode < Keyboard.KEYBOARD_SIZE)
|
||||
if (keyCode < Keyboard.KEYBOARD_SIZE) {
|
||||
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(IGameEventListener::onProcessKeyBinds);
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onProcessKeyBinds();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onSendChatMessage(ChatEvent event) {
|
||||
dispatch(listener -> listener.onSendChatMessage(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onSendChatMessage(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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
|
||||
public final void onRenderPass(RenderEvent event) {
|
||||
/*
|
||||
WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> {
|
||||
drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks());
|
||||
})));
|
||||
*/
|
||||
|
||||
dispatch(listener -> listener.onRenderPass(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onRenderPass(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,52 +141,77 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
break;
|
||||
case POST:
|
||||
cache.closeWorld();
|
||||
if (event.getWorld() != null)
|
||||
if (event.getWorld() != null) {
|
||||
cache.initWorld(event.getWorld());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
dispatch(listener -> listener.onWorldEvent(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onWorldEvent(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onSendPacket(PacketEvent event) {
|
||||
dispatch(listener -> listener.onSendPacket(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onSendPacket(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onReceivePacket(PacketEvent event) {
|
||||
dispatch(listener -> listener.onReceivePacket(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onReceivePacket(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRelativeMove(RelativeMoveEvent event) {
|
||||
dispatch(listener -> listener.onPlayerRelativeMove(event));
|
||||
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onPlayerRotationMove(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
dispatch(listener -> listener.onBlockInteract(event));
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onBlockInteract(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerDeath() {
|
||||
dispatch(IGameEventListener::onPlayerDeath);
|
||||
listeners.forEach(l -> {
|
||||
if (canDispatch(l)) {
|
||||
l.onPlayerDeath();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
private void dispatch(Consumer<IGameEventListener> dispatchFunction) {
|
||||
this.listeners.stream().filter(this::canDispatch).forEach(dispatchFunction);
|
||||
}
|
||||
|
||||
private boolean canDispatch(IGameEventListener listener) {
|
||||
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.chunk.CachedWorld;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.cache.CachedWorld;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
@@ -70,10 +70,11 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
currentlyRunning = this;
|
||||
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
|
||||
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
|
||||
BlockStateInterface.clearCachedChunk();
|
||||
long startTime = System.nanoTime() / 1000000L;
|
||||
boolean slowPath = Baritone.settings().slowPath.get();
|
||||
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 lastPrintout = 0;
|
||||
@@ -125,7 +126,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
numNodes++;
|
||||
if (goal.isInGoal(currentNodePos)) {
|
||||
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));
|
||||
}
|
||||
long constructStart = System.nanoTime();
|
||||
@@ -140,7 +141,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
if (movementToGetToNeighbor == null) {
|
||||
continue;
|
||||
}
|
||||
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
|
||||
BetterBlockPos dest = movementToGetToNeighbor.getDest();
|
||||
long s = System.nanoTime();
|
||||
int chunkX = currentNodePos.x >> 4;
|
||||
int chunkZ = currentNodePos.z >> 4;
|
||||
@@ -256,7 +257,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
bestDist = dist;
|
||||
}
|
||||
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) {
|
||||
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)");
|
||||
@@ -267,40 +268,51 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
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");
|
||||
displayChatMessageRaw("No path found =(");
|
||||
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
||||
logDebug("No path found =(");
|
||||
currentlyRunning = null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) {
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
int x = pos.x;
|
||||
int y = pos.y;
|
||||
int z = pos.z;
|
||||
BetterBlockPos east = new BetterBlockPos(x + 1, y, z);
|
||||
BetterBlockPos west = new BetterBlockPos(x - 1, y, z);
|
||||
BetterBlockPos south = new BetterBlockPos(x, y, z + 1);
|
||||
BetterBlockPos north = new BetterBlockPos(x, y, z - 1);
|
||||
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, west),
|
||||
new MovementTraverse(pos, north),
|
||||
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, y + 1, z + 1)),
|
||||
new MovementAscend(pos, new BetterBlockPos(x, y + 1, z - 1)),
|
||||
|
||||
MovementHelper.generateMovementFallOrDescend(pos, east, calcContext),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, west, calcContext),
|
||||
MovementHelper.generateMovementFallOrDescend(pos, north, 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.SOUTH, EnumFacing.WEST),
|
||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
|
||||
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
|
||||
*/
|
||||
protected double getDistFromStartSq(PathNode n) {
|
||||
int xDiff = n.pos.getX() - start.getX();
|
||||
int yDiff = n.pos.getY() - start.getY();
|
||||
int zDiff = n.pos.getZ() - start.getZ();
|
||||
int xDiff = n.pos.x - start.x;
|
||||
int yDiff = n.pos.y - start.y;
|
||||
int zDiff = n.pos.z - start.z;
|
||||
return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
|
||||
@@ -26,7 +27,7 @@ import baritone.utils.pathing.BetterBlockPos;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class PathNode {
|
||||
public final class PathNode {
|
||||
|
||||
/**
|
||||
* The position of this node
|
||||
@@ -81,7 +82,7 @@ public class PathNode {
|
||||
public PathNode(BetterBlockPos pos, Goal goal) {
|
||||
this.pos = pos;
|
||||
this.previous = null;
|
||||
this.cost = Short.MAX_VALUE;
|
||||
this.cost = ActionCosts.COST_INF;
|
||||
this.goal = goal;
|
||||
this.estimatedCostToGoal = goal.heuristic(pos);
|
||||
this.previousMovement = null;
|
||||
@@ -103,8 +104,9 @@ public class PathNode {
|
||||
// GOTTA GO FAST
|
||||
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
|
||||
// SKRT SKRT
|
||||
//if (obj == null || !(obj instanceof PathNode))
|
||||
//if (obj == null || !(obj instanceof PathNode)) {
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//final PathNode other = (PathNode) obj;
|
||||
//return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalBlock implements Goal {
|
||||
public class GoalBlock implements Goal, IGoalRenderPos {
|
||||
|
||||
/**
|
||||
* The X block position of this goal
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -26,7 +27,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
*
|
||||
* @author avecowa
|
||||
*/
|
||||
public class GoalGetToBlock implements Goal {
|
||||
public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class GoalNear implements Goal {
|
||||
public class GoalNear implements Goal, IGoalRenderPos {
|
||||
final int x;
|
||||
final int y;
|
||||
final int z;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalTwoBlocks implements Goal {
|
||||
public class GoalTwoBlocks implements Goal, IGoalRenderPos {
|
||||
|
||||
/**
|
||||
* The X block position of this goal
|
||||
|
||||
@@ -22,6 +22,7 @@ import baritone.behavior.impl.LookBehavior;
|
||||
import baritone.behavior.impl.LookBehaviorUtils;
|
||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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);
|
||||
|
||||
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
|
||||
@@ -57,21 +58,22 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
|
||||
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.dest = dest;
|
||||
this.positionsToBreak = toBreak;
|
||||
this.positionToPlace = toPlace;
|
||||
}
|
||||
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) {
|
||||
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) {
|
||||
this(src, dest, toBreak, null);
|
||||
}
|
||||
|
||||
public double getCost(CalculationContext context) {
|
||||
if (cost == null) {
|
||||
if (context == null)
|
||||
if (context == null) {
|
||||
context = new CalculationContext();
|
||||
}
|
||||
cost = calculateCost(context);
|
||||
}
|
||||
return cost;
|
||||
@@ -84,6 +86,10 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
return getCost(null);
|
||||
}
|
||||
|
||||
protected void override(double cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public double calculateCostWithoutCaching() {
|
||||
return calculateCost(new CalculationContext());
|
||||
}
|
||||
@@ -128,13 +134,15 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
});
|
||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
||||
|
||||
if (!this.didBreakLastTick)
|
||||
if (!this.didBreakLastTick) {
|
||||
BlockBreakHelper.stopBreakingBlock();
|
||||
}
|
||||
|
||||
currentState = latestState;
|
||||
|
||||
if (isFinished())
|
||||
if (isFinished()) {
|
||||
onFinish(latestState);
|
||||
}
|
||||
|
||||
return currentState.getStatus();
|
||||
}
|
||||
@@ -178,11 +186,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
&& currentState.getStatus() != MovementStatus.WAITING);
|
||||
}
|
||||
|
||||
public BlockPos getSrc() {
|
||||
public BetterBlockPos getSrc() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public BlockPos getDest() {
|
||||
public BetterBlockPos getDest() {
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -270,6 +278,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
} else if (state.getStatus() == MovementStatus.PREPPING) {
|
||||
state.setStatus(MovementStatus.WAITING);
|
||||
}
|
||||
|
||||
if (state.getStatus() == MovementStatus.WAITING) {
|
||||
state.setStatus(MovementStatus.RUNNING);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.pathing.movement.movements.MovementDescend;
|
||||
import baritone.pathing.movement.movements.MovementFall;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -48,14 +49,17 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static boolean avoidBreaking(BlockPos pos, IBlockState state) {
|
||||
Block b = state.getBlock();
|
||||
Block below = BlockStateInterface.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
||||
return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path
|
||||
int x = pos.getX();
|
||||
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
|
||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
|
||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()))
|
||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))
|
||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1))
|
||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1));
|
||||
// call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||
|| BlockStateInterface.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| BlockStateInterface.get(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| BlockStateInterface.get(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| 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) {
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof BlockFire
|
||||
|| block instanceof BlockTripWire
|
||||
|| 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.AIR) {
|
||||
return true;
|
||||
}
|
||||
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL) {
|
||||
return false;
|
||||
}
|
||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||
@@ -106,6 +110,38 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
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) {
|
||||
// for MovementTraverse and MovementAscend
|
||||
// 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) {
|
||||
if (playerPos.equals(doorPos))
|
||||
if (playerPos.equals(doorPos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(doorPos);
|
||||
if (!(state.getBlock() instanceof BlockDoor))
|
||||
if (!(state.getBlock() instanceof BlockDoor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
|
||||
}
|
||||
|
||||
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
|
||||
if (playerPos.equals(gatePos))
|
||||
if (playerPos.equals(gatePos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(gatePos);
|
||||
if (!(state.getBlock() instanceof BlockFenceGate))
|
||||
if (!(state.getBlock() instanceof BlockFenceGate)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN);
|
||||
}
|
||||
|
||||
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) {
|
||||
if (playerPos.equals(blockPos))
|
||||
if (playerPos.equals(blockPos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis();
|
||||
boolean open = blockState.getValue(propertyOpen);
|
||||
@@ -169,10 +210,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static boolean avoidWalkingInto(Block block) {
|
||||
return BlockStateInterface.isLava(block)
|
||||
|| block instanceof BlockCactus
|
||||
|| block instanceof BlockFire
|
||||
|| block instanceof BlockEndPortal
|
||||
|| block instanceof BlockWeb;
|
||||
|| block == Blocks.MAGMA
|
||||
|| block == Blocks.CACTUS
|
||||
|| block == Blocks.FIRE
|
||||
|| block == Blocks.END_PORTAL
|
||||
|| block == Blocks.WEB;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,31 +226,22 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
*/
|
||||
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR) {
|
||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||
return false;
|
||||
}
|
||||
if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
if (state.isBlockNormalCube()) {
|
||||
if (BlockStateInterface.isLava(block) || BlockStateInterface.isWater(block)) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
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;
|
||||
}
|
||||
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
|
||||
return BlockStateInterface.isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
|
||||
}
|
||||
if (Blocks.MAGMA.equals(block)) {
|
||||
return false;
|
||||
if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
|
||||
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) {
|
||||
return canWalkOn(pos, BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
static boolean canFall(BlockPos pos) {
|
||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(BlockPos 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
|
||||
@@ -251,7 +292,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) {
|
||||
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()) {
|
||||
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 strVsBlock = context.getToolSet().getStrVsBlock(state);
|
||||
if (strVsBlock < 0)
|
||||
if (strVsBlock < 0) {
|
||||
return COST_INF;
|
||||
}
|
||||
|
||||
double result = m / strVsBlock;
|
||||
if (includeFalling) {
|
||||
@@ -359,7 +401,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
)).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
|
||||
//SA
|
||||
// A
|
||||
@@ -376,12 +418,13 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
//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
|
||||
// we can't cost shortcut descend because !canWalkThrough doesn't mean canWalkOn
|
||||
}
|
||||
|
||||
// we're clear for a fall 2
|
||||
// let's see how far we can fall
|
||||
for (int fallHeight = 3; true; fallHeight++) {
|
||||
BlockPos onto = dest.down(fallHeight);
|
||||
BetterBlockPos onto = dest.down(fallHeight);
|
||||
if (onto.getY() < 0) {
|
||||
// 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
|
||||
|
||||
@@ -26,6 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -41,7 +42,7 @@ public class MovementAscend extends Movement {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ public class MovementAscend extends Movement {
|
||||
if (!context.hasThrowaway()) {
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
// 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)
|
||||
switch (state.getStatus()) {
|
||||
case WAITING:
|
||||
state.setStatus(MovementStatus.RUNNING);
|
||||
case RUNNING:
|
||||
break;
|
||||
default:
|
||||
return state;
|
||||
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (playerFeet().equals(dest)) {
|
||||
@@ -160,8 +156,8 @@ public class MovementAscend extends Movement {
|
||||
if (player().isSneaking()) {
|
||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
}
|
||||
if (ticksWithoutPlacement > 20) {
|
||||
// After 20 ticks without placement, we might be standing in the way, move back
|
||||
if (ticksWithoutPlacement > 10) {
|
||||
// After 10 ticks without placement, we might be standing in the way, move back
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -24,13 +24,14 @@ import baritone.pathing.movement.MovementState;
|
||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -67,13 +68,8 @@ public class MovementDescend extends Movement {
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
switch (state.getStatus()) {
|
||||
case WAITING:
|
||||
state.setStatus(MovementStatus.RUNNING);
|
||||
case RUNNING:
|
||||
break;
|
||||
default:
|
||||
return state;
|
||||
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
BlockPos playerFeet = playerFeet();
|
||||
|
||||
@@ -23,6 +23,7 @@ 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.Block;
|
||||
import net.minecraft.block.BlockMagma;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -37,16 +38,16 @@ public class MovementDiagonal extends Movement {
|
||||
|
||||
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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
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()});
|
||||
}
|
||||
|
||||
@@ -119,13 +120,8 @@ public class MovementDiagonal extends Movement {
|
||||
@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 (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (playerFeet().equals(dest)) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -31,7 +32,7 @@ public class MovementDownward extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
|
||||
public MovementDownward(BlockPos start, BlockPos end) {
|
||||
public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
|
||||
super(start, end, new BlockPos[]{end});
|
||||
}
|
||||
|
||||
@@ -60,13 +61,8 @@ public class MovementDownward extends Movement {
|
||||
@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 (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (playerFeet().equals(dest)) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
|
||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
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_EMPTY = new ItemStack(Items.BUCKET);
|
||||
|
||||
public MovementFall(BlockPos src, BlockPos dest) {
|
||||
public MovementFall(BetterBlockPos src, BetterBlockPos dest) {
|
||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
|
||||
}
|
||||
|
||||
@@ -96,13 +97,8 @@ public class MovementFall extends Movement {
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
switch (state.getStatus()) {
|
||||
case WAITING:
|
||||
state.setStatus(MovementStatus.RUNNING);
|
||||
case RUNNING:
|
||||
break;
|
||||
default:
|
||||
return state;
|
||||
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
BlockPos playerFeet = playerFeet();
|
||||
@@ -129,8 +125,7 @@ public class MovementFall extends Movement {
|
||||
} else {
|
||||
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
||||
}
|
||||
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 // lilypads
|
||||
|| BlockStateInterface.isWater(dest))) {
|
||||
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads
|
||||
if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
|
||||
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
|
||||
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.Rotation;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -33,7 +34,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
public class MovementPillar extends Movement {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -121,13 +122,8 @@ public class MovementPillar extends Movement {
|
||||
@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 (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
IBlockState fromDown = BlockStateInterface.get(src);
|
||||
@@ -143,7 +139,7 @@ public class MovementPillar extends Movement {
|
||||
if (ladder) {
|
||||
BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
|
||||
if (against == null) {
|
||||
displayChatMessageRaw("Unable to climb vines");
|
||||
logDebug("Unable to climb vines");
|
||||
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
|
||||
}
|
||||
|
||||
@@ -174,7 +170,7 @@ public class MovementPillar extends Movement {
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||
|
||||
// Otherwise jump
|
||||
if (numTicks > 40) {
|
||||
if (numTicks > 20) {
|
||||
double diffX = player().posX - (dest.getX() + 0.5);
|
||||
double diffZ = player().posZ - (dest.getZ() + 0.5);
|
||||
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
|
||||
@@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -42,7 +43,7 @@ public class MovementTraverse extends Movement {
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -125,15 +126,9 @@ public class MovementTraverse extends Movement {
|
||||
@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 (state.getStatus() != MovementState.MovementStatus.RUNNING) {
|
||||
return state;
|
||||
}
|
||||
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, false);
|
||||
|
||||
Block fd = BlockStateInterface.get(src.down()).getBlock();
|
||||
@@ -176,7 +171,7 @@ public class MovementTraverse extends Movement {
|
||||
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder;
|
||||
BlockPos whereAmI = playerFeet();
|
||||
if (whereAmI.getY() != dest.getY() && !ladder) {
|
||||
displayChatMessageRaw("Wrong Y coordinate");
|
||||
logDebug("Wrong Y coordinate");
|
||||
if (whereAmI.getY() < dest.getY()) {
|
||||
state.setInput(InputOverrideHandler.Input.JUMP, true);
|
||||
}
|
||||
@@ -208,7 +203,7 @@ public class MovementTraverse extends Movement {
|
||||
against1 = against1.down();
|
||||
if (MovementHelper.canPlaceAgainst(against1)) {
|
||||
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);
|
||||
}
|
||||
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
|
||||
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
||||
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);
|
||||
}
|
||||
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++) {
|
||||
BlockPos pos = positions().get(i);
|
||||
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
|
||||
displayChatMessageRaw("Cutting off path at edge of loaded chunks");
|
||||
displayChatMessageRaw("Length decreased by " + (positions().size() - i - 1));
|
||||
logDebug("Cutting off path at edge of loaded chunks");
|
||||
logDebug("Length decreased by " + (positions().size() - i - 1));
|
||||
return new CutoffPath(this, i);
|
||||
}
|
||||
}
|
||||
displayChatMessageRaw("Path ends within loaded chunks");
|
||||
logDebug("Path ends within loaded chunks");
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public interface IPath extends Helper {
|
||||
}
|
||||
double factor = Baritone.settings().pathCutoffFactor.get();
|
||||
int newLength = (int) (length() * factor);
|
||||
//displayChatMessageRaw("Static cutoff " + length() + " to " + newLength);
|
||||
//logDebug("Static cutoff " + length() + " to " + newLength);
|
||||
return new CutoffPath(this, newLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ public class PathExecutor implements Helper {
|
||||
if (!whereShouldIBe.equals(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
|
||||
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))) {
|
||||
displayChatMessageRaw("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
||||
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
||||
int previousPos = pathPosition;
|
||||
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
|
||||
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)
|
||||
if (whereAmI.equals(path.positions().get(i))) {
|
||||
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");
|
||||
pathPosition = i - 1;
|
||||
@@ -121,7 +121,7 @@ public class PathExecutor implements Helper {
|
||||
ticksAway++;
|
||||
System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DIST_FROM_PATH);
|
||||
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");
|
||||
pathPosition = path.length() + 3;
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
@@ -134,7 +134,7 @@ public class PathExecutor implements Helper {
|
||||
if (distanceFromPath > MAX_MAX_DIST_FROM_PATH) {
|
||||
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
|
||||
displayChatMessageRaw("too far from path");
|
||||
logDebug("too far from path");
|
||||
pathPosition = path.length() + 3;
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
failed = true;
|
||||
@@ -211,7 +211,7 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
long end = System.nanoTime() / 1000000L;
|
||||
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);
|
||||
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||
@@ -220,7 +220,7 @@ public class PathExecutor implements Helper {
|
||||
currentMovementInitialCostEstimate = movement.getCost(null);
|
||||
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) {
|
||||
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;
|
||||
failed = true;
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
@@ -230,7 +230,7 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
double currentCost = movement.recalculateCost();
|
||||
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;
|
||||
failed = true;
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
@@ -238,7 +238,7 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
MovementState.MovementStatus movementStatus = movement.update();
|
||||
if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
|
||||
displayChatMessageRaw("Movement returns status " + movementStatus);
|
||||
logDebug("Movement returns status " + movementStatus);
|
||||
pathPosition = path.length() + 3;
|
||||
failed = true;
|
||||
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
|
||||
// ticksOnCurrent is greater than recalculateCost + 100
|
||||
// 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();
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
pathPosition = path.length() + 3;
|
||||
@@ -318,7 +318,7 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -18,27 +18,44 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.chunk.WorldData;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.cache.CachedRegion;
|
||||
import baritone.cache.WorldData;
|
||||
import baritone.cache.WorldProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
/**
|
||||
* Wraps get for chuck caching capability
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class BlockStateInterface implements Helper {
|
||||
|
||||
public static int numBlockStateLookups = 0;
|
||||
public static int numTimesChunkSucceeded = 0;
|
||||
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++;
|
||||
// Invalid vertical position
|
||||
if (pos.getY() < 0 || pos.getY() >= 256)
|
||||
return Blocks.AIR.getDefaultState();
|
||||
if (y < 0 || y >= 256) {
|
||||
return AIR;
|
||||
}
|
||||
|
||||
if (!Baritone.settings().pathThroughCachedOnly.get()) {
|
||||
Chunk cached = prev;
|
||||
@@ -47,40 +64,47 @@ public class BlockStateInterface implements Helper {
|
||||
// if it's the same chunk as last time
|
||||
// we can just skip the mc.world.getChunk lookup
|
||||
// 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++;
|
||||
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()) {
|
||||
prev = chunk;
|
||||
return chunk.getBlockState(pos);
|
||||
return chunk.getBlockState(x, y, z);
|
||||
}
|
||||
}
|
||||
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
|
||||
if (world != null) {
|
||||
IBlockState type = world.cache.getBlock(pos);
|
||||
if (type != null) {
|
||||
return type;
|
||||
// same idea here, skip the Long2ObjectOpenHashMap.get if at all possible
|
||||
// except here, it's 512x512 tiles instead of 16x16, so even better repetition
|
||||
CachedRegion cached = prevCached;
|
||||
if (cached == null || cached.getX() != x >> 9 || cached.getZ() != z >> 9) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
return Blocks.AIR.getDefaultState();
|
||||
IBlockState type = cached.getBlock(x & 511, y, z & 511);
|
||||
if (type == null) {
|
||||
return AIR;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static void clearCachedChunk() {
|
||||
prev = null;
|
||||
prevCached = null;
|
||||
}
|
||||
|
||||
public static Block getBlock(BlockPos pos) {
|
||||
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
|
||||
@@ -90,7 +114,7 @@ public class BlockStateInterface implements Helper {
|
||||
* @return Whether or not the block is water
|
||||
*/
|
||||
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) {
|
||||
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.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.MineBehavior;
|
||||
import baritone.behavior.impl.PathingBehavior;
|
||||
import baritone.chunk.ChunkPacker;
|
||||
import baritone.chunk.Waypoint;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.pathing.calc.AStarPathFinder;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
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])));
|
||||
break;
|
||||
default:
|
||||
displayChatMessageRaw("unable to understand lol");
|
||||
logDirect("unable to understand lol");
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
displayChatMessageRaw("unable to parse integer " + ex);
|
||||
logDirect("unable to parse integer " + ex);
|
||||
return;
|
||||
}
|
||||
PathingBehavior.INSTANCE.setGoal(goal);
|
||||
displayChatMessageRaw("Goal: " + goal);
|
||||
logDirect("Goal: " + goal);
|
||||
return;
|
||||
}
|
||||
if (msg.equals("path")) {
|
||||
if (!PathingBehavior.INSTANCE.path()) {
|
||||
if (PathingBehavior.INSTANCE.getGoal() == null) {
|
||||
displayChatMessageRaw("No goal.");
|
||||
logDirect("No goal.");
|
||||
} 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();
|
||||
@@ -119,13 +123,13 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
FollowBehavior.INSTANCE.cancel();
|
||||
MineBehavior.INSTANCE.cancel();
|
||||
event.cancel();
|
||||
displayChatMessageRaw("ok canceled");
|
||||
logDirect("ok canceled");
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("forcecancel")) {
|
||||
AbstractNodeCostSearch.forceCancel();
|
||||
event.cancel();
|
||||
displayChatMessageRaw("ok force canceled");
|
||||
logDirect("ok force canceled");
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("invert")) {
|
||||
@@ -136,8 +140,8 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
} else if (goal instanceof GoalBlock) {
|
||||
runAwayFrom = ((GoalBlock) goal).getGoalPos();
|
||||
} else {
|
||||
displayChatMessageRaw("Goal must be GoalXZ or GoalBlock to invert");
|
||||
displayChatMessageRaw("Inverting goal of player feet");
|
||||
logDirect("Goal must be GoalXZ or GoalBlock to invert");
|
||||
logDirect("Inverting goal of player feet");
|
||||
runAwayFrom = playerFeet();
|
||||
}
|
||||
PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) {
|
||||
@@ -147,7 +151,7 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
}
|
||||
});
|
||||
if (!PathingBehavior.INSTANCE.path()) {
|
||||
displayChatMessageRaw("Currently executing a path. Please cancel it first.");
|
||||
logDirect("Currently executing a path. Please cancel it first.");
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
@@ -155,31 +159,31 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
if (msg.toLowerCase().equals("follow")) {
|
||||
Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt();
|
||||
if (!entity.isPresent()) {
|
||||
displayChatMessageRaw("You aren't looking at an entity bruh");
|
||||
logDirect("You aren't looking at an entity bruh");
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
FollowBehavior.INSTANCE.follow(entity.get());
|
||||
displayChatMessageRaw("Following " + entity.get());
|
||||
logDirect("Following " + entity.get());
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("reloadall")) {
|
||||
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
|
||||
displayChatMessageRaw("ok");
|
||||
logDirect("ok");
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("saveall")) {
|
||||
WorldProvider.INSTANCE.getCurrentWorld().cache.save();
|
||||
displayChatMessageRaw("ok");
|
||||
logDirect("ok");
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().startsWith("find")) {
|
||||
String blockType = msg.toLowerCase().substring(4).trim();
|
||||
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) {
|
||||
Block actually = BlockStateInterface.get(pos).getBlock();
|
||||
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||
@@ -193,20 +197,20 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" ");
|
||||
for (String s : blockTypes) {
|
||||
if (ChunkPacker.stringToBlock(s) == null) {
|
||||
displayChatMessageRaw(s + " isn't a valid block name");
|
||||
logDirect(s + " isn't a valid block name");
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
MineBehavior.INSTANCE.mine(blockTypes);
|
||||
displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().startsWith("thisway")) {
|
||||
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
||||
PathingBehavior.INSTANCE.setGoal(goal);
|
||||
displayChatMessageRaw("Goal: " + goal);
|
||||
logDirect("Goal: " + goal);
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
@@ -218,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
}
|
||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||
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();
|
||||
return;
|
||||
}
|
||||
@@ -226,9 +230,9 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
// might as well show them from oldest to newest
|
||||
List<Waypoint> sorted = new ArrayList<>(waypoints);
|
||||
sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp));
|
||||
displayChatMessageRaw("Waypoints under tag " + tag + ":");
|
||||
logDirect("Waypoints under tag " + tag + ":");
|
||||
for (Waypoint waypoint : sorted) {
|
||||
displayChatMessageRaw(waypoint.toString());
|
||||
logDirect(waypoint.toString());
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
@@ -242,15 +246,15 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||
if (tag == null) {
|
||||
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();
|
||||
if (ChunkPacker.stringToBlock(mining) == null) {
|
||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
||||
logDirect("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
}
|
||||
List<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
|
||||
if (locs.isEmpty()) {
|
||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
||||
logDirect("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
}
|
||||
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);
|
||||
if (waypoint == null) {
|
||||
displayChatMessageRaw("None saved for tag " + tag);
|
||||
logDirect("None saved for tag " + tag);
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
Goal goal = new GoalBlock(waypoint.location);
|
||||
PathingBehavior.INSTANCE.setGoal(goal);
|
||||
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();
|
||||
return;
|
||||
@@ -277,30 +283,30 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
BlockPos spawnPoint = player().getBedLocation();
|
||||
// for some reason the default spawnpoint is underground sometimes
|
||||
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);
|
||||
} else {
|
||||
Goal goal = new GoalBlock(waypoint.location);
|
||||
PathingBehavior.INSTANCE.setGoal(goal);
|
||||
displayChatMessageRaw("Set goal to most recent bed " + goal);
|
||||
logDirect("Set goal to most recent bed " + goal);
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("sethome")) {
|
||||
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();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("home")) {
|
||||
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME);
|
||||
if (waypoint == null) {
|
||||
displayChatMessageRaw("home not saved");
|
||||
logDirect("home not saved");
|
||||
} else {
|
||||
Goal goal = new GoalBlock(waypoint.location);
|
||||
PathingBehavior.INSTANCE.setGoal(goal);
|
||||
displayChatMessageRaw("Set goal to saved home " + goal);
|
||||
logDirect("Set goal to saved home " + goal);
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
@@ -308,6 +314,9 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
if (msg.toLowerCase().equals("costs")) {
|
||||
Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext());
|
||||
List<Movement> moves = new ArrayList<>(Arrays.asList(movements));
|
||||
while (moves.contains(null)) {
|
||||
moves.remove(null);
|
||||
}
|
||||
moves.sort(Comparator.comparingDouble(movement -> movement.getCost(new CalculationContext())));
|
||||
for (Movement move : moves) {
|
||||
String[] parts = move.getClass().toString().split("\\.");
|
||||
@@ -316,7 +325,7 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
if (cost >= ActionCosts.COST_INF) {
|
||||
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();
|
||||
return;
|
||||
@@ -326,13 +335,13 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||
setting.value ^= true;
|
||||
event.cancel();
|
||||
displayChatMessageRaw("Toggled " + setting.getName() + " to " + setting.value);
|
||||
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) {
|
||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
||||
displayChatMessageRaw(setting.toString());
|
||||
logDirect(setting.toString());
|
||||
}
|
||||
event.cancel();
|
||||
return;
|
||||
@@ -353,11 +362,11 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
setting.value = Double.parseDouble(data[1]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
displayChatMessageRaw("Unable to parse " + data[1]);
|
||||
logDirect("Unable to parse " + data[1]);
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
displayChatMessageRaw(setting.toString());
|
||||
logDirect(setting.toString());
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
@@ -365,7 +374,7 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
}
|
||||
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
|
||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
|
||||
displayChatMessageRaw(setting.toString());
|
||||
logDirect(setting.toString());
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,13 +73,24 @@ public interface Helper {
|
||||
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()) {
|
||||
System.out.println("Suppressed debug message:");
|
||||
System.out.println(message);
|
||||
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();
|
||||
component.getStyle().setColor(TextFormatting.GRAY);
|
||||
component.appendSibling(new TextComponentString(" " + message));
|
||||
|
||||
@@ -19,9 +19,11 @@ package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
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.path.IPath;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -183,17 +185,25 @@ public final class PathRenderer implements Helper {
|
||||
double maxY;
|
||||
double y1;
|
||||
double y2;
|
||||
if (goal instanceof GoalBlock) {
|
||||
BlockPos goalPos = ((GoalBlock) goal).getGoalPos();
|
||||
if (goal instanceof IGoalRenderPos) {
|
||||
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
|
||||
minX = goalPos.getX() + 0.002 - renderPosX;
|
||||
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
||||
minZ = goalPos.getZ() + 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;
|
||||
y2 = 1 - y + goalPos.getY() - renderPosY;
|
||||
minY = goalPos.getY() - renderPosY;
|
||||
maxY = minY + 2;
|
||||
if (goal instanceof GoalTwoBlocks) {
|
||||
y1 -= 0.5;
|
||||
y2 -= 0.5;
|
||||
maxY--;
|
||||
}
|
||||
} else if (goal instanceof GoalXZ) {
|
||||
GoalXZ goalPos = (GoalXZ) goal;
|
||||
|
||||
@@ -206,8 +216,12 @@ public final class PathRenderer implements Helper {
|
||||
y2 = 0;
|
||||
minY = 0 - renderPosY;
|
||||
maxY = 256 - renderPosY;
|
||||
} else if (goal instanceof GoalComposite) {
|
||||
for (Goal g : ((GoalComposite) goal).goals()) {
|
||||
drawLitDankGoalBox(player, g, partialTicks, color);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// TODO GoalComposite
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,9 @@ public class ToolSet implements Helper {
|
||||
ItemStack contents = player().inventory.getStackInSlot(slot);
|
||||
|
||||
float blockHard = state.getBlockHardness(null, null);
|
||||
if (blockHard < 0)
|
||||
if (blockHard < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
float speed = contents.getDestroySpeed(state);
|
||||
if (speed > 1) {
|
||||
|
||||
+4
-23
@@ -15,29 +15,10 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @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;
|
||||
}
|
||||
public interface IGoalRenderPos {
|
||||
BlockPos getGoalPos();
|
||||
}
|
||||
@@ -23,6 +23,10 @@ import net.minecraft.util.math.Vec3i;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -60,12 +64,12 @@ public final class BetterBlockPos extends BlockPos {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
public int hashCode() {
|
||||
return (int) hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -83,7 +87,7 @@ public final class BetterBlockPos extends BlockPos {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos up() {
|
||||
public BetterBlockPos up() {
|
||||
// this is unimaginably faster than blockpos.up
|
||||
// that literally calls
|
||||
// this.up(1)
|
||||
@@ -97,26 +101,32 @@ public final class BetterBlockPos extends BlockPos {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos up(int amt) {
|
||||
public BetterBlockPos up(int amt) {
|
||||
// see comment in up()
|
||||
return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos down() {
|
||||
public BetterBlockPos down() {
|
||||
// see comment in up()
|
||||
return new BetterBlockPos(x, y - 1, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos down(int amt) {
|
||||
public BetterBlockPos down(int amt) {
|
||||
// see comment in up()
|
||||
return new BetterBlockPos(x, y - amt, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos offset(EnumFacing dir) {
|
||||
public BetterBlockPos offset(EnumFacing dir) {
|
||||
Vec3i vec = dir.getDirectionVec();
|
||||
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/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
package baritone.cache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user