Skip to content

Saving Custom Data

ScalarVector edited this page Oct 1, 2025 · 1 revision

What is custom data?

'Custom data' refers to implementations of the ITileData interface provided by tModLoader. If you are unfamiliar with this, the features described in this guide are likely of little use to you. While StructureHelper's API and features to interact with such data are relatively simple, tModLoader's API for adding such features to your mod to use is not.

Register your custom data for selection

In order to see your custom data type in the custom data wand for selection, you will first need to make a mod call to register your custom ITileData type. This call is relatively simple and takes only 3 parameters:

  • A call identifier string, this should always be "RegisterCustomData"
  • the Type object for your custom ITileData struct. This will usually be typeof(YourCustomStruct)
  • an instance of your mod's Mod object

A simple example of this call in it's own ModSystem may look like this:

	internal class RegisterStructureHelperDataSystem : ModSystem
	{
		public override void OnModLoad()
		{
			if (ModLoader.TryGetMod("StructureHelper", out Mod sh))
			{
				sh.Call("RegisterCustomData", typeof(YourCustomTileDataStruct), Mod);
			}
		}
	}

Select relevant data per-structure in-game

The ability to save your custom tile data to a structure is entirely opt-in. This is because needlessly saving custom data types into your structure is costly both for file size and performance when saving and generating your structures. When saving your structures, you will be able to use the custom data wand to select from all registered custom data types as to allow you to select a minimal set to save for your use case. When used, this wand will bring up a list of all registered custom ITileData structs, which you can click to select. Select only the tile data you wish to save with a given structure!

image

Save your structure

Save your structure as you normally would! See Structure Wand or Multistructure Wand for more information if needed.

You are done!

Your structure should now generate correctly with custom data (So long as the mod that provides said data is loaded, ofcourse!) when generated via any methods in the Generator API

For more advanced use cases

For those that wish to save custom data manually via the Saver API, they should use Saver.SaveToStructureDataWithCustom, which accepts a list of custom ITileData struct types as a parameter. Note that you do not need to make the Mod.Call call to register the structs passed here! The Mod.Call call is solely to register the type for the custom data wand.

Clone this wiki locally