Advertisement
HalestormXV

Untitled

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