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

import net.minecraft.world.entity.LivingEntity;
import java.util.Optional;
import java.util.Collections;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import java.util.List;
import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos;
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.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.PathfinderMob;

public class InsideBrownianWalk extends Behavior<PathfinderMob> {
    private final float speed;
    
    public InsideBrownianWalk(final float float1) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT));
        this.speed = float1;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final PathfinderMob alg) {
        return !xd.canSeeSky(new BlockPos(alg));
    }
    
    @Override
    protected void start(final ServerLevel xd, final PathfinderMob alg, final long long3) {
        final BlockPos fk2 = new BlockPos(alg);
        final List<BlockPos> list7 = BlockPos.betweenClosedStream(fk2.offset(-1, -1, -1), fk2.offset(1, 1, 1)).map(BlockPos::immutable).collect(Collectors.toList());
        Collections.shuffle(list7);
        final Optional<BlockPos> optional8 = list7.stream().filter(fk -> !xd.canSeeSky(fk)).filter(fk -> xd.loadedAndEntityCanStandOn(fk, alg)).filter(fk -> xd.noCollision(alg)).findFirst();
        optional8.ifPresent(fk -> alg.getBrain().<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(fk, this.speed, 0)));
    }
}
