Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.halestormxv.entity;
- import com.halestormxv.item.CelestialCraft_items;
- import net.minecraft.block.BlockColored;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityAgeable;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.IEntityOwnable;
- import net.minecraft.entity.SharedMonsterAttributes;
- 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.Items;
- import net.minecraft.item.ItemFood;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.pathfinding.PathEntity;
- import net.minecraft.util.DamageSource;
- import net.minecraft.world.EnumDifficulty;
- import net.minecraft.world.World;
- import net.minecraftforge.common.ForgeHooks;
- public class EntityAries extends EntityTameable implements IEntityOwnable
- {
- private float iAmE;
- private float iAmF;
- public int ariesSummonCost = 1;
- public int ariesCounter;
- public EntityAries(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(3, new EntityAILeapAtTarget(this, 0.4F));
- 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(7, new EntityAIWander(this, 1.0D));
- 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.setTamed(false);
- }
- public boolean isAIEnabled(){
- return true;
- }
- protected void applyEntityAttributes(){
- super.applyEntityAttributes();
- this.setCustomNameTag("Aries");
- this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40); //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);
- }
- }
- /**
- * Called when the entity is attacked.
- */
- 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 / 12;
- if ( damage >= 12 )
- {
- return entity.attackEntityFrom(DamageSource.causeMobDamage(this), damage); //i
- }
- }
- return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)12.0F); //i
- }
- /**
- * 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\\\\\\\\\\\\\\\\\\\\\
- ariesCounter += 1;
- if (ariesCounter == 80)
- {
- EntityLivingBase owner = this.getOwner();
- ariesCounter = 0;
- if (owner instanceof EntityPlayer)
- {
- EntityPlayer player = (EntityPlayer) owner;
- player.addExperienceLevel(-ariesSummonCost);
- if (player.experienceTotal < ariesSummonCost)
- {
- this.worldObj.removeEntity(this);
- }
- }
- }
- ///////////////////////////////////////////////////
- this.iAmF = this.iAmE;
- if (this.getOwner() == null)
- {
- this.worldObj.removeEntity(this);
- }
- 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);
- }
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- /* 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());
- }
- */
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- /* 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 EntityAries)
- {
- EntityAries entityaries = (EntityAries)target;
- if (entityaries.isTamed() && entityaries.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 EntityAries(worldObj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement