MinecraftForge icon indicating copy to clipboard operation
MinecraftForge copied to clipboard

[1.15.2] Registering villager types per biome is impossible

Open SilverDavidMC opened this issue 5 years ago • 7 comments

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:

  1. Register a villager type for any mod biome.
  2. 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.

SilverDavidMC avatar Jan 03 '20 05:01 SilverDavidMC

Just tested, still present in 1.15

bageldotjpg avatar Jun 12 '20 22:06 bageldotjpg

Provide a test mod.

LexManos avatar Jun 12 '20 22:06 LexManos

Here ya' go! https://github.com/bageldotjpg/VillagerTypeTestMod

bageldotjpg avatar Jun 13 '20 02:06 bageldotjpg

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.

SilverDavidMC avatar Jul 27 '20 02:07 SilverDavidMC

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.

Shadows-of-Fire avatar Sep 22 '21 00:09 Shadows-of-Fire

Updated test mod to 1.16.1 (32.0.71) latest.log

The mod link leads to a 404, would you mind reuploading?

lentilpietuxxy avatar Oct 04 '21 08:10 lentilpietuxxy