package joshie.harvest.mining.entity;
import joshie.harvest.core.achievements.HFAchievements;
import joshie.harvest.core.helpers.EntityHelper;
import joshie.harvest.core.lib.LootStrings;
import joshie.harvest.mining.MiningHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.pathfinding.PathNodeType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static joshie.harvest.mining.HFMining.ANIMALS_ON_EVERY_FLOOR;
import static joshie.harvest.mining.MiningHelper.COW_FLOORS;
import static joshie.harvest.mining.MiningHelper.MYSTRIL_FLOOR;
public class EntityDarkCow extends EntityMob {
public EntityDarkCow(World world) {
super(world);
setSize(1.4F, 1.4F);
setPathPriority(PathNodeType.WATER, 0.0F);
}
@Nullable
protected ResourceLocation getLootTable() {
return LootStrings.DARK_COW;
}
@Override
public int getMaxSpawnedInChunk() {
return 1;
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(30.0D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(5.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.15D);
}
@SuppressWarnings("unchecked")
@Override
protected void initEntityAI() {
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(4, new EntityAIAttackMelee(this, 0.5D, false));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(8, new EntityAILookIdle(this));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
}
@Override
public void onDeath(DamageSource cause) {
super.onDeath(cause);
EntityPlayer player = EntityHelper.getPlayerFromSource(cause);
if (player != null) {
player.addStat(HFAchievements.killCow);
}
}
@Override
protected boolean isValidLightLevel() {
int floor = MiningHelper.getFloor((int)posX >> 4, (int) posY);
return floor >= MYSTRIL_FLOOR && (ANIMALS_ON_EVERY_FLOOR || (((floor - 8) % COW_FLOORS == 0)))
&& EntityHelper.getEntities(EntityDarkCow.class, this, 32D).size() < 1;
}
@Override
protected SoundEvent getAmbientSound() {
return SoundEvents.ENTITY_COW_AMBIENT;
}
@Override
protected SoundEvent getHurtSound() {
return SoundEvents.ENTITY_COW_HURT;
}
@Override
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_COW_DEATH;
}
@Override
protected void playStepSound(@Nonnull BlockPos pos, @Nonnull Block blockIn) {
playSound(SoundEvents.ENTITY_COW_STEP, 0.15F, 1.0F);
}
@Override
protected float getSoundVolume() {
return 0.4F;
}
@Override
public float getEyeHeight() {
return 1.3F;
}
}