Template:Recipes

From Terraria Mods Wiki
Jump to navigation Jump to search
This template uses Lua.
This template uses Module:Recipes, a script written in the Lua programming language. To learn more about Lua, see tgc:Terraria Wiki:Lua.

This template defines the table "Recipes0". View table.

Template-info.svg Documentation The documentation below is transcluded from Template:Recipes/doc. (edit | history)

This template is used to display crafting recipes. It is a reimplementation of the {{crafts}} template system that is dynamic, more efficient, and more maintainable.

The {{recipes}} system depends on the existence of subpages of <mod name>/Recipes (e.g. Exxo Avalon/Recipes/Hardmode Forge), so-called recipes registration subpages. These pages store the crafting information (which would otherwise be stored on every item's page), grouped by crafting station. If all recipes are stored on those subpages, then it is possible to display the crafting information for any result or ingredient item via {{recipes}}. This facilitates easy updatability in case of patches, as only the recipes registration subpages have to be edited and the information will automatically be updated across the wiki.

Important note: As with {{item}}, all non-vanilla content like items and crafting stations must be prepended by a hash character (e.g. #Super Shotgun, #Crucible of the Cosmos) within the entirety of {{recipes}}!

Usage

Query parameters

The basic usage of {{recipes}} is to query information. There are three query constraint options:

{{ recipes | result/resultnot = <result item constraint> | ingredient/ingredientnot = <ingredient item constraint> | station/stationnot = <station constraint> | where = <custom contraint> }}

station = station1/station2/...

List only recipes that use these stations.

stationnot = station1/station2/...

Exclude recipes that use these stations.

result = result1/result2/...

List only recipes that create this item. It is also possible to do pattern search using SQL LIKE syntax. Example: result=LIKE %Phaseblade, multiple:result=#Super Shotgun/LIKE %Phaseblade. Note that "LIKE" must be all uppercase.

resultnot = result1/result2/...

Exclude recipes that create this item. It is also possible to do pattern search using SQL LIKE syntax. Example: resultnot=LIKE %Phaseblade, multiple:resultnot=#Super Shotgun/LIKE %Phaseblade. Note that "LIKE" must be all uppercase.

ingredient = ingredient1/ingredient2/...

List only recipes that use these items as ingredients. You can use "Any xxx" as ingredient name for some alternative crafting ingredients groups; and, if you query an item in a substitutable item group, you will get "Any xxx" as well. Adding "$" as a prefix ($xxx) will turn this off for that specific item. For example, if you query by |ingredient=Shadewood, you will get recipes as if you query by ingredient=$Shadewood/$Any Wood; |ingredient=$Shadewood/Iron Bar equals to |ingredient=$Shadewood/$Iron Bar/$Any Iron Bar.

It is also possible to do pattern search using SQL LIKE syntax. Example: ingredient=LIKE %Phaseblade, multiple:ingredient=#Super Shotgun/LIKE %Phaseblade. Note that "LIKE" must be all uppercase.

NOTE: The relationship between the above parameters is "and", and the relationship of multiple values inside a single parameter is "or". For example, |station=Sawmill/Loom|resultnot=Silk means (in SQL style):(station = Sawmill OR station = Loom) AND result <> Silk

where = whereString

Defines a custom constraint using SQL where syntax. If specified, all of above parameters are ignored. Used to write complex queries when necessary, use with caution. See the cargo table for the queried database and its fields.

Other parameters

The following parameters are used for certain formatting specifics:

{{ recipes | title = <custom table caption> | grouping = n/no | nostation = y | stationgrouping = n/no | showresultid = y | cate = no/force | link = n/no | expectedrows = <number of expected rows> | sortable = n/no | class/css/style/id = <custom styling> }}

title

Adds a title bar to the recipes table, with specified text.

grouping = n/no

Turn off result & ext cols grouping.

nostation = y

If set, the "Crafting station" column will be hidden. If it is not hidden, then it will display the crafting station as it is formatted in the title parameter of the {{recipes}} call on the respective recipes registration subpage. (For instance, Exxo Avalon recipes with "Adamantite Forge" set as the crafting station will always display the "Adamantite Forge or Titanium Forge or Troxinium Forge" that is set as the title of the {{recipes}} call on Exxo Avalon/Recipes/Hardmode Forge, which also has station=Adamantite Forge.) If that cannot be determined, then it falls back to the default set of formatting rules from the vanilla wiki, and finally to simply {{item|<crafting station>}}.

stationgrouping = n/no

Turn off the "Crafting station" column grouping. Only valid when nostation is not set.

showresultid = y

If set, result items will show their internal item IDs (if available).

cate = no/force

By default, this template will add the page on which it is used to the respective Category:<mod name>/<crafting station> category (e.g. Category:Exxo Avalon/Adamantite Forge or Titanium Forge or Troxinium Forge) if the crafting result is the page title itself. Using cate=no will disable this. Using cate=force will force the categorization, no matter what the result and page title are. The <crafting station> part of the category name will default to simply the exact station as it is registered, but it can be overriden in the catename parameter of the {{recipes}} call on the respective recipes registration subpage. (For instance, Exxo Avalon recipes with "Adamantite Forge" set as the crafting station will be categorized in Category:Exxo Avalon/Adamantite Forge or Titanium Forge or Troxinium Forge (and not in Category:Exxo Avalon/Adamantite Forge), as that is set as the catename in the {{recipes}} call on Exxo Avalon/Recipes/Hardmode Forge, which also has station=Adamantite Forge.)

link = n/no

Set to n/no to stop the result items from linking to their pages.

expectedrows = number

Assert the expected number of rows in this crafts table. If the expected and actual number of rows are not equal, this page will be added to Category:Recipes table with unexpected total number of rows.

sortable = n/no

Makes the table unsortable.

class =
id =
css/style =

HTML class/id/style attributes for the outer wrapper div element.

Examples

For this example, it is assumed we are in the Exxo Avalon mod wiki.

{{recipes|ingredient=#Hydrolyth Bar|station=#Xeradon Anvil|resultnot=LIKE #Milotic%/#Superhardmode Bar|expectedrows=3}}

This code selects all recipes that use Hydrolyth Bars as an ingredient and are crafted at the Xeradon Anvil. It excludes the Milotic armor and the Superhardmode Bar recipes. There are three items whose recipes match these requirements (Elektriwave, Onyx Staff, and Staff of the Tempest Frigid), so we expect three rows.

Register recipes

On the recipes registration subpages, recipes are registered using {{recipes/register}}. For the usage of {{recipes/register}}, see its documentation.

Advanced Usage

Custom Result Cells

resulttemplate = template name used for format result cell.

This template will receive the following arguments:

  • link, showid, noversion: options for {{item}} template used by default display.
  • result, resultid, resultimage, resultname, resulttext, amount: infomation about crafting result.

"@@@@" in template output will be replaced with the default result display.

See Chairs/resultcell for an example.

Custom Table Header

header-result = content of result <th>, default is Result
header-ingredients = content of ingredients<th>, default is Ingredients
header-station = content of crafting station<th>, default is [[Crafting station]]

Adding extra columns/rows around crafting stations

Only valid when nostation is not set.

Define cols:

station-col-before-1
station-col-before-2
station-col-before-3

...
Column headers before crafting station column

station-col-after-1
station-col-after-2
station-col-after-3

...
Column headers before crafting station column

Define index key for row content:

station-index-Furnace = _a

Define index key for "Furnace"(as station parameter), for example

Define actual contents:

_a-row-station-col-before-1 =
_a-row-station-col-before-2 =

...

_a-row-station-col-after-1 =

...
Define contents for <td> using index key.

Adding extra cols/rows around by crafting results

Define columns:

col-A-1
col-A-2

...

col-B-1

...

col-C-1

...

col-D-1

...
The order in which all columns are displayed is:
col-As • Resultcol-Bs • Ingredientscol-Cs • station-col-befores • Crafting Stationstation-col-afters • Col-Ds

Define index key for row content:
Define index key for a row(Priority in this order):

result-index-#3 = _a

Define by row number

result-index-Crimtane Bar-desktop console = _a

Define by result name + version info

result-index-Copper Bar = _a

Define by result name

Define actual contents:

_a-row-col-A-1 =

...
Define contents for <td> using index key, corresponding to the definition of columns.

Adding extra rows

NOTE: extra rows don't count as part of expectedrows.

Before recipe rows:

topextrow-1-col-result =
topextrow-1-col-ingredients =
topextrow-1-col-station =
topextrow-1-col-ingredients =
topextrow-1-col-C-2 =

...

topextrow-2-col-result =

...

After recipe rows:

extrow-1-col-result =
extrow-1-col-ingredients =
extrow-1-col-station =
extrow-1-col-B-1 =
extrow-1-col-C-1 =

...

extrow-2-col-result =

...

See Bars and Recovery potions for examples.

Extract component

Some components of a recipe can be extracted and formatted separately, see {{recipes/extract}}.

Count for result rows

You can use {{recipes/exist}} and {{recipes/count}} to check the existence and number of results of recipes that meet query constraints. Note: you should use {{#if:{{recipes/exist|<constraints>}}}} to check the existence instead of {{#ifeq:{{recipes/count|<constraints>}}|0}}, because the former is much faster and cheaper.