tModLoader v0.11.8.9
A mod to make and play Terraria mods
ModHooks.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
3using System;
4using System.Collections.Generic;
5using System.IO;
6using Terraria.GameInput;
7using Terraria.Graphics;
8using Terraria.Localization;
9using Terraria.UI;
10
11namespace Terraria.ModLoader
12{
13 public abstract partial class Mod
14 {
20 public virtual void UpdateMusic(ref int music, ref MusicPriority priority) {
21 UpdateMusic(ref music);
22 }
23
28 [Obsolete("This UpdateMusic method now obsolete, use the UpdateMusic with the MusicPriority parameter.")]
29 public virtual void UpdateMusic(ref int music) {
30 }
31
36 public virtual void HotKeyPressed(string name) {
37 }
38
44 public virtual void HandlePacket(BinaryReader reader, int whoAmI) {
45 }
46
54 public virtual bool HijackGetData(ref byte messageType, ref BinaryReader reader, int playerNumber) {
55 return false;
56 }
57
61 public 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) {
62 return false;
63 }
64
68 public virtual void ModifyTransformMatrix(ref SpriteViewMatrix Transform) {
69 }
70
74 public virtual void UpdateUI(GameTime gameTime) {
75 }
76
85 public virtual void PreUpdateEntities() {
86 }
87
94 public virtual void MidUpdatePlayerNPC() {
95 }
96
103 public virtual void MidUpdateNPCGore() {
104 }
105
112 public virtual void MidUpdateGoreProjectile() {
113 }
114
121 public virtual void MidUpdateProjectileItem() {
122 }
123
130 public virtual void MidUpdateItemDust() {
131 }
132
139 public virtual void MidUpdateDustTime() {
140 }
141
148 public virtual void MidUpdateTimeWorld() {
149 }
150
157 public virtual void MidUpdateInvasionNet() {
158 }
159
165 public virtual void PostUpdateEverything() {
166 }
167
172 public virtual void ModifyInterfaceLayers(List<GameInterfaceLayer> layers) {
173 }
174
180 public virtual void ModifySunLightColor(ref Color tileColor, ref Color backgroundColor) {
181 }
182
187 public virtual void ModifyLightingBrightness(ref float scale) {
188 }
189
196 public virtual void PostDrawInterface(SpriteBatch spriteBatch) {
197 }
198
203 public virtual void PostDrawFullscreenMap(ref string mouseText) {
204 }
205
209 public virtual void PostUpdateInput() {
210 }
211
215 public virtual void PreSaveAndQuit() {
216 }
217 }
218
219 internal static class ModHooks
220 {
221 //in Terraria.Main.UpdateMusic before updating music boxes call ModHooks.UpdateMusic(ref this.newMusic);
222 internal static void UpdateMusic(ref int music, ref MusicPriority priority) {
223 foreach (Mod mod in ModLoader.Mods) {
224 int modMusic = -1;
225 MusicPriority modPriority = MusicPriority.BiomeLow;
226 mod.UpdateMusic(ref modMusic, ref modPriority);
227 if (modMusic >= 0 && modPriority >= priority) {
228 music = modMusic;
229 priority = modPriority;
230 }
231 }
232 }
233
234 // Pretty much deprecated.
235 internal static void HotKeyPressed() {
236 foreach (var modHotkey in HotKeyLoader.HotKeys) {
237 if (PlayerInput.Triggers.Current.KeyStatus[modHotkey.uniqueName]) {
238 modHotkey.mod.HotKeyPressed(modHotkey.name);
239 }
240 }
241 }
242
243 internal static void ModifyTransformMatrix(ref SpriteViewMatrix Transform) {
244 foreach (Mod mod in ModLoader.Mods) {
245 mod.ModifyTransformMatrix(ref Transform);
246 }
247 }
248
249 internal static void ModifySunLight(ref Color tileColor, ref Color backgroundColor) {
250 if (Main.gameMenu) return;
251 foreach (Mod mod in ModLoader.Mods) {
252 mod.ModifySunLightColor(ref tileColor, ref backgroundColor);
253 }
254 }
255
256 internal static void ModifyLightingBrightness(ref float negLight, ref float negLight2) {
257 float scale = 1f;
258 foreach (Mod mod in ModLoader.Mods) {
259 mod.ModifyLightingBrightness(ref scale);
260 }
261 if (Lighting.NotRetro) {
262 negLight *= scale;
263 negLight2 *= scale;
264 }
265 else {
266 negLight -= (scale - 1f) / 2.307692307692308f;
267 negLight2 -= (scale - 1f) / 0.75f;
268 }
269 negLight = Math.Max(negLight, 0.001f);
270 negLight2 = Math.Max(negLight2, 0.001f);
271 }
272
273 internal static void PostDrawFullscreenMap(ref string mouseText) {
274 foreach (Mod mod in ModLoader.Mods) {
275 mod.PostDrawFullscreenMap(ref mouseText);
276 }
277 }
278
279 internal static void UpdateUI(GameTime gameTime) {
280 if (Main.gameMenu) return;
281 foreach (Mod mod in ModLoader.Mods) {
282 mod.UpdateUI(gameTime);
283 }
284 }
285
286 public static void PreUpdateEntities() {
287 foreach (Mod mod in ModLoader.Mods) {
288 mod.PreUpdateEntities();
289 }
290 }
291
292 public static void MidUpdatePlayerNPC() {
293 foreach (Mod mod in ModLoader.Mods) {
294 mod.MidUpdatePlayerNPC();
295 }
296 }
297
298 public static void MidUpdateNPCGore() {
299 foreach (Mod mod in ModLoader.Mods) {
300 mod.MidUpdateNPCGore();
301 }
302 }
303
304 public static void MidUpdateGoreProjectile() {
305 foreach (Mod mod in ModLoader.Mods) {
306 mod.MidUpdateGoreProjectile();
307 }
308 }
309
310 public static void MidUpdateProjectileItem() {
311 foreach (Mod mod in ModLoader.Mods) {
312 mod.MidUpdateProjectileItem();
313 }
314 }
315
316 public static void MidUpdateItemDust() {
317 foreach (Mod mod in ModLoader.Mods) {
318 mod.MidUpdateItemDust();
319 }
320 }
321
322 public static void MidUpdateDustTime() {
323 foreach (Mod mod in ModLoader.Mods) {
324 mod.MidUpdateDustTime();
325 }
326 }
327
328 public static void MidUpdateTimeWorld() {
329 foreach (Mod mod in ModLoader.Mods) {
330 mod.MidUpdateTimeWorld();
331 }
332 }
333
334 public static void MidUpdateInvasionNet() {
335 foreach (Mod mod in ModLoader.Mods) {
336 mod.MidUpdateInvasionNet();
337 }
338 }
339
340 public static void PostUpdateEverything() {
341 foreach (Mod mod in ModLoader.Mods) {
342 mod.PostUpdateEverything();
343 }
344 }
345
346 internal static void ModifyInterfaceLayers(List<GameInterfaceLayer> layers) {
347 foreach (GameInterfaceLayer layer in layers) {
348 layer.Active = true;
349 }
350 foreach (Mod mod in ModLoader.Mods) {
351 mod.ModifyInterfaceLayers(layers);
352 }
353 }
354
355 internal static void PostDrawInterface(SpriteBatch spriteBatch) {
356 foreach (Mod mod in ModLoader.Mods) {
357 mod.PostDrawInterface(spriteBatch);
358 }
359 }
360
361 internal static void PostUpdateInput() {
362 foreach (Mod mod in ModLoader.Mods) {
363 mod.PostUpdateInput();
364 }
365 }
366
367 internal static void PreSaveAndQuit() {
368 foreach (Mod mod in ModLoader.Mods) {
369 mod.PreSaveAndQuit();
370 }
371 }
372 }
373}
virtual void MidUpdatePlayerNPC()
Called after Players got updated, but before any NPCs get updated.
Definition: ModHooks.cs:94
virtual void ModifySunLightColor(ref Color tileColor, ref Color backgroundColor)
Allows you to modify color of light the sun emits.
Definition: ModHooks.cs:180
virtual void PreUpdateEntities()
Use this if you want to do something before anything in the World gets updated. Called after UI updat...
Definition: ModHooks.cs:85
virtual void MidUpdateTimeWorld()
Called after Time got updated, but before the World gets updated.
Definition: ModHooks.cs:148
virtual void HandlePacket(BinaryReader reader, int whoAmI)
Called whenever a net message / packet is received from a client (if this is a server) or the server ...
Definition: ModHooks.cs:44
virtual void PreSaveAndQuit()
Called in SP or Client when the Save and Quit button is pressed. One use for this hook is clearing ou...
Definition: ModHooks.cs:215
virtual void MidUpdateDustTime()
Called after Dust got updated, but before Time (day/night, events, etc.) gets updated.
Definition: ModHooks.cs:139
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.
Definition: ModHooks.cs:54
virtual void MidUpdateItemDust()
Called after Items got updated, but before any Dust gets updated.
Definition: ModHooks.cs:130
virtual void MidUpdateInvasionNet()
Called after Invasions got updated. The only thing that is updated after this is the Network.
Definition: ModHooks.cs:157
virtual void ModifyLightingBrightness(ref float scale)
Allows you to modify overall brightness of lights. Can be used to create effects similiar to what nig...
Definition: ModHooks.cs:187
virtual void MidUpdateNPCGore()
Called after NPCs got updated, but before any Gores get updated.
Definition: ModHooks.cs:103
virtual void ModifyTransformMatrix(ref SpriteViewMatrix Transform)
Allows you to set the transformation of the screen that is drawn. (Translations, rotations,...
Definition: ModHooks.cs:68
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...
Definition: ModHooks.cs:61
virtual void MidUpdateGoreProjectile()
Called after Gores got updated, but before any Projectiles get updated.
Definition: ModHooks.cs:112
virtual void MidUpdateProjectileItem()
Gets called immediately after all Projectiles are updated, but before any Items get updated.
Definition: ModHooks.cs:121
virtual void PostDrawInterface(SpriteBatch spriteBatch)
Called after interface is drawn but right before mouse and mouse hover text is drawn....
Definition: ModHooks.cs:196
virtual void PostUpdateInput()
Called after the input keys are polled. Allows for modifying things like scroll wheel if your custom ...
Definition: ModHooks.cs:209
virtual void HotKeyPressed(string name)
Called when a hotkey is pressed. Check against the name to verify particular hotkey that was pressed....
Definition: ModHooks.cs:36
virtual void UpdateMusic(ref int music, ref MusicPriority priority)
Allows you to determine what music should currently play.
Definition: ModHooks.cs:20
virtual void PostDrawFullscreenMap(ref string mouseText)
Called while the fullscreen map is active. Allows custom drawing to the map.
Definition: ModHooks.cs:203
virtual void UpdateMusic(ref int music)
A legacy hook that you should no longer use. Use the version with two parameters instead.
Definition: ModHooks.cs:29
virtual void PostUpdateEverything()
Called after the Network got updated, this is the last hook that happens in an update.
Definition: ModHooks.cs:165
virtual void ModifyInterfaceLayers(List< GameInterfaceLayer > layers)
Allows you to modify the elements of the in-game interface that get drawn. GameInterfaceLayer can be ...
Definition: ModHooks.cs:172
virtual void UpdateUI(GameTime gameTime)
Ran every update and suitable for calling Update for UserInterface classes
Definition: ModHooks.cs:74
MusicPriority
This enum dictates from low to high which music selections take priority. Setting appropriate MusicPr...
Definition: MusicPriority.cs:8