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

import javax.annotation.Nullable;
import net.minecraft.world.entity.ai.util.RandomPos;
import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
import net.minecraft.core.SectionPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.PathfinderMob;

public class MoveBackToVillageGoal extends RandomStrollGoal {
    public MoveBackToVillageGoal(final PathfinderMob apg, final double double2, final boolean boolean3) {
        super(apg, double2, 10, boolean3);
    }
    
    @Override
    public boolean canUse() {
        final ServerLevel zd2 = (ServerLevel)this.mob.level;
        final BlockPos fu3 = this.mob.blockPosition();
        return !zd2.isVillage(fu3) && super.canUse();
    }
    
    @Nullable
    @Override
    protected Vec3 getPosition() {
        final ServerLevel zd2 = (ServerLevel)this.mob.level;
        final BlockPos fu3 = this.mob.blockPosition();
        final SectionPos go4 = SectionPos.of(fu3);
        final SectionPos go5 = BehaviorUtils.findSectionClosestToVillage(zd2, go4, 2);
        if (go5 != go4) {
            return RandomPos.getPosTowards(this.mob, 10, 7, Vec3.atBottomCenterOf(go5.center()));
        }
        return null;
    }
}
