baritone/src/main/java/baritone/behavior/FollowBehavior.java

70 lines
2.1 KiB
Java
Raw Normal View History

2018-08-28 02:05:21 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-28 02:05:21 +00:00
* 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 Lesser General Public License for more details.
2018-08-28 02:05:21 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-28 02:05:21 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.behavior;
2018-08-28 02:05:21 +00:00
2018-09-17 17:36:39 +00:00
import baritone.Baritone;
2018-09-12 22:53:29 +00:00
import baritone.api.behavior.Behavior;
2018-09-17 03:16:05 +00:00
import baritone.api.event.events.TickEvent;
2018-08-28 02:05:21 +00:00
import baritone.pathing.goals.GoalNear;
2018-09-17 17:36:39 +00:00
import baritone.pathing.goals.GoalXZ;
import baritone.utils.Helper;
2018-08-28 02:05:21 +00:00
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
2018-08-28 18:43:28 +00:00
/**
* Follow an entity
*
* @author leijurv
*/
2018-09-17 17:36:39 +00:00
public final class FollowBehavior extends Behavior implements Helper {
2018-08-28 02:05:21 +00:00
public static final FollowBehavior INSTANCE = new FollowBehavior();
private Entity following;
2018-08-28 02:05:21 +00:00
2018-09-17 03:16:05 +00:00
private FollowBehavior() {}
2018-08-28 02:05:21 +00:00
@Override
public void onTick(TickEvent event) {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
if (following == null) {
return;
}
// lol this is trashy but it works
2018-09-17 17:36:39 +00:00
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()));
2018-09-17 17:56:37 +00:00
PathingBehavior.INSTANCE.revalidateGoal();
2018-08-28 02:05:21 +00:00
PathingBehavior.INSTANCE.path();
}
public void follow(Entity entity) {
this.following = entity;
}
public Entity following() {
return this.following;
2018-08-28 02:05:21 +00:00
}
public void cancel() {
PathingBehavior.INSTANCE.cancel();
follow(null);
}
}