Advertisement
Guest User

Untitled

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