Tweak: Disable Vanilla Style Tool is broken
3TUSK opened this issue ยท 3 comments
Partial stacktrace:
Caused by: java.lang.UnsupportedOperationException: remove
at java.util.Iterator.remove(Iterator.java:93)
at pl.asie.charset.module.tweaks.remove.CharsetTweakRemoveVanillaTools.postInit(CharsetTweakRemoveVanillaTools.java:61)
at pl.asie.charset.lib.loader.ModuleLoader.passEvent(ModuleLoader.java:524)
... 49 more
Related code:
One possible solution is RegistryManager.ACTIVE.getRegistry(GameData.RECIPES).remove(recipe)
, but I am not exactly sure on this..
I personally wouldn't recommend removing recipes, regardless. It can cause multiple issues with mods that perform lookups on the registry name of the recipe; and with advancements that depend on the recipe. It is much safer to perform a registry replacement, much like you would with a block or item; replacing it with an empty IRecipe.
The way I mentioned is what CraftTweaker implements their recipes.remove()
.
Replacing recipes is safer for sure; meanwhile it may lead to log spam (due to different ModContainer in context)
However if you do insist on direct removal, I believe the best approach is this (although I may be wrong):
for (IRecipe recipe : ForgeRegistries.RECIPES.getValues()) {
if (itemSet.contains(recipe.getRecipeOutput().getItem())) {
((IForgeRegistryModifiable)ForgeRegistries.RECIPES).remove(ForgeRegistries.RECIPES.getKey(recipe));
itemSet.remove(recipe.getRecipeOutput().getItem());
ModCharset.logger.info("Disabled {} (removed recipe)", recipe.getRecipeOutput().getDisplayName());
}
}