tModLoader v0.11.8.9
A mod to make and play Terraria mods
ModDust.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
3using System;
4using System.Collections.Generic;
5using Terraria.GameContent;
6using Terraria.ID;
7
8namespace Terraria.ModLoader
9{
13 public class ModDust
14 {
15 private static int nextDust = DustID.Count;
16 internal static readonly IList<ModDust> dusts = new List<ModDust>();
18 public int updateType = -1;
19
23 public string Name {
24 get;
25 internal set;
26 }
27
31 public Texture2D Texture {
32 get;
33 internal set;
34 }
35
39 public Mod mod {
40 get;
41 internal set;
42 }
43
47 public int Type {
48 get;
49 internal set;
50 }
51
52 internal static int DustCount => nextDust;
53
57 public static ModDust GetDust(int type) {
58 return type >= DustID.Count && type < DustCount ? dusts[type - DustID.Count] : null;
59 }
60
61 internal static int ReserveDustID() {
62 int reserveID = nextDust;
63 nextDust++;
64 return reserveID;
65 }
66 //make Terraria.GameContent.ChildSafety.SafeDust public and not readonly
67 internal static void ResizeArrays() {
68 Array.Resize(ref ChildSafety.SafeDust, nextDust);
69 for (int k = DustID.Count; k < nextDust; k++) {
70 ChildSafety.SafeDust[k] = true;
71 }
72 }
73
74 internal static void Unload() {
75 dusts.Clear();
76 nextDust = DustID.Count;
77 }
78 //in Terraria.Dust.NewDust after initializing dust properties call ModDust.SetupDust(dust);
79 internal static void SetupDust(Dust dust) {
80 ModDust modDust = GetDust(dust.type);
81 if (modDust != null) {
82 dust.frame.X = 0;
83 dust.frame.Y %= 30;
84 modDust.OnSpawn(dust);
85 }
86 }
87 //in Terraria.Dust.UpdateDust after incrementing Dust.dCount call this
88 internal static void SetupUpdateType(Dust dust) {
89 ModDust modDust = GetDust(dust.type);
90 if (modDust != null && modDust.updateType >= 0) {
91 dust.realType = dust.type;
92 dust.type = modDust.updateType;
93 }
94 }
95 //in Terraria.Dust.UdpateDust at end of dust update code call this
96 internal static void TakeDownUpdateType(Dust dust) {
97 if (dust.realType >= 0) {
98 dust.type = dust.realType;
99 dust.realType = -1;
100 }
101 }
102 //in Terraria.Main.DrawDust before universal dust drawing call
103 // ModDust modDust = ModDust.GetDust(dust.type);
104 // if(modDust != null) { modDust.Draw(dust, color5, scale); continue; }
105 internal void Draw(Dust dust, Color alpha, float scale) {
106 Main.spriteBatch.Draw(Texture, dust.position - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(dust.frame), alpha, dust.rotation, new Vector2(4f, 4f), scale, SpriteEffects.None, 0f);
107 if (dust.color != default(Microsoft.Xna.Framework.Color)) {
108 Main.spriteBatch.Draw(Texture, dust.position - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(dust.frame), dust.GetColor(alpha), dust.rotation, new Vector2(4f, 4f), scale, SpriteEffects.None, 0f);
109 }
110 if (alpha == Microsoft.Xna.Framework.Color.Black) {
111 dust.active = false;
112 }
113 }
114
118 public virtual bool Autoload(ref string name, ref string texture) {
119 return mod.Properties.Autoload;
120 }
121
125 public virtual void SetDefaults() {
126 }
127
131 public virtual void OnSpawn(Dust dust) {
132 }
133
134 //in Terraria.Dust.UpdateDust after setting up update type add
135 // ModDust modDust = ModDust.GetDust(dust.type);
136 // if(modDust != null && !modDust.Update(dust)) { ModDust.TakeDownUpdateType(dust); continue; }
140 public virtual bool Update(Dust dust) {
141 return true;
142 }
143
147 public virtual bool MidUpdate(Dust dust) {
148 return false;
149 }
150
151 //in beginning of Terraria.Dust.GetAlpha add
152 // ModDust modDust = ModDust.GetDust(this.type);
153 // if(modDust != null)
154 // {
155 // Color? modColor = modDust.GetAlpha(this, newColor);
156 // if(modColor.HasValue)
157 // {
158 // return modColor.Value;
159 // }
160 // }
164 public virtual Color? GetAlpha(Dust dust, Color lightColor) {
165 return null;
166 }
167 }
168}
This class represents a type of dust that is added by a mod. Only one instance of this class will eve...
Definition: ModDust.cs:14
int updateType
Allows you to choose a type of dust for this type of dust to copy the behavior of....
Definition: ModDust.cs:18
Mod mod
The mod that added this type of dust.
Definition: ModDust.cs:39
Texture2D Texture
The sprite sheet that this type of dust uses. Normally a sprite sheet will consist of a vertical alig...
Definition: ModDust.cs:31
virtual bool MidUpdate(Dust dust)
Allows you to add behavior to this dust on top of the default dust behavior. Return true if you're ap...
Definition: ModDust.cs:147
virtual bool Update(Dust dust)
Allows you to customize how you want this type of dust to behave. Return true to allow for vanilla du...
Definition: ModDust.cs:140
virtual void OnSpawn(Dust dust)
Allows you to modify a dust's fields when it is created.
Definition: ModDust.cs:131
virtual ? Color GetAlpha(Dust dust, Color lightColor)
Allows you to override the color this dust will draw in. Return null to draw it in the normal light c...
Definition: ModDust.cs:164
string Name
The internal name of this type of dust.
Definition: ModDust.cs:23
int Type
The ID of this type of dust.
Definition: ModDust.cs:47
virtual bool Autoload(ref string name, ref string texture)
Allows you to automatically add a type of dust without having to use Mod.AddDust. By default returns ...
Definition: ModDust.cs:118
virtual void SetDefaults()
Allows you to set this ModDust's updateType field and modify the Terraria.GameContent....
Definition: ModDust.cs:125
static ModDust GetDust(int type)
Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists.
Definition: ModDust.cs:57
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
Definition: Mod.cs:25
ModProperties Properties
Definition: Mod.cs:52
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...