Template:ItemIdSet

From Terraria Wiki
Jump to navigation Jump to search
This template uses Lua.
This template uses Module:Iteminfo/idSets, a script written in the Lua programming language. To learn more about Lua, see Terraria Wiki:Lua.
Important.svg
CAUTION: Terraria Wiki code is complex!!!
If you want to use this code on another wiki, wiki.gg staff are not able to assist you.
Please consider picking a different wiki to adapt code from, or making your own templates!
Remember that content on a wiki is more important than fancy formatting.
Template-info.svg Documentation The documentation below is transcluded from Template:ItemIdSet/doc. (edit | history)

This template is used to access the database of item ID sets at Module:Iteminfo/idSets/data. The database reflects the Terraria source code (Terraria.ID.ItemID.Sets plus a few other sets). For instance, the set IsLavaImmuneRegardlessOfRarity consists of a list of items that are never destroyed when dropped in lava.

Either the entire contents of a set can be retrieved (often useful for lists/boolsets like IsLavaImmuneRegardlessOfRarity) or the value of a specific item in a set (often useful for value sets like BonusMeleeSpeedMultiplier).

Usage

Value of a specific item

{{ itemIdSet | <set name> | item = <item ID> }}

Note that this mode only supports simple sets of scalar values (Booleans, integers, floats). Nested sets like flowerPacketInfo cannot be queried with this mode; use the second mode with a combination of array functions for that.

Boolean values are returned as true/false. Use {{bool}} on the result, e.g. {{#if: {{bool|{{itemIdSet|...}}}} | setValue is true | setValue is false }}.

First unnamed parameter

Name of the set to query.

item

ID of the item to query.

Entire content of a set

{{ itemIdSet | <set name> | list = y/yes | sort = id/name (optional) }}

This mode returns the set as an array from Extension:ArrayFunctions. There are a variety of parser functions to further process the returned array. The simplest is {{#af_print:}}, which displays the array in a human-readable format. {{#af_foreach:}} is almost always useful to iterate over the set.

Beware that the values in value sets are usually represented as their respective data types from Extension:ArrayFunctions. Wrapping scalar values in {{#af_show:}} ensures that they are displayed as expected. (This does not concern the keys of value sets, which are technically integers but are always forcibly treated as strings.)

First unnamed parameter

Name of the set to query.

list

Ignores the values of the set and only returns the keys, i.e. the item IDs. This is useful for boolsets like IsLavaImmuneRegardlessOfRarity, where the value (which is always true) is unimportant.

sort

Order of the set, either item ID (id) or item name (name) in the local wiki language. |sort=id is the default if this parameter is not specified. A blank (|sort=) or unrecognized (e.g. |sort=foobar) parameter value will result in the contents being ordered randomly.

Examples

Value of a specific item

Code Result
{{itemIdSet|ShimmerTransformToItem|item=3460}} 947
{{itemIdSet|Workbenches|item=36}} true
{{itemIdSet|Workbenches|item=1}} false
{{bool|{{itemIdSet|Workbenches|item=36}}}} y
{{bool|{{itemIdSet|Workbenches|item=1}}}}
{{itemIdSet|KillsToBanner|item=2971}} 150
{{itemIdSet|BannerStrength|item=3838}} 0.2

Entire content of a set

Code Result
{{#af_print:{{itemIdSet|GrassSeeds}}}}
  • 59: true
  • 62: true
  • 194: true
  • 195: true
  • 369: true
  • 2171: true
  • 5214: true
{{#af_print:{{itemIdSet|GrassSeeds|list=y}}}}
  • 0: 59
  • 1: 62
  • 2: 194
  • 3: 195
  • 4: 369
  • 5: 2171
  • 6: 5214
{{#af_join:{{itemIdSet|GrassSeeds|list=y}}|,\s}} 59, 62, 194, 195, 369, 2171, 5214
{{#af_foreach:{{itemIdSet|GrassSeeds|list=y}}||id|{{itemNameFromId|{{{id}}}}}|delimiter=<br/>}} Corrupt Seeds
Grass Seeds
Mushroom Grass Seeds
Jungle Grass Seeds
Hallowed Seeds
Crimson Seeds
Ash Grass Seeds
{{#af_foreach:{{itemIdSet|GrassSeeds|list=y|sort=name}}||id|{{itemNameFromId|{{{id}}}}}|delimiter=<br/>}} Ash Grass Seeds
Corrupt Seeds
Crimson Seeds
Grass Seeds
Hallowed Seeds
Jungle Grass Seeds
Mushroom Grass Seeds
{{#af_foreach:{{itemIdSet|BonusMeleeSpeedMultiplier}}|id|value|{{{id}}} = {{{value}}}|delimiter=<br/>}}
Caution with scalar values in value sets! They are represented in their internal format.
757 = float__^__0.75
1827 = float__^__0.5
3013 = float__^__0.25
3106 = float__^__0.33
{{#af_foreach:{{itemIdSet|BonusMeleeSpeedMultiplier}}|id|value|{{{id}}} = {{#af_show:{{{value}}}}}|delimiter=<br/>}}
Properly handling scalar values in value sets.
757 = 0.75
1827 = 0.5
3013 = 0.25
3106 = 0.33
<ul>{{#af_foreach:{{itemIdSet|ShimmerCountsAsItem}}|id|value|<li>{{itemNameFromId|{{{id}}}}} → {{itemNameFromId|{{#af_show:{{{value}}}}}}}</li>}}</ul>
  • Shellphone (Home) → Shellphone
  • Shellphone (Spawn) → Shellphone
  • Shellphone (Ocean) → Shellphone
  • Shellphone (Underworld) → Shellphone
  • Guide to Peaceful Coexistence (Inactive) → Guide to Peaceful Coexistence