tModLoader v0.11.8.9
A mod to make and play Terraria mods
WorldHooks.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Terraria.World.Generation;
5
6namespace Terraria.ModLoader
7{
8 //todo: further documentation
12 public static class WorldHooks
13 {
14 internal static readonly IList<ModWorld> worlds = new List<ModWorld>();
15 internal static ModWorld[] NetWorlds;
16
17 internal static void Add(ModWorld modWorld) {
18 worlds.Add(modWorld);
19 }
20
21 internal static void ResizeArrays() {
22 NetWorlds = ModLoader.BuildGlobalHook<ModWorld, Action<BinaryWriter>>(worlds, w => w.NetSend);
23 }
24
25 internal static void Unload() {
26 worlds.Clear();
27 }
28
29 internal static void SetupWorld() {
30 foreach (ModWorld world in worlds) {
31 world.Initialize();
32 }
33 }
34
35 internal static void WriteNetWorldOrder(BinaryWriter w) {
36 w.Write((short)NetWorlds.Length);
37 foreach (var netWorld in NetWorlds) {
38 w.Write(netWorld.mod.netID);
39 w.Write(netWorld.Name);
40 }
41 }
42
43 internal static void ReadNetWorldOrder(BinaryReader r) {
44 short n = r.ReadInt16();
45 NetWorlds = new ModWorld[n];
46 for (short i = 0; i < n; i++)
47 NetWorlds[i] = ModNet.GetMod(r.ReadInt16()).GetModWorld(r.ReadString());
48 }
49
50 public static void PreWorldGen() {
51 foreach (ModWorld modWorld in worlds) {
52 modWorld.PreWorldGen();
53 }
54 }
55
56 public static void ModifyWorldGenTasks(List<GenPass> passes, ref float totalWeight) {
57 foreach (ModWorld modWorld in worlds) {
58 modWorld.ModifyWorldGenTasks(passes, ref totalWeight);
59 }
60 }
61
62 public static void PostWorldGen() {
63 foreach (ModWorld modWorld in worlds) {
64 modWorld.PostWorldGen();
65 }
66 }
67
68 public static void ResetNearbyTileEffects() {
69 foreach (ModWorld modWorld in worlds) {
70 modWorld.ResetNearbyTileEffects();
71 }
72 }
73
74 public static void PreUpdate() {
75 foreach (ModWorld modWorld in worlds) {
76 modWorld.PreUpdate();
77 }
78 }
79
80 public static void PostUpdate() {
81 foreach (ModWorld modWorld in worlds) {
82 modWorld.PostUpdate();
83 }
84 }
85
86 public static void TileCountsAvailable(int[] tileCounts) {
87 foreach (ModWorld modWorld in worlds) {
88 modWorld.TileCountsAvailable(tileCounts);
89 }
90 }
91
92 public static void ChooseWaterStyle(ref int style) {
93 foreach (ModWorld modWorld in worlds) {
94 modWorld.ChooseWaterStyle(ref style);
95 }
96 }
97
98 public static void ModifyHardmodeTasks(List<GenPass> passes) {
99 foreach (ModWorld modWorld in worlds) {
100 modWorld.ModifyHardmodeTasks(passes);
101 }
102 }
103
104 public static void PostDrawTiles() {
105 foreach (ModWorld modWorld in worlds) {
106 modWorld.PostDrawTiles();
107 }
108 }
109 }
110}
ModWorld GetModWorld(string name)
Gets the ModWorld instance with the given name from this mod.
This serves as the central class which loads mods. It contains many static fields and methods related...
Definition: ModLoader.cs:29
static Mod GetMod(int netID)
A ModWorld instance represents an extension of a World. You can store fields in the ModWorld classes ...
Definition: ModWorld.cs:12
virtual void ChooseWaterStyle(ref int style)
Allows you to change the water style (determines water color) that is currently being used.
Definition: ModWorld.cs:118
virtual void TileCountsAvailable(int[] tileCounts)
Allows you to store information about how many of each tile is nearby the player. This is useful for ...
Definition: ModWorld.cs:112
virtual void ModifyWorldGenTasks(List< GenPass > tasks, ref float totalWeight)
A more advanced option to PostWorldGen, this method allows you modify the list of Generation Passes b...
Definition: ModWorld.cs:82
virtual void PostWorldGen()
Use this method to place tiles in the world after world generation is complete.
Definition: ModWorld.cs:88
virtual void PostUpdate()
Use this method to have things happen in the world. In vanilla Terraria, a good example of code suita...
Definition: ModWorld.cs:106
virtual void PreWorldGen()
Allows a mod to run code before a world is generated.
Definition: ModWorld.cs:76
virtual void ResetNearbyTileEffects()
Use this to reset any fields you set in any of your ModTile.NearbyEffects hooks back to their default...
Definition: ModWorld.cs:94
virtual void PostDrawTiles()
Called after drawing Tiles. Can be used for drawing a tile overlay akin to wires. Note that spritebat...
Definition: ModWorld.cs:130
virtual void PreUpdate()
Use this method to have things happen in the world. In vanilla Terraria, a good example of code suita...
Definition: ModWorld.cs:100
virtual void ModifyHardmodeTasks(List< GenPass > list)
Similar to ModifyWorldGenTasks, but occurs in-game when Hardmode starts. Can be used to modify which ...
Definition: ModWorld.cs:124
virtual void Initialize()
Called whenever the world is loaded. This can be used to initialize data structures,...
Definition: ModWorld.cs:39
This is where all ModWorld hooks are gathered and called.
Definition: WorldHooks.cs:13
static void ModifyHardmodeTasks(List< GenPass > passes)
Definition: WorldHooks.cs:98
static void ChooseWaterStyle(ref int style)
Definition: WorldHooks.cs:92
static void ModifyWorldGenTasks(List< GenPass > passes, ref float totalWeight)
Definition: WorldHooks.cs:56
static void ResetNearbyTileEffects()
Definition: WorldHooks.cs:68
static void TileCountsAvailable(int[] tileCounts)
Definition: WorldHooks.cs:86