Advertisement
hassansyyid

Untitled

Jul 9th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.21 KB | None | 0 0
  1. package com.arisux.avp.entities.mob;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.arisux.avp.AliensVsPredator;
  6. import com.arisux.avp.entities.EntityAcidPool;
  7. import com.arisux.avp.entities.EntityAcidProjectile;
  8.  
  9. import net.minecraft.entity.*;
  10. import net.minecraft.entity.ai.*;
  11. import net.minecraft.entity.passive.EntityAnimal;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.world.World;
  15.  
  16. public class EntitySpitter extends EntityXenomorph implements IRangedAttackMob
  17. {
  18.     public EntitySpitter(World par1World)
  19.     {
  20.         super(par1World);
  21.         this.experienceValue = 275;
  22.         this.setSize(1.0F, 3.0F);
  23.     }
  24.  
  25.     @Override
  26.     protected void applyEntityAttributes()
  27.     {
  28.         super.applyEntityAttributes();
  29.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(30.0D);
  30.         this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5500000238418579D);
  31.         this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(4.0D);
  32.     }
  33.  
  34.     @Override
  35.     protected boolean isAIEnabled()
  36.     {
  37.         return true;
  38.     }
  39.  
  40.     @Override
  41.     protected String getHurtSound()
  42.     {
  43.         return AliensVsPredator.properties().SOUND_SPITTER_HURT;
  44.     }
  45.  
  46.     @Override
  47.     protected String getLivingSound()
  48.     {
  49.         return AliensVsPredator.properties().SOUND_SPITTER_LIVING;
  50.     }
  51.  
  52.     @Override
  53.     protected String getDeathSound()
  54.     {
  55.         return AliensVsPredator.properties().SOUND_SPITTER_DEATH;
  56.     }
  57.  
  58.     @Override
  59.     public int getTotalArmorValue()
  60.     {
  61.         return 2;
  62.     }
  63.  
  64.     @Override
  65.     public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float f)
  66.     {
  67.         if (!par1EntityLivingBase.isDead)
  68.         {
  69.             this.getLookHelper().setLookPosition(par1EntityLivingBase.posX, par1EntityLivingBase.posY + par1EntityLivingBase.getEyeHeight(), par1EntityLivingBase.posZ, 10.0F, this.getVerticalFaceSpeed());
  70.  
  71.             if (this.canEntityBeSeen(par1EntityLivingBase))
  72.             {
  73.                 int attackDamage = 2;
  74.  
  75.                 EntityAcidProjectile entityacid = new EntityAcidProjectile(this.worldObj, this, par1EntityLivingBase, 1.6F, 14 - attackDamage * 4);
  76.                 entityacid.setDamage(f * 2.0F + this.rand.nextGaussian() * 0.25D + attackDamage * 0.11F);
  77.                 this.worldObj.spawnEntityInWorld(entityacid);
  78.             }
  79.         }
  80.     }
  81.    
  82.     @Override
  83.     protected void dropRareDrop(int par1)
  84.     {
  85.         if (new Random().nextInt(4) == 1)
  86.             this.entityDropItem(new ItemStack(AliensVsPredator.items().helmXeno), 1);
  87.         if (new Random().nextInt(4) == 1)
  88.             this.entityDropItem(new ItemStack(AliensVsPredator.items().plateXeno), 1);
  89.         if (new Random().nextInt(4) == 1)
  90.             this.entityDropItem(new ItemStack(AliensVsPredator.items().legsXeno), 1);
  91.         if (new Random().nextInt(4) == 1)
  92.             this.entityDropItem(new ItemStack(AliensVsPredator.items().bootsXeno), 1);
  93.  
  94.         super.dropRareDrop(par1);
  95.     }
  96.    
  97.     @Override
  98.     public void attackAI()
  99.     {
  100.         if (worldObj.getWorldInfo().getWorldTime() % 70 == 0)
  101.         {
  102.             double range = this.getEntityAttribute(SharedMonsterAttributes.followRange).getAttributeValue();
  103.             Entity targetEntity = (this.worldObj.findNearestEntityWithinAABB(EntityLiving.class, this.boundingBox.expand(range * 2, 64.0D, range * 2), this));
  104.             Entity targetPlayer = (this.worldObj.findNearestEntityWithinAABB(EntityPlayer.class, this.boundingBox.expand(range * 2, 64.0D, range * 2), this));
  105.             if (targetPlayer != null && !((EntityPlayer) targetPlayer).capabilities.isCreativeMode)
  106.             {
  107.                 this.setAttackTarget((EntityLivingBase) targetPlayer);
  108.                 this.getMoveHelper().setMoveTo(this.getAttackTarget().posX, this.getAttackTarget().posY, this.getAttackTarget().posZ, 1D);
  109.                 if (this.isCollidedHorizontally)
  110.                 {
  111.                     this.addVelocity(0, 0.6D, 0);
  112.                 }
  113.             }
  114.             else if (targetEntity != null && !(targetEntity instanceof EntityAcidPool) && !(targetEntity.getClass().getSuperclass().getSuperclass() == EntitySpeciesAlien.class) && !(targetEntity.getClass().getSuperclass() == EntitySpeciesAlien.class))
  115.             {
  116.                 this.setAttackTarget((EntityLivingBase) targetEntity);
  117.                 this.getMoveHelper().setMoveTo(this.getAttackTarget().posX, this.getAttackTarget().posY, this.getAttackTarget().posZ, 1D);
  118.                 if (this.isCollidedHorizontally)
  119.                 {
  120.                     this.addVelocity(0, 0.6D, 0);
  121.                 }
  122.             }
  123.             else
  124.             {
  125.                 this.setAttackTarget(null);
  126.             }
  127.         }
  128.     }
  129.  
  130.     @Override
  131.     public void onUpdate()
  132.     {
  133.         //Finds Target
  134.         this.attackAI();
  135.  
  136.         //Checks if it's dead or not
  137.         if(this.getAttackTarget() != null && this.getAttackTarget().isDead)
  138.         {
  139.             this.setAttackTarget(null);
  140.         }
  141.        
  142.         //Attacks it
  143.         else if(this.getAttackTarget() != null)
  144.         {
  145.             if(this.getAttackTarget() instanceof EntityPlayer)
  146.             {
  147.                 EntityPlayer target = (EntityPlayer) this.getAttackTarget();
  148.                 //If it's in creative mode stop attacking
  149.                 if(target.capabilities.isCreativeMode)
  150.                 {
  151.                     this.setAttackTarget(null);
  152.                     return;
  153.                 }
  154.                 else
  155.                 {
  156.                     if(this.getDistance(this.getAttackTarget().posX, this.getAttackTarget().posY, this.getAttackTarget().posZ) < 10)
  157.                     {
  158.                         this.attackEntityWithRangedAttack(this.getAttackTarget(), 0.05F);
  159.                     }
  160.                 }
  161.             }
  162.             if(this.getDistance(this.getAttackTarget().posX, this.getAttackTarget().posY, this.getAttackTarget().posZ) < 10)
  163.             {
  164.                 this.attackEntityWithRangedAttack(this.getAttackTarget(), 0.05F);
  165.             }
  166.         }
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement