Files
BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/entity/mob/EntitySmallEarthGolem.java
T

142 lines
4.6 KiB
Java

package WayofTime.alchemicalWizardry.common.entity.mob;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
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.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.common.EntityAITargetAggro;
import WayofTime.alchemicalWizardry.common.entity.projectile.MudProjectile;
public class EntitySmallEarthGolem extends EntityDemon implements IRangedAttackMob {
private final EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 25, 25, 15.0F);
private final EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(
this,
EntityPlayer.class,
1.2D,
false);
private static final float maxTamedHealth = 20.0F;
private static final float maxUntamedHealth = 10.0F;
public EntitySmallEarthGolem(World world) {
super(world, AlchemicalWizardry.entitySmallEarthGolemID);
this.setSize(0.2F, 1.0F);
this.getNavigator().setAvoidsWater(true);
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(2, this.aiSit);
this.tasks.addTask(3, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(5, 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 EntityAITargetAggro(this, EntityPlayer.class, 0, false));
this.setAggro(false);
this.setTamed(false);
if (world != null && !world.isRemote) {
this.setCombatTask();
}
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
}
/**
* Returns true if the newer Entity AI code should be run
*/
@Override
public boolean isAIEnabled() {
return true;
}
/**
* main AI tick function, replaces updateEntityActionState
*/
@Override
protected void updateAITick() {
this.dataWatcher.updateObject(18, this.getHealth());
}
@Override
protected void entityInit() {
super.entityInit();
this.dataWatcher.addObject(18, this.getHealth());
}
protected void playStepSound(int par1, int par2, int par3, int par4) {
this.playSound("mob.zombie.step", 0.15F, 1.0F);
}
@Override
protected String getLivingSound() {
return "none";
}
@Override
protected String getHurtSound() {
return "mob.irongolem.hit";
}
@Override
protected String getDeathSound() {
return "mob.irongolem.death";
}
@Override
protected float getSoundVolume() {
return 0.4F;
}
@Override
public boolean attackEntityAsMob(Entity entity) {
int i = this.isTamed() ? 4 : 2;
return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float) i);
}
@Override
public void attackEntityWithRangedAttack(EntityLivingBase entityLivingBase, float par2) {
MudProjectile hol = new MudProjectile(worldObj, this, entityLivingBase, 1.8f, 0f, 3, 600, false);
this.worldObj.spawnEntityInWorld(hol);
}
/**
* sets this entity's combat AI.
*/
public void setCombatTask() {
this.tasks.removeTask(this.aiAttackOnCollide);
this.tasks.removeTask(this.aiArrowAttack);
this.tasks.addTask(4, this.aiArrowAttack);
}
@Override
protected float maxTamedHealth() {
return maxTamedHealth;
}
@Override
protected float maxUntamedHealth() {
return maxUntamedHealth;
}
}