Guest User

Untitled

a guest
Oct 18th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.98 KB | None | 0 0
  1. package com.halestormxv.entity.goldspirits;
  2.  
  3. import java.util.Calendar;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.halestormxv.Main.handler.ExtendedPlayer;
  8. import com.halestormxv.entity.EntityCyclops;
  9. import com.halestormxv.entity.EntityLunarSpirit;
  10. import com.halestormxv.item.CelestialCraft_items;
  11. import com.halestormxv.item.celKey;
  12. import com.halestormxv.lib.RefStrings;
  13.  
  14. import net.minecraft.block.BlockColored;
  15. import net.minecraft.enchantment.Enchantment;
  16. import net.minecraft.enchantment.EnchantmentHelper;
  17. import net.minecraft.entity.Entity;
  18. import net.minecraft.entity.EntityAgeable;
  19. import net.minecraft.entity.EntityLivingBase;
  20. import net.minecraft.entity.IEntityLivingData;
  21. import net.minecraft.entity.IEntityOwnable;
  22. import net.minecraft.entity.IRangedAttackMob;
  23. import net.minecraft.entity.SharedMonsterAttributes;
  24. import net.minecraft.entity.ai.EntityAIArrowAttack;
  25. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  26. import net.minecraft.entity.ai.EntityAIBeg;
  27. import net.minecraft.entity.ai.EntityAIFollowOwner;
  28. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  29. import net.minecraft.entity.ai.EntityAILeapAtTarget;
  30. import net.minecraft.entity.ai.EntityAILookIdle;
  31. import net.minecraft.entity.ai.EntityAIMate;
  32. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  33. import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
  34. import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
  35. import net.minecraft.entity.ai.EntityAIPanic;
  36. import net.minecraft.entity.ai.EntityAISwimming;
  37. import net.minecraft.entity.ai.EntityAITargetNonTamed;
  38. import net.minecraft.entity.ai.EntityAITempt;
  39. import net.minecraft.entity.ai.EntityAIWander;
  40. import net.minecraft.entity.ai.EntityAIWatchClosest;
  41. import net.minecraft.entity.monster.EntityCreeper;
  42. import net.minecraft.entity.monster.EntityGhast;
  43. import net.minecraft.entity.monster.EntityMob;
  44. import net.minecraft.entity.passive.EntityAnimal;
  45. import net.minecraft.entity.passive.EntityHorse;
  46. import net.minecraft.entity.passive.EntitySheep;
  47. import net.minecraft.entity.passive.EntityTameable;
  48. import net.minecraft.entity.passive.EntityWolf;
  49. import net.minecraft.entity.player.EntityPlayer;
  50. import net.minecraft.entity.projectile.EntityArrow;
  51. import net.minecraft.init.Blocks;
  52. import net.minecraft.init.Items;
  53. import net.minecraft.item.ItemFood;
  54. import net.minecraft.item.ItemStack;
  55. import net.minecraft.nbt.NBTTagCompound;
  56. import net.minecraft.pathfinding.PathEntity;
  57. import net.minecraft.potion.Potion;
  58. import net.minecraft.potion.PotionEffect;
  59. import net.minecraft.util.DamageSource;
  60. import net.minecraft.world.EnumDifficulty;
  61. import net.minecraft.world.World;
  62. import net.minecraft.world.WorldProviderHell;
  63. import net.minecraftforge.common.ForgeHooks;
  64.  
  65. public class EntitySagittarius extends EntityTameable implements IEntityOwnable, IRangedAttackMob
  66. {
  67.     private float iAmE;
  68.     private float iAmF;
  69.     private int spiritSummonCost = 5;
  70.     private int spritTickCounter;
  71.     //private int poisonPulseFXCounter;
  72.     private final int SPIRIT_ID = 4;
  73.     private final float DAMAGE_BASE = (float) 30.0;
  74.     private final int DAMAGE_DIVIDER = 5;
  75.     private final double SPIRIT_BASE_HP = 40; //Divide this number by 2 to get the amount of hearts.
  76.     private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
  77.     private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
  78.  
  79.     public EntitySagittarius(World par1World) {
  80.         super(par1World);
  81.         this.setSize(.9F, 1.9F);
  82.         this.tasks.addTask(1, new EntityAISwimming(this));
  83.         this.tasks.addTask(2, this.aiSit);
  84.         this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
  85.         this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
  86.         this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  87.         this.tasks.addTask(9, new EntityAILookIdle(this));
  88.         this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
  89.         this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
  90.         this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
  91.         this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
  92.         this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityMob.class, 0, true));
  93.         this.addRandomArmor();
  94.         this.setTamed(false);
  95.  
  96.         if (par1World != null && !par1World.isRemote)
  97.         {
  98.             this.setCombatTask();
  99.         }
  100.  
  101.     }
  102.  
  103.     public void setCombatTask()
  104.     {
  105.         this.tasks.removeTask(this.aiAttackOnCollide);
  106.         this.tasks.removeTask(this.aiArrowAttack);
  107.         ItemStack itemstack = this.getHeldItem();
  108.  
  109.         if (itemstack != null && itemstack.getItem() == Items.bow)
  110.         {
  111.             this.tasks.addTask(4, this.aiArrowAttack);
  112.         }
  113.         else
  114.         {
  115.             this.tasks.addTask(4, this.aiAttackOnCollide);
  116.         }
  117.     }
  118.  
  119.     protected void addRandomArmor()
  120.     {
  121.         this.setCurrentItemOrArmor(0, new ItemStack(Items.bow));
  122.     }
  123.  
  124.     public boolean isAIEnabled(){
  125.         return true;
  126.     }
  127.  
  128.     protected void applyEntityAttributes(){
  129.         super.applyEntityAttributes();
  130.         this.setCustomNameTag("Sagittarius");
  131.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(SPIRIT_BASE_HP); //Divide the Number by 2 to get the Hearts in game.
  132.         this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.24000000417232513D);
  133.         this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(6.0D);
  134.     }
  135.  
  136.     public void setAttackTarget(EntityLivingBase p_70624_1_)
  137.     {
  138.         super.setAttackTarget(p_70624_1_);
  139.  
  140.         if (p_70624_1_ == null)
  141.         {
  142.             this.setAngry(false);
  143.         }
  144.         else if (!this.isTamed())
  145.         {
  146.             this.setAngry(true);
  147.         }
  148.     }
  149.  
  150.     public IEntityLivingData onSpawnWithEgg(IEntityLivingData sagi)
  151.     {
  152.         sagi = super.onSpawnWithEgg(sagi);
  153.         this.tasks.addTask(4, this.aiArrowAttack);
  154.         this.addRandomArmor();
  155.         this.enchantEquipment();
  156.         return sagi;
  157.     }
  158.  
  159.     /**
  160.      * Called when the entity is attacked.
  161.      */
  162.     @Override
  163.     public boolean attackEntityFrom(DamageSource targeted, float power)
  164.     {
  165.         if (this.isEntityInvulnerable())
  166.         {
  167.             return false;
  168.         }
  169.         else
  170.         {
  171.             Entity entity = targeted.getEntity();
  172.             this.aiSit.setSitting(false);
  173.  
  174.             if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
  175.             {
  176.                 power = (power + 12.0F) / 2.0F;
  177.             }
  178.  
  179.             return super.attackEntityFrom(targeted, power);
  180.         }
  181.     }
  182.  
  183.     @Override
  184.     public boolean attackEntityAsMob(Entity entity)
  185.     {
  186.         EntityLivingBase owner = this.getOwner();
  187.         if (owner instanceof EntityPlayer)
  188.         {
  189.             EntityPlayer player = (EntityPlayer) owner;
  190.             float damage = player.experienceTotal / DAMAGE_DIVIDER;
  191.             if ( damage >= DAMAGE_BASE )
  192.             {
  193.                 return entity.attackEntityFrom(DamageSource.causeMobDamage(this), damage); //i
  194.             }      
  195.         }
  196.         return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)DAMAGE_BASE); //i
  197.     }
  198.  
  199.     public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)
  200.     {
  201.         EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
  202.         int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
  203.         int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
  204.         entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.difficultySetting.getDifficultyId() * 0.11F));
  205.  
  206.         if (i > 0)
  207.         {
  208.             entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
  209.         }
  210.  
  211.         if (j > 0)
  212.         {
  213.             entityarrow.setKnockbackStrength(j);
  214.         }
  215.  
  216.         if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0)
  217.         {
  218.             entityarrow.setFire(100);
  219.         }
  220.  
  221.         this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
  222.         this.worldObj.spawnEntityInWorld(entityarrow);
  223.     }
  224.  
  225.     /**
  226.      * main AI tick function, replaces updateEntityActionState
  227.      */
  228.     protected void entityInit()
  229.     {
  230.         super.entityInit();
  231.         this.dataWatcher.addObject(18, new Float(this.getHealth()));
  232.         this.dataWatcher.addObject(19, new Byte((byte)0));
  233.         this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
  234.     }
  235.  
  236.     protected void updateAITick()
  237.     {
  238.         this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
  239.     }
  240.  
  241.     public boolean watchingYou()
  242.     {
  243.         return this.dataWatcher.getWatchableObjectByte(19) == 1;
  244.     }
  245.  
  246.     public void onUpdate()
  247.     {
  248.         super.onUpdate();
  249.         /////////////////Cost Handler\\\\\\\\\\\\\\\\\\\\\
  250.         spritTickCounter += 1;
  251.         if (spritTickCounter == 80)
  252.         {
  253.             EntityLivingBase owner = this.getOwner();
  254.             spritTickCounter = 0;
  255.             if (owner instanceof EntityPlayer)
  256.             {
  257.                 EntityPlayer player = (EntityPlayer) owner;
  258.                 player.addExperienceLevel(-spiritSummonCost);
  259.                 if (player.experienceTotal < spiritSummonCost)
  260.                 {
  261.                     ExtendedPlayer instance = ExtendedPlayer.get(player);
  262.                     instance.setSummoned(SPIRIT_ID, false);
  263.                     this.worldObj.removeEntity(this);
  264.                 }
  265.             }
  266.         }
  267.         ///////////////////////////////////////////////////
  268.         ///////////////// Slow Pulse  \\\\\\\\\\\\\\\\\\\\\
  269.         /*poisonPulseFXCounter += 1;
  270.         if (poisonPulseFXCounter == 400)
  271.         {
  272.             List<EntityLivingBase> targetList = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(6.0F, 6.0F, 6.0F));
  273.             EntityLivingBase owner = this.getOwner();  
  274.             poisonPulseFXCounter = 0;
  275.             for (EntityLivingBase targets : targetList)
  276.             {
  277.                 if ( targets != null)
  278.                 {
  279.                     if ( targets != this.getOwner() && targets != this)
  280.                     {
  281.                         targets.addPotionEffect(new PotionEffect(Potion.poison.getId(), 100, 5));
  282.                     }
  283.  
  284.                 }
  285.             }
  286.         }*/
  287.         ///////////////////////////////////////////////////
  288.         this.iAmF = this.iAmE;
  289.  
  290.         if (this.getOwner() == null)
  291.         {
  292.             this.setDead();
  293.         }
  294.  
  295.         //If Died Set Summoned to False
  296.         if (this.isDead)
  297.         {
  298.             EntityLivingBase owner = this.getOwner();
  299.             if (owner instanceof EntityPlayer)
  300.             {
  301.                 EntityPlayer player = (EntityPlayer) owner;
  302.                 ExtendedPlayer instance = ExtendedPlayer.get(player);
  303.                 instance.setSummoned(SPIRIT_ID, false);
  304.             }
  305.         }
  306.  
  307.         if (this.watchingYou())
  308.         {
  309.             this.iAmE += (1.0F - this.iAmF) * 0.4F;
  310.         }
  311.         else
  312.         {
  313.             this.iAmF += (0.0F - this.iAmE) * 0.4F;
  314.         }
  315.  
  316.         if (this.watchingYou())
  317.         {
  318.             this.numTicksToChaseTarget = 10;
  319.         }
  320.     }
  321.  
  322.     public void onLivingUpdate()
  323.     {
  324.         super.onLivingUpdate();
  325.  
  326.         if (!this.worldObj.isRemote && !this.hasPath() && this.onGround)
  327.         {
  328.             this.worldObj.setEntityState(this, (byte)8);           
  329.         }
  330.     }
  331.  
  332.     @Override
  333.     public void writeEntityToNBT(NBTTagCompound p_70014_1_)
  334.     {
  335.         //super.writeEntityToNBT(p_70014_1_);
  336.         //p_70014_1_.setBoolean("Hostile", this.isAngry());
  337.         //p_70014_1_.setByte("ColorCollar", (byte)this.getCollarColor());
  338.     }
  339.  
  340.     @Override
  341.     public void readEntityFromNBT(NBTTagCompound p_70037_1_)
  342.     {
  343.         //super.readEntityFromNBT(p_70037_1_);
  344.         //this.setAngry(p_70037_1_.getBoolean("Hostile"));
  345.  
  346.         //if (p_70037_1_.hasKey("ColorCollar", 99))
  347.         //{
  348.         //  this.setCollarColor(p_70037_1_.getByte("ColorCollar"));
  349.         //}
  350.     }
  351.  
  352.     /**
  353.      * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
  354.      */
  355.     public boolean interact(EntityPlayer player)
  356.     {
  357.         ItemStack itemstack = player.inventory.getCurrentItem();
  358.  
  359.         if (this.isTamed())
  360.         {
  361.             if (itemstack != null)
  362.             {
  363.                 if (itemstack.getItem() instanceof ItemFood)
  364.                 {
  365.                     ItemFood itemfood = (ItemFood)itemstack.getItem();
  366.  
  367.                     if ( (itemfood == CelestialCraft_items.celApple) && (this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) )
  368.                     {
  369.                         if (!player.capabilities.isCreativeMode)
  370.                         {
  371.                             --itemstack.stackSize;
  372.                         }
  373.  
  374.                         this.heal((float)itemfood.func_150905_g(itemstack));
  375.  
  376.                         if (itemstack.stackSize <= 0)
  377.                         {
  378.                             player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
  379.                         }
  380.  
  381.                         return true;
  382.                     }
  383.                 }
  384.                 else if (itemstack.getItem() == Items.dye)
  385.                 {
  386.                     int i = BlockColored.func_150032_b(itemstack.getItemDamage());
  387.  
  388.                     if (i != this.getCollarColor())
  389.                     {
  390.                         this.setCollarColor(i);
  391.  
  392.                         if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
  393.                         {
  394.                             player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
  395.                         }
  396.  
  397.                         return true;
  398.                     }
  399.                 }
  400.             }
  401.  
  402.         }
  403.         if (itemstack != null && itemstack.getItem() == CelestialCraft_items.celApple && !this.isAngry())
  404.         {
  405.             if (!player.capabilities.isCreativeMode)
  406.             {
  407.                 --itemstack.stackSize;
  408.             }
  409.  
  410.             if (itemstack.stackSize <= 0)
  411.             {
  412.                 player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
  413.             }
  414.  
  415.             if (!this.worldObj.isRemote)
  416.             {
  417.                 if (this.rand.nextInt(3) == 0)
  418.                 {
  419.                     this.setTamed(true);
  420.                     this.setPathToEntity((PathEntity)null);
  421.                     this.setAttackTarget((EntityLivingBase)null);
  422.                     this.aiSit.setSitting(true);
  423.                     this.setHealth(20.0F);
  424.                     this.func_152115_b(player.getUniqueID().toString());
  425.                     this.playTameEffect(true);
  426.                     this.worldObj.setEntityState(this, (byte)7);
  427.                 }
  428.                 else
  429.                 {
  430.                     this.playTameEffect(false);
  431.                     this.worldObj.setEntityState(this, (byte)6);
  432.                 }
  433.             }
  434.  
  435.             return true;
  436.         }
  437.  
  438.         return super.interact(player);
  439.     }
  440.  
  441.     public boolean isAngry()
  442.     {
  443.         return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
  444.     }
  445.  
  446.     /**
  447.      * Sets whether this wolf is angry or not.
  448.      */
  449.     public void setAngry(boolean p_70916_1_)
  450.     {
  451.         byte b0 = this.dataWatcher.getWatchableObjectByte(16);
  452.  
  453.         if (p_70916_1_)
  454.         {
  455.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
  456.         }
  457.         else
  458.         {
  459.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
  460.         }
  461.     }
  462.  
  463.     /**
  464.      * Return this Aries's collar color.
  465.      */
  466.     public int getCollarColor()
  467.     {
  468.         return this.dataWatcher.getWatchableObjectByte(20) & 15;
  469.     }
  470.  
  471.     /**
  472.      * Set this Aries's collar color.
  473.      */
  474.     public void setCollarColor(int p_82185_1_)
  475.     {
  476.         this.dataWatcher.updateObject(20, Byte.valueOf((byte)(p_82185_1_ & 15)));
  477.     }
  478.  
  479.     protected boolean canDespawn()
  480.     {
  481.         return !this.isTamed() && this.ticksExisted > 2400;
  482.     }
  483.  
  484.     public boolean func_142018_a(EntityLivingBase target, EntityLivingBase summoner)
  485.     {
  486.         if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast))
  487.         {
  488.             if (target instanceof EntitySagittarius)
  489.             {
  490.                 EntitySagittarius entityspirit = (EntitySagittarius)target;
  491.  
  492.                 if (entityspirit.isTamed() && entityspirit.getOwner() == summoner)
  493.                 {
  494.                     return false;
  495.                 }
  496.             }
  497.  
  498.             return target instanceof EntityPlayer && summoner instanceof EntityPlayer && !((EntityPlayer)summoner).canAttackPlayer((EntityPlayer)target)
  499.                     && target instanceof EntityCyclops && target instanceof EntityLunarSpirit ? false : !(target instanceof EntityHorse) || !((EntityHorse)target).isTame();
  500.         }
  501.         else
  502.         {
  503.             return false;
  504.         }
  505.     }
  506.  
  507.     @Override
  508.     public EntityAgeable createChild(EntityAgeable var1) {
  509.         return new EntitySagittarius(worldObj);
  510.     }
  511.  
  512.  
  513. }
Advertisement
Add Comment
Please, Sign In to add comment