Terraria ModLoader  0.11.7.8
A mod to make and play 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 
16  internal static bool setupRecipes = false;
17 
18  internal static void Add(GlobalRecipe globalRecipe) {
19  globalRecipes.Add(globalRecipe);
20  }
21 
22  internal static void Unload() {
23  globalRecipes.Clear();
24  setupRecipes = false;
25  }
26 
27  internal static void AddRecipes() {
28  foreach (Mod mod in ModLoader.Mods) {
29  try {
30  mod.AddRecipes();
31  foreach (ModItem item in mod.items.Values)
32  item.AddRecipes();
33  foreach (GlobalItem globalItem in mod.globalItems.Values)
34  globalItem.AddRecipes();
35  }
36  catch (Exception e) {
37  e.Data["mod"] = mod.Name;
38  throw;
39  }
40  }
41  }
42 
43  internal static void PostAddRecipes() {
44  foreach (Mod mod in ModLoader.Mods) {
45  try {
46  mod.PostAddRecipes();
47  }
48  catch (Exception e) {
49  e.Data["mod"] = mod.Name;
50  throw;
51  }
52  }
53  }
54 
60  public static bool RecipeAvailable(Recipe recipe) {
61  ModRecipe modRecipe = recipe as ModRecipe;
62  if (modRecipe != null && !modRecipe.RecipeAvailable()) {
63  return false;
64  }
65  foreach (GlobalRecipe globalRecipe in globalRecipes) {
66  if (!globalRecipe.RecipeAvailable(recipe)) {
67  return false;
68  }
69  }
70  return true;
71  }
72 
78  public static void OnCraft(Item item, Recipe recipe) {
79  ModRecipe modRecipe = recipe as ModRecipe;
80  if (modRecipe != null) {
81  modRecipe.OnCraft(item);
82  }
83  foreach (GlobalRecipe globalRecipe in globalRecipes) {
84  globalRecipe.OnCraft(item, recipe);
85  }
86  }
87  }
88 }
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:201
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:28
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:60
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:193
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:78
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