Jump to content

[Documentation] New Recipe System Functions & Other Info


Recommended Posts

This is some documentation about the new recipe system. This doesn't have everything, but should be a solid starting point. I included GLOBAL before every global function, as I assume these will all be used in modmain.

New Recipe Functions

The examples are a bit ridiculous on purpose to get the point across.

AddRecipe2

Spoiler

AddRecipe2(name, ingredients, tech, config, filters)

The AddRecipe2 function is intended for adding custom recipes to the game.

Parameters:
Parameters in bold are required.

  • name - A string, sets the internal name for your recipe. Will also be product of the craft unless otherwise set in the config. Multiple recipes for the same product MUST be named differently, or the last one called will take precedent.
  • ingredients - A table of ingredients used for the recipe. Identically formatted to old AddRecipe ingredient tables.
  • tech - A GLOBAL.TECH variable. The tech level, aka crafting station, that is required to craft the item. See constants.lua's TECH table for a list of possible tech levels.
  • config - A table of configuration settings that can be set for the recipe.
  • filters - A table of crafting filters this recipe will show up in. AddRecipe2 automatically adds your item to the "MODS" filter, unless you remove it manually.

Examples:

Spoiler

Item:



AddRecipe2("awesome_beardhair", -- name
	{ -- ingredients
		GLOBAL.Ingredient("cutgrass", 1),
		GLOBAL.Ingredient("twigs", 1),
	},
	GLOBAL.TECH.SCIENCE_ONE, -- tech
	{ -- config
		product = "beardhair",
		builder_tag = "bearded",
		numtogive = 3,
	}, 
	{ -- filters
		"WEAPONS",
		"RAIN",
		"SUMMER",
	}
)

Structure:



AddRecipe2("awesome_researchlab", -- name
	{ -- ingredients
		GLOBAL.Ingredient("cutgrass", 1),
		GLOBAL.Ingredient("goldnugget", 1),
		GLOBAL.Ingredient("beardhair", 1),
	},
	GLOBAL.TECH.SCIENCE_ONE, -- tech
	{ -- config
		product = "researchlab",
		placer = "researchlab_placer",
		nounlock = true,
	}, 
	{ -- filters
		"MAGIC",
		"DECOR",
	}
)

 

Possible Config Variables:

Spoiler

min_spacing
nounlock
numtogive
builder_tag
atlas
image
testfn
product
build_mode
build_distance

You may be able to use some older config options found in recipe.lua, but they may not be properly supported.

Possible Filters:

Spoiler

"FAVORITES"
"CRAFTING_STATION"
"SPECIAL_EVENT"
"MODS"
"CHARACTER"
"TOOLS"
"LIGHT"
"PROTOTYPERS"
"REFINE"
"WEAPONS"
"ARMOUR"
"CLOTHING"
"RESTORATION"
"MAGIC"
"DECOR"
"STRUCTURES"
"CONTAINERS"
"COOKING"
"GARDENING"
"FISHING"
"SEAFARING"
"RIDING"
"WINTER"
"SUMMER"
"RAIN"
"EVERYTHING"

 

 

AddCharacterRecipe

Spoiler

AddCharacterRecipe(name, ingredients, tech, config, filters)

The AddCharacterRecipe function is intended for adding custom character recipes to the game, based on the builder_tag set. They will show up in the "Survivor Items" section of the crafting menu.

Parameters:
Parameters in bold are required.

  • name - A string, sets the internal name for your recipe. Will also be product of the craft unless otherwise set in the config. Multiple recipes for the same product MUST be named differently, or the last one called will take precedent.
  • ingredients - A table of ingredients used for the recipe. Identically formatted to old AddRecipe ingredient tables.
  • tech - A GLOBAL.TECH variable. The tech level, aka crafting station, that is required to craft the item. See constants.lua's TECH table for a list of possible tech levels.
  • config - A table of configuration settings that can be set for the recipe. builder_tag is required for AddCharacterRecipe.
  • filters - A table of crafting filters names this recipe will show up in. The recipe is automatically added to the character recipes filter by AddCharacterRecipe, but is not added to the "MODS" filter.

Example:

Spoiler


AddCharacterRecipe("awesome_beardhair", -- name
	{ -- ingredients
		GLOBAL.Ingredient("cutgrass", 1),
		GLOBAL.Ingredient("twigs", 1),
	},
	GLOBAL.TECH.NONE, -- tech
	{ -- config
		product = "beardhair",
		builder_tag = "bearded",
		numtogive = 3,
	}, 
	{ -- filters
		"WEAPONS",
	}
)

 

Possible config variables and filter names can be found in the AddRecipe2 section.

 

AddRecipeFilter

Spoiler

AddRecipeFilter(filter_def, index)

The AddRecipeFilter function is intended for adding custom recipe filters to the game. If you're making a custom character filter, it's recommended you  use AddCharacterRecipe in combination with the new built in character recipe filter.

Parameters:
Parameters in bold are required.

  • filter_def - A table of variables required to set up a custom recipe filter.
  • index - A number, sets a filter's priority among other filters.

Example:

Spoiler


-- This string must be set somewhere for the display name of the filter. "EXAMPLE" should match your filter's internal name.
GLOBAL.STRINGS.UI.CRAFTING_FILTERS["EXAMPLE"] = "Example Filter"

AddRecipeFilter(
	{ -- filter_def
		name = "EXAMPLE", -- internal name.
		atlas = "images/crafting_menu_icons.xml",
		image = "filter_modded.tex",
		image_size = 64, -- 64 is default
		custom_pos = false, -- setting to true hides this filter from the normal filter grid.
	},
	5 -- index
)

 

 

 

AddRecipeToFilter

Spoiler

AddRecipeToFilter(recipe_name, filter_name)

The AddRecipeToFilter function is intended for adding a given recipe to a given filter.

Parameters:
Parameters in bold are required.

  • recipe_name - A string, the internal name of a recipe you'd like to effect.
  • filter_name - A string, the name of a filter you'd like to effect.

Example:

Spoiler


AddRecipeToFilter("spear", "DECOR")

 

 

 

RemoveRecipeFromFilter

Spoiler

RemoveRecipeFromFilter(recipe_name, filter_name)

The RemoveRecipeFromFilter function is intended for removing a given recipe from a given filter.

Parameters:
Parameters in bold are required.

  • recipe_name - A string, the internal name of a recipe you'd like to effect.
  • filter_name - A string, the name of a filter you'd like to effect.

Example:

Spoiler


RemoveRecipeFromFilter("spear", "WEAPONS")

 

 

 

Other Info

Custom characters can have a unique icon for their crafting filter by putting an image in images/crafting_menu_avatars/avatar_esctemplate.xml and .tex. Otherwise, the game will automatically use the image in images/avatars/avatar_esctemplate.xml and .tex. Of course, esctemplate should be replaced with your character's prefab name.

If your item's recipe icon is invisible, you likely need to register it's inventory icon with the game properly. See the RegisterInventoryItemAtlas section from Hornete's Modutil Documentation.

 

And that's all I have for you, for now anyway. Have fun!

Edited by TheSkylarr
  • Like 4
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Leonidas IV said:

Beautiful work! The only thing I would add is the parameter type (you wrote it for the tables), typing in documentation is essential.

Good point! I'll get on that pretty soon here.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...