Guest User

Untitled

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