Reproduction steps
To reproduce, use the seed -5957804310435822198 and use the locate command and teleport to the first ocean ruin at 32 ~ -160. When you teleport to -18 ~ -160, the locate command will locate a different ocean ruin even though the first structure you located is nearest to you.
Cause
See this comment
Linked issues
is duplicated by 14
relates to 4
Attachments
Comments 31
Loaded up a new world to try to reproduce the glitch, and I realized my steps to reproduce were not reliable. I did reproduce this bug using 2 valid ocean ruin structures that could be detected by commands, and I did /locate in various places and confirmed that /locate does not always locate the nearest structure unlike in 1.13.2. I edited this report accordingly, redid my steps to reproduce, and tested them, so now they should be completely reliable.
I reported the same bug MCPE-45526 for Bedrock Edition (and that bug has been confirmed). I found examples of /locate failing to find the nearest structure (a stronghold and two monuments) even when I was right on top of it. This bug isn't just in Java Edition.
Here's my steps of reproduction:
1. Use seed -5541185355023925660 and go to exactly
/tp -5831 66 -4607. You might find yourself inside a tree.
2. /locate Desert_Pyramid, it's 241m away.
3. Go 1m north. You should pass through a chunk border doing this.
4. /locate Desert_Pyramid, it's 1060m away!
The locate
command doesn't locate the nearest structure because the locate
command works on Anvil regions and it stops searching when a structure is found. The Anvil file format saves worlds in region files containing 512×512 blocks. The region is used as a base for generating structures, for example, there can be no more than one village per region, one temple, one ocean monument, one ruined nether portal, one desert well, one witch hut, etc. Other structures have different rules: they could be more common (shipwrecks and ocean ruins can occur multiple times per chunk) or rarer (woodland mansions).
The effect of regions can be seen when steps to reproduce posted by @Paint are analysed. The coordinates given are -5831 66 -4607. Mod 512, x and z are: 313, 1. When the player moves 1m north, the player is crossing a chunk boundary that is also on a region boundary. When crossing a region boundary in this way, the locate
command would search a different region for the requested structure, but it searches only one region.
The effect of regions can be seen clearly when looking for ruined Nether portals in the 20w16a snapshot. These occur once per region in the Overworld, in most or all biomes. If one occurs near the edge of a region, crossing a region can cause a nearby ruined portal to be ignored while a farther one is found instead.
If greater accuracy is required, the locate
command should be modified so it searches additional neighbouring regions as well as the current region. It should search an additional region on both sides. The command already searches multiple regions, such as when suitable locations for that structure are not nearby. It should add one extra search region on both sides even if the structure is found. This won't guarantee the closest structure will always be found (eg: the nearest edge of villages), but it will prevent obviously wrong results such as the one that Paint demonstrated.
Affects 22w19a. /locate biome
is very slightly affected, but not nearly as significantly as /locate structure
. /locate poi
is unaffected.
I recently noticed this bug myself in Minecraft 1.19. There were two woodland mansions close to spawn on my world, which I found both via the /locate command. With the second mansion I located with the command, I noticed that according to my coordinates, the first one I located was actually slightly less far away from my position than the second one I located, which was really confusing.
Can confirm in 1.20.5. Also duplicated by MC-271211.
Does it happens in other worlds? Have you tried other villages(maybe the one where you are its not a valid village for some reason)