diff --git a/src/main/java/baritone/behavior/FollowBehavior.java b/src/main/java/baritone/behavior/FollowBehavior.java index 0dd9893d..2ef25c1a 100644 --- a/src/main/java/baritone/behavior/FollowBehavior.java +++ b/src/main/java/baritone/behavior/FollowBehavior.java @@ -50,6 +50,7 @@ public final class FollowBehavior extends Behavior implements Helper { // lol this is trashy but it works GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get()); PathingBehavior.INSTANCE.setGoal(new GoalNear(new BlockPos(g.getX(), following.posY, g.getZ()), Baritone.settings().followRadius.get())); + PathingBehavior.INSTANCE.revalidateGoal(); PathingBehavior.INSTANCE.path(); } diff --git a/src/main/java/baritone/behavior/MineBehavior.java b/src/main/java/baritone/behavior/MineBehavior.java index 33a8e96d..8b6fa2a1 100644 --- a/src/main/java/baritone/behavior/MineBehavior.java +++ b/src/main/java/baritone/behavior/MineBehavior.java @@ -29,7 +29,6 @@ import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalBlock; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; -import baritone.pathing.path.IPath; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.block.Block; @@ -37,7 +36,10 @@ import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; import java.util.stream.Collectors; /** @@ -65,24 +67,7 @@ public final class MineBehavior extends Behavior implements Helper { updateGoal(); } } - if (!Baritone.settings().cancelOnGoalInvalidation.get()) { - return; - } - Optional path = PathingBehavior.INSTANCE.getPath(); - if (!path.isPresent()) { - return; - } - Goal currentGoal = PathingBehavior.INSTANCE.getGoal(); - if (currentGoal == null) { - return; - } - Goal intended = path.get().getGoal(); - BlockPos end = path.get().getDest(); - if (intended.isInGoal(end) && !currentGoal.isInGoal(end)) { - // this path used to end in the goal - // but the goal has changed, so there's no reason to continue... - PathingBehavior.INSTANCE.cancel(); - } + PathingBehavior.INSTANCE.revalidateGoal(); } @Override diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 8d962bd6..3037c4e7 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -338,6 +338,22 @@ public final class PathingBehavior extends Behavior implements Helper { } } + public void revalidateGoal() { + if (!Baritone.settings().cancelOnGoalInvalidation.get()) { + return; + } + if (current == null || goal == null) { + return; + } + Goal intended = current.getPath().getGoal(); + BlockPos end = current.getPath().getDest(); + if (intended.isInGoal(end) && !goal.isInGoal(end)) { + // this path used to end in the goal + // but the goal has changed, so there's no reason to continue... + cancel(); + } + } + @Override public void onRenderPass(RenderEvent event) { // System.out.println("Render passing"); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index a3301cd2..7bbd8c82 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -38,6 +38,7 @@ import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; @@ -236,15 +237,28 @@ public class ExampleBaritoneControl extends Behavior implements Helper { event.cancel(); return; } - if (msg.equals("follow")) { - Optional entity = MovementHelper.whatEntityAmILookingAt(); - if (!entity.isPresent()) { - logDirect("You aren't looking at an entity bruh"); + if (msg.startsWith("follow")) { + String name = msg.substring(6).trim(); + Optional toFollow = Optional.empty(); + if (name.length() == 0) { + toFollow = MovementHelper.whatEntityAmILookingAt(); + } else { + for (EntityPlayer pl : world().playerEntities) { + String theirName = pl.getName().trim().toLowerCase(); + if (!theirName.equals(player().getName().trim().toLowerCase())) { // don't follow ourselves lol + if (theirName.contains(name) || name.contains(theirName)) { + toFollow = Optional.of(pl); + } + } + } + } + if (!toFollow.isPresent()) { + logDirect("Not found"); event.cancel(); return; } - FollowBehavior.INSTANCE.follow(entity.get()); - logDirect("Following " + entity.get()); + FollowBehavior.INSTANCE.follow(toFollow.get()); + logDirect("Following " + toFollow.get()); event.cancel(); return; }