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

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.entity.ai.util.RandomPos;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import net.minecraft.world.entity.ai.memory.WalkTarget;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.PathfinderMob;

public class SetWalkTargetAwayFromEntity extends Behavior<PathfinderMob> {
    private final MemoryModuleType<? extends Entity> memory;
    private final float speed;
    
    public SetWalkTargetAwayFromEntity(final MemoryModuleType<? extends Entity> arl, final float float2) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, (MemoryModuleType<WalkTarget>)arl, MemoryStatus.VALUE_PRESENT));
        this.memory = arl;
        this.speed = float2;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final PathfinderMob alg) {
        final Entity akq4 = (Entity)alg.getBrain().getMemory(this.memory).get();
        return alg.distanceToSqr(akq4) < 36.0;
    }
    
    @Override
    protected void start(final ServerLevel xd, final PathfinderMob alg, final long long3) {
        final Entity akq6 = (Entity)alg.getBrain().getMemory(this.memory).get();
        moveAwayFromMob(alg, akq6, this.speed);
    }
    
    public static void moveAwayFromMob(final PathfinderMob alg, final Entity akq, final float float3) {
        for (int integer4 = 0; integer4 < 10; ++integer4) {
            final Vec3 cvl5 = RandomPos.getLandPosAvoid(alg, 16, 7, akq.position());
            if (cvl5 != null) {
                alg.getBrain().<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(cvl5, float3, 0));
                return;
            }
        }
    }
}
