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

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.Brain;
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 StrollToPoi extends Behavior<PathfinderMob> {
    private final MemoryModuleType<GlobalPos> memoryType;
    private final int closeEnoughDist;
    private final int maxDistanceFromPoi;
    private long nextOkStartTime;
    
    public StrollToPoi(final MemoryModuleType<GlobalPos> awp, final int integer2, final int integer3) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<WalkTarget>)awp, MemoryStatus.VALUE_PRESENT));
        this.memoryType = awp;
        this.closeEnoughDist = integer2;
        this.maxDistanceFromPoi = integer3;
    }
    
    @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 Brain<?> apr6 = apg.getBrain();
            final Optional<GlobalPos> optional7 = apr6.<GlobalPos>getMemory(this.memoryType);
            optional7.ifPresent(gc -> apr6.<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(gc.pos(), 0.4f, this.closeEnoughDist)));
            this.nextOkStartTime = long3 + 80L;
        }
    }
}
