Skip to content

Instantly share code, notes, and snippets.

@yannicklamprecht
Last active December 10, 2017 12:57
Show Gist options
  • Save yannicklamprecht/dbf992b89cca9877764f8e89e0703b91 to your computer and use it in GitHub Desktop.
Save yannicklamprecht/dbf992b89cca9877764f8e89e0703b91 to your computer and use it in GitHub Desktop.
package org.bukkit.pathfinding.goals;
import org.bukkit.entity.Insentient;
import org.bukkit.pathfinding.PathfinderGoal;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
public class PathfinderGoalMoveToLocation implements PathfinderGoal {
private final Location targetLocation;
private final double moveRadius;
private boolean isAlreadySet;
private Insentient pathfinderGoalEntity;
private double walkspeed;
private boolean changedMoved = false;
public PathfinderGoalFollowEntity(Insentient pathfinderGoalEntity, Location targetLocation, double moveRadius, double walkspeed) {
this.targetLocation = targetLocation;
this.moveRadius = moveRadius;
this.pathfinderGoalEntity = pathfinderGoalEntity;
this.walkspeed = walkspeed;
}
public boolean isInterruptible() {
return true;
}
public boolean shouldExecute() {
return this.isAlreadySet = !this.pathfinderGoalEntity.getNavigation().isMovementSet();
}
public boolean shouldInitExecute() {
if (this.isAlreadySet) return false;
return this.pathfinderGoalEntity.getBukkitEntity().getLocation().distance(this.targetLocation) > this.moveRadius;
}
public void initExecute() {
if (!this.isAlreadySet) {
this.pathfinderGoalEntity.getNavigation().moveTo(this.targetLocation, walkspeed);
}
}
public void executeUpdate() {
}
public void reset() {
}
public void move() {
// TODO: 10.12.16 block detection as PathfinderGoal -> move/jump
if (pathfinderGoalEntity.getBukkitEntity().getLocation().add(pathfinderGoalEntity.getBukkitEntity().getLocation().getDirection().normalize()).getBlock().getType() != Material.AIR) {
this.pathfinderGoalEntity.getControllerJump().jump();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment