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

import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.core.Registry;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import net.minecraft.core.GlobalPos;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.npc.Villager;

public class AssignProfessionFromJobSite extends Behavior<Villager> {
    public AssignProfessionFromJobSite() {
        super(ImmutableMap.<MemoryModuleType<GlobalPos>, MemoryStatus>of(MemoryModuleType.JOB_SITE, MemoryStatus.VALUE_PRESENT));
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final Villager axw) {
        return axw.getVillagerData().getProfession() == VillagerProfession.NONE;
    }
    
    @Override
    protected void start(final ServerLevel xd, final Villager axw, final long long3) {
        final GlobalPos fr6 = axw.getBrain().<GlobalPos>getMemory(MemoryModuleType.JOB_SITE).get();
        final MinecraftServer minecraftServer7 = xd.getServer();
        minecraftServer7.getLevel(fr6.dimension()).getPoiManager().getType(fr6.pos()).ifPresent(asu -> Registry.VILLAGER_PROFESSION.stream().filter(axz -> axz.getJobPoiType() == asu).findFirst().ifPresent(axz -> {
            axw.setVillagerData(axw.getVillagerData().setProfession(axz));
            axw.refreshBrain(xd);
        }));
    }
}
