tModLoader v2023.01
A mod to make and play Terraria mods
Terraria.ModLoader.ModSystem Class Reference

ModSystem is an abstract class that your classes can derive from. It contains general-use hooks, and, unlike Mod, can have unlimited amounts of types deriving from it. More...

Inherits Terraria.ModLoader.ModType< TEntity, TModType >.

Inherited by Terraria.ModLoader.Default.LegacyUnloadedTilesSystem, and Terraria.ModLoader.Default.UnloadedSystem.

Public Member Functions

virtual void AddRecipeGroups ()
 Override this method to add recipe groups to the game.
You must add recipe groups by calling the RecipeGroup.RegisterGroup method here.
A recipe group is a set of items that can be used interchangeably in the same recipe.
 
virtual void AddRecipes ()
 Override this method to add recipes to the game.
It is recommended that you do so through instances of Recipe, since it provides methods that simplify recipe creation.
 
virtual bool CanWorldBePlayed (PlayerFileData playerData, WorldFileData worldFileData)
 Allows you to prevent the world and player from being loaded/selected as a valid combination, similar to Journey Mode pairing.
 
virtual bool HijackGetData (ref byte messageType, ref BinaryReader reader, int playerNumber)
 Allows you to modify net message / packet information that is received before the game can act on it. More...
 
virtual bool HijackSendData (int whoAmI, int msgType, int remoteClient, int ignoreClient, NetworkText text, int number, float number2, float number3, float number4, int number5, int number6, int number7)
 Hijacks the send data method. Only use if you absolutely know what you are doing. If any hooks return true, the message is not sent.
 
virtual void LoadWorldData (TagCompound tag)
 Allows you to load custom data you have saved for this system in the currently loading world.
Try to write defensive loading code that won't crash if something's missing. More...
 
virtual void ModifyGameTipVisibility (IReadOnlyList< GameTipData > gameTips)
 Allows you to set the visibility of any added vanilla or modded GameTips. In order to add your OWN tips, add them in your localization file, with the key prefix of "Mods.ModName.GameTips". More...
 
virtual void ModifyHardmodeTasks (List< GenPass > list)
 Similar to ModifyWorldGenTasks, but occurs in-game when Hardmode starts. Can be used to modify which tasks should be done and/or add custom tasks. By default the list will only contain 4 items, the vanilla hardmode tasks called "Hardmode Good", "Hardmode Evil", "Hardmode Walls", and "Hardmode Announcment"
 
virtual void ModifyInterfaceLayers (List< GameInterfaceLayer > layers)
 Allows you to modify the elements of the in-game interface that get drawn. GameInterfaceLayer can be found in the Terraria.UI namespace. Check https://github.com/tModLoader/tModLoader/wiki/Vanilla-Interface-layers-values for vanilla interface layer names More...
 
virtual void ModifyLightingBrightness (ref float scale)
 Allows you to modify overall brightness of lights. Can be used to create effects similiar to what night vision and darkness (de)buffs give you. Values too high or too low might result in glitches. For night vision effect use scale 1.03 More...
 
virtual void ModifyScreenPosition ()
 Use this hook to modify Main.screenPosition after weapon zoom and camera lerp have taken place.
 
virtual void ModifySunLightColor (ref Color tileColor, ref Color backgroundColor)
 Allows you to modify color of light the sun emits. More...
 
virtual void ModifyTimeRate (ref double timeRate, ref double tileUpdateRate, ref double eventUpdateRate)
 Called after all other time calculations. Can be used to modify the speed at which time should progress per tick in seconds, along with the rate at which the tiles in the world and the events in the world should update with it. All fields are measured in in-game minutes per real-life second (min/sec). You may want to consider Main.fastForwardTime and CreativePowerManager.Instance.GetPower<CreativePowers.FreezeTime>().Enabled here. More...
 
virtual void ModifyTransformMatrix (ref SpriteViewMatrix Transform)
 Allows you to set the transformation of the screen that is drawn. (Translations, rotations, scales, etc.)
 
virtual void ModifyWorldGenTasks (List< GenPass > tasks, ref float totalWeight)
 A more advanced option to PostWorldGen, this method allows you modify the list of Generation Passes before a new world begins to be generated. For example, removing the "Planting Trees" pass will cause a world to generate without trees. Placing a new Generation Pass before the "Dungeon" pass will prevent the the mod's pass from cutting into the dungeon.
 
virtual void NetReceive (BinaryReader reader)
 Use this to receive information that was sent in NetSend.
Called whenever MessageID.WorldData is successfully received.
Only called on the client. More...
 
virtual void NetSend (BinaryWriter writer)
 Allows you to send custom data between clients and server, which will be handled in NetReceive. This is useful for syncing information such as bosses that have been defeated.
Called whenever MessageID.WorldData is successfully sent, for example after a boss is defeated, a new day starts, or a player joins the server.
Only called on the server. More...
 
virtual void OnModLoad ()
 This hook is called right after Mod.Load(), which is guaranteed to be called after all content has been autoloaded.
 
virtual void OnModUnload ()
 This hook is called right before Mod.UnLoad()
 
virtual void OnWorldLoad ()
 Called whenever a world is loaded. This can be used to initialize data structures, etc.
If you need to access your data during worldgen, initialize it in PreWorldGen instead, unless you also save it on the world, then you need both. More...
 
virtual void OnWorldUnload ()
 Called whenever a world is unloaded. Use this to deinitialize world-related data structures, etc.
 
virtual void PostAddRecipes ()
 This provides a hook into the mod-loading process immediately after recipes have been added.
You can use this to edit recipes added by other mods.
 
virtual void PostDrawFullscreenMap (ref string mouseText)
 Called while the fullscreen map is active. Allows custom drawing to the map. Using ModMapLayer is more compatible and allows drawing on the minimap and fullscreen maps. More...
 
virtual void PostDrawInterface (SpriteBatch spriteBatch)
 Called after interface is drawn but right before mouse and mouse hover text is drawn. Allows for drawing interface. More...
 
virtual void PostDrawTiles ()
 Called after drawing Tiles. Can be used for drawing a tile overlay akin to wires. Note that spritebatch should be begun and ended within this method.
 
virtual void PostSetupContent ()
 Allows you to load things in your system after the mod's content has been setup (arrays have been resized to fit the content, etc).
 
virtual void PostSetupRecipes ()
 Override this method to do treatment about recipes once they have been setup. You shouldn't edit any recipe here.
 
virtual void PostUpdateDusts ()
 Called after Dusts get updated.
 
virtual void PostUpdateEverything ()
 Called after the Network got updated, this is the last hook that happens in an update.
 
virtual void PostUpdateGores ()
 Called after Gores get updated.
 
virtual void PostUpdateInput ()
 Called after the input keys are polled. Allows for modifying things like scroll wheel if your custom drawing should capture that.
 
virtual void PostUpdateInvasions ()
 Called after Invasions get updated. This hook is not called for multiplayer clients.
 
virtual void PostUpdateItems ()
 Called after Items get updated.
 
virtual void PostUpdateNPCs ()
 Called after NPCs get updated.
 
virtual void PostUpdatePlayers ()
 Called after Players get updated.
 
virtual void PostUpdateProjectiles ()
 Called after Projectiles get updated.
 
virtual void PostUpdateTime ()
 Called after Time gets updated.
 
virtual void PostUpdateWorld ()
 Use this method to have things happen in the world. In vanilla Terraria, a good example of code suitable for this hook is how Falling Stars fall to the ground during the night. This hook is not called for multiplayer clients.
 
virtual void PostWorldGen ()
 Use this method to place tiles in the world after world generation is complete.
 
virtual void PreDrawMapIconOverlay (IReadOnlyList< IMapLayer > layers, MapOverlayDrawContext mapOverlayDrawContext)
 Called right before map icon overlays are drawn. Use this hook to selectively hide existing IMapLayer or ModMapLayer More...
 
virtual void PreSaveAndQuit ()
 Called in SP or Client when the Save and Quit button is pressed. One use for this hook is clearing out custom UI slots to return items to the player.
 
virtual void PreUpdateDusts ()
 Called before Dusts get updated.
 
virtual void PreUpdateEntities ()
 Use this if you want to do something before anything in the World gets updated. Called after UI updates, but before anything in the World (Players, NPCs, Projectiles, Tiles) gets updated. More...
 
virtual void PreUpdateGores ()
 Called before Gores get updated.
 
virtual void PreUpdateInvasions ()
 Called before Invasions get updated. This hook is not called for multiplayer clients.
 
virtual void PreUpdateItems ()
 Called before Items get updated.
 
virtual void PreUpdateNPCs ()
 Called before NPCs get updated.
 
virtual void PreUpdatePlayers ()
 Called before Players get updated.
 
virtual void PreUpdateProjectiles ()
 Called before Projectiles get updated.
 
virtual void PreUpdateTime ()
 Called before Time gets updated.
 
virtual void PreUpdateWorld ()
 Use this method to have things happen in the world. In vanilla Terraria, a good example of code suitable for this hook is how Falling Stars fall to the ground during the night. This hook is not called for multiplayer clients.
 
virtual void PreWorldGen ()
 Allows a mod to run code before a world is generated.
If you use this to initialize data used during worldgen, which you save on the world, also initialize it in OnWorldLoad.
 
virtual void ResetNearbyTileEffects ()
 Use this to reset any fields you set in any of your ModTile.NearbyEffects hooks back to their default values.
 
virtual void SaveWorldData (TagCompound tag)
 Allows you to save custom data for this system in the current world. Useful for things like saving world specific flags.
For example, if your mod adds a boss and you want certain NPC to only spawn once it has been defeated, this is where you would store the information that that boss has been defeated in this world.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values. More...
 
override void SetupContent ()
 Unlike other ModTypes, SetupContent is unsealed for you to do whatever you need. By default it just calls SetStaticDefaults. This is the place to finish initializing your mod's content. For content from other mods, and lookup tables, consider PostSetupContent More...
 
virtual void TileCountsAvailable (ReadOnlySpan< int > tileCounts)
 Allows you to store information about how many of each tile is nearby the player. This is useful for counting how many tiles of a certain custom biome there are.
The tileCounts parameter is a read-only span (treat this as an array) that stores the tile count indexed by tile type.
 
virtual void UpdateUI (GameTime gameTime)
 Ran every update and suitable for calling Update for UserInterface classes
 
virtual string WorldCanBePlayedRejectionMessage (PlayerFileData playerData, WorldFileData worldData)
 
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Whether or not this type should be loaded when it's told to. Returning false disables Mod.AddContent from actually loading this type. More...
 
abstract void Load (Mod mod)
 Called when loading the type. More...
 
abstract void Unload ()
 Called during unloading when needed. More...
 
virtual TModType Clone (TEntity newEntity)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
virtual bool IsLoadingEnabled (Mod mod)
 Allows you to stop Mod.AddContent from actually adding this content. Useful for items that can be disabled by a config. More...
 
virtual void Load ()
 Allows you to perform one-time loading tasks. Beware that mod content has not finished loading here, things like ModContent lookup tables or ID Sets are not fully populated. More...
 
virtual TModType NewInstance (TEntity entity)
 Create a new instance of this ModType for a specific entity More...
 
virtual void SetStaticDefaults ()
 Allows you to modify the properties after initial loading has completed. More...
 
virtual void SetupContent ()
 If you make a new ModType, seal this override, and call SetStaticDefaults in it. More...
 
virtual void Unload ()
 Allows you to safely unload things you added in Load. More...
 

Protected Member Functions

override void Register ()
 If you make a new ModType, seal this override. More...
 
- Protected Member Functions inherited from Terraria.ModLoader.ModType< TEntity, TModType >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 
- Protected Member Functions inherited from Terraria.ModLoader.ModType< TEntity >
abstract TEntity CreateTemplateEntity ()
 
virtual void InitTemplateInstance ()
 Create dummy objects for instanced mod-types More...
 
override void InitTemplateInstance ()
 Create dummy objects for instanced mod-types
 
abstract void Register ()
 If you make a new ModType, seal this override. More...
 
virtual void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties More...
 

Additional Inherited Members

- Properties inherited from Terraria.ModLoader.ModType< TEntity, TModType >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 
- Properties inherited from Terraria.ModLoader.IModType
string FullName [get]
 => $"{Mod.Name}/{Name}" More...
 
Mod Mod [get]
 The mod this belongs to. More...
 
string Name [get]
 The internal name of this instance. More...
 
- Properties inherited from Terraria.ModLoader.ModType< TEntity >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone(TEntity) or via the default constructor Defaults to false (default constructor).
 
TEntity Entity [get, set]
 
string FullName [get]
 The internal name of this, including the mod it is from. More...
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
Mod Mod [get, set]
 The mod this belongs to. More...
 
virtual string Name [get]
 The internal name of this. More...
 

Detailed Description

ModSystem is an abstract class that your classes can derive from. It contains general-use hooks, and, unlike Mod, can have unlimited amounts of types deriving from it.

Member Function Documentation

◆ HijackGetData()

virtual bool Terraria.ModLoader.ModSystem.HijackGetData ( ref byte  messageType,
ref BinaryReader  reader,
int  playerNumber 
)
virtual

Allows you to modify net message / packet information that is received before the game can act on it.

Parameters
messageTypeType of the message.
readerThe reader.
playerNumberThe player number the message is from.

◆ LoadWorldData()

virtual void Terraria.ModLoader.ModSystem.LoadWorldData ( TagCompound  tag)
virtual

Allows you to load custom data you have saved for this system in the currently loading world.
Try to write defensive loading code that won't crash if something's missing.

Parameters
tagThe TagCompound to load data from.

Reimplemented in Terraria.ModLoader.Default.UnloadedSystem.

◆ ModifyGameTipVisibility()

virtual void Terraria.ModLoader.ModSystem.ModifyGameTipVisibility ( IReadOnlyList< GameTipData gameTips)
virtual

Allows you to set the visibility of any added vanilla or modded GameTips. In order to add your OWN tips, add them in your localization file, with the key prefix of "Mods.ModName.GameTips".

Parameters
gameTipsThe current list of all added game tips.

◆ ModifyInterfaceLayers()

virtual void Terraria.ModLoader.ModSystem.ModifyInterfaceLayers ( List< GameInterfaceLayer layers)
virtual

Allows you to modify the elements of the in-game interface that get drawn. GameInterfaceLayer can be found in the Terraria.UI namespace. Check https://github.com/tModLoader/tModLoader/wiki/Vanilla-Interface-layers-values for vanilla interface layer names

Parameters
layersThe layers.

◆ ModifyLightingBrightness()

virtual void Terraria.ModLoader.ModSystem.ModifyLightingBrightness ( ref float  scale)
virtual

Allows you to modify overall brightness of lights. Can be used to create effects similiar to what night vision and darkness (de)buffs give you. Values too high or too low might result in glitches. For night vision effect use scale 1.03

Parameters
scaleBrightness scale

◆ ModifySunLightColor()

virtual void Terraria.ModLoader.ModSystem.ModifySunLightColor ( ref Color  tileColor,
ref Color  backgroundColor 
)
virtual

Allows you to modify color of light the sun emits.

Parameters
tileColorTile lighting color
backgroundColorBackground lighting color

◆ ModifyTimeRate()

virtual void Terraria.ModLoader.ModSystem.ModifyTimeRate ( ref double  timeRate,
ref double  tileUpdateRate,
ref double  eventUpdateRate 
)
virtual

Called after all other time calculations. Can be used to modify the speed at which time should progress per tick in seconds, along with the rate at which the tiles in the world and the events in the world should update with it. All fields are measured in in-game minutes per real-life second (min/sec). You may want to consider Main.fastForwardTime and CreativePowerManager.Instance.GetPower<CreativePowers.FreezeTime>().Enabled here.

Parameters
timeRateThe speed at which time flows in min/sec.
tileUpdateRateThe speed at which tiles in the world update in min/sec.
eventUpdateRateThe speed at which various events in the world (weather changes, fallen star/fairy spawns, etc.) update in min/sec.

◆ NetReceive()

virtual void Terraria.ModLoader.ModSystem.NetReceive ( BinaryReader  reader)
virtual

Use this to receive information that was sent in NetSend.
Called whenever MessageID.WorldData is successfully received.
Only called on the client.

Parameters
readerThe reader.

◆ NetSend()

virtual void Terraria.ModLoader.ModSystem.NetSend ( BinaryWriter  writer)
virtual

Allows you to send custom data between clients and server, which will be handled in NetReceive. This is useful for syncing information such as bosses that have been defeated.
Called whenever MessageID.WorldData is successfully sent, for example after a boss is defeated, a new day starts, or a player joins the server.
Only called on the server.

Parameters
writerThe writer.

◆ OnWorldLoad()

virtual void Terraria.ModLoader.ModSystem.OnWorldLoad ( )
virtual

Called whenever a world is loaded. This can be used to initialize data structures, etc.
If you need to access your data during worldgen, initialize it in PreWorldGen instead, unless you also save it on the world, then you need both.

Reimplemented in Terraria.ModLoader.Default.UnloadedSystem.

◆ PostDrawFullscreenMap()

virtual void Terraria.ModLoader.ModSystem.PostDrawFullscreenMap ( ref string  mouseText)
virtual

Called while the fullscreen map is active. Allows custom drawing to the map. Using ModMapLayer is more compatible and allows drawing on the minimap and fullscreen maps.

Parameters
mouseTextThe mouse text.

◆ PostDrawInterface()

virtual void Terraria.ModLoader.ModSystem.PostDrawInterface ( SpriteBatch  spriteBatch)
virtual

Called after interface is drawn but right before mouse and mouse hover text is drawn. Allows for drawing interface.

Note: This hook should no longer be used. It is better to use the ModifyInterfaceLayers hook.

Parameters
spriteBatchThe sprite batch.

◆ PreDrawMapIconOverlay()

virtual void Terraria.ModLoader.ModSystem.PreDrawMapIconOverlay ( IReadOnlyList< IMapLayer layers,
MapOverlayDrawContext  mapOverlayDrawContext 
)
virtual

Called right before map icon overlays are drawn. Use this hook to selectively hide existing IMapLayer or ModMapLayer

Parameters
layers
mapOverlayDrawContext

◆ PreUpdateEntities()

virtual void Terraria.ModLoader.ModSystem.PreUpdateEntities ( )
virtual

Use this if you want to do something before anything in the World gets updated. Called after UI updates, but before anything in the World (Players, NPCs, Projectiles, Tiles) gets updated.

When Main.autoPause is true or Main.FrameSkipMode is 0 or 2, the game may do a partial update. This means that it only updates menus and some animations, but not the World or Entities. This hook - and every hook after it - only gets called on frames with a full update.

◆ Register()

override void Terraria.ModLoader.ModSystem.Register ( )
protectedvirtual

If you make a new ModType, seal this override.

Implements Terraria.ModLoader.ModType< TEntity, TModType >.

◆ SaveWorldData()

virtual void Terraria.ModLoader.ModSystem.SaveWorldData ( TagCompound  tag)
virtual

Allows you to save custom data for this system in the current world. Useful for things like saving world specific flags.
For example, if your mod adds a boss and you want certain NPC to only spawn once it has been defeated, this is where you would store the information that that boss has been defeated in this world.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values.

Parameters
tagThe TagCompound to save data into. Note that this is always empty by default, and is provided as an argument only for the sake of convenience and optimization.

Reimplemented in Terraria.ModLoader.Default.UnloadedSystem.

◆ SetupContent()

override void Terraria.ModLoader.ModSystem.SetupContent ( )
virtual

Unlike other ModTypes, SetupContent is unsealed for you to do whatever you need. By default it just calls SetStaticDefaults. This is the place to finish initializing your mod's content. For content from other mods, and lookup tables, consider PostSetupContent

Reimplemented from Terraria.ModLoader.ModType< TEntity, TModType >.