Terraria ModLoader  0.11.6.2
A framework for Terraria mods
RecipeHooks.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 
4 namespace Terraria.ModLoader
5 {
9  public static class RecipeHooks
10  {
11  internal static readonly IList<GlobalRecipe> globalRecipes = new List<GlobalRecipe>();
12 
13  internal static void Add(GlobalRecipe globalRecipe) {
14  globalRecipes.Add(globalRecipe);
15  }
16 
17  internal static void Unload() {
18  globalRecipes.Clear();
19  }
20 
21  internal static void AddRecipes() {
22  foreach (Mod mod in ModLoader.Mods) {
23  try {
24  mod.AddRecipes();
25  foreach (ModItem item in mod.items.Values)
26  item.AddRecipes();
27  foreach (GlobalItem globalItem in mod.globalItems.Values)
28  globalItem.AddRecipes();
29  }
30  catch (Exception e) {
31  e.Data["mod"] = mod.Name;
32  throw;
33  }
34  }
35  }
36 
37  internal static void PostAddRecipes() {
38  foreach (Mod mod in ModLoader.Mods) {
39  try {
40  mod.PostAddRecipes();
41  }
42  catch (Exception e) {
43  e.Data["mod"] = mod.Name;
44  throw;
45  }
46  }
47  }
48 
54  public static bool RecipeAvailable(Recipe recipe) {
55  ModRecipe modRecipe = recipe as ModRecipe;
56  if (modRecipe != null && !modRecipe.RecipeAvailable()) {
57  return false;
58  }
59  foreach (GlobalRecipe globalRecipe in globalRecipes) {
60  if (!globalRecipe.RecipeAvailable(recipe)) {
61  return false;
62  }
63  }
64  return true;
65  }
66 
72  public static void OnCraft(Item item, Recipe recipe) {
73  ModRecipe modRecipe = recipe as ModRecipe;
74  if (modRecipe != null) {
75  modRecipe.OnCraft(item);
76  }
77  foreach (GlobalRecipe globalRecipe in globalRecipes) {
78  globalRecipe.OnCraft(item, recipe);
79  }
80  }
81  }
82 }
virtual void OnCraft(Item item)
Allows you to make anything happen when the player uses this recipe. The item parameter is the item ...
Definition: ModRecipe.cs:183
virtual void AddRecipes()
This is essentially the same as Mod.AddRecipes. Do note that this will be called for every instance o...
Definition: ModItem.cs:1051
This is where all ModRecipe and GlobalRecipe hooks are gathered and called.
Definition: RecipeHooks.cs:9
virtual void OnCraft(Item item, Recipe recipe)
Allows you to make anything happen when the player uses the given recipe. The item parameter is the i...
Definition: GlobalRecipe.cs:43
This serves as the central class which loads mods. It contains many static fields and methods related...
Definition: ModLoader.cs:26
virtual bool RecipeAvailable(Recipe recipe)
Whether or not the conditions are met for the given recipe to be available for the player to use...
Definition: GlobalRecipe.cs:34
static bool RecipeAvailable(Recipe recipe)
Returns whether or not the conditions are met for this recipe to be available for the player to use...
Definition: RecipeHooks.cs:54
This class allows you to modify and use hooks for all items, including vanilla items. Create an instance of an overriding class then call Mod.AddGlobalItem to use this.
Definition: GlobalItem.cs:15
virtual bool RecipeAvailable()
Whether or not the conditions are met for this recipe to be available for the player to use...
Definition: ModRecipe.cs:175
virtual void AddRecipes()
Override this method to add recipes to the game. It is recommended that you do so through instances o...
Definition: Mod.cs:100
virtual void PostAddRecipes()
This provides a hook into the mod-loading process immediately after recipes have been added...
Definition: Mod.cs:106
static void OnCraft(Item item, Recipe recipe)
Allows you to make anything happen when a player uses this recipe.
Definition: RecipeHooks.cs:72
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:42
Mod is an abstract class that you will override. It serves as a central place from which the mod&#39;s co...
Definition: Mod.cs:24
This class provides hooks that control all recipes in the game.
Definition: GlobalRecipe.cs:6
This class serves as a place for you to place all your properties and hooks for each item...
Definition: ModItem.cs:16
virtual void AddRecipes()
This is essentially the same as Mod.AddRecipes or ModItem.AddRecipes. Use whichever method makes orga...
Definition: GlobalItem.cs:834
This class extends Terraria.Recipe, meaning you can use it in a similar manner to vanilla recipes...
Definition: ModRecipe.cs:10