Terraria ModLoader  0.11.6.2
A framework for Terraria mods
ItemLoader.cs
Go to the documentation of this file.
1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
3 using System;
4 using System.Collections.Generic;
5 using System.Collections.ObjectModel;
6 using System.IO;
7 using System.Linq;
8 using System.Linq.Expressions;
9 using System.Reflection;
10 using Terraria.ID;
11 using Terraria.Localization;
12 using Terraria.ModLoader.IO;
13 using Terraria.UI;
14 using Terraria.Utilities;
15 
16 namespace Terraria.ModLoader
17 {
21  public static class ItemLoader
22  {
23  private static int nextItem = ItemID.Count;
24  internal static readonly IList<ModItem> items = new List<ModItem>();
25  internal static readonly IList<GlobalItem> globalItems = new List<GlobalItem>();
26  internal static GlobalItem[] InstancedGlobals = new GlobalItem[0];
27  internal static GlobalItem[] NetGlobals;
28  internal static readonly IDictionary<string, int> globalIndexes = new Dictionary<string, int>();
29  internal static readonly IDictionary<Type, int> globalIndexesByType = new Dictionary<Type, int>();
30  internal static readonly ISet<int> animations = new HashSet<int>();
31  internal static readonly int vanillaQuestFishCount = Main.anglerQuestItemNetIDs.Length;
32  internal static readonly int[] vanillaWings = new int[Main.maxWings];
33 
34  private class HookList
35  {
36  public GlobalItem[] arr = new GlobalItem[0];
37  public readonly MethodInfo method;
38 
39  public HookList(MethodInfo method) {
40  this.method = method;
41  }
42  }
43 
44  private static List<HookList> hooks = new List<HookList>();
45 
46  private static HookList AddHook<F>(Expression<Func<GlobalItem, F>> func) {
47  var hook = new HookList(ModLoader.Method(func));
48  hooks.Add(hook);
49  return hook;
50  }
51 
52  private static void FindVanillaWings() {
53  if (vanillaWings[1] != 0)
54  return;
55 
56  Item item = new Item();
57  for (int k = 0; k < ItemID.Count; k++) {
58  item.SetDefaults(k);
59  if (item.wingSlot > 0) {
60  vanillaWings[item.wingSlot] = k;
61  }
62  }
63  }
64 
65  internal static int ReserveItemID() {
66  if (ModNet.AllowVanillaClients) throw new Exception("Adding items breaks vanilla client compatibility");
67 
68  int reserveID = nextItem;
69  nextItem++;
70  return reserveID;
71  }
72 
76  public static ModItem GetItem(int type) {
77  return type >= ItemID.Count && type < ItemCount ? items[type - ItemID.Count] : null;
78  }
79 
80  public static int ItemCount => nextItem;
81 
82  internal static void ResizeArrays(bool unloading) {
83  Array.Resize(ref Main.itemTexture, nextItem);
84  Array.Resize(ref Main.itemFlameLoaded, nextItem);
85  Array.Resize(ref Main.itemFlameTexture, nextItem);
86  Array.Resize(ref Main.itemAnimations, nextItem);
87  Array.Resize(ref Item.itemCaches, nextItem);
88  Array.Resize(ref Item.staff, nextItem);
89  Array.Resize(ref Item.claw, nextItem);
90  Array.Resize(ref Lang._itemNameCache, nextItem);
91  Array.Resize(ref Lang._itemTooltipCache, nextItem);
92  Array.Resize(ref ItemID.Sets.BannerStrength, nextItem);
93  Array.Resize(ref ItemID.Sets.KillsToBanner, nextItem);
94  Array.Resize(ref ItemID.Sets.CanFishInLava, nextItem);
95  //Array.Resize(ref ItemID.Sets.TextureCopyLoad, nextItem); //not needed?
96  Array.Resize(ref ItemID.Sets.TrapSigned, nextItem);
97  Array.Resize(ref ItemID.Sets.Deprecated, nextItem);
98  Array.Resize(ref ItemID.Sets.NeverShiny, nextItem);
99  Array.Resize(ref ItemID.Sets.ItemIconPulse, nextItem);
100  Array.Resize(ref ItemID.Sets.ItemNoGravity, nextItem);
101  Array.Resize(ref ItemID.Sets.ExtractinatorMode, nextItem);
102  Array.Resize(ref ItemID.Sets.StaffMinionSlotsRequired, nextItem);
103  Array.Resize(ref ItemID.Sets.ExoticPlantsForDyeTrade, nextItem);
104  Array.Resize(ref ItemID.Sets.NebulaPickup, nextItem);
105  Array.Resize(ref ItemID.Sets.AnimatesAsSoul, nextItem);
106  Array.Resize(ref ItemID.Sets.gunProj, nextItem);
107  Array.Resize(ref ItemID.Sets.SortingPriorityBossSpawns, nextItem);
108  Array.Resize(ref ItemID.Sets.SortingPriorityWiring, nextItem);
109  Array.Resize(ref ItemID.Sets.SortingPriorityMaterials, nextItem);
110  Array.Resize(ref ItemID.Sets.SortingPriorityExtractibles, nextItem);
111  Array.Resize(ref ItemID.Sets.SortingPriorityRopes, nextItem);
112  Array.Resize(ref ItemID.Sets.SortingPriorityPainting, nextItem);
113  Array.Resize(ref ItemID.Sets.SortingPriorityTerraforming, nextItem);
114  Array.Resize(ref ItemID.Sets.GamepadExtraRange, nextItem);
115  Array.Resize(ref ItemID.Sets.GamepadWholeScreenUseRange, nextItem);
116  Array.Resize(ref ItemID.Sets.GamepadSmartQuickReach, nextItem);
117  Array.Resize(ref ItemID.Sets.Yoyo, nextItem);
118  Array.Resize(ref ItemID.Sets.AlsoABuildingItem, nextItem);
119  Array.Resize(ref ItemID.Sets.LockOnIgnoresCollision, nextItem);
120  Array.Resize(ref ItemID.Sets.LockOnAimAbove, nextItem);
121  Array.Resize(ref ItemID.Sets.LockOnAimCompensation, nextItem);
122  Array.Resize(ref ItemID.Sets.SingleUseInGamepad, nextItem);
123  ItemID.Sets.IsAMaterial = new bool[nextItem]; // clears it, which is desired.
124  for (int k = ItemID.Count; k < nextItem; k++) {
125  Lang._itemNameCache[k] = LocalizedText.Empty;
126  Lang._itemTooltipCache[k] = ItemTooltip.None;
127  ItemID.Sets.BannerStrength[k] = new ItemID.BannerEffect(1f);
128  ItemID.Sets.KillsToBanner[k] = 50;
129  Item.itemCaches[k] = -1;
130  //ItemID.Sets.TextureCopyLoad[k] = -1;
131  ItemID.Sets.ExtractinatorMode[k] = -1;
132  ItemID.Sets.StaffMinionSlotsRequired[k] = 1;
133  ItemID.Sets.SortingPriorityBossSpawns[k] = -1;
134  ItemID.Sets.SortingPriorityWiring[k] = -1;
135  ItemID.Sets.SortingPriorityMaterials[k] = -1;
136  ItemID.Sets.SortingPriorityExtractibles[k] = -1;
137  ItemID.Sets.SortingPriorityRopes[k] = -1;
138  ItemID.Sets.SortingPriorityPainting[k] = -1;
139  ItemID.Sets.SortingPriorityTerraforming[k] = -1;
140  }
141 
142  if (unloading)
143  Array.Resize(ref Main.anglerQuestItemNetIDs, vanillaQuestFishCount);
144  else
145  Main.anglerQuestItemNetIDs = Main.anglerQuestItemNetIDs
146  .Concat(items.Where(modItem => modItem.IsQuestFish()).Select(modItem => modItem.item.type))
147  .ToArray();
148 
149  FindVanillaWings();
150 
151  InstancedGlobals = globalItems.Where(g => g.InstancePerEntity).ToArray();
152  for (int i = 0; i < InstancedGlobals.Length; i++) {
153  InstancedGlobals[i].instanceIndex = i;
154  }
155  NetGlobals = ModLoader.BuildGlobalHook<GlobalItem, Action<Item, BinaryWriter>>(globalItems, g => g.NetSend);
156  foreach (var hook in hooks)
157  hook.arr = ModLoader.BuildGlobalHook(globalItems, hook.method);
158  }
159 
160  internal static void Unload() {
161  items.Clear();
162  nextItem = ItemID.Count;
163  globalItems.Clear();
164  globalIndexes.Clear();
165  globalIndexesByType.Clear();
166  animations.Clear();
167  }
168 
169  internal static bool IsModItem(int index) {
170  return index >= ItemID.Count;
171  }
172 
173  private static bool GeneralPrefix(Item item) {
174  return item.maxStack == 1 && item.damage > 0 && item.ammo == 0 && !item.accessory;
175  }
176  //add to Terraria.Item.Prefix
177  internal static bool MeleePrefix(Item item) {
178  return item.modItem != null && GeneralPrefix(item) && item.melee && !item.noUseGraphic;
179  }
180  //add to Terraria.Item.Prefix
181  internal static bool WeaponPrefix(Item item) {
182  return item.modItem != null && GeneralPrefix(item) && item.melee && item.noUseGraphic;
183  }
184  //add to Terraria.Item.Prefix
185  internal static bool RangedPrefix(Item item) {
186  return item.modItem != null && GeneralPrefix(item) && (item.ranged || item.thrown);
187  }
188  //add to Terraria.Item.Prefix
189  internal static bool MagicPrefix(Item item) {
190  return item.modItem != null && GeneralPrefix(item) && (item.magic || item.summon);
191  }
192 
193  private static HookList HookSetDefaults = AddHook<Action<Item>>(g => g.SetDefaults);
194 
195  internal static void SetDefaults(Item item, bool createModItem = true) {
196  if (IsModItem(item.type) && createModItem)
197  item.modItem = GetItem(item.type).NewInstance(item);
198 
199  item.globalItems = InstancedGlobals.Select(g => g.NewInstance(item)).ToArray();
200 
201  item.modItem?.AutoDefaults();
202  item.modItem?.SetDefaults();
203 
204  foreach (var g in HookSetDefaults.arr)
205  g.Instance(item).SetDefaults(item);
206  }
207 
208  internal static GlobalItem GetGlobalItem(Item item, Mod mod, string name) {
209  int index;
210  return globalIndexes.TryGetValue(mod.Name + ':' + name, out index) ? globalItems[index].Instance(item) : null;
211  }
212 
213  internal static GlobalItem GetGlobalItem(Item item, Type type) {
214  int index;
215  return globalIndexesByType.TryGetValue(type, out index) ? (index > -1 ? globalItems[index].Instance(item) : null) : null;
216  }
217 
218  //near end of Terraria.Main.DrawItem before default drawing call
219  // if(ItemLoader.animations.Contains(item.type))
220  // { ItemLoader.DrawAnimatedItem(item, whoAmI, color, alpha, rotation, scale); return; }
221  internal static void DrawAnimatedItem(Item item, int whoAmI, Color color, Color alpha, float rotation, float scale) {
222  int frameCount = Main.itemAnimations[item.type].FrameCount;
223  int frameDuration = Main.itemAnimations[item.type].TicksPerFrame;
224  Main.itemFrameCounter[whoAmI]++;
225  if (Main.itemFrameCounter[whoAmI] >= frameDuration) {
226  Main.itemFrameCounter[whoAmI] = 0;
227  Main.itemFrame[whoAmI]++;
228  }
229  if (Main.itemFrame[whoAmI] >= frameCount) {
230  Main.itemFrame[whoAmI] = 0;
231  }
232  Rectangle frame = Main.itemTexture[item.type].Frame(1, frameCount, 0, Main.itemFrame[whoAmI]);
233  float offX = (float)(item.width / 2 - frame.Width / 2);
234  float offY = (float)(item.height - frame.Height);
235  Main.spriteBatch.Draw(Main.itemTexture[item.type], new Vector2(item.position.X - Main.screenPosition.X + (float)(frame.Width / 2) + offX, item.position.Y - Main.screenPosition.Y + (float)(frame.Height / 2) + offY), new Rectangle?(frame), alpha, rotation, frame.Size() / 2f, scale, SpriteEffects.None, 0f);
236  if (item.color != default(Color)) {
237  Main.spriteBatch.Draw(Main.itemTexture[item.type], new Vector2(item.position.X - Main.screenPosition.X + (float)(frame.Width / 2) + offX, item.position.Y - Main.screenPosition.Y + (float)(frame.Height / 2) + offY), new Rectangle?(frame), item.GetColor(color), rotation, frame.Size() / 2f, scale, SpriteEffects.None, 0f);
238  }
239  }
240 
241  private static Rectangle AnimatedItemFrame(Item item) {
242  int frameCount = Main.itemAnimations[item.type].FrameCount;
243  int frameDuration = Main.itemAnimations[item.type].TicksPerFrame;
244  return Main.itemAnimations[item.type].GetFrame(Main.itemTexture[item.type]);
245  }
246 
247  private static HookList HookChoosePrefix = AddHook<Func<Item, UnifiedRandom, int>>(g => g.ChoosePrefix);
248 
249  public static int ChoosePrefix(Item item, UnifiedRandom rand) {
250  foreach (var g in HookChoosePrefix.arr) {
251  int pre = g.Instance(item).ChoosePrefix(item, rand);
252  if (pre > 0) {
253  return pre;
254  }
255  }
256  if (item.modItem != null) {
257  int pre = item.modItem.ChoosePrefix(rand);
258  if (pre > 0) {
259  return pre;
260  }
261  }
262  return -1;
263  }
264 
265  private static HookList HookPrefixChance = AddHook<Func<Item, int, UnifiedRandom, bool?>>(g => g.PrefixChance);
266 
272  public static bool? PrefixChance(Item item, int pre, UnifiedRandom rand) {
273  bool? result = null;
274  foreach (var g in HookPrefixChance.arr) {
275  bool? r = g.Instance(item).PrefixChance(item, pre, rand);
276  if (r.HasValue)
277  result = r.Value && (result ?? true);
278  }
279  if (item.modItem != null) {
280  bool? r = item.modItem.PrefixChance(pre, rand);
281  if (r.HasValue)
282  result = r.Value && (result ?? true);
283  }
284  return result;
285  }
286 
287  private static HookList HookAllowPrefix = AddHook<Func<Item, int, bool>>(g => g.AllowPrefix);
288  public static bool AllowPrefix(Item item, int pre) {
289  bool result = true;
290  foreach (var g in HookAllowPrefix.arr) {
291  result &= g.Instance(item).AllowPrefix(item, pre);
292  }
293  if (item.modItem != null) {
294  result &= item.modItem.AllowPrefix(pre);
295  }
296  return result;
297  }
298 
299  private static HookList HookCanUseItem = AddHook<Func<Item, Player, bool>>(g => g.CanUseItem);
300  //in Terraria.Player.ItemCheck
301  // inside block if (this.controlUseItem && this.itemAnimation == 0 && this.releaseUseItem && item.useStyle > 0)
302  // set initial flag2 to ItemLoader.CanUseItem(item, this)
309  public static bool CanUseItem(Item item, Player player) {
310  bool flag = true;
311  if (item.modItem != null)
312  flag &= item.modItem.CanUseItem(player);
313 
314  foreach (var g in HookCanUseItem.arr)
315  flag &= g.Instance(item).CanUseItem(item, player);
316 
317  return flag;
318  }
319 
320  private static HookList HookUseStyle = AddHook<Action<Item, Player>>(g => g.UseStyle);
321  //in Terraria.Player.ItemCheck after useStyle if/else chain call ItemLoader.UseStyle(item, this)
325  public static void UseStyle(Item item, Player player) {
326  if (item.IsAir)
327  return;
328 
329  item.modItem?.UseStyle(player);
330 
331  foreach (var g in HookUseStyle.arr)
332  g.Instance(item).UseStyle(item, player);
333  }
334 
335  private static HookList HookHoldStyle = AddHook<Action<Item, Player>>(g => g.HoldStyle);
336  //in Terraria.Player.ItemCheck after holdStyle if/else chain call ItemLoader.HoldStyle(item, this)
340  public static void HoldStyle(Item item, Player player) {
341  if (item.IsAir || player.pulley || player.itemAnimation > 0)
342  return;
343 
344  item.modItem?.HoldStyle(player);
345 
346  foreach (var g in HookHoldStyle.arr)
347  g.Instance(item).HoldStyle(item, player);
348  }
349 
350  private static HookList HookHoldItem = AddHook<Action<Item, Player>>(g => g.HoldItem);
351  //in Terraria.Player.ItemCheck before this.controlUseItem setting this.releaseUseItem call ItemLoader.HoldItem(item, this)
355  public static void HoldItem(Item item, Player player) {
356  if (item.IsAir)
357  return;
358 
359  item.modItem?.HoldItem(player);
360 
361  foreach (var g in HookHoldItem.arr)
362  g.Instance(item).HoldItem(item, player);
363  }
364 
365  private static HookList HookUseTimeMultiplier = AddHook<Func<Item, Player, float>>(g => g.UseTimeMultiplier);
366  public static float UseTimeMultiplier(Item item, Player player) {
367  if (item.IsAir)
368  return 1f;
369 
370  float multiplier = item.modItem?.UseTimeMultiplier(player) ?? 1f;
371 
372  foreach (var g in HookUseTimeMultiplier.arr)
373  multiplier *= g.Instance(item).UseTimeMultiplier(item, player);
374 
375  return multiplier;
376  }
377 
378  private static HookList HookMeleeSpeedMultiplier = AddHook<Func<Item, Player, float>>(g => g.MeleeSpeedMultiplier);
379  public static float MeleeSpeedMultiplier(Item item, Player player) {
380  if (item.IsAir)
381  return 1f;
382 
383  float multiplier = item.modItem?.MeleeSpeedMultiplier(player) ?? 1f;
384 
385  foreach (var g in HookMeleeSpeedMultiplier.arr)
386  multiplier *= g.Instance(item).MeleeSpeedMultiplier(item, player);
387 
388  return multiplier;
389  }
390 
391  private delegate void DelegateGetHealLife(Item item, Player player, bool quickHeal, ref int healValue);
392  private static HookList HookGetHealLife = AddHook<DelegateGetHealLife>(g => g.GetHealLife);
396  public static void GetHealLife(Item item, Player player, bool quickHeal, ref int healValue) {
397  if (item.IsAir)
398  return;
399 
400  item.modItem?.GetHealLife(player, quickHeal, ref healValue);
401 
402  foreach (var g in HookGetHealLife.arr)
403  g.Instance(item).GetHealLife(item, player, quickHeal, ref healValue);
404  }
405 
406  private delegate void DelegateGetHealMana(Item item, Player player, bool quickHeal, ref int healValue);
407  private static HookList HookGetHealMana = AddHook<DelegateGetHealMana>(g => g.GetHealMana);
411  public static void GetHealMana(Item item, Player player, bool quickHeal, ref int healValue) {
412  if (item.IsAir)
413  return;
414 
415  item.modItem?.GetHealMana(player, quickHeal, ref healValue);
416 
417  foreach (var g in HookGetHealMana.arr)
418  g.Instance(item).GetHealMana(item, player, quickHeal, ref healValue);
419  }
420 
421  private delegate void DelegateModifyManaCost(Item item, Player player, ref float reduce, ref float mult);
422  private static HookList HookModifyManaCost = AddHook<DelegateModifyManaCost>(g => g.ModifyManaCost);
426  public static void ModifyManaCost(Item item, Player player, ref float reduce, ref float mult) {
427  if (item.IsAir)
428  return;
429 
430  item.modItem?.ModifyManaCost(player, ref reduce, ref mult);
431 
432  foreach (var g in HookModifyManaCost.arr) {
433  g.Instance(item).ModifyManaCost(item, player, ref reduce, ref mult);
434  }
435  }
436 
437  private static HookList HookOnMissingMana = AddHook<Action<Item, Player, int>>(g => g.OnMissingMana);
441  public static void OnMissingMana(Item item, Player player, int neededMana) {
442  if (item.IsAir)
443  return;
444 
445  item.modItem?.OnMissingMana(player, neededMana);
446 
447  foreach (var g in HookOnMissingMana.arr) {
448  g.Instance(item).OnMissingMana(item, player, neededMana);
449  }
450  }
451 
452  private static HookList HookOnConsumeMana = AddHook<Action<Item, Player, int>>(g => g.OnConsumeMana);
456  public static void OnConsumeMana(Item item, Player player, int manaConsumed) {
457  if (item.IsAir)
458  return;
459 
460  item.modItem?.OnConsumeMana(player, manaConsumed);
461 
462  foreach (var g in HookOnConsumeMana.arr) {
463  g.Instance(item).OnConsumeMana(item, player, manaConsumed);
464  }
465  }
466 
467  private delegate void DelegateGetWeaponDamage(Item item, Player player, ref int damage);
468  [Obsolete]
469  private static HookList HookGetWeaponDamage = AddHook<DelegateGetWeaponDamage>(g => g.GetWeaponDamage);
473  [Obsolete]
474  public static void GetWeaponDamage(Item item, Player player, ref int damage) {
475  if (item.IsAir)
476  return;
477 
478  item.modItem?.GetWeaponDamage(player, ref damage);
479 
480  foreach (var g in HookGetWeaponDamage.arr)
481  g.Instance(item).GetWeaponDamage(item, player, ref damage);
482  }
483 
484  private delegate void DelegateModifyWeaponDamageOld(Item item, Player player, ref float add, ref float mult);
485  private static HookList HookModifyWeaponDamageOld = AddHook<DelegateModifyWeaponDamage>(g => g.ModifyWeaponDamage);
486  private delegate void DelegateModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat);
487  private static HookList HookModifyWeaponDamage = AddHook<DelegateModifyWeaponDamage>(g => g.ModifyWeaponDamage);
491  public static void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat) {
492  if (item.IsAir)
493  return;
494 
495  item.modItem?.ModifyWeaponDamage(player, ref add, ref mult);
496  item.modItem?.ModifyWeaponDamage(player, ref add, ref mult, ref flat);
497 
498  foreach (var g in HookModifyWeaponDamageOld.arr)
499  g.Instance(item).ModifyWeaponDamage(item, player, ref add, ref mult);
500  foreach (var g in HookModifyWeaponDamage.arr)
501  g.Instance(item).ModifyWeaponDamage(item, player, ref add, ref mult, ref flat);
502  }
503 
504  private delegate void DelegateGetWeaponKnockback(Item item, Player player, ref float knockback);
505  private static HookList HookGetWeaponKnockback = AddHook<DelegateGetWeaponKnockback>(g => g.GetWeaponKnockback);
509  public static void GetWeaponKnockback(Item item, Player player, ref float knockback) {
510  if (item.IsAir)
511  return;
512 
513  item.modItem?.GetWeaponKnockback(player, ref knockback);
514 
515  foreach (var g in HookGetWeaponKnockback.arr)
516  g.Instance(item).GetWeaponKnockback(item, player, ref knockback);
517  }
518 
519 
520  private delegate void DelegateGetWeaponCrit(Item item, Player player, ref int crit);
521  private static HookList HookGetWeaponCrit = AddHook<DelegateGetWeaponCrit>(g => g.GetWeaponCrit);
525  public static void GetWeaponCrit(Item item, Player player, ref int crit) {
526  if (item.IsAir)
527  return;
528 
529  item.modItem?.GetWeaponCrit(player, ref crit);
530 
531  foreach (var g in HookGetWeaponCrit.arr)
532  g.Instance(item).GetWeaponCrit(item, player, ref crit);
533  }
534 
538  public static bool CheckProjOnSwing(Player player, Item item) {
539  return item.modItem == null || !item.modItem.OnlyShootOnSwing || player.itemAnimation == player.itemAnimationMax - 1;
540  }
541 
542  private delegate void DelegateOldPickAmmo(Item item, Player player, ref int type, ref float speed, ref int damage, ref float knockback); // deprecated
543  private static HookList HookOldPickAmmo = AddHook<DelegateOldPickAmmo>(g => g.PickAmmo); // deprecated
544 
545  private delegate void DelegatePickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref int damage, ref float knockback);
546  private static HookList HookPickAmmo = AddHook<DelegatePickAmmo>(g => g.PickAmmo);
550  public static void PickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref int damage, ref float knockback) {
551  ammo.modItem?.PickAmmo(weapon, player, ref type, ref speed, ref damage, ref knockback);
552  ammo.modItem?.PickAmmo(player, ref type, ref speed, ref damage, ref knockback); // deprecated
553 
554  foreach (var g in HookPickAmmo.arr) {
555  g.Instance(ammo).PickAmmo(weapon, ammo, player, ref type, ref speed, ref damage, ref knockback);
556  }
557  foreach (var g in HookOldPickAmmo.arr) {
558  g.Instance(ammo).PickAmmo(ammo, player, ref type, ref speed, ref damage, ref knockback); // deprecated
559  }
560  }
561 
562  private static HookList HookConsumeAmmo = AddHook<Func<Item, Player, bool>>(g => g.ConsumeAmmo);
563  //near end of Terraria.Player.PickAmmo before flag2 is checked add
564  // if(!ItemLoader.ConsumeAmmo(sItem, item, this)) { flag2 = true; }
568  public static bool ConsumeAmmo(Item item, Item ammo, Player player) {
569  if (item.modItem != null && !item.modItem.ConsumeAmmo(player) ||
570  ammo.modItem != null && !ammo.modItem.ConsumeAmmo(player))
571  return false;
572 
573  foreach (var g in HookConsumeAmmo.arr) {
574  if (!g.Instance(item).ConsumeAmmo(item, player) ||
575  !g.Instance(ammo).ConsumeAmmo(ammo, player))
576  return false;
577  }
578 
579  return true;
580  }
581 
582  private static HookList HookOnConsumeAmmo = AddHook<Action<Item, Player>>(g => g.OnConsumeAmmo);
586  public static void OnConsumeAmmo(Item item, Item ammo, Player player) {
587  if (item.IsAir)
588  return;
589 
590  item.modItem?.OnConsumeAmmo(player);
591  ammo.modItem?.OnConsumeAmmo(player);
592 
593  foreach (var g in HookOnConsumeAmmo.arr) {
594  g.Instance(item).OnConsumeAmmo(item, player);
595  g.Instance(ammo).OnConsumeAmmo(ammo, player);
596  }
597  }
598 
599  private delegate bool DelegateShoot(Item item, Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack);
600  private static HookList HookShoot = AddHook<DelegateShoot>(g => g.Shoot);
601  //in Terraria.Player.ItemCheck at end of if/else chain for shooting place if on last else
602  // if(ItemLoader.Shoot(item, this, ref vector2, ref num78, ref num79, ref num71, ref num73, ref num74))
615  public static bool Shoot(Item item, Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) {
616  bool result = true;
617 
618  foreach (var g in HookShoot.arr) {
619  result &= g.Instance(item).Shoot(item, player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack);
620  }
621 
622  if (result && item.modItem != null) {
623  return item.modItem.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack);
624  }
625 
626  return result;
627  }
628 
629  private delegate void DelegateUseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox);
630  private static HookList HookUseItemHitbox = AddHook<DelegateUseItemHitbox>(g => g.UseItemHitbox);
631  //in Terraria.Player.ItemCheck after end of useStyle if/else chain for melee hitbox
632  // call ItemLoader.UseItemHitbox(item, this, ref r2, ref flag17)
636  public static void UseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox) {
637  item.modItem?.UseItemHitbox(player, ref hitbox, ref noHitbox);
638 
639  foreach (var g in HookUseItemHitbox.arr)
640  g.Instance(item).UseItemHitbox(item, player, ref hitbox, ref noHitbox);
641  }
642 
643  private static HookList HookMeleeEffects = AddHook<Action<Item, Player, Rectangle>>(g => g.MeleeEffects);
644  //in Terraria.Player.ItemCheck after magma stone dust effect for melee weapons
645  // call ItemLoader.MeleeEffects(item, this, r2)
649  public static void MeleeEffects(Item item, Player player, Rectangle hitbox) {
650  item.modItem?.MeleeEffects(player, hitbox);
651 
652  foreach (var g in HookMeleeEffects.arr)
653  g.Instance(item).MeleeEffects(item, player, hitbox);
654  }
655 
656  private static HookList HookCanHitNPC = AddHook<Func<Item, Player, NPC, bool?>>(g => g.CanHitNPC);
657  //in Terraria.Player.ItemCheck before checking whether npc type can be hit add
658  // bool? modCanHit = ItemLoader.CanHitNPC(item, this, Main.npc[num292]);
659  // if(modCanHit.HasValue && !modCanHit.Value) { continue; }
660  //in if statement afterwards add || (modCanHit.HasValue && modCanHit.Value)
667  public static bool? CanHitNPC(Item item, Player player, NPC target) {
668  bool? canHit = item.modItem?.CanHitNPC(player, target);
669  if (canHit.HasValue && !canHit.Value) {
670  return false;
671  }
672  foreach (var g in HookCanHitNPC.arr) {
673  bool? globalCanHit = g.Instance(item).CanHitNPC(item, player, target);
674  if (globalCanHit.HasValue) {
675  if (globalCanHit.Value) {
676  canHit = true;
677  }
678  else {
679  return false;
680  }
681  }
682  }
683  return canHit;
684  }
685 
686  private delegate void DelegateModifyHitNPC(Item item, Player player, NPC target, ref int damage, ref float knockBack, ref bool crit);
687  private static HookList HookModifyHitNPC = AddHook<DelegateModifyHitNPC>(g => g.ModifyHitNPC);
688  //in Terraria.Player.ItemCheck for melee attacks after damage variation
689  // call ItemLoader.ModifyHitNPC(item, this, Main.npc[num292], ref num282, ref num283, ref flag18)
693  public static void ModifyHitNPC(Item item, Player player, NPC target, ref int damage, ref float knockBack, ref bool crit) {
694  item.modItem?.ModifyHitNPC(player, target, ref damage, ref knockBack, ref crit);
695 
696  foreach (var g in HookModifyHitNPC.arr)
697  g.Instance(item).ModifyHitNPC(item, player, target, ref damage, ref knockBack, ref crit);
698  }
699 
700  private static HookList HookOnHitNPC = AddHook<Action<Item, Player, NPC, int, float, bool>>(g => g.OnHitNPC);
701  //in Terraria.Player.ItemCheck for melee attacks before updating informational accessories
702  // call ItemLoader.OnHitNPC(item, this, Main.npc[num292], num295, num283, flag18)
706  public static void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit) {
707  item.modItem?.OnHitNPC(player, target, damage, knockBack, crit);
708 
709  foreach (var g in HookOnHitNPC.arr)
710  g.Instance(item).OnHitNPC(item, player, target, damage, knockBack, crit);
711  }
712 
713  private static HookList HookCanHitPvp = AddHook<Func<Item, Player, Player, bool>>(g => g.CanHitPvp);
714  //in Terraria.Player.ItemCheck add to beginning of pvp collision check
719  public static bool CanHitPvp(Item item, Player player, Player target) {
720  foreach (var g in HookCanHitPvp.arr)
721  if (!g.Instance(item).CanHitPvp(item, player, target))
722  return false;
723 
724  return item.modItem == null || item.modItem.CanHitPvp(player, target);
725  }
726 
727  private delegate void DelegateModifyHitPvp(Item item, Player player, Player target, ref int damage, ref bool crit);
728  private static HookList HookModifyHitPvp = AddHook<DelegateModifyHitPvp>(g => g.ModifyHitPvp);
729  //in Terraria.Player.ItemCheck for pvp melee attacks after damage variation
730  // call ItemLoader.ModifyHitPvp(item, this, Main.player[num302], ref num282, ref flag20)
734  public static void ModifyHitPvp(Item item, Player player, Player target, ref int damage, ref bool crit) {
735  item.modItem?.ModifyHitPvp(player, target, ref damage, ref crit);
736 
737  foreach (var g in HookModifyHitPvp.arr)
738  g.Instance(item).ModifyHitPvp(item, player, target, ref damage, ref crit);
739  }
740 
741  private static HookList HookOnHitPvp = AddHook<Action<Item, Player, Player, int, bool>>(g => g.OnHitPvp);
742  //in Terraria.Player.ItemCheck for pvp melee attacks before NetMessage stuff
743  // call ItemLoader.OnHitPvp(item, this, Main.player[num302], num304, flag20)
747  public static void OnHitPvp(Item item, Player player, Player target, int damage, bool crit) {
748  item.modItem?.OnHitPvp(player, target, damage, crit);
749 
750  foreach (var g in HookOnHitPvp.arr)
751  g.Instance(item).OnHitPvp(item, player, target, damage, crit);
752  }
753 
754  private static HookList HookUseItem = AddHook<Func<Item, Player, bool>>(g => g.UseItem);
759  public static bool UseItem(Item item, Player player) {
760  if (item.IsAir)
761  return false;
762 
763  bool flag = false;
764  if (item.modItem != null)
765  flag |= item.modItem.UseItem(player);
766 
767  foreach (var g in HookUseItem.arr)
768  flag |= g.Instance(item).UseItem(item, player);
769 
770  return flag;
771  }
772 
773  private static HookList HookConsumeItem = AddHook<Func<Item, Player, bool>>(g => g.ConsumeItem);
774  //near end of Terraria.Player.ItemCheck
775  // if (flag22 && ItemLoader.ConsumeItem(item, this))
779  public static bool ConsumeItem(Item item, Player player) {
780  if (item.IsAir) return true;
781  if (item.modItem != null && !item.modItem.ConsumeItem(player))
782  return false;
783 
784  foreach (var g in HookConsumeItem.arr)
785  if (!g.Instance(item).ConsumeItem(item, player))
786  return false;
787 
788  OnConsumeItem(item, player);
789  return true;
790  }
791 
792  private static HookList HookOnConsumeItem = AddHook<Action<Item, Player>>(g => g.OnConsumeItem);
796  public static void OnConsumeItem(Item item, Player player) {
797  if (item.IsAir)
798  return;
799 
800  item.modItem?.OnConsumeItem(player);
801 
802  foreach (var g in HookOnConsumeItem.arr)
803  g.Instance(item).OnConsumeItem(item, player);
804  }
805 
806  private static HookList HookUseItemFrame = AddHook<Func<Item, Player, bool>>(g => g.UseItemFrame);
807  //in Terraria.Player.PlayerFrame at end of useStyle if/else chain
808  // call if(ItemLoader.UseItemFrame(this.inventory[this.selectedItem], this)) { return; }
812  public static bool UseItemFrame(Item item, Player player) {
813  if (item.modItem != null && item.modItem.UseItemFrame(player))
814  return true;
815 
816  foreach (var g in HookUseItemFrame.arr)
817  if (g.Instance(item).UseItemFrame(item, player))
818  return true;
819 
820  return false;
821  }
822 
823  private static HookList HookHoldItemFrame = AddHook<Func<Item, Player, bool>>(g => g.HoldItemFrame);
824  //in Terraria.Player.PlayerFrame at end of holdStyle if statements
825  // call if(ItemLoader.HoldItemFrame(this.inventory[this.selectedItem], this)) { return; }
829  public static bool HoldItemFrame(Item item, Player player) {
830  if (item.IsAir)
831  return false;
832 
833  if (item.modItem != null && item.modItem.HoldItemFrame(player))
834  return true;
835 
836  foreach (var g in HookHoldItemFrame.arr)
837  if (g.Instance(item).HoldItemFrame(item, player))
838  return true;
839 
840  return false;
841  }
842 
843  private static HookList HookAltFunctionUse = AddHook<Func<Item, Player, bool>>(g => g.AltFunctionUse);
847  public static bool AltFunctionUse(Item item, Player player) {
848  if (item.IsAir)
849  return false;
850 
851  if (item.modItem != null && item.modItem.AltFunctionUse(player))
852  return true;
853 
854  foreach (var g in HookAltFunctionUse.arr)
855  if (g.Instance(item).AltFunctionUse(item, player))
856  return true;
857 
858  return false;
859  }
860 
861  private static HookList HookUpdateInventory = AddHook<Action<Item, Player>>(g => g.UpdateInventory);
862  //place at end of first for loop in Terraria.Player.UpdateEquips
863  // call ItemLoader.UpdateInventory(this.inventory[j], this)
867  public static void UpdateInventory(Item item, Player player) {
868  if (item.IsAir)
869  return;
870 
871  item.modItem?.UpdateInventory(player);
872 
873  foreach (var g in HookUpdateInventory.arr)
874  g.Instance(item).UpdateInventory(item, player);
875  }
876 
877  private static HookList HookUpdateEquip = AddHook<Action<Item, Player>>(g => g.UpdateEquip);
878  //place in second for loop of Terraria.Player.UpdateEquips before prefix checking
879  // call ItemLoader.UpdateEquip(this.armor[k], this)
883  public static void UpdateEquip(Item item, Player player) {
884  if (item.IsAir)
885  return;
886 
887  item.modItem?.UpdateEquip(player);
888 
889  foreach (var g in HookUpdateEquip.arr)
890  g.Instance(item).UpdateEquip(item, player);
891  }
892 
893  private static HookList HookUpdateAccessory = AddHook<Action<Item, Player, bool>>(g => g.UpdateAccessory);
894  //place at end of third for loop of Terraria.Player.UpdateEquips
895  // call ItemLoader.UpdateAccessory(this.armor[l], this, this.hideVisual[l])
899  public static void UpdateAccessory(Item item, Player player, bool hideVisual) {
900  if (item.IsAir)
901  return;
902 
903  item.modItem?.UpdateAccessory(player, hideVisual);
904 
905  foreach (var g in HookUpdateAccessory.arr)
906  g.Instance(item).UpdateAccessory(item, player, hideVisual);
907  }
908 
912  public static void UpdateVanity(Player player) {
913  foreach (EquipType type in EquipLoader.EquipTypes) {
914  int slot = EquipLoader.GetPlayerEquip(player, type);
915  EquipTexture texture = EquipLoader.GetEquipTexture(type, slot);
916  texture?.UpdateVanity(player, type);
917  }
918  }
919 
920  private static HookList HookUpdateArmorSet = AddHook<Action<Player, string>>(g => g.UpdateArmorSet);
921  //at end of Terraria.Player.UpdateArmorSets call ItemLoader.UpdateArmorSet(this, this.armor[0], this.armor[1], this.armor[2])
925  public static void UpdateArmorSet(Player player, Item head, Item body, Item legs) {
926  if (head.modItem != null && head.modItem.IsArmorSet(head, body, legs))
927  head.modItem.UpdateArmorSet(player);
928 
929  if (body.modItem != null && body.modItem.IsArmorSet(head, body, legs))
930  body.modItem.UpdateArmorSet(player);
931 
932  if (legs.modItem != null && legs.modItem.IsArmorSet(head, body, legs))
933  legs.modItem.UpdateArmorSet(player);
934 
935  foreach (GlobalItem globalItem in HookUpdateArmorSet.arr) {
936  string set = globalItem.IsArmorSet(head, body, legs);
937  if (!string.IsNullOrEmpty(set))
938  globalItem.UpdateArmorSet(player, set);
939  }
940  }
941 
942  private static HookList HookPreUpdateVanitySet = AddHook<Action<Player, string>>(g => g.PreUpdateVanitySet);
943  //in Terraria.Player.PlayerFrame after setting armor effects fields call this
947  public static void PreUpdateVanitySet(Player player) {
948  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
949  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
950  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
951  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
952  headTexture.PreUpdateVanitySet(player);
953 
954  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
955  bodyTexture.PreUpdateVanitySet(player);
956 
957  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
958  legTexture.PreUpdateVanitySet(player);
959 
960  foreach (GlobalItem globalItem in HookPreUpdateVanitySet.arr) {
961  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
962  if (!string.IsNullOrEmpty(set))
963  globalItem.PreUpdateVanitySet(player, set);
964  }
965  }
966 
967  private static HookList HookUpdateVanitySet = AddHook<Action<Player, string>>(g => g.UpdateVanitySet);
968  //in Terraria.Player.PlayerFrame after armor sets creating dust call this
972  public static void UpdateVanitySet(Player player) {
973  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
974  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
975  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
976  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
977  headTexture.UpdateVanitySet(player);
978 
979  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
980  bodyTexture.UpdateVanitySet(player);
981 
982  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
983  legTexture.UpdateVanitySet(player);
984 
985  foreach (GlobalItem globalItem in HookUpdateVanitySet.arr) {
986  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
987  if (!string.IsNullOrEmpty(set))
988  globalItem.UpdateVanitySet(player, set);
989  }
990  }
991 
992  private static HookList HookArmorSetShadows = AddHook<Action<Player, string>>(g => g.ArmorSetShadows);
993  //in Terraria.Main.DrawPlayers after armor combinations setting flags call
994  // ItemLoader.ArmorSetShadows(player);
998  public static void ArmorSetShadows(Player player) {
999  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
1000  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
1001  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
1002  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
1003  headTexture.ArmorSetShadows(player);
1004 
1005  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
1006  bodyTexture.ArmorSetShadows(player);
1007 
1008  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
1009  legTexture.ArmorSetShadows(player);
1010 
1011  foreach (GlobalItem globalItem in HookArmorSetShadows.arr) {
1012  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
1013  if (!string.IsNullOrEmpty(set))
1014  globalItem.ArmorSetShadows(player, set);
1015  }
1016  }
1017 
1018  private delegate void DelegateSetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes);
1019  private static HookList HookSetMatch = AddHook<DelegateSetMatch>(g => g.SetMatch);
1023  public static void SetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes) {
1024  EquipTexture texture = EquipLoader.GetEquipTexture((EquipType)armorSlot, type);
1025  texture?.SetMatch(male, ref equipSlot, ref robes);
1026 
1027  foreach (var g in HookSetMatch.arr)
1028  g.SetMatch(armorSlot, type, male, ref equipSlot, ref robes);
1029  }
1030 
1031  private static HookList HookCanRightClick = AddHook<Func<Item, bool>>(g => g.CanRightClick);
1032  //in Terraria.UI.ItemSlot.RightClick in end of item-opening if/else chain before final else
1033  // make else if(ItemLoader.CanRightClick(inv[slot]))
1037  public static bool CanRightClick(Item item) {
1038  if (item.IsAir || !Main.mouseRight)
1039  return false;
1040 
1041  if (item.modItem != null && item.modItem.CanRightClick())
1042  return true;
1043 
1044  foreach (var g in HookCanRightClick.arr)
1045  if (g.Instance(item).CanRightClick(item))
1046  return true;
1047 
1048  return false;
1049  }
1050 
1051  private static HookList HookRightClick = AddHook<Action<Item, Player>>(g => g.RightClick);
1052  //in Terraria.UI.ItemSlot in block from CanRightClick call ItemLoader.RightClick(inv[slot], player)
1064  public static void RightClick(Item item, Player player) {
1065  if (!Main.mouseRightRelease)
1066  return;
1067 
1068  item.modItem?.RightClick(player);
1069 
1070  foreach (var g in HookRightClick.arr)
1071  g.Instance(item).RightClick(item, player);
1072 
1073  if (ConsumeItem(item, player) && --item.stack == 0)
1074  item.SetDefaults();
1075 
1076  Main.PlaySound(7);
1077  Main.stackSplit = 30;
1078  Main.mouseRightRelease = false;
1079  Recipe.FindRecipes();
1080  }
1081 
1082  //in Terraria.UI.ItemSlot add this to boss bag check
1086  public static bool IsModBossBag(Item item) {
1087  return item.modItem != null && item.modItem.BossBagNPC > 0;
1088  }
1089 
1090  //in Terraria.Player.OpenBossBag after setting num14 call
1091  // ItemLoader.OpenBossBag(type, this, ref num14);
1095  public static void OpenBossBag(int type, Player player, ref int npc) {
1096  ModItem modItem = GetItem(type);
1097  if (modItem != null && modItem.BossBagNPC > 0) {
1098  modItem.OpenBossBag(player);
1099  npc = modItem.BossBagNPC;
1100  }
1101  }
1102 
1103  private static HookList HookPreOpenVanillaBag = AddHook<Func<string, Player, int, bool>>(g => g.PreOpenVanillaBag);
1104  //in beginning of Terraria.Player.openBag methods add
1105  // if(!ItemLoader.PreOpenVanillaBag("bagName", this, arg)) { return; }
1106  //at the end of the following methods in Player.cs, add: NPCLoader.blockLoot.Clear(); // clear blockloot
1107  //methods: OpenBossBag, openCrate, openGoodieBag, openHerbBag, openLockbox, openPresent
1111  public static bool PreOpenVanillaBag(string context, Player player, int arg) {
1112  bool result = true;
1113  foreach (var g in HookPreOpenVanillaBag.arr)
1114  result &= g.PreOpenVanillaBag(context, player, arg);
1115 
1116  if (!result) {
1117  NPCLoader.blockLoot.Clear(); // clear blockloot
1118  return false;
1119  }
1120 
1121  return true;
1122  }
1123 
1124  private static HookList HookOpenVanillaBag = AddHook<Action<string, Player, int>>(g => g.OpenVanillaBag);
1125  //in Terraria.Player.openBag methods after PreOpenVanillaBag if statements
1126  // add ItemLoader.OpenVanillaBag("bagname", this, arg);
1130  public static void OpenVanillaBag(string context, Player player, int arg) {
1131  foreach (var g in HookOpenVanillaBag.arr)
1132  g.OpenVanillaBag(context, player, arg);
1133  }
1134 
1135  private delegate bool DelegateReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount);
1136  private static HookList HookReforgePrice = AddHook<DelegateReforgePrice>(g => g.ReforgePrice);
1142  public static bool ReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount) {
1143  bool b = item.modItem?.ReforgePrice(ref reforgePrice, ref canApplyDiscount) ?? true;
1144  foreach (var g in HookReforgePrice.arr)
1145  b &= g.Instance(item).ReforgePrice(item, ref reforgePrice, ref canApplyDiscount);
1146  return b;
1147  }
1148 
1149  // @todo: PreReforge marked obsolete until v0.11
1150  private static HookList HookPreReforge = AddHook<Func<Item, bool>>(g => g.NewPreReforge);
1154  public static bool PreReforge(Item item) {
1155  bool b = item.modItem?.NewPreReforge() ?? true;
1156  foreach (var g in HookPreReforge.arr)
1157  b &= g.Instance(item).NewPreReforge(item);
1158  return b;
1159  }
1160 
1161  private static HookList HookPostReforge = AddHook<Action<Item>>(g => g.PostReforge);
1165  public static void PostReforge(Item item) {
1166  item.modItem?.PostReforge();
1167  foreach (var g in HookPostReforge.arr)
1168  g.Instance(item).PostReforge(item);
1169  }
1170 
1171  private delegate void DelegateDrawHands(int body, ref bool drawHands, ref bool drawArms);
1172  private static HookList HookDrawHands = AddHook<DelegateDrawHands>(g => g.DrawHands);
1176  public static void DrawHands(Player player, ref bool drawHands, ref bool drawArms) {
1177  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
1178  texture?.DrawHands(ref drawHands, ref drawArms);
1179 
1180  foreach (var g in HookDrawHands.arr)
1181  g.DrawHands(player.body, ref drawHands, ref drawArms);
1182  }
1183 
1184  private delegate void DelegateDrawHair(int body, ref bool drawHair, ref bool drawAltHair);
1185  private static HookList HookDrawHair = AddHook<DelegateDrawHair>(g => g.DrawHair);
1186  //in Terraria.Main.DrawPlayerHead after if statement that sets flag2 to true
1187  // call ItemLoader.DrawHair(drawPlayer, ref flag, ref flag2)
1188  //in Terraria.Main.DrawPlayer after if statement that sets flag5 to true
1189  // call ItemLoader.DrawHair(drawPlayer, ref flag4, ref flag5)
1193  public static void DrawHair(Player player, ref bool drawHair, ref bool drawAltHair) {
1194  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
1195  texture?.DrawHair(ref drawHair, ref drawAltHair);
1196 
1197  foreach (var g in HookDrawHair.arr)
1198  g.DrawHair(player.body, ref drawHair, ref drawAltHair);
1199  }
1200 
1201  private static HookList HookDrawHead = AddHook<Func<int, bool>>(g => g.DrawHead);
1202  //in Terraria.Main.DrawPlayerHead in if statement after ItemLoader.DrawHair
1203  //and in Terraria.Main.DrawPlayer in if (!drawPlayer.invis && drawPlayer.head != 38 && drawPlayer.head != 135)
1204  // use && with ItemLoader.DrawHead(drawPlayer)
1208  public static bool DrawHead(Player player) {
1209  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
1210  if (texture != null && !texture.DrawHead())
1211  return false;
1212 
1213  foreach (var g in HookDrawHead.arr)
1214  if (!g.DrawHead(player.head))
1215  return false;
1216 
1217  return true;
1218  }
1219 
1220  private static HookList HookDrawBody = AddHook<Func<int, bool>>(g => g.DrawBody);
1224  public static bool DrawBody(Player player) {
1225  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
1226  if (texture != null && !texture.DrawBody())
1227  return false;
1228 
1229  foreach (var g in HookDrawBody.arr)
1230  if (!g.DrawBody(player.body))
1231  return false;
1232 
1233  return true;
1234  }
1235 
1236  private static HookList HookDrawLegs = AddHook<Func<int, int, bool>>(g => g.DrawLegs);
1240  public static bool DrawLegs(Player player) {
1241  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
1242  if (texture != null && !texture.DrawLegs())
1243  return false;
1244 
1245  texture = EquipLoader.GetEquipTexture(EquipType.Shoes, player.shoe);
1246  if (texture != null && !texture.DrawLegs())
1247  return false;
1248 
1249  foreach (var g in HookDrawLegs.arr)
1250  if (!g.DrawLegs(player.legs, player.shoe))
1251  return false;
1252 
1253  return true;
1254  }
1255 
1256  private delegate void DelegateDrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor);
1257  private static HookList HookDrawArmorColor = AddHook<DelegateDrawArmorColor>(g => g.DrawArmorColor);
1261  public static void DrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color,
1262  ref int glowMask, ref Color glowMaskColor) {
1263  EquipTexture texture = EquipLoader.GetEquipTexture(type, slot);
1264  texture?.DrawArmorColor(drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor);
1265 
1266  foreach (var g in HookDrawArmorColor.arr)
1267  g.DrawArmorColor(type, slot, drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor);
1268  }
1269 
1270  private delegate void DelegateArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color);
1271  private static HookList HookArmorArmGlowMask = AddHook<DelegateArmorArmGlowMask>(g => g.ArmorArmGlowMask);
1275  public static void ArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color) {
1276  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, slot);
1277  texture?.ArmorArmGlowMask(drawPlayer, shadow, ref glowMask, ref color);
1278 
1279  foreach (var g in HookArmorArmGlowMask.arr)
1280  g.ArmorArmGlowMask(slot, drawPlayer, shadow, ref glowMask, ref color);
1281  }
1282 
1286  public static Item GetWing(Player player) {
1287  Item item = null;
1288  for (int k = 3; k < 8 + player.extraAccessorySlots; k++) {
1289  if (player.armor[k].wingSlot == player.wingsLogic) {
1290  item = player.armor[k];
1291  }
1292  }
1293  if (item != null) {
1294  return item;
1295  }
1296  if (player.wingsLogic > 0 && player.wingsLogic < Main.maxWings) {
1297  item = new Item();
1298  item.SetDefaults(vanillaWings[player.wingsLogic]);
1299  return item;
1300  }
1301  if (player.wingsLogic >= Main.maxWings) {
1302  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1303  if (texture?.item != null)
1304  return texture.item.item;
1305  }
1306  return null;
1307  }
1308 
1309  private delegate void DelegateVerticalWingSpeeds(Item item, Player player, ref float ascentWhenFalling, ref float ascentWhenRising, ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend);
1310  private static HookList HookVerticalWingSpeeds = AddHook<DelegateVerticalWingSpeeds>(g => g.VerticalWingSpeeds);
1311  //in Terraria.Player.WingMovement after if statements that set num1-5
1312  // call ItemLoader.VerticalWingSpeeds(this, ref num2, ref num5, ref num4, ref num3, ref num)
1316  public static void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising,
1317  ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend) {
1318  Item item = GetWing(player);
1319  if (item == null) {
1320  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1321  texture?.VerticalWingSpeeds(
1322  player, ref ascentWhenFalling, ref ascentWhenRising, ref maxCanAscendMultiplier,
1323  ref maxAscentMultiplier, ref constantAscend);
1324  return;
1325  }
1326 
1327  item.modItem?.VerticalWingSpeeds(player, ref ascentWhenFalling, ref ascentWhenRising, ref maxCanAscendMultiplier,
1328  ref maxAscentMultiplier, ref constantAscend);
1329 
1330  foreach (var g in HookVerticalWingSpeeds.arr)
1331  g.Instance(item).VerticalWingSpeeds(item, player, ref ascentWhenFalling, ref ascentWhenRising,
1332  ref maxCanAscendMultiplier, ref maxAscentMultiplier, ref constantAscend);
1333  }
1334 
1335  private delegate void DelegateHorizontalWingSpeeds(Item item, Player player, ref float speed, ref float acceleration);
1336  private static HookList HookHorizontalWingSpeeds = AddHook<DelegateHorizontalWingSpeeds>(g => g.HorizontalWingSpeeds);
1337  //in Terraria.Player.Update after wingsLogic if statements modifying accRunSpeed and runAcceleration
1338  // call ItemLoader.HorizontalWingSpeeds(this)
1342  public static void HorizontalWingSpeeds(Player player) {
1343  Item item = GetWing(player);
1344  if (item == null) {
1345  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1346  texture?.HorizontalWingSpeeds(player, ref player.accRunSpeed, ref player.runAcceleration);
1347  return;
1348  }
1349 
1350  item.modItem?.HorizontalWingSpeeds(player, ref player.accRunSpeed, ref player.runAcceleration);
1351 
1352  foreach (var g in HookHorizontalWingSpeeds.arr)
1353  g.Instance(item).HorizontalWingSpeeds(item, player, ref player.accRunSpeed, ref player.runAcceleration);
1354  }
1355 
1356  private static HookList HookWingUpdate = AddHook<Func<int, Player, bool, bool>>(g => g.WingUpdate);
1360  public static bool WingUpdate(Player player, bool inUse) {
1361  if (player.wings <= 0)
1362  return false;
1363 
1364  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wings);
1365  bool? retVal = texture?.WingUpdate(player, inUse);
1366 
1367  foreach (var g in HookWingUpdate.arr)
1368  retVal |= g.WingUpdate(player.wings, player, inUse);
1369 
1370  return retVal ?? false;
1371  }
1372 
1373  private delegate void DelegateUpdate(Item item, ref float gravity, ref float maxFallSpeed);
1374  private static HookList HookUpdate = AddHook<DelegateUpdate>(g => g.Update);
1375  //in Terraria.Item.UpdateItem before item movement (denoted by ItemID.Sets.ItemNoGravity)
1376  // call ItemLoader.Update(this, ref num, ref num2)
1380  public static void Update(Item item, ref float gravity, ref float maxFallSpeed) {
1381  item.modItem?.Update(ref gravity, ref maxFallSpeed);
1382 
1383  foreach (var g in HookUpdate.arr)
1384  g.Instance(item).Update(item, ref gravity, ref maxFallSpeed);
1385  }
1386 
1387  private static HookList HookCanBurnInLava = AddHook<Func<Item, bool>>(g => g.CanBurnInLava);
1391  public static bool CanBurnInLava(Item item)
1392  {
1393  foreach (var g in HookCanBurnInLava.arr)
1394  if (g.Instance(item).CanBurnInLava(item))
1395  return true;
1396 
1397  return item.modItem?.CanBurnInLava() ?? false;
1398  }
1399 
1400  private static HookList HookPostUpdate = AddHook<Action<Item>>(g => g.PostUpdate);
1404  public static void PostUpdate(Item item) {
1405  item.modItem?.PostUpdate();
1406 
1407  foreach (var g in HookPostUpdate.arr)
1408  g.Instance(item).PostUpdate(item);
1409  }
1410 
1411  private delegate void DelegateGrabRange(Item item, Player player, ref int grabRange);
1412  private static HookList HookGrabRange = AddHook<DelegateGrabRange>(g => g.GrabRange);
1413  //in Terraria.Player.GrabItems after increasing grab range add
1414  // ItemLoader.GrabRange(Main.item[j], this, ref num);
1418  public static void GrabRange(Item item, Player player, ref int grabRange) {
1419  item.modItem?.GrabRange(player, ref grabRange);
1420 
1421  foreach (var g in HookGrabRange.arr)
1422  g.Instance(item).GrabRange(item, player, ref grabRange);
1423  }
1424 
1425  private static HookList HookGrabStyle = AddHook<Func<Item, Player, bool>>(g => g.GrabStyle);
1426  //in Terraria.Player.GrabItems between setting beingGrabbed to true and grab styles add
1427  // if(ItemLoader.GrabStyle(Main.item[j], this)) { } else
1431  public static bool GrabStyle(Item item, Player player) {
1432  foreach (var g in HookGrabStyle.arr)
1433  if (g.Instance(item).GrabStyle(item, player))
1434  return true;
1435 
1436  return item.modItem != null && item.modItem.GrabStyle(player);
1437  }
1438 
1439  private static HookList HookCanPickup = AddHook<Func<Item, Player, bool>>(g => g.CanPickup);
1440  //in Terraria.Player.GrabItems first per item if statement add
1441  // && ItemLoader.CanPickup(Main.item[j], this)
1442  public static bool CanPickup(Item item, Player player) {
1443  foreach (var g in HookCanPickup.arr)
1444  if (!g.Instance(item).CanPickup(item, player))
1445  return false;
1446 
1447  return item.modItem?.CanPickup(player) ?? true;
1448  }
1449 
1450  private static HookList HookOnPickup = AddHook<Func<Item, Player, bool>>(g => g.OnPickup);
1451  //in Terraria.Player.GrabItems before special pickup effects add
1452  // if(!ItemLoader.OnPickup(Main.item[j], this)) { Main.item[j] = new Item(); continue; }
1456  public static bool OnPickup(Item item, Player player) {
1457  foreach (var g in HookOnPickup.arr)
1458  if (!g.Instance(item).OnPickup(item, player))
1459  return false;
1460 
1461  return item.modItem?.OnPickup(player) ?? true;
1462  }
1463 
1464  private static HookList HookItemSpace = AddHook<Func<Item, Player, bool>>(g => g.ItemSpace);
1465  //in Terraria.Player.GrabItems before grab effect
1466  // (this.ItemSpace(Main.item[j]) || ItemLoader.ExtraPickupSpace(Main.item[j], this)
1467  public static bool ItemSpace(Item item, Player player) {
1468  foreach (var g in HookItemSpace.arr)
1469  if (g.Instance(item).ItemSpace(item, player))
1470  return true;
1471 
1472  return item.modItem?.ItemSpace(player) ?? false;
1473  }
1474 
1475  private static HookList HookGetAlpha = AddHook<Func<Item, Color, Color?>>(g => g.GetAlpha);
1476  //in Terraria.UI.ItemSlot.GetItemLight remove type too high check
1477  //in beginning of Terraria.Item.GetAlpha call
1478  // Color? modColor = ItemLoader.GetAlpha(this, newColor);
1479  // if(modColor.HasValue) { return modColor.Value; }
1483  public static Color? GetAlpha(Item item, Color lightColor) {
1484  if (item.IsAir)
1485  return null;
1486 
1487  foreach (var g in HookGetAlpha.arr) {
1488  Color? color = g.Instance(item).GetAlpha(item, lightColor);
1489  if (color.HasValue)
1490  return color;
1491  }
1492 
1493  return item.modItem?.GetAlpha(lightColor);
1494  }
1495 
1496  private delegate bool DelegatePreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI);
1497  private static HookList HookPreDrawInWorld = AddHook<DelegatePreDrawInWorld>(g => g.PreDrawInWorld);
1498  //in Terraria.Main.DrawItem after ItemSlot.GetItemLight call
1499  // if(!ItemLoader.PreDrawInWorld(item, Main.spriteBatch, color, alpha, ref rotation, ref scale)) { return; }
1503  public static bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) {
1504  bool flag = true;
1505  if (item.modItem != null)
1506  flag &= item.modItem.PreDrawInWorld(spriteBatch, lightColor, alphaColor, ref rotation, ref scale, whoAmI);
1507 
1508  foreach (var g in HookPreDrawInWorld.arr)
1509  flag &= g.Instance(item).PreDrawInWorld(item, spriteBatch, lightColor, alphaColor, ref rotation, ref scale, whoAmI);
1510 
1511  return flag;
1512  }
1513 
1514  private static HookList HookPostDrawInWorld = AddHook<Action<Item, SpriteBatch, Color, Color, float, float, int>>(g => g.PostDrawInWorld);
1515  //in Terraria.Main.DrawItem before every return (including for PreDrawInWorld) and at end of method call
1516  // ItemLoader.PostDrawInWorld(item, Main.spriteBatch, color, alpha, rotation, scale)
1520  public static void PostDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) {
1521  item.modItem?.PostDrawInWorld(spriteBatch, lightColor, alphaColor, rotation, scale, whoAmI);
1522 
1523  foreach (var g in HookPostDrawInWorld.arr)
1524  g.Instance(item).PostDrawInWorld(item, spriteBatch, lightColor, alphaColor, rotation, scale, whoAmI);
1525  }
1526 
1527  private static HookList HookPreDrawInInventory = AddHook<Func<Item, SpriteBatch, Vector2, Rectangle, Color, Color, Vector2, float, bool>>(g => g.PreDrawInInventory);
1528  //in Terraria.UI.ItemSlot.Draw place item-drawing code inside if statement
1529  // if(ItemLoader.PreDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
1530  // item.GetColor(color), origin, num4 * num3))
1534  public static bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame,
1535  Color drawColor, Color itemColor, Vector2 origin, float scale) {
1536  bool flag = true;
1537  foreach (var g in HookPreDrawInInventory.arr)
1538  flag &= g.Instance(item).PreDrawInInventory(item, spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1539 
1540  if (item.modItem != null)
1541  flag &= item.modItem.PreDrawInInventory(spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1542 
1543  return flag;
1544  }
1545 
1546  private static HookList HookPostDrawInInventory = AddHook<Action<Item, SpriteBatch, Vector2, Rectangle, Color, Color, Vector2, float>>(g => g.PostDrawInInventory);
1547  //in Terraria.UI.ItemSlot.Draw after if statement for PreDrawInInventory call
1548  // ItemLoader.PostDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
1549  // item.GetColor(color), origin, num4 * num3);
1553  public static void PostDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame,
1554  Color drawColor, Color itemColor, Vector2 origin, float scale) {
1555  item.modItem?.PostDrawInInventory(spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1556 
1557  foreach (var g in HookPostDrawInInventory.arr)
1558  g.Instance(item).PostDrawInInventory(item, spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1559  }
1560 
1561  private static HookList HookHoldoutOffset = AddHook<Func<int, Vector2?>>(g => g.HoldoutOffset);
1562  public static void HoldoutOffset(float gravDir, int type, ref Vector2 offset) {
1563  ModItem modItem = GetItem(type);
1564  if (modItem != null) {
1565  Vector2? modOffset = modItem.HoldoutOffset();
1566  if (modOffset.HasValue) {
1567  offset.X = modOffset.Value.X;
1568  offset.Y += gravDir * modOffset.Value.Y;
1569  }
1570  }
1571  foreach (var g in HookHoldoutOffset.arr) {
1572  Vector2? modOffset = g.HoldoutOffset(type);
1573  if (modOffset.HasValue) {
1574  offset.X = modOffset.Value.X;
1575  offset.Y = Main.itemTexture[type].Height / 2f + gravDir * modOffset.Value.Y;
1576  }
1577  }
1578  }
1579 
1580  private static HookList HookHoldoutOrigin = AddHook<Func<int, Vector2?>>(g => g.HoldoutOrigin);
1581  public static void HoldoutOrigin(Player player, ref Vector2 origin) {
1582  Item item = player.inventory[player.selectedItem];
1583  Vector2 modOrigin = Vector2.Zero;
1584  if (item.modItem != null) {
1585  Vector2? modOrigin2 = item.modItem.HoldoutOrigin();
1586  if (modOrigin2.HasValue) {
1587  modOrigin = modOrigin2.Value;
1588  }
1589  }
1590  foreach (var g in HookHoldoutOrigin.arr) {
1591  Vector2? modOrigin2 = g.Instance(item).HoldoutOrigin(item.type);
1592  if (modOrigin2.HasValue) {
1593  modOrigin = modOrigin2.Value;
1594  }
1595  }
1596  modOrigin.X *= player.direction;
1597  modOrigin.Y *= -player.gravDir;
1598  origin += modOrigin;
1599  }
1600 
1601  private static HookList HookCanEquipAccessory = AddHook<Func<Item, Player, int, bool>>(g => g.CanEquipAccessory);
1602  //in Terraria.UI.ItemSlot.AccCheck replace 2nd and 3rd return false with
1603  // return !ItemLoader.CanEquipAccessory(item, slot)
1604  public static bool CanEquipAccessory(Item item, int slot) {
1605  Player player = Main.player[Main.myPlayer];
1606  if (item.modItem != null && !item.modItem.CanEquipAccessory(player, slot))
1607  return false;
1608 
1609  foreach (var g in HookCanEquipAccessory.arr)
1610  if (!g.Instance(item).CanEquipAccessory(item, player, slot))
1611  return false;
1612 
1613  return true;
1614  }
1615 
1616  private delegate void DelegateExtractinatorUse(int extractType, ref int resultType, ref int resultStack);
1617  private static HookList HookExtractinatorUse = AddHook<DelegateExtractinatorUse>(g => g.ExtractinatorUse);
1618  public static void ExtractinatorUse(ref int resultType, ref int resultStack, int extractType) {
1619  GetItem(extractType)?.ExtractinatorUse(ref resultType, ref resultStack);
1620 
1621  foreach (var g in HookExtractinatorUse.arr)
1622  g.ExtractinatorUse(extractType, ref resultType, ref resultStack);
1623  }
1624 
1625  public static void AutoLightSelect(Item item, ref bool dryTorch, ref bool wetTorch, ref bool glowstick) {
1626  if (item.modItem != null) {
1627  item.modItem.AutoLightSelect(ref dryTorch, ref wetTorch, ref glowstick);
1628  if (wetTorch) {
1629  dryTorch = false;
1630  glowstick = false;
1631  }
1632  if (dryTorch) {
1633  glowstick = false;
1634  }
1635  }
1636  }
1637 
1638  private delegate void DelegateCaughtFishStack(int type, ref int stack);
1639  private static HookList HookCaughtFishStack = AddHook<DelegateCaughtFishStack>(g => g.CaughtFishStack);
1640  public static void CaughtFishStack(Item item) {
1641  item.modItem?.CaughtFishStack(ref item.stack);
1642 
1643  foreach (var g in HookCaughtFishStack.arr)
1644  g.Instance(item).CaughtFishStack(item.type, ref item.stack);
1645  }
1646 
1647  private static HookList HookIsAnglerQuestAvailable = AddHook<Func<int, bool>>(g => g.IsAnglerQuestAvailable);
1648  public static void IsAnglerQuestAvailable(int itemID, ref bool notAvailable) {
1649  ModItem modItem = GetItem(itemID);
1650  if (modItem != null)
1651  notAvailable |= !modItem.IsAnglerQuestAvailable();
1652 
1653  foreach (var g in HookIsAnglerQuestAvailable.arr)
1654  notAvailable |= !g.IsAnglerQuestAvailable(itemID);
1655  }
1656 
1657  private delegate void DelegateAnglerChat(int type, ref string chat, ref string catchLocation);
1658  private static HookList HookAnglerChat = AddHook<DelegateAnglerChat>(g => g.AnglerChat);
1659  public static string AnglerChat(int type) {
1660  string chat = "";
1661  string catchLocation = "";
1662  GetItem(type)?.AnglerQuestChat(ref chat, ref catchLocation);
1663 
1664  foreach (var g in HookAnglerChat.arr)
1665  g.AnglerChat(type, ref chat, ref catchLocation);
1666 
1667  if (string.IsNullOrEmpty(chat) || string.IsNullOrEmpty(catchLocation))
1668  return null;
1669 
1670  return chat + "\n\n(" + catchLocation + ")";
1671  }
1672 
1673  private static HookList HookOnCraft = AddHook<Action<Item, Recipe>>(g => g.OnCraft);
1674  public static void OnCraft(Item item, Recipe recipe) {
1675  item.modItem?.OnCraft(recipe);
1676  foreach (var g in HookOnCraft.arr)
1677  g.Instance(item).OnCraft(item, recipe);
1678  }
1679 
1680  private delegate bool DelegatePreDrawTooltip(Item item, ReadOnlyCollection<TooltipLine> lines, ref int x, ref int y);
1681  private static HookList HookPreDrawTooltip = AddHook<DelegatePreDrawTooltip>(g => g.PreDrawTooltip);
1682  public static bool PreDrawTooltip(Item item, ReadOnlyCollection<TooltipLine> lines, ref int x, ref int y) {
1683  bool modItemPreDraw = item.modItem?.PreDrawTooltip(lines, ref x, ref y) ?? true;
1684  List<bool> globalItemPreDraw = new List<bool>();
1685  foreach (var g in HookPreDrawTooltip.arr)
1686  globalItemPreDraw.Add(g.PreDrawTooltip(item, lines, ref x, ref y));
1687  return modItemPreDraw && globalItemPreDraw.All(z => z);
1688  }
1689 
1690  private delegate void DelegatePostDrawTooltip(Item item, ReadOnlyCollection<DrawableTooltipLine> lines);
1691  private static HookList HookPostDrawTooltip = AddHook<DelegatePostDrawTooltip>(g => g.PostDrawTooltip);
1692  public static void PostDrawTooltip(Item item, ReadOnlyCollection<DrawableTooltipLine> lines) {
1693  item.modItem?.PostDrawTooltip(lines);
1694  foreach (var g in HookPostDrawTooltip.arr)
1695  g.Instance(item).PostDrawTooltip(item, lines);
1696  }
1697 
1698  private delegate bool DelegatePreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset);
1699  private static HookList HookPreDrawTooltipLine = AddHook<DelegatePreDrawTooltipLine>(g => g.PreDrawTooltipLine);
1700  public static bool PreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset) {
1701  bool modItemPreDrawLine = item.modItem?.PreDrawTooltipLine(line, ref yOffset) ?? true;
1702  List<bool> globalItemPreDrawLine = new List<bool>();
1703  foreach (var g in HookPreDrawTooltipLine.arr)
1704  globalItemPreDrawLine.Add(g.PreDrawTooltipLine(item, line, ref yOffset));
1705  return modItemPreDrawLine && globalItemPreDrawLine.All(x => x);
1706  }
1707 
1708  private delegate void DelegatePostDrawTooltipLine(Item item, DrawableTooltipLine line);
1709  private static HookList HookPostDrawTooltipLine = AddHook<DelegatePostDrawTooltipLine>(g => g.PostDrawTooltipLine);
1710  public static void PostDrawTooltipLine(Item item, DrawableTooltipLine line) {
1711  item.modItem?.PostDrawTooltipLine(line);
1712  foreach (var g in HookPostDrawTooltipLine.arr)
1713  g.Instance(item).PostDrawTooltipLine(item, line);
1714  }
1715 
1716  private static HookList HookModifyTooltips = AddHook<Action<Item, List<TooltipLine>>>(g => g.ModifyTooltips);
1717  public static List<TooltipLine> ModifyTooltips(Item item, ref int numTooltips, string[] names, ref string[] text,
1718  ref bool[] modifier, ref bool[] badModifier, ref int oneDropLogo, out Color?[] overrideColor) {
1719  List<TooltipLine> tooltips = new List<TooltipLine>();
1720  for (int k = 0; k < numTooltips; k++) {
1721  TooltipLine tooltip = new TooltipLine(names[k], text[k]);
1722  tooltip.isModifier = modifier[k];
1723  tooltip.isModifierBad = badModifier[k];
1724  if (k == oneDropLogo) {
1725  tooltip.oneDropLogo = true;
1726  }
1727  tooltips.Add(tooltip);
1728  }
1729  item.modItem?.ModifyTooltips(tooltips);
1730  foreach (var g in HookModifyTooltips.arr)
1731  g.Instance(item).ModifyTooltips(item, tooltips);
1732 
1733  numTooltips = tooltips.Count;
1734  text = new string[numTooltips];
1735  modifier = new bool[numTooltips];
1736  badModifier = new bool[numTooltips];
1737  oneDropLogo = -1;
1738  overrideColor = new Color?[numTooltips];
1739  for (int k = 0; k < numTooltips; k++) {
1740  text[k] = tooltips[k].text;
1741  modifier[k] = tooltips[k].isModifier;
1742  badModifier[k] = tooltips[k].isModifierBad;
1743  if (tooltips[k].oneDropLogo) {
1744  oneDropLogo = k;
1745  }
1746  overrideColor[k] = tooltips[k].overrideColor;
1747  }
1748 
1749  return tooltips;
1750  }
1751 
1752  private static HookList HookNeedsSaving = AddHook<Func<Item, bool>>(g => g.NeedsSaving);
1753  public static bool NeedsModSaving(Item item) {
1754  return item.type != 0 && (item.modItem != null || item.prefix >= PrefixID.Count || HookNeedsSaving.arr.Count(g => g.Instance(item).NeedsSaving(item)) > 0);
1755  }
1756 
1757  internal static void WriteNetGlobalOrder(BinaryWriter w) {
1758  w.Write((short)NetGlobals.Length);
1759  foreach (var globalItem in NetGlobals) {
1760  w.Write(globalItem.mod.netID);
1761  w.Write(globalItem.Name);
1762  }
1763  }
1764 
1765  internal static void ReadNetGlobalOrder(BinaryReader r) {
1766  short n = r.ReadInt16();
1767  NetGlobals = new GlobalItem[n];
1768  for (short i = 0; i < n; i++)
1769  NetGlobals[i] = ModNet.GetMod(r.ReadInt16()).GetGlobalItem(r.ReadString());
1770  }
1771 
1772  private static bool HasMethod(Type t, string method, params Type[] args) {
1773  return t.GetMethod(method, args).DeclaringType != typeof(GlobalItem);
1774  }
1775 
1776  internal static void VerifyGlobalItem(GlobalItem item) {
1777  var type = item.GetType();
1778  int saveMethods = 0;
1779  if (HasMethod(type, "NeedsSaving", typeof(Item))) saveMethods++;
1780  if (HasMethod(type, "Save", typeof(Item))) saveMethods++;
1781  if (HasMethod(type, "Load", typeof(Item), typeof(TagCompound))) saveMethods++;
1782  if (saveMethods > 0 && saveMethods < 3)
1783  throw new Exception(type + " must override all of (NeedsSaving/Save/Load) or none");
1784 
1785  int netMethods = 0;
1786  if (HasMethod(type, "NetSend", typeof(Item), typeof(BinaryWriter))) netMethods++;
1787  if (HasMethod(type, "NetReceive", typeof(Item), typeof(BinaryReader))) netMethods++;
1788  if (netMethods == 1)
1789  throw new Exception(type + " must override both of (NetSend/NetReceive) or none");
1790 
1791  bool hasInstanceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
1792  .Any(f => f.DeclaringType != typeof(GlobalItem));
1793 
1794  if (hasInstanceFields) {
1795  if (!item.InstancePerEntity)
1796  throw new Exception(type + " has instance fields but does not set InstancePerEntity to true. Either use static fields, or per instance globals");
1797 
1798  if (!item.CloneNewInstances &&
1799  !HasMethod(type, "NewInstance", typeof(Item)) &&
1800  !HasMethod(type, "Clone", typeof(Item), typeof(Item)))
1801  throw new Exception(type + " has InstancePerEntity but must either set CloneNewInstances to true, or override NewInstance(Item) or Clone(Item, Item)");
1802  }
1803  }
1804  }
1805 }
virtual void UpdateVanitySet(Player player)
Allows you to create special effects (such as dust) when the player wears this equipment texture&#39;s va...
Definition: EquipTexture.cs:97
virtual string IsArmorSet(Item head, Item body, Item legs)
Allows you to determine whether the player is wearing an armor set, and return a name for this set...
Definition: GlobalItem.cs:443
static bool Shoot(Item item, Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
Calls each GlobalItem.Shoot hook, then ModItem.Shoot, until one of them returns false. If all of them return true, returns true.
Definition: ItemLoader.cs:615
static bool CanPickup(Item item, Player player)
Definition: ItemLoader.cs:1442
virtual int BossBagNPC
The type of NPC that drops this boss bag. Used to determine how many coins this boss bag contains...
Definition: ModItem.cs:1005
static void HoldItem(Item item, Player player)
Calls ModItem.HoldItem and all GlobalItem.HoldItem hooks.
Definition: ItemLoader.cs:355
virtual bool IsAnglerQuestAvailable()
Whether or not specific conditions have been satisfied for the Angler to be able to request this item...
Definition: ModItem.cs:985
static void OnConsumeItem(Item item, Player player)
Calls ModItem.OnConsumeItem and all GlobalItem.OnConsumeItem hooks.
Definition: ItemLoader.cs:796
static void OpenBossBag(int type, Player player, ref int npc)
If the item is a modded item and ModItem.bossBagNPC is greater than 0, calls ModItem.OpenBossBag and sets npc to ModItem.bossBagNPC.
Definition: ItemLoader.cs:1095
static void IsAnglerQuestAvailable(int itemID, ref bool notAvailable)
Definition: ItemLoader.cs:1648
static void UseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox)
Calls ModItem.UseItemHitbox, then all GlobalItem.UseItemHitbox hooks.
Definition: ItemLoader.cs:636
static readonly EquipType[] EquipTypes
Definition: EquipLoader.cs:32
virtual void UpdateVanitySet(Player player, string set)
Allows you to create special effects (such as dust) when the player wears the vanity set with the giv...
Definition: GlobalItem.cs:493
static EquipTexture GetEquipTexture(EquipType type, int slot)
Gets the equipment texture for the specified equipment type and ID.
Definition: EquipLoader.cs:56
static bool AllowVanillaClients
Definition: ModNet.cs:53
static void GetWeaponCrit(Item item, Player player, ref int crit)
Calls ModItem.GetWeaponCrit, then all GlobalItem.GetWeaponCrit hooks.
Definition: ItemLoader.cs:525
static Item GetWing(Player player)
s Returns the wing item that the player is functionally using. If player.wingsLogic has been modified...
Definition: ItemLoader.cs:1286
static void MeleeEffects(Item item, Player player, Rectangle hitbox)
Calls ModItem.MeleeEffects and all GlobalItem.MeleeEffects hooks.
Definition: ItemLoader.cs:649
static void OnHitPvp(Item item, Player player, Player target, int damage, bool crit)
Calls ModItem.OnHitPvp and all GlobalItem.OnHitPvp hooks.
Definition: ItemLoader.cs:747
virtual void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising, ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
Allows you to modify vertical wing speeds.
static void ArmorSetShadows(Player player)
If the player&#39;s head texture&#39;s IsVanitySet returns true, calls the equipment texture&#39;s ArmorSetShadow...
Definition: ItemLoader.cs:998
static bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
Returns the "and" operator on the results of ModItem.PreDrawInWorld and all GlobalItem.PreDrawInWorld hooks.
Definition: ItemLoader.cs:1503
static bool WingUpdate(Player player, bool inUse)
If wings can be seen on the player, calls the player&#39;s wing&#39;s equipment texture&#39;s WingUpdate and all ...
Definition: ItemLoader.cs:1360
static bool CheckProjOnSwing(Player player, Item item)
If the item is a modded item, ModItem.checkProjOnSwing is true, and the player is not at the beginnin...
Definition: ItemLoader.cs:538
static bool CanRightClick(Item item)
Calls ModItem.CanRightClick, then all GlobalItem.CanRightClick hooks, until one of the returns true...
Definition: ItemLoader.cs:1037
static bool ConsumeAmmo(Item item, Item ammo, Player player)
Calls ModItem.ConsumeAmmo for the weapon, ModItem.ConsumeAmmo for the ammo, then each GlobalItem...
Definition: ItemLoader.cs:568
static void PickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref int damage, ref float knockback)
Calls ModItem.PickAmmo, then all GlobalItem.PickAmmo hooks.
Definition: ItemLoader.cs:550
This serves as a place for you to program behaviors of equipment textures. This is useful for equipme...
Definition: EquipTexture.cs:8
static void PostDrawTooltip(Item item, ReadOnlyCollection< DrawableTooltipLine > lines)
Definition: ItemLoader.cs:1692
This class serves as a way to store information about a line of tooltip for an item. You will create and manipulate objects of this class if you use the ModifyTooltips hook.
Definition: TooltipLine.cs:8
virtual Vector2 HoldoutOffset()
Allows you to determine the offset of this item&#39;s sprite when used by the player. This is only used f...
Definition: ModItem.cs:930
Item item
The item object that this ModItem controls.
Definition: ModItem.cs:26
static bool CanUseItem(Item item, Player player)
Returns the "and" operation on the results of ModItem.CanUseItem and all GlobalItem.CanUseItem hooks. Does not fail fast (every hook is called).
Definition: ItemLoader.cs:309
static float UseTimeMultiplier(Item item, Player player)
Definition: ItemLoader.cs:366
virtual void PreUpdateVanitySet(Player player)
Allows you to create special effects (such as the necro armor&#39;s hurt noise) when the player wears thi...
Definition: EquipTexture.cs:87
static readonly IList< int > blockLoot
Allows you to stop an NPC from dropping loot by adding item IDs to this list. This list will be clear...
Definition: NPCLoader.cs:34
This serves as the central class which loads mods. It contains many static fields and methods related...
Definition: ModLoader.cs:26
virtual bool DrawBody()
Return false to hide the player&#39;s body when this body equipment texture is worn. By default this will...
static void AutoLightSelect(Item item, ref bool dryTorch, ref bool wetTorch, ref bool glowstick)
Definition: ItemLoader.cs:1625
static Rectangle AnimatedItemFrame(Item item)
Definition: ItemLoader.cs:241
static bool OnPickup(Item item, Player player)
Calls all GlobalItem.OnPickup hooks then ModItem.OnPickup, until one of the returns false...
Definition: ItemLoader.cs:1456
static bool DrawHead(Player player)
Calls the item&#39;s head equipment texture&#39;s DrawHead hook, then all GlobalItem.DrawHead hooks...
Definition: ItemLoader.cs:1208
static void Update(Item item, ref float gravity, ref float maxFallSpeed)
Calls ModItem.Update, then all GlobalItem.Update hooks.
Definition: ItemLoader.cs:1380
static void OnMissingMana(Item item, Player player, int neededMana)
Calls ModItem.OnMissingMana, then all GlobalItem.OnMissingMana hooks.
Definition: ItemLoader.cs:441
static bool ReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount)
Call all ModItem.ReforgePrice, then GlobalItem.ReforgePrice hooks.
Definition: ItemLoader.cs:1142
static void FindVanillaWings()
Definition: ItemLoader.cs:52
static void ModifyHitPvp(Item item, Player player, Player target, ref int damage, ref bool crit)
Calls ModItem.ModifyHitPvp, then all GlobalItem.ModifyHitPvp hooks.
Definition: ItemLoader.cs:734
static void ModifyHitNPC(Item item, Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
Calls ModItem.ModifyHitNPC, then all GlobalItem.ModifyHitNPC hooks.
Definition: ItemLoader.cs:693
static void PostDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
Calls ModItem.PostDrawInInventory, then all GlobalItem.PostDrawInInventory hooks. ...
Definition: ItemLoader.cs:1553
static void HorizontalWingSpeeds(Player player)
If the player is using wings, this uses the result of GetWing, and calls ModItem.HorizontalWingSpeeds...
Definition: ItemLoader.cs:1342
static void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult, ref float flat)
Calls ModItem.HookModifyWeaponDamage, then all GlobalItem.HookModifyWeaponDamage hooks.
Definition: ItemLoader.cs:491
static bool CanHitNPC(Item item, Player player, NPC target)
Gathers the results of ModItem.CanHitNPC and all GlobalItem.CanHitNPC hooks. If any of them returns f...
Definition: ItemLoader.cs:667
static bool UseItem(Item item, Player player)
Returns true if any of ModItem.UseItem or GlobalItem.UseItem return true Does not fail fast (calls ev...
Definition: ItemLoader.cs:759
static ModItem GetItem(int type)
Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the...
Definition: ItemLoader.cs:76
static void PostDrawTooltipLine(Item item, DrawableTooltipLine line)
Definition: ItemLoader.cs:1710
static void UpdateEquip(Item item, Player player)
Calls ModItem.UpdateEquip and all GlobalItem.UpdateEquip hooks.
Definition: ItemLoader.cs:883
This serves as a central place to store equipment slots and their corresponding textures. You will use this to obtain the IDs for your equipment textures.
Definition: EquipLoader.cs:11
static void OnConsumeAmmo(Item item, Item ammo, Player player)
Calls ModItem.OnConsumeAmmo for the weapon, ModItem.OnConsumeAmmo for the ammo, then each GlobalItem...
Definition: ItemLoader.cs:586
static void GetHealMana(Item item, Player player, bool quickHeal, ref int healValue)
Calls ModItem.GetHealMana, then all GlobalItem.GetHealMana hooks.
Definition: ItemLoader.cs:411
static bool CanHitPvp(Item item, Player player, Player target)
Calls all GlobalItem.CanHitPvp hooks, then ModItem.CanHitPvp, until one of them returns false...
Definition: ItemLoader.cs:719
static int ChoosePrefix(Item item, UnifiedRandom rand)
Definition: ItemLoader.cs:249
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:6
static Mod GetMod(int netID)
virtual bool WingUpdate(Player player, bool inUse)
Allows for wing textures to do various things while in use. "inUse" is whether or not the jump button...
static Color GetAlpha(Item item, Color lightColor)
Calls all GlobalItem.GetAlpha hooks then ModItem.GetAlpha, until one of them returns a color...
Definition: ItemLoader.cs:1483
static void CaughtFishStack(Item item)
Definition: ItemLoader.cs:1640
static void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit)
Calls ModItem.OnHitNPC and all GlobalItem.OnHitNPC hooks.
Definition: ItemLoader.cs:706
This class allows you to modify and use hooks for all items, including vanilla items. Create an instance of an overriding class then call Mod.AddGlobalItem to use this.
Definition: GlobalItem.cs:15
static void OpenVanillaBag(string context, Player player, int arg)
Calls all GlobalItem.OpenVanillaBag hooks.
Definition: ItemLoader.cs:1130
virtual bool CloneNewInstances
Whether instances of this GlobalItem are created through Clone or constructor (by default implementat...
Definition: GlobalItem.cs:56
static void DrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
Calls the item&#39;s equipment texture&#39;s DrawArmorColor hook, then all GlobalItem.DrawArmorColor hooks...
Definition: ItemLoader.cs:1261
static void PreUpdateVanitySet(Player player)
If the player&#39;s head texture&#39;s IsVanitySet returns true, calls the equipment texture&#39;s PreUpdateVanit...
Definition: ItemLoader.cs:947
static string AnglerChat(int type)
Definition: ItemLoader.cs:1659
bool isModifier
Whether or not this tooltip gives prefix information. This will make it so that the tooltip is colore...
Definition: TooltipLine.cs:25
static bool DrawBody(Player player)
Calls the item&#39;s body equipment texture&#39;s DrawBody hook, then all GlobalItem.DrawBody hooks...
Definition: ItemLoader.cs:1224
virtual void DrawArmorColor(Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
Allows you to modify the colors in which this armor texture and surrounding accessories are drawn...
static bool UseItemFrame(Item item, Player player)
Calls ModItem.UseItemFrame, then all GlobalItem.UseItemFrame hooks, until one of them returns true...
Definition: ItemLoader.cs:812
virtual void UpdateArmorSet(Player player, string set)
Allows you to give set bonuses to your armor set with the given name. The set name will be the same a...
Definition: GlobalItem.cs:453
static void ArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color)
Calls the item&#39;s body equipment texture&#39;s ArmorArmGlowMask hook, then all GlobalItem.ArmorArmGlowMask hooks.
Definition: ItemLoader.cs:1275
static bool NeedsModSaving(Item item)
Definition: ItemLoader.cs:1753
This serves as the central class from which item-related functions are carried out. It also stores a list of mod items by ID.
Definition: ItemLoader.cs:21
static void UpdateArmorSet(Player player, Item head, Item body, Item legs)
If the head&#39;s ModItem.IsArmorSet returns true, calls the head&#39;s ModItem.UpdateArmorSet. This is then repeated for the body, then the legs. Then for each GlobalItem, if GlobalItem.IsArmorSet returns a non-empty string, calls GlobalItem.UpdateArmorSet with that string.
Definition: ItemLoader.cs:925
static bool PrefixChance(Item item, int pre, UnifiedRandom rand)
Allows for blocking, forcing and altering chance of prefix rolling. False (block) takes precedence ov...
Definition: ItemLoader.cs:272
static void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising, ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
If the player is using wings, this uses the result of GetWing, and calls ModItem.VerticalWingSpeeds t...
Definition: ItemLoader.cs:1316
static bool GrabStyle(Item item, Player player)
Calls all GlobalItem.GrabStyle hooks then ModItem.GrabStyle, until one of them returns true...
Definition: ItemLoader.cs:1431
static bool AllowPrefix(Item item, int pre)
Definition: ItemLoader.cs:288
ModItem item
The item that is associated with this equipment texture. Null if no item is associated with this...
Definition: EquipTexture.cs:53
virtual void ArmorSetShadows(Player player)
Allows you to determine special visual effects this vanity set has on the player without having to co...
static void DrawHands(Player player, ref bool drawHands, ref bool drawArms)
Calls the item&#39;s body equipment texture&#39;s DrawHands hook, then all GlobalItem.DrawHands hooks...
Definition: ItemLoader.cs:1176
static void RightClick(Item item, Player player)
If Main.mouseRightRelease is true, the following steps are taken:
Definition: ItemLoader.cs:1064
bool isModifierBad
If isModifier is true, this determines whether the tooltip is colored green or red.
Definition: TooltipLine.cs:29
static void GetWeaponKnockback(Item item, Player player, ref float knockback)
Calls ModItem.GetWeaponKnockback, then all GlobalItem.GetWeaponKnockback hooks.
Definition: ItemLoader.cs:509
static void HoldStyle(Item item, Player player)
If the player is not holding onto a rope and is not in the middle of using an item, calls ModItem.HoldStyle and all GlobalItem.HoldStyle hooks.
Definition: ItemLoader.cs:340
static bool CanEquipAccessory(Item item, int slot)
Definition: ItemLoader.cs:1604
static void ModifyManaCost(Item item, Player player, ref float reduce, ref float mult)
Calls ModItem.ModifyManaCost, then all GlobalItem.ModifyManaCost hooks.
Definition: ItemLoader.cs:426
static bool AltFunctionUse(Item item, Player player)
Calls ModItem.AltFunctionUse, then all GlobalItem.AltFunctionUse hooks, until one of them returns tru...
Definition: ItemLoader.cs:847
virtual void SetMatch(bool male, ref int equipSlot, ref bool robes)
Allows you to modify the equipment that the player appears to be wearing. This hook will only be call...
static void UpdateVanitySet(Player player)
If the player&#39;s head texture&#39;s IsVanitySet returns true, calls the equipment texture&#39;s UpdateVanitySe...
Definition: ItemLoader.cs:972
static bool ItemSpace(Item item, Player player)
Definition: ItemLoader.cs:1467
virtual bool IsVanitySet(int head, int body, int legs)
Returns whether or not the head armor, body armor, and leg armor textures make up a set...
Definition: EquipTexture.cs:76
virtual void PreUpdateVanitySet(Player player, string set)
Allows you to create special effects (such as the necro armor&#39;s hurt noise) when the player wears the...
Definition: GlobalItem.cs:485
static void GetWeaponDamage(Item item, Player player, ref int damage)
Calls ModItem.GetWeaponDamage, then all GlobalItem.GetWeaponDamage hooks.
Definition: ItemLoader.cs:474
static List< TooltipLine > ModifyTooltips(Item item, ref int numTooltips, string[] names, ref string[] text, ref bool[] modifier, ref bool[] badModifier, ref int oneDropLogo, out Color?[] overrideColor)
Definition: ItemLoader.cs:1717
static void OnConsumeMana(Item item, Player player, int manaConsumed)
Calls ModItem.OnConsumeMana, then all GlobalItem.OnConsumeMana hooks.
Definition: ItemLoader.cs:456
static bool PreReforge(Item item)
Calls ModItem.PreReforge, then all GlobalItem.PreReforge hooks.
Definition: ItemLoader.cs:1154
virtual void DrawHair(ref bool drawHair, ref bool drawAltHair)
Allows you to determine whether the player&#39;s hair or alt (hat) hair draws when this head equipment te...
static bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
Returns the "and" operator on the results of all GlobalItem.PreDrawInInventory hooks and ModItem...
Definition: ItemLoader.cs:1534
virtual void UpdateVanity(Player player, EquipType type)
Allows you to create special effects (such as dust) when this equipment texture is displayed on the p...
Definition: EquipTexture.cs:63
static void HoldoutOrigin(Player player, ref Vector2 origin)
Definition: ItemLoader.cs:1581
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:42
This serves as the central class from which NPC-related functions are carried out. It also stores a list of mod NPCs by ID.
Definition: NPCLoader.cs:19
static void UpdateInventory(Item item, Player player)
Calls ModItem.UpdateInventory and all GlobalItem.UpdateInventory hooks.
Definition: ItemLoader.cs:867
static bool HasMethod(Type t, string method, params Type[] args)
Definition: ItemLoader.cs:1772
static float MeleeSpeedMultiplier(Item item, Player player)
Definition: ItemLoader.cs:379
GlobalItem Instance(Item item)
virtual void OpenBossBag(Player player)
Allows you to give items to the given player when this item is right-clicked in the inventory if the ...
Definition: ModItem.cs:669
Mod is an abstract class that you will override. It serves as a central place from which the mod&#39;s co...
Definition: Mod.cs:24
static bool PreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset)
Definition: ItemLoader.cs:1700
static void UseStyle(Item item, Player player)
Calls ModItem.UseStyle and all GlobalItem.UseStyle hooks.
Definition: ItemLoader.cs:325
static bool CanBurnInLava(Item item)
Calls ModItem.CanBurnInLava.
Definition: ItemLoader.cs:1391
This class serves as a place for you to place all your properties and hooks for each item...
Definition: ModItem.cs:16
static void ExtractinatorUse(ref int resultType, ref int resultStack, int extractType)
Definition: ItemLoader.cs:1618
virtual bool DrawHead()
Return false to hide the player&#39;s head when this head equipment texture is worn. By default this will...
static void GetHealLife(Item item, Player player, bool quickHeal, ref int healValue)
Calls ModItem.GetHealLife, then all GlobalItem.GetHealLife hooks.
Definition: ItemLoader.cs:396
This class serves as a way to store information about a line that will be drawn of tooltip for an ite...
static bool IsModBossBag(Item item)
Returns whether ModItem.bossBagNPC is greater than 0. Returns false if item is not a modded item...
Definition: ItemLoader.cs:1086
static bool ConsumeItem(Item item, Player player)
If ModItem.ConsumeItem or any of the GlobalItem.ConsumeItem hooks returns false, sets consume to fals...
Definition: ItemLoader.cs:779
static void OnCraft(Item item, Recipe recipe)
Definition: ItemLoader.cs:1674
static void UpdateVanity(Player player)
Calls each of the item&#39;s equipment texture&#39;s UpdateVanity hook.
Definition: ItemLoader.cs:912
static void UpdateAccessory(Item item, Player player, bool hideVisual)
Calls ModItem.UpdateAccessory and all GlobalItem.UpdateAccessory hooks.
Definition: ItemLoader.cs:899
static bool PreOpenVanillaBag(string context, Player player, int arg)
Calls each GlobalItem.PreOpenVanillaBag hook until one of them returns false. Returns true if all of ...
Definition: ItemLoader.cs:1111
virtual void ArmorSetShadows(Player player, string set)
Allows you to determine special visual effects a vanity has on the player without having to code them...
Definition: GlobalItem.cs:502
static void HoldoutOffset(float gravDir, int type, ref Vector2 offset)
Definition: ItemLoader.cs:1562
virtual bool DrawLegs()
Return false to hide the player&#39;s legs when this leg or shoe equipment texture is worn...
virtual void DrawHands(ref bool drawHands, ref bool drawArms)
Allows you to determine whether the skin/shirt on the player&#39;s arms and hands are drawn when this bod...
static void DrawHair(Player player, ref bool drawHair, ref bool drawAltHair)
Calls the item&#39;s head equipment texture&#39;s DrawHair hook, then all GlobalItem.DrawHair hooks...
Definition: ItemLoader.cs:1193
static bool GeneralPrefix(Item item)
Definition: ItemLoader.cs:173
virtual bool InstancePerEntity
Whether to create a new GlobalItem instance for every Item that exists. Useful for storing informatio...
Definition: GlobalItem.cs:48
static void PostDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
Calls ModItem.PostDrawInWorld, then all GlobalItem.PostDrawInWorld hooks.
Definition: ItemLoader.cs:1520
static bool HoldItemFrame(Item item, Player player)
Calls ModItem.HoldItemFrame, then all GlobalItem.HoldItemFrame hooks, until one of them returns true...
Definition: ItemLoader.cs:829
static void PostUpdate(Item item)
Calls ModItem.PostUpdate and all GlobalItem.PostUpdate hooks.
Definition: ItemLoader.cs:1404
virtual void HorizontalWingSpeeds(Player player, ref float speed, ref float acceleration)
Allows you to modify horizontal wing speeds.
virtual void ArmorArmGlowMask(Player drawPlayer, float shadow, ref int glowMask, ref Color color)
Allows you to modify which glow mask and in what color is drawn on the player&#39;s arms. Note that this is only called for body equipment textures. By default this will call the associated ModItem&#39;s ArmorArmGlowMask if there is an associated ModItem.
static bool PreDrawTooltip(Item item, ReadOnlyCollection< TooltipLine > lines, ref int x, ref int y)
Definition: ItemLoader.cs:1682
static void GrabRange(Item item, Player player, ref int grabRange)
Calls ModItem.GrabRange, then all GlobalItem.GrabRange hooks.
Definition: ItemLoader.cs:1418
static bool DrawLegs(Player player)
Calls the item&#39;s leg equipment texture&#39;s DrawLegs hook, then the item&#39;s shoe equipment texture&#39;s Draw...
Definition: ItemLoader.cs:1240
virtual string IsVanitySet(int head, int body, int legs)
Returns whether or not the head armor, body armor, and leg armor textures make up a set...
Definition: GlobalItem.cs:463
static void PostReforge(Item item)
Calls ModItem.PostReforge, then all GlobalItem.PostReforge hooks.
Definition: ItemLoader.cs:1165
static void SetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes)
Calls EquipTexture.SetMatch, then all GlobalItem.SetMatch hooks.
Definition: ItemLoader.cs:1023