[1.15.2] Registering villager types per biome is impossible
Minecraft Version: 1.15.2 & 1.16.1
Forge Version: 28.1.107 (for 1.14. Still exists in 1.15 and 1.16 all the same)
Logs: crash-2020-01-02_21.04.52-server.txt
Steps to Reproduce:
- Register a villager type for any mod biome.
- Startup and crash, getting the log above.
Description of issue: On startup, the villager professions set up their trades before any forge events get to them. The fisherman in particular has a trade that is biome specific, asking for boats of an appropriate wood type. In the constructor for this trade (net.minecraft.entity.merchant.villager.VillagerTrades.EmeraldForVillageTypeItemTrade (170)), the code checks to see if the passed list is missing a boat trade for the registered biome types. If a trade isn't defined, it throws an exception and crashes on startup. Since this list cannot be touched this effectively makes adding new biome types for villagers impossible. Overriding the trade using the VillagerTradesEvent has no effect since this crash occurs before the event fires. A solution to this problem is to remove the check in the constructor, and instead change the getOffer method to use a getOrDefault() instead of a get(), since the entire purpose of the check is to ensure there is no null trade.
Just tested, still present in 1.15
Provide a test mod.
Here ya' go! https://github.com/bageldotjpg/VillagerTypeTestMod
A solution if someone else haves this issue is to call the map of trades, VillagerTrades.VILLAGER_DEFAULT_TRADES, to force it to initialize before you register your villager types. Some debug text printing out the size of the map should do the trick. That way the fisherman doesn't freak out about not knowing what boat to sell in your biome. The downside is that he sells air in its place, so you'll need to use the VillagerTradesEvent to fix that for your biomes and a whole bunch of reflection to even make that possible.
The quickest fix is to change the exception to a debug log error, but it doesn't really solve the problem that new villager type fishermen would still be selling empty stacks.
I think the "best" fix would be to default whatever trades that map is not immediately aware of to whatever trade that VillagerType.PLAINS uses.
The mod link leads to a 404, would you mind reuploading?