![]() |
tModLoader v2025.03
A mod to make and play Terraria mods
|
SetFactory is responsible for creating "custom ID sets" for content. "Custom ID sets" refers to arrays indexed by content ids. The ID set contains data applying to all instances of content of a specific type. This is typically metadata or data controlling how code will interact with each type of content. Each vanilla ID class contains a SetFactory instance called "Factory" which is used to initialize the ID sets contained within the ID class. For example ItemID.Sets.Factory is used to initialize ItemID.Sets.IsFood with true values for food items such as ItemID.PadThai. Modded content updates ID sets in ModType.SetStaticDefaults: ItemID.Sets.IsFood[Type] = true;
. Code in tModLoader and individual mods might consult the data in ItemID.Sets.IsFood for whatever purpose they want. Mods can make their own custom ID sets through the methods of this class. The CreateNamedSet(string) methods create custom ID sets that facilitate collaborative "named ID sets". Mods using the same "named ID set" will share a reference to the same array merging together all the entries and changes. More information can be found in the Custom and Named ID Sets pull request.
More...
Classes | |
class | NamedSetKey |
Used to construct the key for this "named ID set". Must be chained with a RegisterXSet method to create and register the set for sharing. More... | |
Public Member Functions | |
SetFactory (int size) | |
SetFactory (int size, string idClassName, Func< int, string > getName=null) | |
SetFactory (int size, string idClassName, IdDictionary search) | |
void | Clear () |
bool[] | CreateBoolSet (bool defaultState, params int[] types) |
Creates and returns a bool array ID set. All values will be defaultState except the indexes passed in (types ) will be the opposite of defaultState . | |
bool[] | CreateBoolSet (params int[] types) |
Creates and returns a bool array ID set. All values will be false except the indexes passed in (types ) will be true. | |
T[] | CreateCustomSet< T > (T defaultState, params object[] inputs) |
Creates and returns an array ID set of the supplied Type. This should be used for creating ID sets not covered by the other methods, such as for classes (string, List<T>), nullable primitives (bool?), and structs (Color). All values are defaultState except for the values passed in as inputs . The inputs contain index value pairs listed one after the other. For example CreateCustomSet<string>(null, ItemID.CopperOre, "Ugly", ItemID.SilverOre, "Pretty") will result in an array filled with null except the CopperOre index will have a value of "Ugly" and the SilverOre index a value of "Pretty". Note that for non-null class values used for defaultState , the reference will be shared with all default entries, so be mindful when working with these sets to not accidentally affect the shared default state object. For example passing in new List<int> as defaultState will make it very likely to be misused on accident. | |
float[] | CreateFloatSet (float defaultState, params float[] inputs) |
Creates and returns a float array ID set. All values are defaultState except for the values passed in as inputs . The inputs contain index value pairs listed one after the other. For example CreateFloatSet(1f, ItemID.CopperOre, 1.5f, ItemID.SilverOre, 2.3f) will result in an array filled with 1f except the CopperOre index will have a value of 1.5f and the SilverOre index a value of 2.3f. | |
int[] | CreateIntSet (int defaultState, params int[] inputs) |
Creates and returns an int array ID set. All values are defaultState except for the values passed in as inputs . The inputs contain index value pairs listed one after the other. For example CreateIntSet(-1, ItemID.CopperOre, 10, ItemID.SilverOre, 20) will result in an array filled with -1 except the CopperOre index will have a value of 10 and the SilverOre index a value of 20. | |
int[] | CreateIntSet (params int[] types) |
Creates and returns an int array ID set. All values are -1 except for the values passed in as types . The types contain index value pairs listed one after the other. For example CreateIntSet([ItemID.CopperOre, 10, ItemID.SilverOre, 20]) will result in an array filled with -1 except the CopperOre index will have a value of 10 and the SilverOre index a value of 20. | |
NamedSetKey | CreateNamedSet (Mod mod, string key) |
The final key for this named ID set using this overload will be: "{mod.Name}/{key}" CreateNamedSet(string) | |
NamedSetKey | CreateNamedSet (string fullKey) |
The final key for this named ID set using this overload will be "{key}" directly if it contains a "/". Otherwise, the final key will be derived automatically from the currently loading mod: "{loadingMod.Name}/{key}" | |
NamedSetKey | CreateNamedSet (string modName, string key) |
The final key for this named ID set using this overload will be: "{modName}/{key}" | |
ushort[] | CreateUshortSet (ushort defaultState, params ushort[] inputs) |
Creates and returns a ushort array ID set. All values are defaultState except for the values passed in as inputs . The inputs contain index value pairs listed one after the other. For example CreateUshortSet(0, ItemID.CopperOre, 10, ItemID.SilverOre, 20) will result in an array filled with 0 except the CopperOre index will have a value of 10 and the SilverOre index a value of 20. | |
void | MergeNamedSets< T > (params string[] inputSetNames) |
Causes sets registered with the provided keys (and matching SetFactory and Type) to be merged as if they are registered with the same key. This is useful for situations where established set keys are determined to have identical meaning but the involved mods are incapable of updating to collaborate on the shared key, either due to dependent mods or inactivity. Essentially, the sets will be merged and share the same data. The default value must still be consistent between the sets. This must be called before the ResizeArrays stage of mod loading, such as in a Load method. | |
void | Recycle< T > (T[] buffer) |
void | RegisterNamedCustomSet< T > (NamedSetKey setKey, T defaultValue, ref T[] input) |
Manually registers a named ID set. This is typically done through the Terraria.ID.XID.Sets.Factory.CreateNamedSet().RegisterXSet() methods, but this method can be used for manually initialized arrays. The set reference passed in might be changed by this method when merging with existing data. Throws an exception if the data length or default value does not match a named ID set with the same key registered before this. More... | |
Static Public Member Functions | |
static void | ResizeArrays (bool unloading) |
Protected Member Functions | |
bool[] | GetBoolBuffer () |
float[] | GetFloatBuffer () |
int[] | GetIntBuffer () |
ushort[] | GetUshortBuffer () |
Protected Attributes | |
int | _size |
SetFactory is responsible for creating "custom ID sets" for content. "Custom ID sets" refers to arrays indexed by content ids. The ID set contains data applying to all instances of content of a specific type. This is typically metadata or data controlling how code will interact with each type of content. Each vanilla ID class contains a SetFactory instance called "Factory" which is used to initialize the ID sets contained within the ID class.
For example ItemID.Sets.Factory is used to initialize ItemID.Sets.IsFood with true values for food items such as ItemID.PadThai. Modded content updates ID sets in ModType.SetStaticDefaults: ItemID.Sets.IsFood[Type] = true;
. Code in tModLoader and individual mods might consult the data in ItemID.Sets.IsFood for whatever purpose they want.
Mods can make their own custom ID sets through the methods of this class. The CreateNamedSet(string) methods create custom ID sets that facilitate collaborative "named ID sets". Mods using the same "named ID set" will share a reference to the same array merging together all the entries and changes. More information can be found in the Custom and Named ID Sets pull request
.
void SetFactory.RegisterNamedCustomSet< T > | ( | NamedSetKey | setKey, |
T | defaultValue, | ||
ref T[] | input | ||
) |
Manually registers a named ID set. This is typically done through the Terraria.ID.XID.Sets.Factory.CreateNamedSet().RegisterXSet()
methods, but this method can be used for manually initialized arrays. The set reference passed in might be changed by this method when merging with existing data. Throws an exception if the data length or default value does not match a named ID set with the same key registered before this.