Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.halestormxv.entity;
  2.  
  3. import com.halestormxv.item.CelestialCraft_items;
  4.  
  5. import net.minecraft.block.BlockColored;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityAgeable;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.SharedMonsterAttributes;
  10. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  11. import net.minecraft.entity.ai.EntityAIBeg;
  12. import net.minecraft.entity.ai.EntityAIFollowOwner;
  13. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  14. import net.minecraft.entity.ai.EntityAILeapAtTarget;
  15. import net.minecraft.entity.ai.EntityAILookIdle;
  16. import net.minecraft.entity.ai.EntityAIMate;
  17. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  18. import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
  19. import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
  20. import net.minecraft.entity.ai.EntityAIPanic;
  21. import net.minecraft.entity.ai.EntityAISwimming;
  22. import net.minecraft.entity.ai.EntityAITargetNonTamed;
  23. import net.minecraft.entity.ai.EntityAITempt;
  24. import net.minecraft.entity.ai.EntityAIWander;
  25. import net.minecraft.entity.ai.EntityAIWatchClosest;
  26. import net.minecraft.entity.monster.EntityCreeper;
  27. import net.minecraft.entity.monster.EntityGhast;
  28. import net.minecraft.entity.monster.EntityMob;
  29. import net.minecraft.entity.passive.EntityAnimal;
  30. import net.minecraft.entity.passive.EntityHorse;
  31. import net.minecraft.entity.passive.EntitySheep;
  32. import net.minecraft.entity.passive.EntityTameable;
  33. import net.minecraft.entity.passive.EntityWolf;
  34. import net.minecraft.entity.player.EntityPlayer;
  35. import net.minecraft.entity.projectile.EntityArrow;
  36. import net.minecraft.init.Items;
  37. import net.minecraft.item.ItemFood;
  38. import net.minecraft.item.ItemStack;
  39. import net.minecraft.nbt.NBTTagCompound;
  40. import net.minecraft.pathfinding.PathEntity;
  41. import net.minecraft.util.DamageSource;
  42. import net.minecraft.world.World;
  43. import net.minecraftforge.common.ForgeHooks;
  44.  
  45. public class EntityAries extends EntityTameable
  46. {
  47.     private float iAmE;
  48.     private float iAmF;
  49.     public EntityAries(World par1World) {
  50.         super(par1World);
  51.         //First Argument is Priority, Second Argument taken from net.minecraft.entity.ai
  52.         this.setSize(.9F, 1.9F);   
  53.         this.tasks.addTask(1, new EntityAISwimming(this));
  54.         this.tasks.addTask(2, this.aiSit);
  55.         this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
  56.         this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
  57.         this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
  58.         this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
  59.         this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  60.         this.tasks.addTask(9, new EntityAILookIdle(this));
  61.         this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
  62.         this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
  63.         this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
  64.         this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
  65.         this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityMob.class, 0, true));
  66.         this.setTamed(false);
  67.        
  68.     }
  69.    
  70.     public boolean isAIEnabled(){
  71.         return true;
  72.     }
  73.    
  74.     protected void applyEntityAttributes(){
  75.         super.applyEntityAttributes();
  76.         this.setCustomNameTag("Aries");
  77.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40); //Divide the Number by 2 to get the Hearts in game.
  78.         this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
  79.         this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(6.0D);
  80.     }
  81.    
  82.     public void setAttackTarget(EntityLivingBase p_70624_1_)
  83.     {
  84.         super.setAttackTarget(p_70624_1_);
  85.  
  86.         if (p_70624_1_ == null)
  87.         {
  88.             this.setAngry(false);
  89.         }
  90.         else if (!this.isTamed())
  91.         {
  92.             this.setAngry(true);
  93.         }
  94.     }
  95.    
  96.     /**
  97.      * Called when the entity is attacked.
  98.      */
  99.     public boolean attackEntityFrom(DamageSource targeted, float power)
  100.     {
  101.         if (this.isEntityInvulnerable())
  102.         {
  103.             return false;
  104.         }
  105.         else
  106.         {
  107.             Entity entity = targeted.getEntity();
  108.             this.aiSit.setSitting(false);
  109.  
  110.             if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
  111.             {
  112.                 power = (power + 12.0F) / 2.0F;
  113.             }
  114.  
  115.             return super.attackEntityFrom(targeted, power);
  116.         }
  117.     }
  118.  
  119.     public boolean attackEntityAsMob(Entity entity)
  120.     {
  121.         int i = this.isTamed() ? 4 : 2;
  122.         return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);
  123.     }
  124.  
  125.     /**
  126.      * main AI tick function, replaces updateEntityActionState
  127.      */
  128.     protected void entityInit()
  129.     {
  130.         super.entityInit();
  131.         this.dataWatcher.addObject(18, new Float(this.getHealth()));
  132.         this.dataWatcher.addObject(19, new Byte((byte)0));
  133.         this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
  134.     }
  135.    
  136.     protected void updateAITick()
  137.     {
  138.         this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
  139.     }
  140.    
  141.     public boolean watchingYou()
  142.     {
  143.         return this.dataWatcher.getWatchableObjectByte(19) == 1;
  144.     }
  145.    
  146.     public void onUpdate()
  147.     {
  148.         super.onUpdate();
  149.         this.iAmF = this.iAmE;
  150.  
  151.         if (this.watchingYou())
  152.         {
  153.             this.iAmE += (1.0F - this.iAmF) * 0.4F;
  154.         }
  155.         else
  156.         {
  157.             this.iAmF += (0.0F - this.iAmE) * 0.4F;
  158.         }
  159.  
  160.         if (this.watchingYou())
  161.         {
  162.             this.numTicksToChaseTarget = 10;
  163.         }
  164.     }
  165.     /**
  166.      * (abstract) Protected helper method to write subclass entity data to NBT.
  167.      */
  168.     public void writeEntityToNBT(NBTTagCompound p_70014_1_)
  169.     {
  170.         super.writeEntityToNBT(p_70014_1_);
  171.         p_70014_1_.setBoolean("Hostile", this.isAngry());
  172.         p_70014_1_.setByte("ColorCollar", (byte)this.getCollarColor());
  173.     }
  174.  
  175.     /**
  176.      * (abstract) Protected helper method to read subclass entity data from NBT.
  177.      */
  178.     public void readEntityFromNBT(NBTTagCompound p_70037_1_)
  179.     {
  180.         super.readEntityFromNBT(p_70037_1_);
  181.         this.setAngry(p_70037_1_.getBoolean("Hostile"));
  182.  
  183.         if (p_70037_1_.hasKey("ColorCollar", 99))
  184.         {
  185.             this.setCollarColor(p_70037_1_.getByte("ColorCollar"));
  186.         }
  187.     }
  188.    
  189.     /**
  190.      * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
  191.      */
  192.     public boolean interact(EntityPlayer p_70085_1_)
  193.     {
  194.         ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();
  195.  
  196.         if (this.isTamed())
  197.         {
  198.             if (itemstack != null)
  199.             {
  200.                 if (itemstack.getItem() instanceof ItemFood)
  201.                 {
  202.                     ItemFood itemfood = (ItemFood)itemstack.getItem();
  203.  
  204.                     if ( (itemfood == CelestialCraft_items.celApple) && (this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) )
  205.                     {
  206.                         if (!p_70085_1_.capabilities.isCreativeMode)
  207.                         {
  208.                             --itemstack.stackSize;
  209.                         }
  210.  
  211.                         this.heal((float)itemfood.func_150905_g(itemstack));
  212.  
  213.                         if (itemstack.stackSize <= 0)
  214.                         {
  215.                             p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
  216.                         }
  217.  
  218.                         return true;
  219.                     }
  220.                 }
  221.                 else if (itemstack.getItem() == Items.dye)
  222.                 {
  223.                     int i = BlockColored.func_150032_b(itemstack.getItemDamage());
  224.  
  225.                     if (i != this.getCollarColor())
  226.                     {
  227.                         this.setCollarColor(i);
  228.  
  229.                         if (!p_70085_1_.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
  230.                         {
  231.                             p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
  232.                         }
  233.  
  234.                         return true;
  235.                     }
  236.                 }
  237.             }
  238.  
  239.         }
  240.         if (itemstack != null && itemstack.getItem() == Items.bone && !this.isAngry())
  241.         {
  242.             if (!p_70085_1_.capabilities.isCreativeMode)
  243.             {
  244.                 --itemstack.stackSize;
  245.             }
  246.  
  247.             if (itemstack.stackSize <= 0)
  248.             {
  249.                 p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
  250.             }
  251.  
  252.             if (!this.worldObj.isRemote)
  253.             {
  254.                 if (this.rand.nextInt(3) == 0)
  255.                 {
  256.                     this.setTamed(true);
  257.                     this.setPathToEntity((PathEntity)null);
  258.                     this.setAttackTarget((EntityLivingBase)null);
  259.                     this.aiSit.setSitting(true);
  260.                     this.setHealth(20.0F);
  261.                     this.func_152115_b(p_70085_1_.getUniqueID().toString());
  262.                     this.playTameEffect(true);
  263.                     this.worldObj.setEntityState(this, (byte)7);
  264.                 }
  265.                 else
  266.                 {
  267.                     this.playTameEffect(false);
  268.                     this.worldObj.setEntityState(this, (byte)6);
  269.                 }
  270.             }
  271.  
  272.             return true;
  273.         }
  274.  
  275.         return super.interact(p_70085_1_);
  276.     }
  277.            
  278.             public boolean isAngry()
  279.             {
  280.                 return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
  281.             }
  282.  
  283.             /**
  284.              * Sets whether this wolf is angry or not.
  285.              */
  286.             public void setAngry(boolean p_70916_1_)
  287.             {
  288.                 byte b0 = this.dataWatcher.getWatchableObjectByte(16);
  289.  
  290.                 if (p_70916_1_)
  291.                 {
  292.                     this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
  293.                 }
  294.                 else
  295.                 {
  296.                     this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
  297.                 }
  298.             }
  299.  
  300.             /**
  301.              * Return this Aries's collar color.
  302.              */
  303.             public int getCollarColor()
  304.             {
  305.                 return this.dataWatcher.getWatchableObjectByte(20) & 15;
  306.             }
  307.  
  308.             /**
  309.              * Set this Aries's collar color.
  310.              */
  311.             public void setCollarColor(int p_82185_1_)
  312.             {
  313.                 this.dataWatcher.updateObject(20, Byte.valueOf((byte)(p_82185_1_ & 15)));
  314.             }
  315.            
  316.             protected boolean canDespawn()
  317.             {
  318.                 return !this.isTamed() && this.ticksExisted > 2400;
  319.             }
  320.            
  321.             public boolean func_142018_a(EntityLivingBase target, EntityLivingBase summoner)
  322.             {
  323.                 if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast))
  324.                 {
  325.                     if (target instanceof EntityAries)
  326.                     {
  327.                         EntityAries entityaries = (EntityAries)target;
  328.  
  329.                         if (entityaries.isTamed() && entityaries.getOwner() == summoner)
  330.                         {
  331.                             return false;
  332.                         }
  333.                     }
  334.  
  335.                     return target instanceof EntityPlayer && summoner instanceof EntityPlayer && !((EntityPlayer)summoner).canAttackPlayer((EntityPlayer)target) && target instanceof EntityCyclops && target instanceof EntityLunarSpirit ? false : !(target instanceof EntityHorse) || !((EntityHorse)target).isTame();
  336.                 }
  337.                 else
  338.                 {
  339.                     return false;
  340.                 }
  341.             }
  342.            
  343.             @Override
  344.             public EntityAgeable createChild(EntityAgeable var1) {
  345.                 return new EntityAries(worldObj);
  346.             }
  347.            
  348.  
  349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement