FollowBehavior
This commit is contained in:
parent
af3bc18079
commit
27a3adeceb
@ -18,10 +18,7 @@
|
|||||||
package baritone;
|
package baritone;
|
||||||
|
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.behavior.impl.LookBehavior;
|
import baritone.behavior.impl.*;
|
||||||
import baritone.behavior.impl.MemoryBehavior;
|
|
||||||
import baritone.behavior.impl.PathingBehavior;
|
|
||||||
import baritone.behavior.impl.LocationTrackingBehavior;
|
|
||||||
import baritone.api.event.GameEventHandler;
|
import baritone.api.event.GameEventHandler;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@ -81,6 +78,7 @@ public enum Baritone {
|
|||||||
registerBehavior(LookBehavior.INSTANCE);
|
registerBehavior(LookBehavior.INSTANCE);
|
||||||
registerBehavior(MemoryBehavior.INSTANCE);
|
registerBehavior(MemoryBehavior.INSTANCE);
|
||||||
registerBehavior(LocationTrackingBehavior.INSTANCE);
|
registerBehavior(LocationTrackingBehavior.INSTANCE);
|
||||||
|
registerBehavior(FollowBehavior.INSTANCE);
|
||||||
}
|
}
|
||||||
this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
|
this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
|
||||||
if (!Files.exists(dir.toPath())) {
|
if (!Files.exists(dir.toPath())) {
|
||||||
|
55
src/main/java/baritone/behavior/impl/FollowBehavior.java
Normal file
55
src/main/java/baritone/behavior/impl/FollowBehavior.java
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ package baritone.utils;
|
|||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.Settings;
|
import baritone.Settings;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
|
import baritone.behavior.impl.FollowBehavior;
|
||||||
import baritone.behavior.impl.PathingBehavior;
|
import baritone.behavior.impl.PathingBehavior;
|
||||||
import baritone.chunk.ChunkPacker;
|
import baritone.chunk.ChunkPacker;
|
||||||
import baritone.chunk.Waypoint;
|
import baritone.chunk.Waypoint;
|
||||||
@ -30,8 +31,10 @@ import baritone.pathing.goals.*;
|
|||||||
import baritone.pathing.movement.ActionCosts;
|
import baritone.pathing.movement.ActionCosts;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
@ -131,6 +134,18 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (msg.toLowerCase().equals("follow")) {
|
||||||
|
Optional<Entity> 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")) {
|
if (msg.toLowerCase().equals("reloadall")) {
|
||||||
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
|
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
|
||||||
displayChatMessageRaw("ok");
|
displayChatMessageRaw("ok");
|
||||||
|
Loading…
Reference in New Issue
Block a user