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.world.entity.Entity;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.PathfinderMob;

public class MoveBackToVillage extends RandomStrollGoal {
    public MoveBackToVillage(final PathfinderMob alg, final double double2) {
        super(alg, double2, 10);
    }
    
    @Override
    public boolean canUse() {
        final ServerLevel xd2 = (ServerLevel)this.mob.level;
        final BlockPos fk3 = new BlockPos(this.mob);
        return !xd2.isVillage(fk3) && super.canUse();
    }
    
    @Nullable
    @Override
    protected Vec3 getPosition() {
        final ServerLevel xd2 = (ServerLevel)this.mob.level;
        final BlockPos fk3 = new BlockPos(this.mob);
        final SectionPos gd4 = SectionPos.of(fk3);
        final SectionPos gd5 = BehaviorUtils.findSectionClosestToVillage(xd2, gd4, 2);
        if (gd5 != gd4) {
            return RandomPos.getPosTowards(this.mob, 10, 7, new Vec3(gd5.center()));
        }
        return null;
    }
}
