package net.minecraft.world.entity.monster;

import java.util.function.Predicate;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.Items;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ProjectileWeaponItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.LightLayer;
import java.util.Random;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.BlockPos;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.PathfinderMob;

public abstract class Monster extends PathfinderMob implements Enemy {
    protected Monster(final EntityType<? extends Monster> aoq, final Level bqb) {
        super(aoq, bqb);
        this.xpReward = 5;
    }
    
    @Override
    public SoundSource getSoundSource() {
        return SoundSource.HOSTILE;
    }
    
    @Override
    public void aiStep() {
        this.updateSwingTime();
        this.updateNoActionTime();
        super.aiStep();
    }
    
    protected void updateNoActionTime() {
        final float float2 = this.getBrightness();
        if (float2 > 0.5f) {
            this.noActionTime += 2;
        }
    }
    
    @Override
    protected boolean shouldDespawnInPeaceful() {
        return true;
    }
    
    @Override
    protected SoundEvent getSwimSound() {
        return SoundEvents.HOSTILE_SWIM;
    }
    
    @Override
    protected SoundEvent getSwimSplashSound() {
        return SoundEvents.HOSTILE_SPLASH;
    }
    
    @Override
    public boolean hurt(final DamageSource anw, final float float2) {
        return !this.isInvulnerableTo(anw) && super.hurt(anw, float2);
    }
    
    @Override
    protected SoundEvent getHurtSound(final DamageSource anw) {
        return SoundEvents.HOSTILE_HURT;
    }
    
    @Override
    protected SoundEvent getDeathSound() {
        return SoundEvents.HOSTILE_DEATH;
    }
    
    @Override
    protected SoundEvent getFallDamageSound(final int integer) {
        if (integer > 4) {
            return SoundEvents.HOSTILE_BIG_FALL;
        }
        return SoundEvents.HOSTILE_SMALL_FALL;
    }
    
    @Override
    public float getWalkTargetValue(final BlockPos fu, final LevelReader bqd) {
        return 0.5f - bqd.getBrightness(fu);
    }
    
    public static boolean isDarkEnoughToSpawn(final LevelAccessor bqc, final BlockPos fu, final Random random) {
        if (bqc.getBrightness(LightLayer.SKY, fu) > random.nextInt(32)) {
            return false;
        }
        final int integer4 = bqc.getLevel().isThundering() ? bqc.getMaxLocalRawBrightness(fu, 10) : bqc.getMaxLocalRawBrightness(fu);
        return integer4 <= random.nextInt(8);
    }
    
    public static boolean checkMonsterSpawnRules(final EntityType<? extends Monster> aoq, final LevelAccessor bqc, final MobSpawnType apb, final BlockPos fu, final Random random) {
        return bqc.getDifficulty() != Difficulty.PEACEFUL && isDarkEnoughToSpawn(bqc, fu, random) && Mob.checkMobSpawnRules(aoq, bqc, apb, fu, random);
    }
    
    public static boolean checkAnyLightMonsterSpawnRules(final EntityType<? extends Monster> aoq, final LevelAccessor bqc, final MobSpawnType apb, final BlockPos fu, final Random random) {
        return bqc.getDifficulty() != Difficulty.PEACEFUL && Mob.checkMobSpawnRules(aoq, bqc, apb, fu, random);
    }
    
    public static AttributeSupplier.Builder createMonsterAttributes() {
        return Mob.createMobAttributes().add(Attributes.ATTACK_DAMAGE);
    }
    
    @Override
    protected boolean shouldDropExperience() {
        return true;
    }
    
    @Override
    protected boolean shouldDropLoot() {
        return true;
    }
    
    public boolean isPreventingPlayerRest(final Player bec) {
        return true;
    }
    
    @Override
    public ItemStack getProjectile(final ItemStack bki) {
        if (bki.getItem() instanceof ProjectileWeaponItem) {
            final Predicate<ItemStack> predicate3 = ((ProjectileWeaponItem)bki.getItem()).getSupportedHeldProjectiles();
            final ItemStack bki2 = ProjectileWeaponItem.getHeldProjectile(this, predicate3);
            return bki2.isEmpty() ? new ItemStack(Items.ARROW) : bki2;
        }
        return ItemStack.EMPTY;
    }
}
