Darkhax-Minecraft / Bookshelf

A library mod which adds additional code support beyond what is provided by Forge.
GNU Lesser General Public License v2.1
142 stars 39 forks source link

ItemTier Initialization #150

Closed ChampionAsh5357 closed 3 years ago

ChampionAsh5357 commented 3 years ago

This a simple fix around registry execution for item tiers. Since an ItemTier would most likely be declared in a static final field, there needs to be extra care taken on the inputted ingredient parameters to make sure that they are not loaded until the registry has finished. To counteract this, static final initializer methods were used to add suppliers to all available constructors. The original constructors are deprecated as they should be removed during the next api break. All the fields are now properly deferred until first access.

There would be an issue of tags not being loaded yet. However, the only access provided to the ingredient is within RecipeContainer, so there should be no issue in basic implementation.

Also, to save on resources and not construct the supplier output over and over, a Lazy was used to make the supplier deterministic and save the first access.