question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TradeHelpers will duplicate trade entries like crazy

See original GitHub issue

Not 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. image

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: image

After the 2nd TradeOfferHelper.registerVillagerOffers call: image

After the 3rd TradeOfferHelper.registerVillagerOffers call: image

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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Technici4ncommented, Apr 24, 2021

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.

0reactions
sfPlayer1commented, May 1, 2021

Fixed via https://github.com/FabricMC/fabric/pull/1430, please reopen if issues persist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 3 Strategies for Master Copy Traders | Bybit Learn
Looking to add to your arsenal of trading strategies as a Bybit master copy traders? Get started with these top copy trading strategies....
Read more >
How to Make (and Lose) $2000000 Day Trading - StartupBros
Imagine this: You've just gone long the corn futures market for 2 contracts. You're up $5000 on a trade in two hours. Awesome,...
Read more >
10 Best FREE Copy Trading Platforms & Apps (DEC 2022)
Bybit considers it as malicious trade and can ban the master trader. 2. BingX — Exchange + Copy Trading App. BingX is a...
Read more >
Are You Undertrading or Overtrading? - Investopedia
Entry and exit from stocks should not be random ; there should be a reason behind each trade supported by the trading plan....
Read more >
The Truth About Trading Daily Timeframe Nobody Tells You
When you trade on the lower timeframe, news events (like FOMC, NFP, etc.) is a big thing. You'll notice the price goes “crazy”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found