Advertisement
Guest User

Untitled

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