From 27a3adecebfa1e12ba9c3fb7315e2c0f4bd8813b Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 27 Aug 2018 19:05:21 -0700 Subject: [PATCH] FollowBehavior --- src/main/java/baritone/Baritone.java | 6 +- .../behavior/impl/FollowBehavior.java | 55 +++++++++++++++++++ .../utils/ExampleBaritoneControl.java | 15 +++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/main/java/baritone/behavior/impl/FollowBehavior.java diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 0ef6da9d..2a88ed21 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -18,10 +18,7 @@ package baritone; import baritone.behavior.Behavior; -import baritone.behavior.impl.LookBehavior; -import baritone.behavior.impl.MemoryBehavior; -import baritone.behavior.impl.PathingBehavior; -import baritone.behavior.impl.LocationTrackingBehavior; +import baritone.behavior.impl.*; import baritone.api.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; @@ -81,6 +78,7 @@ public enum Baritone { registerBehavior(LookBehavior.INSTANCE); registerBehavior(MemoryBehavior.INSTANCE); registerBehavior(LocationTrackingBehavior.INSTANCE); + registerBehavior(FollowBehavior.INSTANCE); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/behavior/impl/FollowBehavior.java b/src/main/java/baritone/behavior/impl/FollowBehavior.java new file mode 100644 index 00000000..7ac54c32 --- /dev/null +++ b/src/main/java/baritone/behavior/impl/FollowBehavior.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +package baritone.behavior.impl; + +import baritone.api.event.events.TickEvent; +import baritone.behavior.Behavior; +import baritone.pathing.goals.GoalNear; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; + +public class FollowBehavior extends Behavior { + public static final FollowBehavior INSTANCE = new FollowBehavior(); + + private FollowBehavior() { + } + + Entity following; + + @Override + public void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + return; + } + if (following == null) { + return; + } + // lol this is trashy but it works + PathingBehavior.INSTANCE.setGoal(new GoalNear(new BlockPos(following), 3)); + PathingBehavior.INSTANCE.path(); + } + + public void follow(Entity follow) { + this.following = follow; + } + + public void cancel() { + PathingBehavior.INSTANCE.cancel(); + follow(null); + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 3b9cc18e..997011df 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.Settings; import baritone.behavior.Behavior; +import baritone.behavior.impl.FollowBehavior; import baritone.behavior.impl.PathingBehavior; import baritone.chunk.ChunkPacker; import baritone.chunk.Waypoint; @@ -30,8 +31,10 @@ import baritone.pathing.goals.*; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; +import baritone.pathing.movement.MovementHelper; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -131,6 +134,18 @@ public class ExampleBaritoneControl extends Behavior { event.cancel(); return; } + if (msg.toLowerCase().equals("follow")) { + Optional entity = MovementHelper.whatEntityAmILookingAt(); + if (!entity.isPresent()) { + displayChatMessageRaw("You aren't looking at an entity bruh"); + event.cancel(); + return; + } + FollowBehavior.INSTANCE.follow(entity.get()); + displayChatMessageRaw("Following " + entity.get()); + event.cancel(); + return; + } if (msg.toLowerCase().equals("reloadall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk(); displayChatMessageRaw("ok");