Terraria ModLoader  0.11.7.5
A mod to make and play Terraria mods
ModGore.cs
Go to the documentation of this file.
1 using Microsoft.Xna.Framework;
2 using System;
3 using System.Collections.Generic;
4 using Terraria.GameContent;
5 using Terraria.ID;
6 
7 namespace Terraria.ModLoader
8 {
12  public class ModGore
13  {
14  private static int nextGore = GoreID.Count;
15  public static int GoreCount => nextGore;
16  internal static readonly IDictionary<string, int> gores = new Dictionary<string, int>();
17  internal static readonly IDictionary<int, ModGore> modGores = new Dictionary<int, ModGore>();
18 
20  public int updateType = -1;
21 
22  internal static int ReserveGoreID() {
23  int reserveID = nextGore;
24  nextGore++;
25  return reserveID;
26  }
27 
31  public static int GetGoreSlot(string texture) {
32  if (gores.ContainsKey(texture)) {
33  return gores[texture];
34  }
35  else {
36  return 0;
37  }
38  }
39 
40  //in Terraria.GameContent.ChildSafety make SafeGore internal and not readonly
41  internal static void ResizeAndFillArrays() {
42  Array.Resize(ref Main.goreLoaded, nextGore);
43  Array.Resize(ref Main.goreTexture, nextGore);
44  Array.Resize(ref ChildSafety.SafeGore, nextGore);
45  Array.Resize(ref GoreID.Sets.SpecialAI, nextGore);
46  Array.Resize(ref GoreID.Sets.DisappearSpeed, nextGore);
47  Array.Resize(ref GoreID.Sets.DisappearSpeedAlpha, nextGore);
48  for (int k = GoreID.Count; k < nextGore; k++) {
49  Main.goreLoaded[k] = true;
50  GoreID.Sets.DisappearSpeed[k] = 1;
51  GoreID.Sets.DisappearSpeedAlpha[k] = 1;
52  }
53  foreach (string texture in gores.Keys) {
54  Main.goreTexture[gores[texture]] = ModContent.GetTexture(texture);
55  }
56  }
57 
58  internal static void Unload() {
59  gores.Clear();
60  modGores.Clear();
61  nextGore = GoreID.Count;
62  }
63 
64  //in Terraria.Gore add modGore property (internal set)
65  //in Terraria.Gore.NewGore after resetting properties call ModGore.SetupGore(Main.gore[num]);
66  internal static void SetupGore(Gore gore) {
67  if (modGores.ContainsKey(gore.type)) {
68  gore.modGore = modGores[gore.type];
69  gore.modGore.OnSpawn(gore);
70  }
71  else {
72  gore.modGore = null;
73  }
74  }
75 
76  internal static void SetupUpdateType(Gore gore) {
77  if (gore.modGore != null && gore.modGore.updateType > 0) {
78  gore.realType = gore.type;
79  gore.type = gore.modGore.updateType;
80  }
81  }
82 
83  internal static void TakeDownUpdateType(Gore gore) {
84  if (gore.realType > 0) {
85  gore.type = gore.realType;
86  gore.realType = 0;
87  }
88  }
89 
90  //in Terraria.Main.DrawGore and DrawGoreBehind replace type checks with this
91  internal static bool DrawBackGore(Gore gore) {
92  if (gore.modGore != null) {
93  return gore.modGore.DrawBehind(gore);
94  }
95  return ((gore.type >= 706 && gore.type <= 717) || gore.type == 943) && (gore.frame < 7 || gore.frame > 9);
96  }
97 
101  public virtual void OnSpawn(Gore gore) {
102  }
103 
104  //in Terraria.Gore.Update at beginning of if block checking for active add
105  // if(this.modGore != null && !this.modGore.Update(this)) { return; }
109  public virtual bool Update(Gore gore) {
110  return true;
111  }
112 
113  //at beginning of Terraria.Gore.Update add
114  // if(this.modGore != null) { Color? modColor = this.modGore.GetAlpha(this, newColor);
115  // if(modColor.HasValue) { return modColor.Value; } }
120  public virtual Color? GetAlpha(Gore gore, Color lightColor) {
121  return null;
122  }
123 
127  public virtual bool DrawBehind(Gore gore) {
128  return false;
129  }
130  }
131 }
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
Definition: ModContent.cs:72
virtual bool DrawBehind(Gore gore)
Allows you to determine whether or not this gore will draw behind tiles, etc. Returns false by defaul...
Definition: ModGore.cs:127
This class allows you to customize the behavior of a custom gore. Create a new instance of this and p...
Definition: ModGore.cs:12
Manages content added by mods. Liasons between mod content and Terraria&#39;s arrays and oversees the Loa...
Definition: ModContent.cs:26
virtual void OnSpawn(Gore gore)
Allows you to modify a gore&#39;s fields when it is created.
Definition: ModGore.cs:101
virtual Color GetAlpha(Gore gore, Color lightColor)
Allows you to override the color this gore will draw in. Return null to draw it in the normal light c...
Definition: ModGore.cs:120
static int GetGoreSlot(string texture)
Gets the type of the custom gore corresponding to the given texture. Returns 0 if the texture does no...
Definition: ModGore.cs:31
virtual bool Update(Gore gore)
Allows you to customize how you want this type of gore to behave. Return true to allow for vanilla go...
Definition: ModGore.cs:109