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.util.math.MathHelper;
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.CHICK_FLOORS;
public class EntityDarkChick extends EntityMob {
public float wingRotation;
public float destPos;
public float oFlapSpeed;
public float oFlap;
public float wingRotDelta = 1.0F;
public EntityDarkChick(World world) {
super(world);
setSize(0.4F, 0.7F);
setPathPriority(PathNodeType.WATER, 0.0F);
}
@Nullable
protected ResourceLocation getLootTable() {
return LootStrings.DARK_CHICK;
}
@Override
public int getMaxSpawnedInChunk() {
return 1;
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(2D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0.5D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25D);
}
@SuppressWarnings("unchecked")
@Override
protected void initEntityAI() {
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(4, new EntityAIAttackMelee(this, 0.8D, 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(@Nonnull DamageSource cause) {
super.onDeath(cause);
EntityPlayer player = EntityHelper.getPlayerFromSource(cause);
if (player != null) {
player.addStat(HFAchievements.killChick);
}
}
@Override
protected boolean isValidLightLevel() {
int floor = MiningHelper.getFloor((int)posX >> 4, (int) posY);
return floor >= 10 && (ANIMALS_ON_EVERY_FLOOR || ((floor - 3) % CHICK_FLOORS == 0))
&& EntityHelper.getEntities(EntityDarkChick.class, this, 16D).size() < 2;
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
this.oFlap = this.wingRotation;
this.oFlapSpeed = this.destPos;
this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1 : 4) * 0.3D);
this.destPos = MathHelper.clamp_float(this.destPos, 0.0F, 1.0F);
if (!this.onGround && this.wingRotDelta < 1.0F) {
this.wingRotDelta = 1.0F;
}
this.wingRotDelta = (float) ((double) this.wingRotDelta * 0.9D);
if (!this.onGround && this.motionY < 0.0D) {
this.motionY *= 0.6D;
}
this.wingRotation += this.wingRotDelta * 2.0F;
}
@Override
public void fall(float distance, float damageMultiplier) {}
@Override
protected SoundEvent getAmbientSound() {
return SoundEvents.ENTITY_CHICKEN_AMBIENT;
}
@Override
protected SoundEvent getHurtSound() {
return SoundEvents.ENTITY_CHICKEN_HURT;
}
@Override
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_CHICKEN_DEATH;
}
@Override
protected void playStepSound(@Nonnull BlockPos pos, @Nonnull Block blockIn) {
playSound(SoundEvents.ENTITY_CHICKEN_STEP, 0.15F, 1.1F);
}
@Override
public float getEyeHeight() {
return this.height;
}
}