PathFinderGoalPet.java (1819B)
1 package me.night.nullvalkyrie.entities.pets; 2 3 import java.util.EnumSet; 4 5 import net.minecraft.world.entity.*; 6 import net.minecraft.world.entity.ai.goal.Goal; 7 8 public class PathFinderGoalPet extends Goal { 9 private final Mob pet; // our pet 10 private LivingEntity owner; // owner 11 private final double speed; // pet's speed 12 private final float distance; // distance between owner & pet 13 private double x; // x 14 private double y; // y 15 private double z; // z 16 17 18 public PathFinderGoalPet(Mob mob, double speed, float distance) { 19 this.pet = mob; 20 this.speed = speed; 21 this.distance = distance; 22 this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK, Flag.TARGET, Flag.JUMP)); 23 } 24 25 @Override 26 public boolean canUse() { 27 this.owner = this.pet.getTarget(); 28 if (this.owner == null) return false; 29 else if (this.pet.getDisplayName() == null) return false; 30 else if (!this.pet.getDisplayName().getString().contains(this.owner.getName().getString())) return false; 31 else if (this.owner.distanceToSqr(this.pet) > (double) (this.distance * this.distance)) { 32 pet.getBukkitEntity().teleport(this.owner.getBukkitEntity().getLocation()); 33 return false; 34 } else { 35 this.x = this.owner.getX(); 36 this.y = this.owner.getY(); 37 this.z = this.owner.getZ(); 38 return true; 39 } 40 } 41 42 @Override 43 public void start() { 44 this.pet.getNavigation().moveTo(this.x, this.y, this.z, this.speed); 45 } 46 47 @Override 48 public boolean canContinueToUse() { 49 return !this.pet.getNavigation().isDone() && this.owner.distanceToSqr(this.pet) < (double) (this.distance * this.distance); 50 } 51 52 @Override 53 public void stop() { 54 this.owner = null; 55 } 56 57 }