Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. package fr.mff.facmod.entity.AI;
  2.  
  3. import java.util.Collections;
  4. import java.util.Comparator;
  5. import java.util.List;
  6.  
  7. import com.google.common.base.Predicate;
  8.  
  9. import fr.mff.facmod.entity.EntityFactionGuardian;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.EntityCreature;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.IEntityOwnable;
  14. import net.minecraft.entity.ai.EntityAIDefendVillage;
  15. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  16. import net.minecraft.entity.ai.EntityAITarget;
  17. import net.minecraft.entity.monster.EntityIronGolem;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.util.EntitySelectors;
  20.  
  21. public class EntityAIGuardian
  22.   extends EntityAITarget
  23. {
  24.   private final Class targetClass;
  25.   private final int targetChance;
  26.   private EntityFactionGuardian golem;
  27.   private final EntityAINearestAttackableTarget.Sorter theNearestAttackableTargetSorter;
  28.   private final IEntitySelector targetEntitySelector;
  29.   private EntityLivingBase targetEntity;
  30.   private static final String __OBFID = "CL_00001620";
  31.  
  32.   public EntityAIGuardian(EntityFactionGuardian p_i1663_1_, Class p_i1663_2_, int p_i1663_3_, boolean p_i1663_4_)
  33.   {
  34.     this(p_i1663_1_, p_i1663_2_, p_i1663_3_, p_i1663_4_, false);
  35.     this.golem = p_i1663_1_;
  36.       System.out.println("test");
  37.  
  38.   }
  39.  
  40.   public EntityAIGuardian(EntityFactionGuardian p_i1664_1_, Class p_i1664_2_, int p_i1664_3_, boolean p_i1664_4_, boolean p_i1664_5_)
  41.   {
  42.     this(p_i1664_1_, p_i1664_2_, p_i1664_3_, p_i1664_4_, p_i1664_5_, (IEntitySelector)null);
  43.     this.golem = p_i1664_1_;
  44.       System.out.println("test"); //marche
  45.  
  46.   }
  47.  
  48.   public EntityAIGuardian(EntityCreature p_i1665_1_, Class p_i1665_2_, int p_i1665_3_, boolean p_i1665_4_, boolean p_i1665_5_, IEntitySelector p_i1665_6_)
  49.   {
  50.     super(p_i1665_1_, p_i1665_4_, p_i1665_5_);
  51.       System.out.println("test"); // marche
  52.     this.targetClass = p_i1665_2_;
  53.     this.targetChance = p_i1665_3_;
  54.     this.theNearestAttackableTargetSorter = new EntityAINearestAttackableTarget.Sorter(p_i1665_1_);
  55.     setMutexBits(1);
  56.     this.targetEntitySelector = new IEntitySelector(){
  57.       public boolean isEntityApplicable(Entity entity)
  58.       {
  59.           System.out.println("test"); // marche pas
  60.         if ((entity instanceof EntityPlayer))
  61.         {
  62.           EntityPlayer player = (EntityPlayer)entity;
  63.           if ((!EntityAIGuardian.this.golem.checkWhitelist((EntityPlayer)entity)) && (!player.capabilities.isCreativeMode)) {
  64.             return true;
  65.           }
  66.         }
  67.         return false;
  68.       }
  69.     };
  70.   }
  71.  
  72.   public void startExecuting()
  73.   {
  74.     this.taskOwner.setAttackTarget(this.targetEntity);
  75.     super.startExecuting();
  76.   }
  77.  
  78.   public static class Sorter
  79.     implements Comparator
  80.   {
  81.     private final Entity theEntity;
  82.    
  83.     public Sorter(Entity p_i1662_1_)
  84.     {
  85.       this.theEntity = p_i1662_1_;
  86.     }
  87.    
  88.     public int compare(Entity p_compare_1_, Entity p_compare_2_)
  89.     {
  90.       double d0 = this.theEntity.getDistanceSqToEntity(p_compare_1_);
  91.       double d1 = this.theEntity.getDistanceSqToEntity(p_compare_2_);
  92.       return d0 < d1 ? -1 : d0 > d1 ? 1 : 0;
  93.     }
  94.    
  95.     public int compare(Object p_compare_1_, Object p_compare_2_)
  96.     {
  97.       return compare((Entity)p_compare_1_, (Entity)p_compare_2_);
  98.     }
  99.   }
  100.  
  101.  public boolean shouldExecute()
  102.    {
  103.      if ((this.targetChance > 0) && (this.taskOwner.getRNG().nextInt(this.targetChance) != 0))
  104.   {
  105.      return false;
  106.   }
  107.    return true;
  108.    }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement