Guest User

EntityAIMoveToBlock.java

a guest
Jun 28th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.89 KB | None | 0 0
  1. package uk.co.ijay.earlyfuture.entity.ai;
  2.  
  3. import uk.co.ijay.earlyfuture.EarlyFuture;
  4. import net.minecraft.entity.EntityCreature;
  5. import net.minecraft.entity.ai.EntityAIBase;
  6. import net.minecraft.world.World;
  7.  
  8. public abstract class EntityAIMoveToBlock extends EntityAIBase
  9. {
  10.     private final EntityCreature    entityCreature;
  11.     private final double            field_179492_d;
  12.     protected int                   field_179496_a;
  13.     private int                     field_179493_e;
  14.     private int                     field_179490_f;
  15.     protected int                   destinationBlockX;
  16.     protected int                   destinationBlockY;
  17.     protected int                   destinationBlockZ;
  18.     private boolean                 field_179491_g;
  19.     private int                     field_179497_h;
  20.     private static final String     __OBFID = "CL_00002252";
  21.    
  22.     public EntityAIMoveToBlock(EntityCreature p_i45888_1_, double p_i45888_2_, int p_i45888_4_)
  23.     {
  24.         this.destinationBlockX = 0;
  25.         this.destinationBlockY = 0;
  26.         this.destinationBlockZ = 0;
  27.         this.entityCreature = p_i45888_1_;
  28.         this.field_179492_d = p_i45888_2_;
  29.         this.field_179497_h = p_i45888_4_;
  30.         this.setMutexBits(5);
  31.     }
  32.    
  33.     @Override
  34.     public boolean shouldExecute()
  35.     {
  36.         EarlyFuture.LOG.info("Called shouldExecute()");
  37.         if(this.field_179496_a > 0)
  38.         {
  39.             --this.field_179496_a;
  40.             return false;
  41.         }
  42.         else
  43.         {
  44.             EarlyFuture.LOG.info("Got past the first hurdle");
  45.             this.field_179496_a = 200 + this.entityCreature.getRNG().nextInt(200);
  46.             return this.func_179489_g();
  47.         }
  48.     }
  49.    
  50.     @Override
  51.     public boolean continueExecuting()
  52.     {
  53.         return this.field_179493_e >= -this.field_179490_f
  54.             && this.field_179493_e <= 1200
  55.             && this.isTargetBlock(this.entityCreature.worldObj, this.destinationBlockX, this.destinationBlockY,
  56.                 this.destinationBlockZ);
  57.     }
  58.    
  59.     @Override
  60.     public void startExecuting()
  61.     {
  62.         this.entityCreature.getNavigator().tryMoveToXYZ((double) ((float) this.destinationBlockX) + 0.5D,
  63.             (double) (this.destinationBlockY + 1), (double) ((float) this.destinationBlockZ) + 0.5D,
  64.             this.field_179492_d);
  65.         this.field_179493_e = 0;
  66.         this.field_179490_f = this.entityCreature.getRNG().nextInt(this.entityCreature.getRNG().nextInt(1200) + 1200) + 1200;
  67.     }
  68.    
  69.     @Override
  70.     public void resetTask()
  71.     {
  72.     }
  73.    
  74.     @Override
  75.     public void updateTask()
  76.     {
  77.         if(this.entityCreature.getDistanceSq(this.destinationBlockX + 0.5D, this.destinationBlockY + 1.5D,
  78.             this.destinationBlockZ + 0.5D) > 1.0D)
  79.         {
  80.             this.field_179491_g = false;
  81.             ++this.field_179493_e;
  82.            
  83.             if(this.field_179493_e % 40 == 0)
  84.             {
  85.                 this.entityCreature.getNavigator().tryMoveToXYZ((double) ((float) this.destinationBlockX) + 0.5D,
  86.                     (double) (this.destinationBlockY + 1), (double) ((float) this.destinationBlockZ) + 0.5D,
  87.                     this.field_179492_d);
  88.             }
  89.         }
  90.         else
  91.         {
  92.             this.field_179491_g = true;
  93.             --this.field_179493_e;
  94.         }
  95.     }
  96.    
  97.     protected boolean func_179487_f()
  98.     {
  99.         return this.field_179491_g;
  100.     }
  101.    
  102.     private boolean func_179489_g()
  103.     {
  104.         int i = this.field_179497_h;
  105.         boolean flag = true;
  106.         double posX = this.entityCreature.posX;
  107.         double posY = this.entityCreature.posY;
  108.         double posZ = this.entityCreature.posZ;
  109.        
  110.         for(int j = 0; j <= 1; j = j > 0 ? -j : 1 - j)
  111.         {
  112.             for(int k = 0; k < i; ++k)
  113.             {
  114.                 for(int l = 0; l <= k; l = l > 0 ? -l : 1 - l)
  115.                 {
  116.                     for(int i1 = l < k && l > -k ? k : 0; i1 <= k; i1 = i1 > 0 ? -i1 : 1 - i1)
  117.                     {
  118.                         double posX1 = posX + l;
  119.                         double posY1 = posY + j - 1;
  120.                         double posZ1 = posZ + i1;
  121.                        
  122.                         if(this.entityCreature.isWithinHomeDistance((int) posX1, (int) posY1, (int) posZ1)
  123.                             && this.isTargetBlock(this.entityCreature.worldObj, posX1, posY1, posZ1))
  124.                         {
  125.                             this.destinationBlockX = (int) posX1;
  126.                             this.destinationBlockY = (int) posY1;
  127.                             this.destinationBlockZ = (int) posZ1;
  128.                             return true;
  129.                         }
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.        
  135.         return false;
  136.     }
  137.    
  138.     protected abstract boolean isTargetBlock(World worldIn, double targetX, double targetY, double targetZ);
  139. }
Advertisement
Add Comment
Please, Sign In to add comment