Advertisement
Guest User

Untitled

a guest
May 13th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1. package CustomDesires;
  2.  
  3. import org.bukkit.entity.Entity;
  4.  
  5. import java.util.*;
  6. import net.minecraft.server.v1_5_R3.*;
  7. import de.kumpelblase2.remoteentities.api.RemoteEntity;
  8. import de.kumpelblase2.remoteentities.api.thinking.DesireType;
  9. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireTargetBase;
  10. import de.kumpelblase2.remoteentities.persistence.ParameterData;
  11. import de.kumpelblase2.remoteentities.persistence.SerializeAs;
  12. import de.kumpelblase2.remoteentities.utilities.NMSClassMap;
  13. import de.kumpelblase2.remoteentities.utilities.ReflectionUtil;
  14.  
  15. public class DesireFindEnemyMinion extends DesireTargetBase{
  16.  
  17.     @SerializeAs(pos = 5)
  18.     protected int m_targetChance;
  19.     @SerializeAs(pos = 4)
  20.     protected Class<? extends Entity> m_targetClass;
  21.     protected DistanceComparator m_comparator;
  22.     protected EntityLiving m_target;
  23.     @SerializeAs(pos = 6)
  24.     protected IEntitySelector m_selector;
  25.     protected boolean m_onlyAtNight;
  26.    
  27.     public DesireFindEnemyMinion(RemoteEntity inEntity,Class<?> inTargetClass,float inDistance, boolean inShouldCheckSight, int inChance,IEntitySelector inSelecto)
  28.     {
  29.         this(inEntity,inTargetClass, inDistance, inShouldCheckSight, false, inChance, inSelecto);
  30.     }
  31.    
  32.     @SuppressWarnings("unchecked")
  33.     public DesireFindEnemyMinion(RemoteEntity inEntity, Class<?> inTargetClass, float inDistance, boolean inShouldCheckSight, boolean inShouldMelee, int inChance, IEntitySelector inSelector)
  34.     {
  35.         super(inEntity, inDistance, inShouldCheckSight, inShouldMelee);
  36.         this.m_comparator = new DistanceComparator(null, this.getEntityHandle());
  37.         this.m_targetChance = inChance;
  38.        
  39.         if(Entity.class.isAssignableFrom(inTargetClass))
  40.             this.m_targetClass = (Class<? extends Entity>)inTargetClass;
  41.         else
  42.             this.m_targetClass = (Class<? extends Entity>)NMSClassMap.getNMSClass(inTargetClass);
  43.    
  44.         this.m_onlyAtNight = false;
  45.         this.m_type = DesireType.PRIMAL_INSTINCT;
  46.         this.m_selector = inSelector;
  47.     }
  48.  
  49.    
  50.     @SuppressWarnings("unchecked")
  51.     @Override
  52.     public boolean shouldExecute()
  53.     {
  54.         if(this.getEntityHandle() == null)
  55.             return false;
  56.    
  57.         if(this.m_onlyAtNight && this.getEntityHandle().world.v())
  58.             return false;
  59.         else if(this.m_targetChance > 0 && this.getEntityHandle().aE().nextInt(this.m_targetChance) != 0)
  60.             return false;
  61.         else
  62.         {
  63.             if(this.m_targetClass == EntityHuman.class)
  64.             {
  65.                 return false;
  66.             }
  67.             else
  68.             {
  69.                 List<EntityLiving> entities = this.getEntityHandle().world.a(this.m_targetClass, this.getEntityHandle().boundingBox.grow(this.m_distance, 4, this.m_distance), this.m_selector);
  70.                 Collections.sort(entities, this.m_comparator);
  71.                 Iterator<EntityLiving> it = entities.iterator();
  72.                 while(it.hasNext())
  73.                 {
  74.                     EntityLiving entity = it.next();
  75.                         if(this.isSuitableTarget(entity, false) && !entity.getCustomName().split("[")[0].equals(this.getRemoteEntity().getBukkitEntity().getCustomName().split("[")[0]))
  76.                         {
  77.                             if(it instanceof EntityHuman){
  78.                                 return false;
  79.                             }
  80.                             this.m_target = entity;
  81.                             return true;
  82.                         }
  83.                 }
  84.             }
  85.     return false;
  86.     }
  87.     }
  88.    
  89.     @Override
  90.     public void startExecuting()
  91.     {
  92.         this.getEntityHandle().setGoalTarget(this.m_target);
  93.         super.startExecuting();
  94.     }
  95.    
  96.     @Override
  97.     public ParameterData[] getSerializeableData()
  98.     {
  99.         return ReflectionUtil.getParameterDataForClass(this).toArray(new ParameterData[0]);
  100.     }
  101.  
  102.    
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement