function replaceItemInAllRecipes(event, oldItem, newItem) {
  Platform.getMods().forEach((modId, modInfo) => {
    event.forEachRecipe({ mod: modId }, (recipe) => {
      const recipeJsonString = recipe.json.toString();
      if (!recipeJsonString.includes(`"${oldItem}"`)) return;

      const newRecipeJson = JSON.parse(recipeJsonString.replace(`"${oldItem}"`, `"${newItem}"`));

      event.remove({ id: `${recipe.id}` });
      event.custom(newRecipeJson).id(`${recipe.id}`);
      console.log(`${recipe.id} from ${modInfo.name} has been edited.`);
    });
  });
}

ServerEvents.recipes((event) => {
  replaceItemInAllRecipes(event, 'irons_spellbooks:blood_vial', 'hexerei:blood_bottle');
  event.replaceInput({ input: 'kaleidoscope_cookery:oil' }, 'kaleidoscope_cookery:oil', 'hexerei:animal_fat');
  event.replaceInput({ output: 'kaleidoscope_cookery:oil' }, 'kaleidoscope_cookery:oil', 'hexerei:animal_fat');
});
