follow player by name
This commit is contained in:
parent
043dd80e28
commit
e981bfa346
@ -50,6 +50,7 @@ public final class FollowBehavior extends Behavior implements Helper {
|
|||||||
// lol this is trashy but it works
|
// lol this is trashy but it works
|
||||||
GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get());
|
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.setGoal(new GoalNear(new BlockPos(g.getX(), following.posY, g.getZ()), Baritone.settings().followRadius.get()));
|
||||||
|
PathingBehavior.INSTANCE.revalidateGoal();
|
||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import baritone.pathing.goals.Goal;
|
|||||||
import baritone.pathing.goals.GoalBlock;
|
import baritone.pathing.goals.GoalBlock;
|
||||||
import baritone.pathing.goals.GoalComposite;
|
import baritone.pathing.goals.GoalComposite;
|
||||||
import baritone.pathing.goals.GoalTwoBlocks;
|
import baritone.pathing.goals.GoalTwoBlocks;
|
||||||
import baritone.pathing.path.IPath;
|
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@ -37,7 +36,10 @@ import net.minecraft.init.Blocks;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
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;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,24 +67,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Baritone.settings().cancelOnGoalInvalidation.get()) {
|
PathingBehavior.INSTANCE.revalidateGoal();
|
||||||
return;
|
|
||||||
}
|
|
||||||
Optional<IPath> 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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
|
@Override
|
||||||
public void onRenderPass(RenderEvent event) {
|
public void onRenderPass(RenderEvent event) {
|
||||||
// System.out.println("Render passing");
|
// System.out.println("Render passing");
|
||||||
|
@ -38,6 +38,7 @@ import baritone.utils.pathing.BetterBlockPos;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
@ -236,15 +237,28 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.equals("follow")) {
|
if (msg.startsWith("follow")) {
|
||||||
Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt();
|
String name = msg.substring(6).trim();
|
||||||
if (!entity.isPresent()) {
|
Optional<Entity> toFollow = Optional.empty();
|
||||||
logDirect("You aren't looking at an entity bruh");
|
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();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FollowBehavior.INSTANCE.follow(entity.get());
|
FollowBehavior.INSTANCE.follow(toFollow.get());
|
||||||
logDirect("Following " + entity.get());
|
logDirect("Following " + toFollow.get());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user