package net.minecraft.world.entity.ai.behavior;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.util.IntRange;
import net.minecraft.world.entity.AgableMob;

public class BabyFollowAdult<E extends AgableMob> extends Behavior<E> {
    private final IntRange followRange;
    private final float speedModifier;
    
    public BabyFollowAdult(final IntRange adx, final float float2) {
        super(ImmutableMap.<MemoryModuleType<AgableMob>, MemoryStatus>of(MemoryModuleType.NEAREST_VISIBLE_ADULT, MemoryStatus.VALUE_PRESENT, (MemoryModuleType<AgableMob>)MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT));
        this.followRange = adx;
        this.speedModifier = float2;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final E aok) {
        if (!aok.isBaby()) {
            return false;
        }
        final AgableMob aok2 = this.getNearestAdult(aok);
        return aok.closerThan(aok2, this.followRange.getMaxInclusive() + 1) && !aok.closerThan(aok2, this.followRange.getMinInclusive());
    }
    
    @Override
    protected void start(final ServerLevel zd, final E aok, final long long3) {
        BehaviorUtils.setWalkAndLookTargetMemories(aok, this.getNearestAdult(aok), this.speedModifier, this.followRange.getMinInclusive() - 1);
    }
    
    private AgableMob getNearestAdult(final E aok) {
        return aok.getBrain().<AgableMob>getMemory(MemoryModuleType.NEAREST_VISIBLE_ADULT).get();
    }
}
