Skip to content

Support using Mod Call

JavidPack edited this page Aug 21, 2024 · 8 revisions

Modded Item Category and Filter Support

RecipeBrowser provides Mod.Call functionality to allow modders to provide additional filters and categories to the Recipe Browser menus. Mod.Call allows for mods to communicate with each other and cooperate, more info on Mod.Call can be learned from the tModLoader wiki. The most common reason to want to integrate with Recipe Browser is for adding support for your Weapon class. This guide will go through each Mod.Call pattern and corresponding arguments in detail below.

Mod.Calls

All Mod.Call listed are expected to be used before Mod.AddRecipes, which means you should integrate with RecipeBrowser in ModSystem.PostSetupContent or Mod.PostSetupContent. For organizational purposes, it is recommended to use ModSystem.PostSetupContent in a class dedicated to integrating with other mods or integrating with just RecipeBrowser. As the current Mod.Call patterns all operate only on the client, be sure to check if(!Main.dedServ) first. See the complete examples below to see this in action.

Current

These Mod.Call patterns are the currently available patterns.

AddItemCategory

"AddItemCategory", string SortName, string Parent, Asset<Texture2D> Icon, Predicate<Item> belongs
Adds an item category with the given SortName displayed on hover. If Parent is null or empty, the category will be added to the top row of the Recipe Browser category and filter UI. If Parent matches an existing category, this category will be a sub-category. Existing categories can be found on SharedUI.cs. Icon should be a 24x24 icon in a similar style to the existing icons. This Icon is the image used for the button the user can click on. belongs should return true is the provided Item belongs to the category.

Note

Icon can technically be a Texture2D, and had to be prior to v0.10.5, but Asset<Texture2D> is preferred because the textures can load more efficiently, speeding up mod load times. See the tModLoader wiki page on Asset for more information.

AddItemFilter

"AddItemFilter", string FilterName, string Parent, Asset<Texture2D> Icon, Predicate<Item> passesFilter
Adds an item filter. The parameters work the same as AddItemCategory. The Parent parameter refers to a category or sub-category name.

Note

Icon can technically be a Texture2D, and had to be prior to v0.10.5, but Asset<Texture2D> is preferred because the textures can load more efficiently, speeding up mod load times. See the tModLoader wiki page on Asset for more information.

Weak Reference Approach

Yet to be implemented.

Examples

AddItemCategory -- Adding a Weapon Class

Here is a complete example of how to get your boss in the boss log:

// In "public class RecipeBrowserIntegrationSystem : ModSystem". If running from the Mod class, change "Mod.Assets" to "this.Assets"
public override void PostSetupContent() {
	if (ModLoader.TryGetMod("RecipeBrowser", out Mod mod) && !Main.dedServ) {
		mod.Call(new object[5]
		{
			"AddItemCategory",
			"MyWeaponClass",
			"Weapons",
			Mod.Assets.Request<Texture2D>("RecipeBrowserMyWeaponClassWeaponIcon"), // 24x24 icon
			(Predicate<Item>)((Item item) =>
			{
				if (item.damage > 0)
				{
					return item.CountsAsClass<MyWeaponClass>();
				}
				return false;
			})
		});
	}
}