Updated description by @unknown Oct. 7, 2020
Wandering traders do not seem to have any spawning limitations at all other than spawning in the overworld only. Code analysis provided in this comment and the one following.
Steps to reproduce
Build a large platform and cover it with blocks that prevent other land mobs from spawning, e.g. bedrock, glass, buttons, source water, flowing water.
Wait.
Expected result
Nothing spawns.
Actual result
Wandering traders and their llamas spawn.
Original description
Hello,
I decided to start playing on survival on Bedrock (I'm a Java-fan) and created a new world. There is nothing special in the world: Desert and forest near spawn. But then came the Wandering Trader... Idk how.
The wandering trader should only be able to spawn in village gathering sites, but they appear to spawn anywhere in the world. This includes oceans and caves.
Related issues
is duplicated by
relates to
Attachments
Comments


I think it's intentional because it also happens to the Java Edition.
Don't know about spawning in caves, but imo spawning in oceans and on land is intentional

WAI per https://www.minecraft.net/en-us/article/meet-wandering-trader
"We thought it would be neat if the Wandering Trader could travel from village to village, sometimes encountering the player in the wilderness."
"They can appear when you least expect it – either out in the overworld or occasionally in villages, appearing at the local gather site."

@Nicholas Jay: thank you for the reference. Clearly it is intended that wandering traders can spawn outside of villages, so the original description of this report was incorrect in expecting traders to spawn only in villages. However, it is not clear that wandering traders are intended to spawn anywhere whatsoever, not doing any block checks at all and spawning where nothing else can, even in dangerous places. For example, they spawn on buttons, on glass, in water streams, on bedrock, in the middle of the ocean, deep in caves, and on the edges of cliffs where their llamas push them to their death (see also MCPE-45756).
Some of these spots are amusing, but some are a huge annoyance. It's even worse because of MCPE-44312. I am currently dealing with trader llamas continually blocking baby drowned from a trap I set for them in a mob farm. Either the baby drowned kills the trader, or the trader spawns where it gets immediately pushed out and falls. Either way, it leaves behind llamas that never despawn in a place where I don't want anything to spawn:
[media]

Code Analysis Wandering Traders do not spawn according to the standard environmental spawning algorithm (Spawner::tick
). The other mob event added in V&P — the pillager patrol — is data-driven and does use the environmental spawning algorithm to spawn. The code for managing the spawning and despawning of the wandering trader is in the WanderingTraderScheduler
class and is called by VillageManager::tick
. WanderingTraderScheduler
's algorithm for finding a spawn spot for a wandering trader is different than the environmental spawning algorithm's resulting in the Wandering Trader appearing in places where they are not wanted, including underground and on roofs.
Solution Follow the example of the Pillager Patrol and make the WanderTrader spawn according to the environmental spawning algorithm. This will make them follow the spawn logic expected by players. As the environmental spawning algorithm has been receiving lots of bug fixes and new features in 1.14 and 1.16, migrating wander trader spawning to an environmental spawn would allow wandering traders to benefit from the changes.
Impact There is likely no negative impact for players by replacing WanderingTraderScheduler
with a Spawner::tick
implementation.

Some additional code-digging from Reed Cartwright exposes the bug here more fully:
So when looking for a location to spawn a wandering trader, the game picks a random value and then looks up and down for a location to spawn the wandering trader, picking the "closest" one. The algorithm that looks down makes sense. It searches for the first
SolidBlocking
block below an air block (that is at or below the search start).However, the algorithm that looks up is different. It searches for the first air block that is above a block that is
SolidBlocking
and returns the block below the air block.Consider this scenario. A = air block, S =
SolidBlocking
block, . = Other block (e.g. torches, plants)A
A
. <-NextTopSolidBlockAbove
.
S
S <- search start
S
A
A
.
.
S <-NextTopSolidBlockBelow
S
Obviously the .
block here could be anything--water, glass, button, probably even lava. Wandering traders can spawn on any of them as long as there is air above and a solid block somewhere below. One way to fix that would be to require the solid block to be immediately below the air block, instead of anywhere below it. But it might be better to move the trader to the environmental spawning algorithm as Reed suggested above, like patrols.

Still present in 1.17.40.21. Picture shows trader just after he spawned in front of me (below y=0).
[media]
Still occurs in 1.17.41 and 1.18.0.24

Can confirm for 1.18.2.
[media][media]

They do spawn at any height but hey that means some more trades.

Please read my comment again, and it's obvious that there is no attempt to chat with people like a forum. It's literally just a very detailed bug report meant to help the devs. This bug seems unrelated, but every time I search and make this topic, it leads to this page. And a bot says that I'm supposed to add the extra information here, so I did. This is new information not discussed in this thread yet. I've never had any issues reporting bugs in this site, until now. I'm honestly not sure what else you want me to do, can you please edit this entire comment chain to match what you want? All this back-and-forth is cluttering this thread.
I have a player-made surface village with a bell, and Wandering Traders are consistently spawning in the new caves over 64 blocks below that bell, in the exact same spot, several times. This is definitely not coincidental. I've given ample space for the Wandering Trader to spawn near the surface bell, but they never did. The Y-range of the Wandering Trader bell spawn is messed up and can spawn very far from the bell vertically. Before 1.18, they spawned in the caves a few blocks below that bell (which is undesirable) but after 1.18 it gets much worse, spawning even deeper. This issue has been going on for a long time, on a lot of my villages.
I'm aware that Wandering Traders can spawn underground. When I go caving, they can spawn nearby. The issue is that, when I'm on the surface on my village, the Wandering Trader should spawn close to the village center (bell). But instead, they kept clogging the caves underneath, creating hundreds of persistent trader llamas (MCPE-102302) and zombies carrying leads (MCPE-125111) under your base, causing huge lag. This bug is also a big reason why some players can't seem to find Wandering Traders on their base.

@unknown: You seem to be at least trying to come to a meeting of the minds now, so I'll try to work with you. However, as stated in our guidelines and FAQ, which I have repeatedly pleaded with you to read, the bug tracker is not where this conversation belongs, it belongs on the MCPE Mojira subreddit. I would be happy to discuss all of this at length with you there, but please be patient with me as I do not keep a constant watch on Reddit posts. If you prefer, you can start a discussion with us on the Mojira Discord (also linked in our documentation), but note that I don't monitor Discord normally.
It's critical that you learn how to use the site properly. I realize our documentation is long and boring, but if you don't learn it we might eventually have to remove you from the site. Practically every genuine bug affects many people, so if we don't get helpful input from you, we'll get it from somebody who understands how the site works. In other words, if you don't want to be bothered reading our documentation, that's fine, but in that case we don't need your input.
(Edited January 10 to correct the name of the subreddit.)

Molly Oliver: after outside discussion with Auldrick and more thorough testing I have reopened and confirmed your report (MCPE-151591) as a distinct issue from this one.

What I understand from this is that y’all think wandering traders should have more spawning limitations, which I agree with. But also I personally think it makes sense for a something with no home, destination, or sense of direction to spawn in a cave or on a cliff. Just saying what I think about this.