Skip to content

Instantly share code, notes, and snippets.

@orlp
Last active March 24, 2024 00:55
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlp/db1ca6dbb82727c4a939c95694a52b81 to your computer and use it in GitHub Desktop.
Save orlp/db1ca6dbb82727c4a939c95694a52b81 to your computer and use it in GitHub Desktop.

Villager mechanics in 1.14. All this data has been deduced by using the following commands:

/data get entity @e[type=minecraft:villager,limit=1,sort=nearest] Brain.memories
/execute as orlp at orlp run tellraw @s {"nbt":"Brain.memories","entity":"@e[type=villager,sort=nearest,limit=1]"}

A villager is awake from 0-11999 and tries to sleep between 12000 and 23999.

A villager will claim a bed if:

  • They are within a 48 block sphere of the bed.
  • It is 'pathfinding'.
  • The bed is not already claimed by another villager.

That's it! Line of sight, time of day - doesn't matter. The location of a bed is the block where its pillows are.

After this the villager will remember the coordinates of its bed. And even though I can't find the NBT data on the bed block, the bed does seem to remember by what villager it is claimed.

Note that these are two different pieces of information, and they can get desynchronized! If a bed is destroyed and a new bed is placed on the same location without the villager realizing, the bed is no longer claimed, and can be claimed by a another villager. The result will be two villagers claiming the same bed. If a villager dies or forgets its bed, the bed will also become unclaimed.

There are two ways a villager can forget where it thinks its bed is. The first occurs when:

  • The villager tries to sleep.
  • The villager is in range (~2 blocks) of where its bed used to be.
  • The bed is gone. This check is done by checking whether there is a bed that has its pillows at its coordinates. You can remove and rotate the bed with the pillows in the same spot and the villager will still use the bed and not forget it.

The second way occurs when:

  • The villager tries to sleep.
  • The villager is at least 150 blocks away in TAXICAB DISTANCE metric.
  • The villager is 'pathfinding'.

Workstations are claimed exactly the same as beds! Time of day, line of sight, it all doesn't matter. Villagers will claim workbenches all the same, even when sleeping! Lots of misinformation about this.

There is (AFAIK) only one way to stop a villager that is in range of a workstation or bed from trying to claim it: stop the villager from pathfinding. I don't know exactly the mechanics of pathfinding, but I do know that surrounding a villager with eight solid blocks (glass works) at their feet or eye level so that it can not move works. Four should be enough in 1.14.1, but you need four more for the diagonals in 1.14 because of a bug that causes monsters to try and pathfind through diagonal blocks: https://bugs.mojang.com/browse/MC-142817.

A villager will try to interact with their workstation nearly constantly between daytime 2000 and 9000. I haven't seen a villager try to interact with their workstation outside of these hours.

A villager can interact with their workstation horizontally even with a two block gap. Vertically a villager will interact with a workstation directly above their head, but not a block above that.

A villager will revert to being unemployed if:

  • They are in range of their claimed workstation's coordinates.
  • There is no workstation of their current profession at their remembered coordinates.

Or:

  • The villager is trying to interact with their workstation.
  • The villager is at least 100 blocks away in TAXICAB DISTANCE metric.
  • The villager is 'pathfinding'.

If the villager is standing on the ground they can reach across a one block gap , two if they're trying to pathfind in that direction (due to e.g. a trapdoor) - I assume because they're pushing into the block a bit. They can even reach a workstation that is one more block down, but not up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment