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 java.util.Objects;
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> arl, final int integer2, final int integer3) {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<WalkTarget>)arl, MemoryStatus.VALUE_PRESENT));
        this.memoryType = arl;
        this.closeEnoughDist = integer2;
        this.maxDistanceFromPoi = integer3;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final PathfinderMob alg) {
        final Optional<GlobalPos> optional4 = alg.getBrain().<GlobalPos>getMemory(this.memoryType);
        return optional4.isPresent() && Objects.equals(xd.getDimension().getType(), optional4.get().dimension()) && optional4.get().pos().closerThan(alg.position(), this.maxDistanceFromPoi);
    }
    
    @Override
    protected void start(final ServerLevel xd, final PathfinderMob alg, final long long3) {
        if (long3 > this.nextOkStartTime) {
            final Brain<?> alp6 = alg.getBrain();
            final Optional<GlobalPos> optional7 = alp6.<GlobalPos>getMemory(this.memoryType);
            optional7.ifPresent(fr -> alp6.<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(fr.pos(), 0.4f, this.closeEnoughDist)));
            this.nextOkStartTime = long3 + 80L;
        }
    }
}
