TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ AddEquipTexture()

static int Terraria.ModLoader.EquipLoader.AddEquipTexture ( Mod mod,
string texture,
EquipType type,
ModItem item = null,
string name = null,
EquipTexture equipTexture = null )
inlinestatic

Adds an equipment texture of the specified type, internal name, and/or associated item to your mod.
If no internal name is provided, the associated item's name will be used instead.
You can then get the ID for your texture by calling EquipLoader.GetEquipTexture, and using the EquipTexture's Slot property.
If you need to override EquipmentTexture's hooks, you can specify the class of the equipment texture class.

If both an internal name and associated item are provided, the EquipTexture's name will be set to the internal name, alongside the keys for the equipTexture dictionary.
Additionally, if multiple EquipTextures of the same type are registered for the same item, the first one to be added will be the one automatically displayed on the player and mannequins.

Parameters
modThe mod the equipment texture is from.
equipTextureThe equip texture.
itemThe item.
nameThe internal name.
typeThe type.
textureThe texture.
Returns
the ID / slot that is assigned to the equipment texture.

Definition at line 284 of file EquipLoader.cs.

285 {
286 if (!mod.loading)
287 {
288 throw new Exception("AddEquipTexture can only be called from Mod.Load or Mod.Autoload");
289 }
290 if (name == null && item == null)
291 {
292 throw new Exception("AddEquipTexture requires either an item or a name be provided");
293 }
294 if (equipTexture == null)
295 {
296 equipTexture = new EquipTexture();
297 }
298 ModContent.Request<Texture2D>(texture);
299 equipTexture.Texture = texture;
300 equipTexture.Name = name ?? item.Name;
301 equipTexture.Type = type;
302 equipTexture.Item = item;
303 int num2 = (equipTexture.Slot = ReserveEquipID(type));
304 int slot = num2;
306 mod.equipTextures[Tuple.Create(name ?? item.Name, type)] = equipTexture;
307 if (item != null)
308 {
309 if (!idToSlot.TryGetValue(item.Type, out var slots))
310 {
311 slots = (idToSlot[item.Type] = new Dictionary<EquipType, int>());
312 }
313 slots[type] = slot;
314 if (type == EquipType.Head || type == EquipType.Body || type == EquipType.Legs)
315 {
316 slotToId[type][slot] = item.Type;
317 }
318 }
319 return slot;
320 }
static readonly Dictionary< EquipType, Dictionary< int, int > > slotToId
static readonly Dictionary< int, Dictionary< EquipType, int > > idToSlot
static readonly Dictionary< EquipType, Dictionary< int, EquipTexture > > equipTextures
static int ReserveEquipID(EquipType type)
EquipType
This is an enum of all the types of equipment that exist. An equipment type is defined as a type or l...
Definition EquipType.cs:7

References Terraria.ModLoader.EquipLoader.equipTextures, Terraria.ModLoader.Mod.equipTextures, Terraria.ModLoader.EquipLoader.idToSlot, Terraria.ModLoader.Mod.loading, Terraria.ModLoader.EquipLoader.ReserveEquipID(), and Terraria.ModLoader.EquipLoader.slotToId.

Referenced by Terraria.ModLoader.Default.Patreon.xAqult_Lens.Load(), Terraria.ModLoader.Default.Patreon.Tantamount_Head.OnCreated(), and Terraria.ModLoader.ModItem.Register().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: