follow player by name

This commit is contained in:
Leijurv 2018-09-17 10:56:37 -07:00
parent 043dd80e28
commit e981bfa346
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 42 additions and 26 deletions

View File

@ -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();
}

View File

@ -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<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();
}
PathingBehavior.INSTANCE.revalidateGoal();
}
@Override

View File

@ -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");

View File

@ -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> 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<Entity> 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;
}