Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package lolmod.entitys.ai;
  2.  
  3. import lolmod.entitys.EntityNeutral;
  4. import net.minecraft.entity.ai.EntityAIBase;
  5. import net.minecraft.pathfinding.PathNavigate;
  6.  
  7. public class EntityAIWalkHome extends EntityAIBase {
  8.     private final EntityNeutral creature;
  9.     private final double moveSpeed;
  10.     private final PathNavigate pathfinder;
  11.  
  12.     public EntityAIWalkHome(EntityNeutral creatureIn) {
  13.         this.creature = creatureIn;
  14.         this.moveSpeed = 1D;
  15.         this.pathfinder = creatureIn.getNavigator();
  16.         this.setMutexBits(1);
  17.     }
  18.  
  19.     /**
  20.      * Returns whether the EntityAIBase should begin execution.
  21.      */
  22.     public boolean shouldExecute() {
  23.         return this.creature.getPatienceBar()<=0 && this.creature.getDistance(this.creature.getHomePosition().getX(), this.creature.getHomePosition().getY(), this.creature.getHomePosition().getZ()) > 1;
  24.     }
  25.  
  26.     /**
  27.      * Returns whether an in-progress EntityAIBase should continue executing
  28.      */
  29.     public boolean shouldContinueExecuting() {
  30.         return !this.pathfinder.noPath() && shouldExecute();
  31.     }
  32.  
  33.     /**
  34.      * Execute a one shot task or start executing a continuous task
  35.      */
  36.     public void startExecuting() {
  37.         this.pathfinder.tryMoveToXYZ(this.creature.getHomePosition().getX(), this.creature.getHomePosition().getY(), this.creature.getHomePosition().getZ(), moveSpeed);
  38.     }
  39.  
  40.     /**
  41.      * Reset the task's internal state. Called when this task is interrupted by another one
  42.      */
  43.     public void resetTask() {
  44.         this.pathfinder.clearPathEntity();
  45.     }
  46.  
  47.     /**
  48.      * Keep ticking a continuous task that has already been started
  49.      */
  50.     public void updateTask() {
  51.         this.creature.getLookHelper().setLookPosition(this.creature.getHomePosition().getX(), this.creature.getHomePosition().getY()+2, this.creature.getHomePosition().getZ(), 10.0F, (float)this.creature.getVerticalFaceSpeed());
  52.  
  53.         this.pathfinder.tryMoveToXYZ(this.creature.getHomePosition().getX(), this.creature.getHomePosition().getY(), this.creature.getHomePosition().getZ(), moveSpeed);
  54.         if(this.pathfinder.noPath())
  55.             this.creature.setPatienceBar(100);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement