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

import net.minecraft.world.entity.LivingEntity;
import java.util.Optional;
import net.minecraft.world.entity.Entity;
import java.util.Collections;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import java.util.List;
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 speedModifier;
    
    public InsideBrownianWalk(final float float1) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT));
        this.speedModifier = float1;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final PathfinderMob apg) {
        return !zd.canSeeSky(apg.blockPosition());
    }
    
    @Override
    protected void start(final ServerLevel zd, final PathfinderMob apg, final long long3) {
        final BlockPos fu2 = apg.blockPosition();
        final List<BlockPos> list7 = BlockPos.betweenClosedStream(fu2.offset(-1, -1, -1), fu2.offset(1, 1, 1)).map(BlockPos::immutable).collect(Collectors.toList());
        Collections.shuffle(list7);
        final Optional<BlockPos> optional8 = list7.stream().filter(fu -> !zd.canSeeSky(fu)).filter(fu -> zd.loadedAndEntityCanStandOn(fu, apg)).filter(fu -> zd.noCollision(apg)).findFirst();
        optional8.ifPresent(fu -> apg.getBrain().<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(fu, this.speedModifier, 0)));
    }
}
