Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.halestormxv.entity.goldspirits;
- import java.util.Calendar;
- import java.util.List;
- import java.util.Random;
- import com.halestormxv.Main.handler.ExtendedPlayer;
- import com.halestormxv.entity.EntityCyclops;
- import com.halestormxv.entity.EntityLunarSpirit;
- import com.halestormxv.item.CelestialCraft_items;
- import com.halestormxv.item.celKey;
- import com.halestormxv.lib.RefStrings;
- import net.minecraft.block.BlockColored;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityAgeable;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.IEntityLivingData;
- import net.minecraft.entity.IEntityOwnable;
- import net.minecraft.entity.IRangedAttackMob;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.EntityAIArrowAttack;
- import net.minecraft.entity.ai.EntityAIAttackOnCollide;
- import net.minecraft.entity.ai.EntityAIBeg;
- import net.minecraft.entity.ai.EntityAIFollowOwner;
- import net.minecraft.entity.ai.EntityAIHurtByTarget;
- import net.minecraft.entity.ai.EntityAILeapAtTarget;
- import net.minecraft.entity.ai.EntityAILookIdle;
- import net.minecraft.entity.ai.EntityAIMate;
- import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
- import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
- import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
- import net.minecraft.entity.ai.EntityAIPanic;
- import net.minecraft.entity.ai.EntityAISwimming;
- import net.minecraft.entity.ai.EntityAITargetNonTamed;
- import net.minecraft.entity.ai.EntityAITempt;
- import net.minecraft.entity.ai.EntityAIWander;
- import net.minecraft.entity.ai.EntityAIWatchClosest;
- import net.minecraft.entity.monster.EntityCreeper;
- import net.minecraft.entity.monster.EntityGhast;
- import net.minecraft.entity.monster.EntityMob;
- import net.minecraft.entity.passive.EntityAnimal;
- import net.minecraft.entity.passive.EntityHorse;
- import net.minecraft.entity.passive.EntitySheep;
- import net.minecraft.entity.passive.EntityTameable;
- import net.minecraft.entity.passive.EntityWolf;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.item.ItemFood;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.pathfinding.PathEntity;
- import net.minecraft.potion.Potion;
- import net.minecraft.potion.PotionEffect;
- import net.minecraft.util.DamageSource;
- import net.minecraft.world.EnumDifficulty;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldProviderHell;
- import net.minecraftforge.common.ForgeHooks;
- public class EntitySagittarius extends EntityTameable implements IEntityOwnable, IRangedAttackMob
- {
- private float iAmE;
- private float iAmF;
- private int spiritSummonCost = 5;
- private int spritTickCounter;
- //private int poisonPulseFXCounter;
- private final int SPIRIT_ID = 4;
- private final float DAMAGE_BASE = (float) 30.0;
- private final int DAMAGE_DIVIDER = 5;
- private final double SPIRIT_BASE_HP = 40; //Divide this number by 2 to get the amount of hearts.
- private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
- private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
- public EntitySagittarius(World par1World) {
- super(par1World);
- this.setSize(.9F, 1.9F);
- this.tasks.addTask(1, new EntityAISwimming(this));
- this.tasks.addTask(2, this.aiSit);
- this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
- this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
- this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
- this.tasks.addTask(9, new EntityAILookIdle(this));
- this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
- this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
- this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
- this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
- this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityMob.class, 0, true));
- this.addRandomArmor();
- this.setTamed(false);
- if (par1World != null && !par1World.isRemote)
- {
- this.setCombatTask();
- }
- }
- public void setCombatTask()
- {
- this.tasks.removeTask(this.aiAttackOnCollide);
- this.tasks.removeTask(this.aiArrowAttack);
- ItemStack itemstack = this.getHeldItem();
- if (itemstack != null && itemstack.getItem() == Items.bow)
- {
- this.tasks.addTask(4, this.aiArrowAttack);
- }
- else
- {
- this.tasks.addTask(4, this.aiAttackOnCollide);
- }
- }
- protected void addRandomArmor()
- {
- this.setCurrentItemOrArmor(0, new ItemStack(Items.bow));
- }
- public boolean isAIEnabled(){
- return true;
- }
- protected void applyEntityAttributes(){
- super.applyEntityAttributes();
- this.setCustomNameTag("Sagittarius");
- this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(SPIRIT_BASE_HP); //Divide the Number by 2 to get the Hearts in game.
- this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.24000000417232513D);
- this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(6.0D);
- }
- public void setAttackTarget(EntityLivingBase p_70624_1_)
- {
- super.setAttackTarget(p_70624_1_);
- if (p_70624_1_ == null)
- {
- this.setAngry(false);
- }
- else if (!this.isTamed())
- {
- this.setAngry(true);
- }
- }
- public IEntityLivingData onSpawnWithEgg(IEntityLivingData sagi)
- {
- sagi = super.onSpawnWithEgg(sagi);
- this.tasks.addTask(4, this.aiArrowAttack);
- this.addRandomArmor();
- this.enchantEquipment();
- return sagi;
- }
- /**
- * Called when the entity is attacked.
- */
- @Override
- public boolean attackEntityFrom(DamageSource targeted, float power)
- {
- if (this.isEntityInvulnerable())
- {
- return false;
- }
- else
- {
- Entity entity = targeted.getEntity();
- this.aiSit.setSitting(false);
- if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
- {
- power = (power + 12.0F) / 2.0F;
- }
- return super.attackEntityFrom(targeted, power);
- }
- }
- @Override
- public boolean attackEntityAsMob(Entity entity)
- {
- EntityLivingBase owner = this.getOwner();
- if (owner instanceof EntityPlayer)
- {
- EntityPlayer player = (EntityPlayer) owner;
- float damage = player.experienceTotal / DAMAGE_DIVIDER;
- if ( damage >= DAMAGE_BASE )
- {
- return entity.attackEntityFrom(DamageSource.causeMobDamage(this), damage); //i
- }
- }
- return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)DAMAGE_BASE); //i
- }
- public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)
- {
- EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
- int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
- int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
- entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.difficultySetting.getDifficultyId() * 0.11F));
- if (i > 0)
- {
- entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
- }
- if (j > 0)
- {
- entityarrow.setKnockbackStrength(j);
- }
- if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0)
- {
- entityarrow.setFire(100);
- }
- this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
- this.worldObj.spawnEntityInWorld(entityarrow);
- }
- /**
- * main AI tick function, replaces updateEntityActionState
- */
- protected void entityInit()
- {
- super.entityInit();
- this.dataWatcher.addObject(18, new Float(this.getHealth()));
- this.dataWatcher.addObject(19, new Byte((byte)0));
- this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
- }
- protected void updateAITick()
- {
- this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
- }
- public boolean watchingYou()
- {
- return this.dataWatcher.getWatchableObjectByte(19) == 1;
- }
- public void onUpdate()
- {
- super.onUpdate();
- /////////////////Cost Handler\\\\\\\\\\\\\\\\\\\\\
- spritTickCounter += 1;
- if (spritTickCounter == 80)
- {
- EntityLivingBase owner = this.getOwner();
- spritTickCounter = 0;
- if (owner instanceof EntityPlayer)
- {
- EntityPlayer player = (EntityPlayer) owner;
- player.addExperienceLevel(-spiritSummonCost);
- if (player.experienceTotal < spiritSummonCost)
- {
- ExtendedPlayer instance = ExtendedPlayer.get(player);
- instance.setSummoned(SPIRIT_ID, false);
- this.worldObj.removeEntity(this);
- }
- }
- }
- ///////////////////////////////////////////////////
- ///////////////// Slow Pulse \\\\\\\\\\\\\\\\\\\\\
- /*poisonPulseFXCounter += 1;
- if (poisonPulseFXCounter == 400)
- {
- List<EntityLivingBase> targetList = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(6.0F, 6.0F, 6.0F));
- EntityLivingBase owner = this.getOwner();
- poisonPulseFXCounter = 0;
- for (EntityLivingBase targets : targetList)
- {
- if ( targets != null)
- {
- if ( targets != this.getOwner() && targets != this)
- {
- targets.addPotionEffect(new PotionEffect(Potion.poison.getId(), 100, 5));
- }
- }
- }
- }*/
- ///////////////////////////////////////////////////
- this.iAmF = this.iAmE;
- if (this.getOwner() == null)
- {
- this.setDead();
- }
- //If Died Set Summoned to False
- if (this.isDead)
- {
- EntityLivingBase owner = this.getOwner();
- if (owner instanceof EntityPlayer)
- {
- EntityPlayer player = (EntityPlayer) owner;
- ExtendedPlayer instance = ExtendedPlayer.get(player);
- instance.setSummoned(SPIRIT_ID, false);
- }
- }
- if (this.watchingYou())
- {
- this.iAmE += (1.0F - this.iAmF) * 0.4F;
- }
- else
- {
- this.iAmF += (0.0F - this.iAmE) * 0.4F;
- }
- if (this.watchingYou())
- {
- this.numTicksToChaseTarget = 10;
- }
- }
- public void onLivingUpdate()
- {
- super.onLivingUpdate();
- if (!this.worldObj.isRemote && !this.hasPath() && this.onGround)
- {
- this.worldObj.setEntityState(this, (byte)8);
- }
- }
- @Override
- public void writeEntityToNBT(NBTTagCompound p_70014_1_)
- {
- //super.writeEntityToNBT(p_70014_1_);
- //p_70014_1_.setBoolean("Hostile", this.isAngry());
- //p_70014_1_.setByte("ColorCollar", (byte)this.getCollarColor());
- }
- @Override
- public void readEntityFromNBT(NBTTagCompound p_70037_1_)
- {
- //super.readEntityFromNBT(p_70037_1_);
- //this.setAngry(p_70037_1_.getBoolean("Hostile"));
- //if (p_70037_1_.hasKey("ColorCollar", 99))
- //{
- // this.setCollarColor(p_70037_1_.getByte("ColorCollar"));
- //}
- }
- /**
- * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
- */
- public boolean interact(EntityPlayer player)
- {
- ItemStack itemstack = player.inventory.getCurrentItem();
- if (this.isTamed())
- {
- if (itemstack != null)
- {
- if (itemstack.getItem() instanceof ItemFood)
- {
- ItemFood itemfood = (ItemFood)itemstack.getItem();
- if ( (itemfood == CelestialCraft_items.celApple) && (this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) )
- {
- if (!player.capabilities.isCreativeMode)
- {
- --itemstack.stackSize;
- }
- this.heal((float)itemfood.func_150905_g(itemstack));
- if (itemstack.stackSize <= 0)
- {
- player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
- }
- return true;
- }
- }
- else if (itemstack.getItem() == Items.dye)
- {
- int i = BlockColored.func_150032_b(itemstack.getItemDamage());
- if (i != this.getCollarColor())
- {
- this.setCollarColor(i);
- if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
- {
- player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
- }
- return true;
- }
- }
- }
- }
- if (itemstack != null && itemstack.getItem() == CelestialCraft_items.celApple && !this.isAngry())
- {
- if (!player.capabilities.isCreativeMode)
- {
- --itemstack.stackSize;
- }
- if (itemstack.stackSize <= 0)
- {
- player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
- }
- if (!this.worldObj.isRemote)
- {
- if (this.rand.nextInt(3) == 0)
- {
- this.setTamed(true);
- this.setPathToEntity((PathEntity)null);
- this.setAttackTarget((EntityLivingBase)null);
- this.aiSit.setSitting(true);
- this.setHealth(20.0F);
- this.func_152115_b(player.getUniqueID().toString());
- this.playTameEffect(true);
- this.worldObj.setEntityState(this, (byte)7);
- }
- else
- {
- this.playTameEffect(false);
- this.worldObj.setEntityState(this, (byte)6);
- }
- }
- return true;
- }
- return super.interact(player);
- }
- public boolean isAngry()
- {
- return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
- }
- /**
- * Sets whether this wolf is angry or not.
- */
- public void setAngry(boolean p_70916_1_)
- {
- byte b0 = this.dataWatcher.getWatchableObjectByte(16);
- if (p_70916_1_)
- {
- this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
- }
- else
- {
- this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
- }
- }
- /**
- * Return this Aries's collar color.
- */
- public int getCollarColor()
- {
- return this.dataWatcher.getWatchableObjectByte(20) & 15;
- }
- /**
- * Set this Aries's collar color.
- */
- public void setCollarColor(int p_82185_1_)
- {
- this.dataWatcher.updateObject(20, Byte.valueOf((byte)(p_82185_1_ & 15)));
- }
- protected boolean canDespawn()
- {
- return !this.isTamed() && this.ticksExisted > 2400;
- }
- public boolean func_142018_a(EntityLivingBase target, EntityLivingBase summoner)
- {
- if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast))
- {
- if (target instanceof EntitySagittarius)
- {
- EntitySagittarius entityspirit = (EntitySagittarius)target;
- if (entityspirit.isTamed() && entityspirit.getOwner() == summoner)
- {
- return false;
- }
- }
- 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();
- }
- else
- {
- return false;
- }
- }
- @Override
- public EntityAgeable createChild(EntityAgeable var1) {
- return new EntitySagittarius(worldObj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment