Advertisement
Guest User

Untitled

a guest
May 16th, 2015
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. package com.nosrick.minersgotchi.ai;
  2.  
  3. import java.util.UUID;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.EntityCreature;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.ai.EntityAIBase;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.pathfinding.PathNavigate;
  11. import net.minecraft.server.MinecraftServer;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.world.World;
  14.  
  15. public class GotchiAIFollowOwner extends EntityAIBase
  16. {
  17.     protected EntityCreature m_Gotchi;
  18.     protected EntityPlayer m_Owner;
  19.     protected World m_World;
  20.     protected double m_Thing1;
  21.     protected PathNavigate m_Navigator;
  22.     protected int m_Thing2;
  23.     protected float m_MinDistance;
  24.     protected float m_MaxDistance;
  25.     private boolean m_AvoidsWater;
  26.    
  27.     public GotchiAIFollowOwner(EntityCreature gotchiRef, UUID ownerIDRef, double ref1, float minDistRef, float maxDistRef)
  28.     {
  29.         m_Gotchi = gotchiRef;
  30.         m_World = m_Gotchi.worldObj;
  31.        
  32.         if(ownerIDRef != null)
  33.         {
  34.             m_Owner = m_World.func_152378_a(ownerIDRef);
  35.         }
  36.        
  37.         m_Thing1 = ref1;
  38.         m_Navigator = m_Gotchi.getNavigator();
  39.        
  40.         m_MinDistance = minDistRef;
  41.         m_MaxDistance = maxDistRef;
  42.        
  43.         this.setMutexBits(3);
  44.     }
  45.    
  46.     public void SetOwner(UUID ownerRef, int dimensionRef)
  47.     {
  48.         World world = MinecraftServer.getServer().worldServerForDimension(dimensionRef);
  49.         m_Owner = world.func_152378_a(ownerRef);
  50.         if(m_Owner != null)
  51.         {
  52.             System.out.println("Owner is " + m_Owner.getUniqueID());
  53.         }
  54.         else
  55.         {
  56.             System.out.println("OWNER IS NULL");
  57.         }
  58.     }
  59.    
  60.     @Override
  61.     public void startExecuting()
  62.     {
  63.         m_Thing2 = 0;
  64.         m_AvoidsWater = m_Navigator.getAvoidsWater();
  65.         m_Navigator.setAvoidsWater(false);
  66.     }
  67.    
  68.     @Override
  69.     public boolean shouldExecute()
  70.     {
  71.         if(m_Owner != null)
  72.         {
  73.             if(m_Gotchi.getDistanceSqToEntity(m_Owner) < (double)(m_MinDistance * m_MaxDistance))
  74.             {
  75.                 return true;
  76.             }
  77.         }
  78.        
  79.         return false;
  80.     }
  81.    
  82.     @Override
  83.     public boolean continueExecuting()
  84.     {
  85.         if(m_Owner == null)
  86.         {
  87.             return false;
  88.         }
  89.         return !m_Navigator.noPath() && m_Gotchi.getDistanceSqToEntity(m_Owner) > (double)(this.m_MinDistance * this.m_MaxDistance);
  90.     }
  91.    
  92.     @Override
  93.     public void updateTask()
  94.     {
  95.         if(m_Owner != null)
  96.         {
  97.             m_Gotchi.getLookHelper().setLookPositionWithEntity(m_Owner, 10.0F, (float)m_Gotchi.getVerticalFaceSpeed());
  98.            
  99.             if(--m_Thing2 <= 0)
  100.             {
  101.                 m_Thing2 = 10;
  102.                
  103.                 if(!m_Navigator.tryMoveToEntityLiving(m_Owner, m_Thing1))
  104.                 {
  105.                     if(!m_Gotchi.getLeashed())
  106.                     {
  107.                         if(m_Gotchi.getDistanceSqToEntity(m_Owner) >= 144.0D)
  108.                         {
  109.                             int i = MathHelper.floor_double(m_Owner.posX);
  110.                             int k = MathHelper.floor_double(m_Owner.posZ);
  111.                             int j = MathHelper.floor_double(m_Owner.boundingBox.minY);
  112.                            
  113.                             //m_Gotchi.setLocationAndAngles((double)(i + 0.5F), (double)k, (double)(j + 0.5F), m_Gotchi.rotationYaw, m_Gotchi.rotationPitch);
  114.                             m_Gotchi.setLocationAndAngles(i, j, k, m_Gotchi.rotationYaw, m_Gotchi.rotationPitch);
  115.                             m_Navigator.clearPathEntity();
  116.                             return;
  117.                            
  118.                             /*
  119.                             for(int l = 0; l <= 4; ++l)
  120.                             {
  121.                                 for(int m = 0; m <= 4; ++m)
  122.                                 {
  123.                                     if((l < 1 || m < 1 || l > 3 || m > 3) && World.doesBlockHaveSolidTopSurface(m_World, i + l, k - 1, j + m) &&
  124.                                             m_World.getBlock(i + l, k, j + m).isNormalCube() && m_World.getBlock(i + l, k + 1, j + m).isNormalCube())
  125.                                     {
  126.                                         m_Gotchi.setLocationAndAngles((double)((float)(i + l) + 0.5F), (double)k, (double)((float)(j + m) + 0.5F), m_Gotchi.rotationYaw, m_Gotchi.rotationPitch);
  127.                                         m_Navigator.clearPathEntity();
  128.                                         return;
  129.                                     }
  130.                                 }
  131.                             }
  132.                             */
  133.                         }
  134.                     }
  135.                 }
  136.             }
  137.         }
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement