Charset (1.10.x)

Charset (1.10.x)

3M Downloads

Tweak: Disable Vanilla Style Tool is broken

3TUSK opened this issue ยท 3 comments

commented

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:

Iterator<IRecipe> iterator = CraftingManager.REGISTRY.iterator();
while (iterator.hasNext()) {
ItemStack output = iterator.next().getRecipeOutput();
if (!output.isEmpty() && itemSet.contains(output.getItem())) {
iterator.remove();
itemSet.remove(output.getItem());
ModCharset.logger.info("Disabled " + Item.REGISTRY.getNameForObject(output.getItem()).toString() + " (removed recipe)");
}
}

One possible solution is RegistryManager.ACTIVE.getRegistry(GameData.RECIPES).remove(recipe), but I am not exactly sure on this..

commented

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.

commented

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)

commented

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());
	}
}