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 java.util.Optional;
import net.minecraft.core.Position;
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.core.GlobalPos;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.PathfinderMob;

public class StrollAroundPoi extends Behavior<PathfinderMob> {
    private final MemoryModuleType<GlobalPos> memoryType;
    private long nextOkStartTime;
    private final int maxDistanceFromPoi;
    
    public StrollAroundPoi(final MemoryModuleType<GlobalPos> awp, final int integer) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<WalkTarget>)awp, MemoryStatus.VALUE_PRESENT));
        this.memoryType = awp;
        this.maxDistanceFromPoi = integer;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final PathfinderMob apg) {
        final Optional<GlobalPos> optional4 = apg.getBrain().<GlobalPos>getMemory(this.memoryType);
        return optional4.isPresent() && zd.dimension() == optional4.get().dimension() && optional4.get().pos().closerThan(apg.position(), this.maxDistanceFromPoi);
    }
    
    @Override
    protected void start(final ServerLevel zd, final PathfinderMob apg, final long long3) {
        if (long3 > this.nextOkStartTime) {
            final Optional<Vec3> optional6 = Optional.<Vec3>ofNullable(RandomPos.getLandPos(apg, 8, 6));
            apg.getBrain().<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, optional6.map(dem -> new WalkTarget(dem, 0.4f, 1)));
            this.nextOkStartTime = long3 + 180L;
        }
    }
}
