In a villager's NBT, they have Brain > memories > "minecraft:job_site"
They also have VillagerData > profession
I have attempted to call the Bukkit Villager
Additionally, I also call
The villager walks to the block, which tells me I have the right handle and my NMS is configured correctly.
But what happens is this: If the villager already has a profession, this code just strips them, making them have
Best case scenario, they find whatever nearby random profession block and go take that random profession.
Their job_block NBT data seems to get updated (I forget what iteration I last confirmed that). But given that their profession is "NONE", they just look like a normal (not nitwit) villager, and their NBT shows "NONE" as their profession.
How do I set the villager's profession and specific job block?
They also have VillagerData > profession
I have attempted to call the Bukkit Villager
setProfession(Profession.FARMER)
, as well as the NMS Villager to getVillagerData()
, setProfession(VillagerProfession.FARMER)
, and then put it back with setVillagerData(villagerData)
.Additionally, I also call
brain.setMemory(JOB_SITE, BlockPos(...))
for the block position. Part of my code also has them walk to the block.
Java:
var nmsVillager = ((CraftVillager)bukkitVillager).getHandle();
nmsVillager.getNavigation().moveTo(block.getX(), block.getY(), block.getZ(), 1);
bukkitVillager.setProfession(Profession.FARMER);
Brain<Villager> villagerBrain = nmsVillager.getBrain();
VillagerData villagerData = nmsVillager.getVillagerData();
villagerData.setProfession(VillagerProfession.FARMER);
nmsVillager.setVillagerData(villagerData);
villagerBrain.setMemory(MemoryModuleType.JOB_SITE, Optional.of(GlobalPos.of(Level.OVERWORLD, new BlockPos(block.getX(), block.getY(), block.getZ()))));
The villager walks to the block, which tells me I have the right handle and my NMS is configured correctly.
But what happens is this: If the villager already has a profession, this code just strips them, making them have
NONE
as their profession. Of course they walk toward the block, but then they do nothing.Best case scenario, they find whatever nearby random profession block and go take that random profession.
Their job_block NBT data seems to get updated (I forget what iteration I last confirmed that). But given that their profession is "NONE", they just look like a normal (not nitwit) villager, and their NBT shows "NONE" as their profession.
How do I set the villager's profession and specific job block?