TradeHelpers will duplicate trade entries like crazy
See original GitHub issueNot only was TradeHelpers nuking other mod’s trades a thing, it seems the API is also broken as well. Using the latest Fabric API, I noticed that villagers would show multiple entries for the same trade even though I only added it once.
In this case with a custom villager, calling TradeOfferHelper.registerVillagerOffers
multiple times to add trades to each trade level will duplicate all the other trade levels each time. Specifically, the issue is caused by refreshVillagerOffers being called every time TradeOfferHelper.registerVillagerOffers
is called by a mod.
Here is a more detailed look at what is going on using a debugger. I am calling TradeOfferHelper.registerVillagerOffers
5 times in order to add trades to each trade level. Show here is the entries in TradeOfferInternals.VILLAGER_TRADE_FACTORIES
at the start of refreshVillagerOffers.
After the 1st TradeOfferHelper.registerVillagerOffers call:
After the 2nd TradeOfferHelper.registerVillagerOffers call:
After the 3rd TradeOfferHelper.registerVillagerOffers call:
Notice how on the second call, level 1 trades were duplicated. And on the third call, level 1 and 2 trades were duplicated again. And it keeps growing every time it is called making the trade map bloated like crazy. Someone suggested it is because it doesn’t do a deep copy of the original vanilla maps it is suppose to replace. Instead it is feeding itself over and over. https://github.com/FabricMC/fabric/blob/12865e786ce2102d344304a679b70084be84d166/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersMixin.java#L42
However, a better solution for everyone is to trash the whole system and have the API just add/remove trades directly from vanilla’s trade maps instead with none of these caching and reloadable system. It would both solve this issue and prevent the API from nuking other mod’s trades when those mods do not use the API.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Data-driven trades could then be removed from the map directly if necessary, for now it will require a mixin, and we can add an API for that later on.
Fixed via https://github.com/FabricMC/fabric/pull/1430, please reopen if issues persist.