-
Notifications
You must be signed in to change notification settings - Fork 6
en Basic VaultLoaden
VaultLoadenAttribute is an automatic resource loading attribute designed for Terraria ModLoader mod developers. By adding this attribute to static fields or properties, resources such as textures and sounds can be automatically assigned without manual loading, simplifying resource management.
- Automatically loads textures, sounds, effects, and other resources for static fields or properties.
- Supports intelligent path completion and namespace replacement.
- Supports cross-mod resource referencing.
- Resource type can be auto-inferred or manually specified.
| Resource Type | Member Type | AssetMode Value |
|---|---|---|
| Sound | SoundStyle |
AssetMode.Sound |
| Texture | Asset<Texture2D> |
AssetMode.Texture |
| Shader (.xnb) | Asset<Effect> |
AssetMode.Effects |
| Armor Shader | ArmorShaderData |
AssetMode.ArmorShader |
| Misc Shader | MiscShaderData |
AssetMode.MiscShader |
Apply the [VaultLoaden] attribute to a static field or property, optionally specifying the path and asset type.
[VaultLoaden("Assets/Sounds/MySound", AssetMode.Sound)]
public static SoundStyle MySoundEffect;If the path ends with /, the field name will be automatically appended to the path:
[VaultLoaden("Assets/Textures/UI/", AssetMode.Texture)]
public static Asset<Texture2D> ButtonBackground;
// Actual path: Assets/Textures/UI/ButtonBackgroundYou can use the {@namespace} placeholder in the path to automatically replace with the namespace path:
namespace MyMod.Content.UI {
[VaultLoaden("{@namespace}/Panels/", AssetMode.Texture)]
public static Asset<Texture2D> MainPanel;
}
// Actual path: MyMod/Content/UI/Panels/MainPanelIf AssetMode is not specified, the type will be inferred from the field type:
[VaultLoaden("Assets/Sounds/MenuOpen")]
public static SoundStyle MenuOpenSound;
// Automatically inferred as AssetMode.Sound[VaultLoaden("Assets/Effects/Glow/")]
public static Asset<Effect> GlowEffect;
// Auto-completes field name, final path: Assets/Effects/Glow/GlowEffect[VaultLoaden("Assets/Effects/Glow/GlowEffect", AssetMode.ArmorShader, "CustomPass")]
public static ArmorShaderData CustomShader;
// Uses effect pass name "CustomPass"If effectPassname is omitted, it defaults to {EffectName}Pass.
To load a resource from another mod, prefix the path with @ModName/:
[VaultLoaden("@ExampleMod/Assets/Textures/ExtraBar", AssetMode.Texture)]
public static Asset<Texture2D> ExtraBarTex;
// Loads resource from mod named ExampleMod- Only supports static fields or properties.
- Properties must have a public or non-public setter.
- Unsupported types (e.g., string, int) are not allowed.
| Error Message | Cause |
|---|---|
| Cannot determine asset mode for ... | Resource type cannot be inferred. Specify AssetMode manually. |
| Property ... has no setter. | Property lacks a setter and cannot be assigned. |
| Member ... couldn't find Mod "xxx" | Specified mod name does not exist or is misspelled. |
| Attribute path on member ... is empty or invalid | Path is empty or formatted incorrectly. |
| After the Effect is loaded, there is an error message saying "Pass or Filters.Scene" | Incorrect EffectPassname or missing pass in effect file. |
public class AssetClass1
{
// Auto-inferred as Sound
[VaultLoaden("Assets/Sounds/Click")]
public static SoundStyle ClickSound;
// Auto-inferred as Texture (field name used: ButtonBackground)
[VaultLoaden("Assets/Textures/", AssetMode.Texture)]
public static Asset<Texture2D> ButtonBackground;
// Namespace replacement example
[VaultLoaden("{@namespace}/Icons/Warning", AssetMode.Texture)]
public static Asset<Texture2D> WarningIcon;
// Load effect and specify pass name
[VaultLoaden("Effects/Beam", AssetMode.Effects, "GlowPass")]
public static Asset<Effect> BeamEffect;
// Load ArmorShaderData
[VaultLoaden("Effects/Armor/ColdShader", AssetMode.ArmorShader)]
public static ArmorShaderData ColdArmorShader;
// Load resource from another mod
[VaultLoaden("@OtherMod/Textures/Cursor", AssetMode.Texture)]
public static Asset<Texture2D> OtherCursor;
}
// Automatically load resource members from AssetClass2 in the "Assets/Image/" folder
[VaultLoaden("Assets/Image/")]
public class AssetClass2
{
public static Asset<Texture2D> Image1; // Loads "Assets/Image/Image1"
public static Asset<Texture2D> Image2; // Loads "Assets/Image/Image2"
public static Asset<Texture2D> Image3; // Loads "Assets/Image/Image3"
}
// It's optional to end the path with '/', the system will automatically append it if missing
[VaultLoaden("Assets/Image")]
public class AssetClass3
{
public static Asset<Texture2D> Image1; // Loads "Assets/Image/Image1"
public static Asset<Texture2D> Image2; // Loads "Assets/Image/Image2"
public static Asset<Texture2D> Image3; // Loads "Assets/Image/Image3"
// Class-level and member-level tags do not conflict;
// members with their own tag will be skipped by the class-level loader
[VaultLoaden("@OtherMod/Textures/")]
public static Asset<Texture2D> MyFaceImage; // Loads "OtherMod/Textures/MyFaceImage"
}