Terraria ModLoader  0.11.1
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  return item.modItem.ChoosePrefix(rand);
258  }
259  return -1;
260  }
261 
262  private static HookList HookCanUseItem = AddHook<Func<Item, Player, bool>>(g => g.CanUseItem);
263  //in Terraria.Player.ItemCheck
264  // inside block if (this.controlUseItem && this.itemAnimation == 0 && this.releaseUseItem && item.useStyle > 0)
265  // set initial flag2 to ItemLoader.CanUseItem(item, this)
272  public static bool CanUseItem(Item item, Player player) {
273  bool flag = true;
274  if (item.modItem != null)
275  flag &= item.modItem.CanUseItem(player);
276 
277  foreach (var g in HookCanUseItem.arr)
278  flag &= g.Instance(item).CanUseItem(item, player);
279 
280  return flag;
281  }
282 
283  private static HookList HookUseStyle = AddHook<Action<Item, Player>>(g => g.UseStyle);
284  //in Terraria.Player.ItemCheck after useStyle if/else chain call ItemLoader.UseStyle(item, this)
288  public static void UseStyle(Item item, Player player) {
289  if (item.IsAir)
290  return;
291 
292  item.modItem?.UseStyle(player);
293 
294  foreach (var g in HookUseStyle.arr)
295  g.Instance(item).UseStyle(item, player);
296  }
297 
298  private static HookList HookHoldStyle = AddHook<Action<Item, Player>>(g => g.HoldStyle);
299  //in Terraria.Player.ItemCheck after holdStyle if/else chain call ItemLoader.HoldStyle(item, this)
303  public static void HoldStyle(Item item, Player player) {
304  if (item.IsAir || player.pulley || player.itemAnimation > 0)
305  return;
306 
307  item.modItem?.HoldStyle(player);
308 
309  foreach (var g in HookHoldStyle.arr)
310  g.Instance(item).HoldStyle(item, player);
311  }
312 
313  private static HookList HookHoldItem = AddHook<Action<Item, Player>>(g => g.HoldItem);
314  //in Terraria.Player.ItemCheck before this.controlUseItem setting this.releaseUseItem call ItemLoader.HoldItem(item, this)
318  public static void HoldItem(Item item, Player player) {
319  if (item.IsAir)
320  return;
321 
322  item.modItem?.HoldItem(player);
323 
324  foreach (var g in HookHoldItem.arr)
325  g.Instance(item).HoldItem(item, player);
326  }
327 
328  private static HookList HookUseTimeMultiplier = AddHook<Func<Item, Player, float>>(g => g.UseTimeMultiplier);
329  public static float UseTimeMultiplier(Item item, Player player) {
330  if (item.IsAir)
331  return 1f;
332 
333  float multiplier = item.modItem?.UseTimeMultiplier(player) ?? 1f;
334 
335  foreach (var g in HookUseTimeMultiplier.arr)
336  multiplier *= g.Instance(item).UseTimeMultiplier(item, player);
337 
338  return multiplier;
339  }
340 
341  private static HookList HookMeleeSpeedMultiplier = AddHook<Func<Item, Player, float>>(g => g.MeleeSpeedMultiplier);
342  public static float MeleeSpeedMultiplier(Item item, Player player) {
343  if (item.IsAir)
344  return 1f;
345 
346  float multiplier = item.modItem?.MeleeSpeedMultiplier(player) ?? 1f;
347 
348  foreach (var g in HookMeleeSpeedMultiplier.arr)
349  multiplier *= g.Instance(item).MeleeSpeedMultiplier(item, player);
350 
351  return multiplier;
352  }
353 
354  private delegate void DelegateGetHealLife(Item item, Player player, bool quickHeal, ref int healValue);
355  private static HookList HookGetHealLife = AddHook<DelegateGetHealLife>(g => g.GetHealLife);
359  public static void GetHealLife(Item item, Player player, bool quickHeal, ref int healValue) {
360  if (item.IsAir)
361  return;
362 
363  item.modItem?.GetHealLife(player, quickHeal, ref healValue);
364 
365  foreach (var g in HookGetHealLife.arr)
366  g.Instance(item).GetHealLife(item, player, quickHeal, ref healValue);
367  }
368 
369  private delegate void DelegateGetHealMana(Item item, Player player, bool quickHeal, ref int healValue);
370  private static HookList HookGetHealMana = AddHook<DelegateGetHealMana>(g => g.GetHealMana);
374  public static void GetHealMana(Item item, Player player, bool quickHeal, ref int healValue) {
375  if (item.IsAir)
376  return;
377 
378  item.modItem?.GetHealMana(player, quickHeal, ref healValue);
379 
380  foreach (var g in HookGetHealMana.arr)
381  g.Instance(item).GetHealMana(item, player, quickHeal, ref healValue);
382  }
383 
384  private delegate void DelegateModifyManaCost(Item item, Player player, ref float reduce, ref float mult);
385  private static HookList HookModifyManaCost = AddHook<DelegateModifyManaCost>(g => g.ModifyManaCost);
389  public static void ModifyManaCost(Item item, Player player, ref float reduce, ref float mult) {
390  if (item.IsAir)
391  return;
392 
393  item.modItem?.ModifyManaCost(player, ref reduce, ref mult);
394 
395  foreach (var g in HookModifyManaCost.arr) {
396  g.Instance(item).ModifyManaCost(item, player, ref reduce, ref mult);
397  }
398  }
399 
400  private static HookList HookOnMissingMana = AddHook<Action<Item, Player, int>>(g => g.OnMissingMana);
404  public static void OnMissingMana(Item item, Player player, int neededMana) {
405  if (item.IsAir)
406  return;
407 
408  item.modItem?.OnMissingMana(player, neededMana);
409 
410  foreach (var g in HookOnMissingMana.arr) {
411  g.Instance(item).OnMissingMana(item, player, neededMana);
412  }
413  }
414 
415  private static HookList HookOnConsumeMana = AddHook<Action<Item, Player, int>>(g => g.OnConsumeMana);
419  public static void OnConsumeMana(Item item, Player player, int manaConsumed) {
420  if (item.IsAir)
421  return;
422 
423  item.modItem?.OnConsumeMana(player, manaConsumed);
424 
425  foreach (var g in HookOnConsumeMana.arr) {
426  g.Instance(item).OnConsumeMana(item, player, manaConsumed);
427  }
428  }
429 
430  private delegate void DelegateGetWeaponDamage(Item item, Player player, ref int damage);
431  [Obsolete]
432  private static HookList HookGetWeaponDamage = AddHook<DelegateGetWeaponDamage>(g => g.GetWeaponDamage);
436  [Obsolete]
437  public static void GetWeaponDamage(Item item, Player player, ref int damage) {
438  if (item.IsAir)
439  return;
440 
441  item.modItem?.GetWeaponDamage(player, ref damage);
442 
443  foreach (var g in HookGetWeaponDamage.arr)
444  g.Instance(item).GetWeaponDamage(item, player, ref damage);
445  }
446 
447  private delegate void DelegateModifyWeaponDamage(Item item, Player player, ref float add, ref float mult);
448  private static HookList HookModifyWeaponDamage = AddHook<DelegateModifyWeaponDamage>(g => g.ModifyWeaponDamage);
452  public static void ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult) {
453  if (item.IsAir)
454  return;
455 
456  item.modItem?.ModifyWeaponDamage(player, ref add, ref mult);
457 
458  foreach (var g in HookModifyWeaponDamage.arr)
459  g.Instance(item).ModifyWeaponDamage(item, player, ref add, ref mult);
460  }
461 
462  private delegate void DelegateGetWeaponKnockback(Item item, Player player, ref float knockback);
463  private static HookList HookGetWeaponKnockback = AddHook<DelegateGetWeaponKnockback>(g => g.GetWeaponKnockback);
467  public static void GetWeaponKnockback(Item item, Player player, ref float knockback) {
468  if (item.IsAir)
469  return;
470 
471  item.modItem?.GetWeaponKnockback(player, ref knockback);
472 
473  foreach (var g in HookGetWeaponKnockback.arr)
474  g.Instance(item).GetWeaponKnockback(item, player, ref knockback);
475  }
476 
477 
478  private delegate void DelegateGetWeaponCrit(Item item, Player player, ref int crit);
479  private static HookList HookGetWeaponCrit = AddHook<DelegateGetWeaponCrit>(g => g.GetWeaponCrit);
483  public static void GetWeaponCrit(Item item, Player player, ref int crit) {
484  if (item.IsAir)
485  return;
486 
487  item.modItem?.GetWeaponCrit(player, ref crit);
488 
489  foreach (var g in HookGetWeaponCrit.arr)
490  g.Instance(item).GetWeaponCrit(item, player, ref crit);
491  }
492 
496  public static bool CheckProjOnSwing(Player player, Item item) {
497  return item.modItem == null || !item.modItem.OnlyShootOnSwing || player.itemAnimation == player.itemAnimationMax - 1;
498  }
499 
500  private delegate void DelegateOldPickAmmo(Item item, Player player, ref int type, ref float speed, ref int damage, ref float knockback); // deprecated
501  private static HookList HookOldPickAmmo = AddHook<DelegateOldPickAmmo>(g => g.PickAmmo); // deprecated
502 
503  private delegate void DelegatePickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref int damage, ref float knockback);
504  private static HookList HookPickAmmo = AddHook<DelegatePickAmmo>(g => g.PickAmmo);
508  public static void PickAmmo(Item weapon, Item ammo, Player player, ref int type, ref float speed, ref int damage, ref float knockback) {
509  ammo.modItem?.PickAmmo(weapon, player, ref type, ref speed, ref damage, ref knockback);
510  ammo.modItem?.PickAmmo(player, ref type, ref speed, ref damage, ref knockback); // deprecated
511 
512  foreach (var g in HookPickAmmo.arr) {
513  g.Instance(ammo).PickAmmo(weapon, ammo, player, ref type, ref speed, ref damage, ref knockback);
514  }
515  foreach (var g in HookOldPickAmmo.arr) {
516  g.Instance(ammo).PickAmmo(ammo, player, ref type, ref speed, ref damage, ref knockback); // deprecated
517  }
518  }
519 
520  private static HookList HookConsumeAmmo = AddHook<Func<Item, Player, bool>>(g => g.ConsumeAmmo);
521  //near end of Terraria.Player.PickAmmo before flag2 is checked add
522  // if(!ItemLoader.ConsumeAmmo(sItem, item, this)) { flag2 = true; }
526  public static bool ConsumeAmmo(Item item, Item ammo, Player player) {
527  if (item.modItem != null && !item.modItem.ConsumeAmmo(player) ||
528  ammo.modItem != null && !ammo.modItem.ConsumeAmmo(player))
529  return false;
530 
531  foreach (var g in HookConsumeAmmo.arr) {
532  if (!g.Instance(item).ConsumeAmmo(item, player) ||
533  !g.Instance(ammo).ConsumeAmmo(ammo, player))
534  return false;
535  }
536 
537  return true;
538  }
539 
540  private static HookList HookOnConsumeAmmo = AddHook<Action<Item, Player>>(g => g.OnConsumeAmmo);
544  public static void OnConsumeAmmo(Item item, Item ammo, Player player) {
545  if (item.IsAir)
546  return;
547 
548  item.modItem?.OnConsumeAmmo(player);
549  ammo.modItem?.OnConsumeAmmo(player);
550 
551  foreach (var g in HookOnConsumeAmmo.arr) {
552  g.Instance(item).OnConsumeAmmo(item, player);
553  g.Instance(ammo).OnConsumeAmmo(ammo, player);
554  }
555  }
556 
557  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);
558  private static HookList HookShoot = AddHook<DelegateShoot>(g => g.Shoot);
559  //in Terraria.Player.ItemCheck at end of if/else chain for shooting place if on last else
560  // if(ItemLoader.Shoot(item, this, ref vector2, ref num78, ref num79, ref num71, ref num73, ref num74))
573  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) {
574  foreach (var g in HookShoot.arr)
575  if (!g.Instance(item).Shoot(item, player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack))
576  return false;
577 
578  if (item.modItem != null && !item.modItem.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack))
579  return false;
580 
581  return true;
582  }
583 
584  private delegate void DelegateUseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox);
585  private static HookList HookUseItemHitbox = AddHook<DelegateUseItemHitbox>(g => g.UseItemHitbox);
586  //in Terraria.Player.ItemCheck after end of useStyle if/else chain for melee hitbox
587  // call ItemLoader.UseItemHitbox(item, this, ref r2, ref flag17)
591  public static void UseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox) {
592  item.modItem?.UseItemHitbox(player, ref hitbox, ref noHitbox);
593 
594  foreach (var g in HookUseItemHitbox.arr)
595  g.Instance(item).UseItemHitbox(item, player, ref hitbox, ref noHitbox);
596  }
597 
598  private static HookList HookMeleeEffects = AddHook<Action<Item, Player, Rectangle>>(g => g.MeleeEffects);
599  //in Terraria.Player.ItemCheck after magma stone dust effect for melee weapons
600  // call ItemLoader.MeleeEffects(item, this, r2)
604  public static void MeleeEffects(Item item, Player player, Rectangle hitbox) {
605  item.modItem?.MeleeEffects(player, hitbox);
606 
607  foreach (var g in HookMeleeEffects.arr)
608  g.Instance(item).MeleeEffects(item, player, hitbox);
609  }
610 
611  private static HookList HookCanHitNPC = AddHook<Func<Item, Player, NPC, bool?>>(g => g.CanHitNPC);
612  //in Terraria.Player.ItemCheck before checking whether npc type can be hit add
613  // bool? modCanHit = ItemLoader.CanHitNPC(item, this, Main.npc[num292]);
614  // if(modCanHit.HasValue && !modCanHit.Value) { continue; }
615  //in if statement afterwards add || (modCanHit.HasValue && modCanHit.Value)
622  public static bool? CanHitNPC(Item item, Player player, NPC target) {
623  bool? canHit = item.modItem?.CanHitNPC(player, target);
624  if (canHit.HasValue && !canHit.Value) {
625  return false;
626  }
627  foreach (var g in HookCanHitNPC.arr) {
628  bool? globalCanHit = g.Instance(item).CanHitNPC(item, player, target);
629  if (globalCanHit.HasValue) {
630  if (globalCanHit.Value) {
631  canHit = true;
632  }
633  else {
634  return false;
635  }
636  }
637  }
638  return canHit;
639  }
640 
641  private delegate void DelegateModifyHitNPC(Item item, Player player, NPC target, ref int damage, ref float knockBack, ref bool crit);
642  private static HookList HookModifyHitNPC = AddHook<DelegateModifyHitNPC>(g => g.ModifyHitNPC);
643  //in Terraria.Player.ItemCheck for melee attacks after damage variation
644  // call ItemLoader.ModifyHitNPC(item, this, Main.npc[num292], ref num282, ref num283, ref flag18)
648  public static void ModifyHitNPC(Item item, Player player, NPC target, ref int damage, ref float knockBack, ref bool crit) {
649  item.modItem?.ModifyHitNPC(player, target, ref damage, ref knockBack, ref crit);
650 
651  foreach (var g in HookModifyHitNPC.arr)
652  g.Instance(item).ModifyHitNPC(item, player, target, ref damage, ref knockBack, ref crit);
653  }
654 
655  private static HookList HookOnHitNPC = AddHook<Action<Item, Player, NPC, int, float, bool>>(g => g.OnHitNPC);
656  //in Terraria.Player.ItemCheck for melee attacks before updating informational accessories
657  // call ItemLoader.OnHitNPC(item, this, Main.npc[num292], num295, num283, flag18)
661  public static void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit) {
662  item.modItem?.OnHitNPC(player, target, damage, knockBack, crit);
663 
664  foreach (var g in HookOnHitNPC.arr)
665  g.Instance(item).OnHitNPC(item, player, target, damage, knockBack, crit);
666  }
667 
668  private static HookList HookCanHitPvp = AddHook<Func<Item, Player, Player, bool>>(g => g.CanHitPvp);
669  //in Terraria.Player.ItemCheck add to beginning of pvp collision check
674  public static bool CanHitPvp(Item item, Player player, Player target) {
675  foreach (var g in HookCanHitPvp.arr)
676  if (!g.Instance(item).CanHitPvp(item, player, target))
677  return false;
678 
679  return item.modItem == null || item.modItem.CanHitPvp(player, target);
680  }
681 
682  private delegate void DelegateModifyHitPvp(Item item, Player player, Player target, ref int damage, ref bool crit);
683  private static HookList HookModifyHitPvp = AddHook<DelegateModifyHitPvp>(g => g.ModifyHitPvp);
684  //in Terraria.Player.ItemCheck for pvp melee attacks after damage variation
685  // call ItemLoader.ModifyHitPvp(item, this, Main.player[num302], ref num282, ref flag20)
689  public static void ModifyHitPvp(Item item, Player player, Player target, ref int damage, ref bool crit) {
690  item.modItem?.ModifyHitPvp(player, target, ref damage, ref crit);
691 
692  foreach (var g in HookModifyHitPvp.arr)
693  g.Instance(item).ModifyHitPvp(item, player, target, ref damage, ref crit);
694  }
695 
696  private static HookList HookOnHitPvp = AddHook<Action<Item, Player, Player, int, bool>>(g => g.OnHitPvp);
697  //in Terraria.Player.ItemCheck for pvp melee attacks before NetMessage stuff
698  // call ItemLoader.OnHitPvp(item, this, Main.player[num302], num304, flag20)
702  public static void OnHitPvp(Item item, Player player, Player target, int damage, bool crit) {
703  item.modItem?.OnHitPvp(player, target, damage, crit);
704 
705  foreach (var g in HookOnHitPvp.arr)
706  g.Instance(item).OnHitPvp(item, player, target, damage, crit);
707  }
708 
709  private static HookList HookUseItem = AddHook<Func<Item, Player, bool>>(g => g.UseItem);
714  public static bool UseItem(Item item, Player player) {
715  if (item.IsAir)
716  return false;
717 
718  bool flag = false;
719  if (item.modItem != null)
720  flag |= item.modItem.UseItem(player);
721 
722  foreach (var g in HookUseItem.arr)
723  flag |= g.Instance(item).UseItem(item, player);
724 
725  return flag;
726  }
727 
728  private static HookList HookConsumeItem = AddHook<Func<Item, Player, bool>>(g => g.ConsumeItem);
729  //near end of Terraria.Player.ItemCheck
730  // if (flag22 && ItemLoader.ConsumeItem(item, this))
734  public static bool ConsumeItem(Item item, Player player) {
735  if (item.IsAir) return true;
736  if (item.modItem != null && !item.modItem.ConsumeItem(player))
737  return false;
738 
739  foreach (var g in HookConsumeItem.arr)
740  if (!g.Instance(item).ConsumeItem(item, player))
741  return false;
742 
743  OnConsumeItem(item, player);
744  return true;
745  }
746 
747  private static HookList HookOnConsumeItem = AddHook<Action<Item, Player>>(g => g.OnConsumeItem);
751  public static void OnConsumeItem(Item item, Player player) {
752  if (item.IsAir)
753  return;
754 
755  item.modItem?.OnConsumeItem(player);
756 
757  foreach (var g in HookOnConsumeItem.arr)
758  g.Instance(item).OnConsumeItem(item, player);
759  }
760 
761  private static HookList HookUseItemFrame = AddHook<Func<Item, Player, bool>>(g => g.UseItemFrame);
762  //in Terraria.Player.PlayerFrame at end of useStyle if/else chain
763  // call if(ItemLoader.UseItemFrame(this.inventory[this.selectedItem], this)) { return; }
767  public static bool UseItemFrame(Item item, Player player) {
768  if (item.modItem != null && item.modItem.UseItemFrame(player))
769  return true;
770 
771  foreach (var g in HookUseItemFrame.arr)
772  if (g.Instance(item).UseItemFrame(item, player))
773  return true;
774 
775  return false;
776  }
777 
778  private static HookList HookHoldItemFrame = AddHook<Func<Item, Player, bool>>(g => g.HoldItemFrame);
779  //in Terraria.Player.PlayerFrame at end of holdStyle if statements
780  // call if(ItemLoader.HoldItemFrame(this.inventory[this.selectedItem], this)) { return; }
784  public static bool HoldItemFrame(Item item, Player player) {
785  if (item.IsAir)
786  return false;
787 
788  if (item.modItem != null && item.modItem.HoldItemFrame(player))
789  return true;
790 
791  foreach (var g in HookHoldItemFrame.arr)
792  if (g.Instance(item).HoldItemFrame(item, player))
793  return true;
794 
795  return false;
796  }
797 
798  private static HookList HookAltFunctionUse = AddHook<Func<Item, Player, bool>>(g => g.AltFunctionUse);
802  public static bool AltFunctionUse(Item item, Player player) {
803  if (item.IsAir)
804  return false;
805 
806  if (item.modItem != null && item.modItem.AltFunctionUse(player))
807  return true;
808 
809  foreach (var g in HookAltFunctionUse.arr)
810  if (g.Instance(item).AltFunctionUse(item, player))
811  return true;
812 
813  return false;
814  }
815 
816  private static HookList HookUpdateInventory = AddHook<Action<Item, Player>>(g => g.UpdateInventory);
817  //place at end of first for loop in Terraria.Player.UpdateEquips
818  // call ItemLoader.UpdateInventory(this.inventory[j], this)
822  public static void UpdateInventory(Item item, Player player) {
823  if (item.IsAir)
824  return;
825 
826  item.modItem?.UpdateInventory(player);
827 
828  foreach (var g in HookUpdateInventory.arr)
829  g.Instance(item).UpdateInventory(item, player);
830  }
831 
832  private static HookList HookUpdateEquip = AddHook<Action<Item, Player>>(g => g.UpdateEquip);
833  //place in second for loop of Terraria.Player.UpdateEquips before prefix checking
834  // call ItemLoader.UpdateEquip(this.armor[k], this)
838  public static void UpdateEquip(Item item, Player player) {
839  if (item.IsAir)
840  return;
841 
842  item.modItem?.UpdateEquip(player);
843 
844  foreach (var g in HookUpdateEquip.arr)
845  g.Instance(item).UpdateEquip(item, player);
846  }
847 
848  private static HookList HookUpdateAccessory = AddHook<Action<Item, Player, bool>>(g => g.UpdateAccessory);
849  //place at end of third for loop of Terraria.Player.UpdateEquips
850  // call ItemLoader.UpdateAccessory(this.armor[l], this, this.hideVisual[l])
854  public static void UpdateAccessory(Item item, Player player, bool hideVisual) {
855  if (item.IsAir)
856  return;
857 
858  item.modItem?.UpdateAccessory(player, hideVisual);
859 
860  foreach (var g in HookUpdateAccessory.arr)
861  g.Instance(item).UpdateAccessory(item, player, hideVisual);
862  }
863 
867  public static void UpdateVanity(Player player) {
868  foreach (EquipType type in EquipLoader.EquipTypes) {
869  int slot = EquipLoader.GetPlayerEquip(player, type);
870  EquipTexture texture = EquipLoader.GetEquipTexture(type, slot);
871  texture?.UpdateVanity(player, type);
872  }
873  }
874 
875  private static HookList HookUpdateArmorSet = AddHook<Action<Player, string>>(g => g.UpdateArmorSet);
876  //at end of Terraria.Player.UpdateArmorSets call ItemLoader.UpdateArmorSet(this, this.armor[0], this.armor[1], this.armor[2])
880  public static void UpdateArmorSet(Player player, Item head, Item body, Item legs) {
881  if (head.modItem != null && head.modItem.IsArmorSet(head, body, legs))
882  head.modItem.UpdateArmorSet(player);
883 
884  if (body.modItem != null && body.modItem.IsArmorSet(head, body, legs))
885  body.modItem.UpdateArmorSet(player);
886 
887  if (legs.modItem != null && legs.modItem.IsArmorSet(head, body, legs))
888  legs.modItem.UpdateArmorSet(player);
889 
890  foreach (GlobalItem globalItem in HookUpdateArmorSet.arr) {
891  string set = globalItem.IsArmorSet(head, body, legs);
892  if (!string.IsNullOrEmpty(set))
893  globalItem.UpdateArmorSet(player, set);
894  }
895  }
896 
897  private static HookList HookPreUpdateVanitySet = AddHook<Action<Player, string>>(g => g.PreUpdateVanitySet);
898  //in Terraria.Player.PlayerFrame after setting armor effects fields call this
902  public static void PreUpdateVanitySet(Player player) {
903  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
904  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
905  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
906  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
907  headTexture.PreUpdateVanitySet(player);
908 
909  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
910  bodyTexture.PreUpdateVanitySet(player);
911 
912  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
913  legTexture.PreUpdateVanitySet(player);
914 
915  foreach (GlobalItem globalItem in HookPreUpdateVanitySet.arr) {
916  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
917  if (!string.IsNullOrEmpty(set))
918  globalItem.PreUpdateVanitySet(player, set);
919  }
920  }
921 
922  private static HookList HookUpdateVanitySet = AddHook<Action<Player, string>>(g => g.UpdateVanitySet);
923  //in Terraria.Player.PlayerFrame after armor sets creating dust call this
927  public static void UpdateVanitySet(Player player) {
928  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
929  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
930  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
931  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
932  headTexture.UpdateVanitySet(player);
933 
934  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
935  bodyTexture.UpdateVanitySet(player);
936 
937  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
938  legTexture.UpdateVanitySet(player);
939 
940  foreach (GlobalItem globalItem in HookUpdateVanitySet.arr) {
941  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
942  if (!string.IsNullOrEmpty(set))
943  globalItem.UpdateVanitySet(player, set);
944  }
945  }
946 
947  private static HookList HookArmorSetShadows = AddHook<Action<Player, string>>(g => g.ArmorSetShadows);
948  //in Terraria.Main.DrawPlayers after armor combinations setting flags call
949  // ItemLoader.ArmorSetShadows(player);
953  public static void ArmorSetShadows(Player player) {
954  EquipTexture headTexture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
955  EquipTexture bodyTexture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
956  EquipTexture legTexture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
957  if (headTexture != null && headTexture.IsVanitySet(player.head, player.body, player.legs))
958  headTexture.ArmorSetShadows(player);
959 
960  if (bodyTexture != null && bodyTexture.IsVanitySet(player.head, player.body, player.legs))
961  bodyTexture.ArmorSetShadows(player);
962 
963  if (legTexture != null && legTexture.IsVanitySet(player.head, player.body, player.legs))
964  legTexture.ArmorSetShadows(player);
965 
966  foreach (GlobalItem globalItem in HookArmorSetShadows.arr) {
967  string set = globalItem.IsVanitySet(player.head, player.body, player.legs);
968  if (!string.IsNullOrEmpty(set))
969  globalItem.ArmorSetShadows(player, set);
970  }
971  }
972 
973  private delegate void DelegateSetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes);
974  private static HookList HookSetMatch = AddHook<DelegateSetMatch>(g => g.SetMatch);
978  public static void SetMatch(int armorSlot, int type, bool male, ref int equipSlot, ref bool robes) {
979  EquipTexture texture = EquipLoader.GetEquipTexture((EquipType)armorSlot, type);
980  texture?.SetMatch(male, ref equipSlot, ref robes);
981 
982  foreach (var g in HookSetMatch.arr)
983  g.SetMatch(armorSlot, type, male, ref equipSlot, ref robes);
984  }
985 
986  private static HookList HookCanRightClick = AddHook<Func<Item, bool>>(g => g.CanRightClick);
987  //in Terraria.UI.ItemSlot.RightClick in end of item-opening if/else chain before final else
988  // make else if(ItemLoader.CanRightClick(inv[slot]))
992  public static bool CanRightClick(Item item) {
993  if (item.IsAir || !Main.mouseRight)
994  return false;
995 
996  if (item.modItem != null && item.modItem.CanRightClick())
997  return true;
998 
999  foreach (var g in HookCanRightClick.arr)
1000  if (g.Instance(item).CanRightClick(item))
1001  return true;
1002 
1003  return false;
1004  }
1005 
1006  private static HookList HookRightClick = AddHook<Action<Item, Player>>(g => g.RightClick);
1007  //in Terraria.UI.ItemSlot in block from CanRightClick call ItemLoader.RightClick(inv[slot], player)
1019  public static void RightClick(Item item, Player player) {
1020  if (!Main.mouseRightRelease)
1021  return;
1022 
1023  item.modItem?.RightClick(player);
1024 
1025  foreach (var g in HookRightClick.arr)
1026  g.Instance(item).RightClick(item, player);
1027 
1028  if (ConsumeItem(item, player) && --item.stack == 0)
1029  item.SetDefaults();
1030 
1031  Main.PlaySound(7);
1032  Main.stackSplit = 30;
1033  Main.mouseRightRelease = false;
1034  Recipe.FindRecipes();
1035  }
1036 
1037  //in Terraria.UI.ItemSlot add this to boss bag check
1041  public static bool IsModBossBag(Item item) {
1042  return item.modItem != null && item.modItem.BossBagNPC > 0;
1043  }
1044 
1045  //in Terraria.Player.OpenBossBag after setting num14 call
1046  // ItemLoader.OpenBossBag(type, this, ref num14);
1050  public static void OpenBossBag(int type, Player player, ref int npc) {
1051  ModItem modItem = GetItem(type);
1052  if (modItem != null && modItem.BossBagNPC > 0) {
1053  modItem.OpenBossBag(player);
1054  npc = modItem.BossBagNPC;
1055  }
1056  }
1057 
1058  private static HookList HookPreOpenVanillaBag = AddHook<Func<string, Player, int, bool>>(g => g.PreOpenVanillaBag);
1059  //in beginning of Terraria.Player.openBag methods add
1060  // if(!ItemLoader.PreOpenVanillaBag("bagName", this, arg)) { return; }
1061  //at the end of the following methods in Player.cs, add: NPCLoader.blockLoot.Clear(); // clear blockloot
1062  //methods: OpenBossBag, openCrate, openGoodieBag, openHerbBag, openLockbox, openPresent
1066  public static bool PreOpenVanillaBag(string context, Player player, int arg) {
1067  foreach (var g in HookPreOpenVanillaBag.arr)
1068  if (!g.PreOpenVanillaBag(context, player, arg)) {
1069  NPCLoader.blockLoot.Clear(); // clear blockloot
1070  return false;
1071  }
1072 
1073  return true;
1074  }
1075 
1076  private static HookList HookOpenVanillaBag = AddHook<Action<string, Player, int>>(g => g.OpenVanillaBag);
1077  //in Terraria.Player.openBag methods after PreOpenVanillaBag if statements
1078  // add ItemLoader.OpenVanillaBag("bagname", this, arg);
1082  public static void OpenVanillaBag(string context, Player player, int arg) {
1083  foreach (var g in HookOpenVanillaBag.arr)
1084  g.OpenVanillaBag(context, player, arg);
1085  }
1086 
1087  private delegate bool DelegateReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount);
1088  private static HookList HookReforgePrice = AddHook<DelegateReforgePrice>(g => g.ReforgePrice);
1094  public static bool ReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount) {
1095  bool b = item.modItem?.ReforgePrice(ref reforgePrice, ref canApplyDiscount) ?? true;
1096  foreach (var g in HookReforgePrice.arr)
1097  b &= g.Instance(item).ReforgePrice(item, ref reforgePrice, ref canApplyDiscount);
1098  return b;
1099  }
1100 
1101  // @todo: PreReforge marked obsolete until v0.11
1102  private static HookList HookPreReforge = AddHook<Func<Item, bool>>(g => g.NewPreReforge);
1106  public static bool PreReforge(Item item) {
1107  bool b = item.modItem?.NewPreReforge() ?? true;
1108  foreach (var g in HookPreReforge.arr)
1109  b &= g.Instance(item).NewPreReforge(item);
1110  return b;
1111  }
1112 
1113  private static HookList HookPostReforge = AddHook<Action<Item>>(g => g.PostReforge);
1117  public static void PostReforge(Item item) {
1118  item.modItem?.PostReforge();
1119  foreach (var g in HookPostReforge.arr)
1120  g.Instance(item).PostReforge(item);
1121  }
1122 
1123  private delegate void DelegateDrawHands(int body, ref bool drawHands, ref bool drawArms);
1124  private static HookList HookDrawHands = AddHook<DelegateDrawHands>(g => g.DrawHands);
1128  public static void DrawHands(Player player, ref bool drawHands, ref bool drawArms) {
1129  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
1130  texture?.DrawHands(ref drawHands, ref drawArms);
1131 
1132  foreach (var g in HookDrawHands.arr)
1133  g.DrawHands(player.body, ref drawHands, ref drawArms);
1134  }
1135 
1136  private delegate void DelegateDrawHair(int body, ref bool drawHair, ref bool drawAltHair);
1137  private static HookList HookDrawHair = AddHook<DelegateDrawHair>(g => g.DrawHair);
1138  //in Terraria.Main.DrawPlayerHead after if statement that sets flag2 to true
1139  // call ItemLoader.DrawHair(drawPlayer, ref flag, ref flag2)
1140  //in Terraria.Main.DrawPlayer after if statement that sets flag5 to true
1141  // call ItemLoader.DrawHair(drawPlayer, ref flag4, ref flag5)
1145  public static void DrawHair(Player player, ref bool drawHair, ref bool drawAltHair) {
1146  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
1147  texture?.DrawHair(ref drawHair, ref drawAltHair);
1148 
1149  foreach (var g in HookDrawHair.arr)
1150  g.DrawHair(player.body, ref drawHair, ref drawAltHair);
1151  }
1152 
1153  private static HookList HookDrawHead = AddHook<Func<int, bool>>(g => g.DrawHead);
1154  //in Terraria.Main.DrawPlayerHead in if statement after ItemLoader.DrawHair
1155  //and in Terraria.Main.DrawPlayer in if (!drawPlayer.invis && drawPlayer.head != 38 && drawPlayer.head != 135)
1156  // use && with ItemLoader.DrawHead(drawPlayer)
1160  public static bool DrawHead(Player player) {
1161  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Head, player.head);
1162  if (texture != null && !texture.DrawHead())
1163  return false;
1164 
1165  foreach (var g in HookDrawHead.arr)
1166  if (!g.DrawHead(player.head))
1167  return false;
1168 
1169  return true;
1170  }
1171 
1172  private static HookList HookDrawBody = AddHook<Func<int, bool>>(g => g.DrawBody);
1176  public static bool DrawBody(Player player) {
1177  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, player.body);
1178  if (texture != null && !texture.DrawBody())
1179  return false;
1180 
1181  foreach (var g in HookDrawBody.arr)
1182  if (!g.DrawBody(player.head))
1183  return false;
1184 
1185  return true;
1186  }
1187 
1188  private static HookList HookDrawLegs = AddHook<Func<int, int, bool>>(g => g.DrawLegs);
1192  public static bool DrawLegs(Player player) {
1193  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Legs, player.legs);
1194  if (texture != null && !texture.DrawLegs())
1195  return false;
1196 
1197  texture = EquipLoader.GetEquipTexture(EquipType.Shoes, player.shoe);
1198  if (texture != null && !texture.DrawLegs())
1199  return false;
1200 
1201  foreach (var g in HookDrawLegs.arr)
1202  if (!g.DrawLegs(player.legs, player.shoe))
1203  return false;
1204 
1205  return true;
1206  }
1207 
1208  private delegate void DelegateDrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor);
1209  private static HookList HookDrawArmorColor = AddHook<DelegateDrawArmorColor>(g => g.DrawArmorColor);
1213  public static void DrawArmorColor(EquipType type, int slot, Player drawPlayer, float shadow, ref Color color,
1214  ref int glowMask, ref Color glowMaskColor) {
1215  EquipTexture texture = EquipLoader.GetEquipTexture(type, slot);
1216  texture?.DrawArmorColor(drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor);
1217 
1218  foreach (var g in HookDrawArmorColor.arr)
1219  g.DrawArmorColor(type, slot, drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor);
1220  }
1221 
1222  private delegate void DelegateArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color);
1223  private static HookList HookArmorArmGlowMask = AddHook<DelegateArmorArmGlowMask>(g => g.ArmorArmGlowMask);
1227  public static void ArmorArmGlowMask(int slot, Player drawPlayer, float shadow, ref int glowMask, ref Color color) {
1228  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Body, slot);
1229  texture?.ArmorArmGlowMask(drawPlayer, shadow, ref glowMask, ref color);
1230 
1231  foreach (var g in HookArmorArmGlowMask.arr)
1232  g.ArmorArmGlowMask(slot, drawPlayer, shadow, ref glowMask, ref color);
1233  }
1234 
1238  public static Item GetWing(Player player) {
1239  Item item = null;
1240  for (int k = 3; k < 8 + player.extraAccessorySlots; k++) {
1241  if (player.armor[k].wingSlot == player.wingsLogic) {
1242  item = player.armor[k];
1243  }
1244  }
1245  if (item != null) {
1246  return item;
1247  }
1248  if (player.wingsLogic > 0 && player.wingsLogic < Main.maxWings) {
1249  item = new Item();
1250  item.SetDefaults(vanillaWings[player.wingsLogic]);
1251  return item;
1252  }
1253  if (player.wingsLogic >= Main.maxWings) {
1254  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1255  if (texture?.item != null)
1256  return texture.item.item;
1257  }
1258  return null;
1259  }
1260 
1261  private delegate void DelegateVerticalWingSpeeds(Item item, Player player, ref float ascentWhenFalling, ref float ascentWhenRising, ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend);
1262  private static HookList HookVerticalWingSpeeds = AddHook<DelegateVerticalWingSpeeds>(g => g.VerticalWingSpeeds);
1263  //in Terraria.Player.WingMovement after if statements that set num1-5
1264  // call ItemLoader.VerticalWingSpeeds(this, ref num2, ref num5, ref num4, ref num3, ref num)
1268  public static void VerticalWingSpeeds(Player player, ref float ascentWhenFalling, ref float ascentWhenRising,
1269  ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend) {
1270  Item item = GetWing(player);
1271  if (item == null) {
1272  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1273  texture?.VerticalWingSpeeds(
1274  player, ref ascentWhenFalling, ref ascentWhenRising, ref maxCanAscendMultiplier,
1275  ref maxAscentMultiplier, ref constantAscend);
1276  return;
1277  }
1278 
1279  item.modItem?.VerticalWingSpeeds(player, ref ascentWhenFalling, ref ascentWhenRising, ref maxCanAscendMultiplier,
1280  ref maxAscentMultiplier, ref constantAscend);
1281 
1282  foreach (var g in HookVerticalWingSpeeds.arr)
1283  g.Instance(item).VerticalWingSpeeds(item, player, ref ascentWhenFalling, ref ascentWhenRising,
1284  ref maxCanAscendMultiplier, ref maxAscentMultiplier, ref constantAscend);
1285  }
1286 
1287  private delegate void DelegateHorizontalWingSpeeds(Item item, Player player, ref float speed, ref float acceleration);
1288  private static HookList HookHorizontalWingSpeeds = AddHook<DelegateHorizontalWingSpeeds>(g => g.HorizontalWingSpeeds);
1289  //in Terraria.Player.Update after wingsLogic if statements modifying accRunSpeed and runAcceleration
1290  // call ItemLoader.HorizontalWingSpeeds(this)
1294  public static void HorizontalWingSpeeds(Player player) {
1295  Item item = GetWing(player);
1296  if (item == null) {
1297  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wingsLogic);
1298  texture?.HorizontalWingSpeeds(player, ref player.accRunSpeed, ref player.runAcceleration);
1299  return;
1300  }
1301 
1302  item.modItem?.HorizontalWingSpeeds(player, ref player.accRunSpeed, ref player.runAcceleration);
1303 
1304  foreach (var g in HookHorizontalWingSpeeds.arr)
1305  g.Instance(item).HorizontalWingSpeeds(item, player, ref player.accRunSpeed, ref player.runAcceleration);
1306  }
1307 
1308  private static HookList HookWingUpdate = AddHook<Func<int, Player, bool, bool>>(g => g.WingUpdate);
1312  public static bool WingUpdate(Player player, bool inUse) {
1313  if (player.wings <= 0)
1314  return false;
1315 
1316  EquipTexture texture = EquipLoader.GetEquipTexture(EquipType.Wings, player.wings);
1317  bool? retVal = texture?.WingUpdate(player, inUse);
1318 
1319  foreach (var g in HookWingUpdate.arr)
1320  retVal |= g.WingUpdate(player.wings, player, inUse);
1321 
1322  return retVal ?? false;
1323  }
1324 
1325  private delegate void DelegateUpdate(Item item, ref float gravity, ref float maxFallSpeed);
1326  private static HookList HookUpdate = AddHook<DelegateUpdate>(g => g.Update);
1327  //in Terraria.Item.UpdateItem before item movement (denoted by ItemID.Sets.ItemNoGravity)
1328  // call ItemLoader.Update(this, ref num, ref num2)
1332  public static void Update(Item item, ref float gravity, ref float maxFallSpeed) {
1333  item.modItem?.Update(ref gravity, ref maxFallSpeed);
1334 
1335  foreach (var g in HookUpdate.arr)
1336  g.Instance(item).Update(item, ref gravity, ref maxFallSpeed);
1337  }
1338 
1339  private static HookList HookPostUpdate = AddHook<Action<Item>>(g => g.PostUpdate);
1343  public static void PostUpdate(Item item) {
1344  item.modItem?.PostUpdate();
1345 
1346  foreach (var g in HookPostUpdate.arr)
1347  g.Instance(item).PostUpdate(item);
1348  }
1349 
1350  private delegate void DelegateGrabRange(Item item, Player player, ref int grabRange);
1351  private static HookList HookGrabRange = AddHook<DelegateGrabRange>(g => g.GrabRange);
1352  //in Terraria.Player.GrabItems after increasing grab range add
1353  // ItemLoader.GrabRange(Main.item[j], this, ref num);
1357  public static void GrabRange(Item item, Player player, ref int grabRange) {
1358  item.modItem?.GrabRange(player, ref grabRange);
1359 
1360  foreach (var g in HookGrabRange.arr)
1361  g.Instance(item).GrabRange(item, player, ref grabRange);
1362  }
1363 
1364  private static HookList HookGrabStyle = AddHook<Func<Item, Player, bool>>(g => g.GrabStyle);
1365  //in Terraria.Player.GrabItems between setting beingGrabbed to true and grab styles add
1366  // if(ItemLoader.GrabStyle(Main.item[j], this)) { } else
1370  public static bool GrabStyle(Item item, Player player) {
1371  foreach (var g in HookGrabStyle.arr)
1372  if (g.Instance(item).GrabStyle(item, player))
1373  return true;
1374 
1375  return item.modItem != null && item.modItem.GrabStyle(player);
1376  }
1377 
1378  private static HookList HookCanPickup = AddHook<Func<Item, Player, bool>>(g => g.CanPickup);
1379  //in Terraria.Player.GrabItems first per item if statement add
1380  // && ItemLoader.CanPickup(Main.item[j], this)
1381  public static bool CanPickup(Item item, Player player) {
1382  foreach (var g in HookCanPickup.arr)
1383  if (!g.Instance(item).CanPickup(item, player))
1384  return false;
1385 
1386  return item.modItem?.CanPickup(player) ?? true;
1387  }
1388 
1389  private static HookList HookOnPickup = AddHook<Func<Item, Player, bool>>(g => g.OnPickup);
1390  //in Terraria.Player.GrabItems before special pickup effects add
1391  // if(!ItemLoader.OnPickup(Main.item[j], this)) { Main.item[j] = new Item(); continue; }
1395  public static bool OnPickup(Item item, Player player) {
1396  foreach (var g in HookOnPickup.arr)
1397  if (!g.Instance(item).OnPickup(item, player))
1398  return false;
1399 
1400  return item.modItem?.OnPickup(player) ?? true;
1401  }
1402 
1403  private static HookList HookItemSpace = AddHook<Func<Item, Player, bool>>(g => g.ItemSpace);
1404  //in Terraria.Player.GrabItems before grab effect
1405  // (this.ItemSpace(Main.item[j]) || ItemLoader.ExtraPickupSpace(Main.item[j], this)
1406  public static bool ItemSpace(Item item, Player player) {
1407  foreach (var g in HookItemSpace.arr)
1408  if (g.Instance(item).ItemSpace(item, player))
1409  return true;
1410 
1411  return item.modItem?.ItemSpace(player) ?? false;
1412  }
1413 
1414  private static HookList HookGetAlpha = AddHook<Func<Item, Color, Color?>>(g => g.GetAlpha);
1415  //in Terraria.UI.ItemSlot.GetItemLight remove type too high check
1416  //in beginning of Terraria.Item.GetAlpha call
1417  // Color? modColor = ItemLoader.GetAlpha(this, newColor);
1418  // if(modColor.HasValue) { return modColor.Value; }
1422  public static Color? GetAlpha(Item item, Color lightColor) {
1423  if (item.IsAir)
1424  return null;
1425 
1426  foreach (var g in HookGetAlpha.arr) {
1427  Color? color = g.Instance(item).GetAlpha(item, lightColor);
1428  if (color.HasValue)
1429  return color;
1430  }
1431 
1432  return item.modItem?.GetAlpha(lightColor);
1433  }
1434 
1435  private delegate bool DelegatePreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI);
1436  private static HookList HookPreDrawInWorld = AddHook<DelegatePreDrawInWorld>(g => g.PreDrawInWorld);
1437  //in Terraria.Main.DrawItem after ItemSlot.GetItemLight call
1438  // if(!ItemLoader.PreDrawInWorld(item, Main.spriteBatch, color, alpha, ref rotation, ref scale)) { return; }
1442  public static bool PreDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) {
1443  bool flag = true;
1444  if (item.modItem != null)
1445  flag &= item.modItem.PreDrawInWorld(spriteBatch, lightColor, alphaColor, ref rotation, ref scale, whoAmI);
1446 
1447  foreach (var g in HookPreDrawInWorld.arr)
1448  flag &= g.Instance(item).PreDrawInWorld(item, spriteBatch, lightColor, alphaColor, ref rotation, ref scale, whoAmI);
1449 
1450  return flag;
1451  }
1452 
1453  private static HookList HookPostDrawInWorld = AddHook<Action<Item, SpriteBatch, Color, Color, float, float, int>>(g => g.PostDrawInWorld);
1454  //in Terraria.Main.DrawItem before every return (including for PreDrawInWorld) and at end of method call
1455  // ItemLoader.PostDrawInWorld(item, Main.spriteBatch, color, alpha, rotation, scale)
1459  public static void PostDrawInWorld(Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) {
1460  item.modItem?.PostDrawInWorld(spriteBatch, lightColor, alphaColor, rotation, scale, whoAmI);
1461 
1462  foreach (var g in HookPostDrawInWorld.arr)
1463  g.Instance(item).PostDrawInWorld(item, spriteBatch, lightColor, alphaColor, rotation, scale, whoAmI);
1464  }
1465 
1466  private static HookList HookPreDrawInInventory = AddHook<Func<Item, SpriteBatch, Vector2, Rectangle, Color, Color, Vector2, float, bool>>(g => g.PreDrawInInventory);
1467  //in Terraria.UI.ItemSlot.Draw place item-drawing code inside if statement
1468  // if(ItemLoader.PreDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
1469  // item.GetColor(color), origin, num4 * num3))
1473  public static bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame,
1474  Color drawColor, Color itemColor, Vector2 origin, float scale) {
1475  bool flag = true;
1476  foreach (var g in HookPreDrawInInventory.arr)
1477  flag &= g.Instance(item).PreDrawInInventory(item, spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1478 
1479  if (item.modItem != null)
1480  flag &= item.modItem.PreDrawInInventory(spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1481 
1482  return flag;
1483  }
1484 
1485  private static HookList HookPostDrawInInventory = AddHook<Action<Item, SpriteBatch, Vector2, Rectangle, Color, Color, Vector2, float>>(g => g.PostDrawInInventory);
1486  //in Terraria.UI.ItemSlot.Draw after if statement for PreDrawInInventory call
1487  // ItemLoader.PostDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
1488  // item.GetColor(color), origin, num4 * num3);
1492  public static void PostDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame,
1493  Color drawColor, Color itemColor, Vector2 origin, float scale) {
1494  item.modItem?.PostDrawInInventory(spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1495 
1496  foreach (var g in HookPostDrawInInventory.arr)
1497  g.Instance(item).PostDrawInInventory(item, spriteBatch, position, frame, drawColor, itemColor, origin, scale);
1498  }
1499 
1500  private static HookList HookHoldoutOffset = AddHook<Func<int, Vector2?>>(g => g.HoldoutOffset);
1501  public static void HoldoutOffset(float gravDir, int type, ref Vector2 offset) {
1502  ModItem modItem = GetItem(type);
1503  if (modItem != null) {
1504  Vector2? modOffset = modItem.HoldoutOffset();
1505  if (modOffset.HasValue) {
1506  offset.X = modOffset.Value.X;
1507  offset.Y += gravDir * modOffset.Value.Y;
1508  }
1509  }
1510  foreach (var g in HookHoldoutOffset.arr) {
1511  Vector2? modOffset = g.HoldoutOffset(type);
1512  if (modOffset.HasValue) {
1513  offset.X = modOffset.Value.X;
1514  offset.Y = Main.itemTexture[type].Height / 2f + gravDir * modOffset.Value.Y;
1515  }
1516  }
1517  }
1518 
1519  private static HookList HookHoldoutOrigin = AddHook<Func<int, Vector2?>>(g => g.HoldoutOrigin);
1520  public static void HoldoutOrigin(Player player, ref Vector2 origin) {
1521  Item item = player.inventory[player.selectedItem];
1522  Vector2 modOrigin = Vector2.Zero;
1523  if (item.modItem != null) {
1524  Vector2? modOrigin2 = item.modItem.HoldoutOrigin();
1525  if (modOrigin2.HasValue) {
1526  modOrigin = modOrigin2.Value;
1527  }
1528  }
1529  foreach (var g in HookHoldoutOrigin.arr) {
1530  Vector2? modOrigin2 = g.Instance(item).HoldoutOrigin(item.type);
1531  if (modOrigin2.HasValue) {
1532  modOrigin = modOrigin2.Value;
1533  }
1534  }
1535  modOrigin.X *= player.direction;
1536  modOrigin.Y *= -player.gravDir;
1537  origin += modOrigin;
1538  }
1539 
1540  private static HookList HookCanEquipAccessory = AddHook<Func<Item, Player, int, bool>>(g => g.CanEquipAccessory);
1541  //in Terraria.UI.ItemSlot.AccCheck replace 2nd and 3rd return false with
1542  // return !ItemLoader.CanEquipAccessory(item, slot)
1543  public static bool CanEquipAccessory(Item item, int slot) {
1544  Player player = Main.player[Main.myPlayer];
1545  if (item.modItem != null && !item.modItem.CanEquipAccessory(player, slot))
1546  return false;
1547 
1548  foreach (var g in HookCanEquipAccessory.arr)
1549  if (!g.Instance(item).CanEquipAccessory(item, player, slot))
1550  return false;
1551 
1552  return true;
1553  }
1554 
1555  private delegate void DelegateExtractinatorUse(int extractType, ref int resultType, ref int resultStack);
1556  private static HookList HookExtractinatorUse = AddHook<DelegateExtractinatorUse>(g => g.ExtractinatorUse);
1557  public static void ExtractinatorUse(ref int resultType, ref int resultStack, int extractType) {
1558  GetItem(extractType)?.ExtractinatorUse(ref resultType, ref resultStack);
1559 
1560  foreach (var g in HookExtractinatorUse.arr)
1561  g.ExtractinatorUse(extractType, ref resultType, ref resultStack);
1562  }
1563 
1564  public static void AutoLightSelect(Item item, ref bool dryTorch, ref bool wetTorch, ref bool glowstick) {
1565  if (item.modItem != null) {
1566  item.modItem.AutoLightSelect(ref dryTorch, ref wetTorch, ref glowstick);
1567  if (wetTorch) {
1568  dryTorch = false;
1569  glowstick = false;
1570  }
1571  if (dryTorch) {
1572  glowstick = false;
1573  }
1574  }
1575  }
1576 
1577  private delegate void DelegateCaughtFishStack(int type, ref int stack);
1578  private static HookList HookCaughtFishStack = AddHook<DelegateCaughtFishStack>(g => g.CaughtFishStack);
1579  public static void CaughtFishStack(Item item) {
1580  item.modItem?.CaughtFishStack(ref item.stack);
1581 
1582  foreach (var g in HookCaughtFishStack.arr)
1583  g.Instance(item).CaughtFishStack(item.type, ref item.stack);
1584  }
1585 
1586  private static HookList HookIsAnglerQuestAvailable = AddHook<Func<int, bool>>(g => g.IsAnglerQuestAvailable);
1587  public static void IsAnglerQuestAvailable(int itemID, ref bool notAvailable) {
1588  ModItem modItem = GetItem(itemID);
1589  if (modItem != null)
1590  notAvailable |= !modItem.IsAnglerQuestAvailable();
1591 
1592  foreach (var g in HookIsAnglerQuestAvailable.arr)
1593  notAvailable |= !g.IsAnglerQuestAvailable(itemID);
1594  }
1595 
1596  private delegate void DelegateAnglerChat(int type, ref string chat, ref string catchLocation);
1597  private static HookList HookAnglerChat = AddHook<DelegateAnglerChat>(g => g.AnglerChat);
1598  public static string AnglerChat(int type) {
1599  string chat = "";
1600  string catchLocation = "";
1601  GetItem(type)?.AnglerQuestChat(ref chat, ref catchLocation);
1602 
1603  foreach (var g in HookAnglerChat.arr)
1604  g.AnglerChat(type, ref chat, ref catchLocation);
1605 
1606  if (string.IsNullOrEmpty(chat) || string.IsNullOrEmpty(catchLocation))
1607  return null;
1608 
1609  return chat + "\n\n(" + catchLocation + ")";
1610  }
1611 
1612  private static HookList HookOnCraft = AddHook<Action<Item, Recipe>>(g => g.OnCraft);
1613  public static void OnCraft(Item item, Recipe recipe) {
1614  item.modItem?.OnCraft(recipe);
1615  foreach (var g in HookOnCraft.arr)
1616  g.Instance(item).OnCraft(item, recipe);
1617  }
1618 
1619  private delegate bool DelegatePreDrawTooltip(Item item, ReadOnlyCollection<TooltipLine> lines, ref int x, ref int y);
1620  private static HookList HookPreDrawTooltip = AddHook<DelegatePreDrawTooltip>(g => g.PreDrawTooltip);
1621  public static bool PreDrawTooltip(Item item, ReadOnlyCollection<TooltipLine> lines, ref int x, ref int y) {
1622  bool modItemPreDraw = item.modItem?.PreDrawTooltip(lines, ref x, ref y) ?? true;
1623  List<bool> globalItemPreDraw = new List<bool>();
1624  foreach (var g in HookPreDrawTooltip.arr)
1625  globalItemPreDraw.Add(g.PreDrawTooltip(item, lines, ref x, ref y));
1626  return modItemPreDraw && globalItemPreDraw.All(z => z);
1627  }
1628 
1629  private delegate void DelegatePostDrawTooltip(Item item, ReadOnlyCollection<DrawableTooltipLine> lines);
1630  private static HookList HookPostDrawTooltip = AddHook<DelegatePostDrawTooltip>(g => g.PostDrawTooltip);
1631  public static void PostDrawTooltip(Item item, ReadOnlyCollection<DrawableTooltipLine> lines) {
1632  item.modItem?.PostDrawTooltip(lines);
1633  foreach (var g in HookPostDrawTooltip.arr)
1634  g.Instance(item).PostDrawTooltip(item, lines);
1635  }
1636 
1637  private delegate bool DelegatePreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset);
1638  private static HookList HookPreDrawTooltipLine = AddHook<DelegatePreDrawTooltipLine>(g => g.PreDrawTooltipLine);
1639  public static bool PreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset) {
1640  bool modItemPreDrawLine = item.modItem?.PreDrawTooltipLine(line, ref yOffset) ?? true;
1641  List<bool> globalItemPreDrawLine = new List<bool>();
1642  foreach (var g in HookPreDrawTooltipLine.arr)
1643  globalItemPreDrawLine.Add(g.PreDrawTooltipLine(item, line, ref yOffset));
1644  return modItemPreDrawLine && globalItemPreDrawLine.All(x => x);
1645  }
1646 
1647  private delegate void DelegatePostDrawTooltipLine(Item item, DrawableTooltipLine line);
1648  private static HookList HookPostDrawTooltipLine = AddHook<DelegatePostDrawTooltipLine>(g => g.PostDrawTooltipLine);
1649  public static void PostDrawTooltipLine(Item item, DrawableTooltipLine line) {
1650  item.modItem?.PostDrawTooltipLine(line);
1651  foreach (var g in HookPostDrawTooltipLine.arr)
1652  g.Instance(item).PostDrawTooltipLine(item, line);
1653  }
1654 
1655  private static HookList HookModifyTooltips = AddHook<Action<Item, List<TooltipLine>>>(g => g.ModifyTooltips);
1656  public static List<TooltipLine> ModifyTooltips(Item item, ref int numTooltips, string[] names, ref string[] text,
1657  ref bool[] modifier, ref bool[] badModifier, ref int oneDropLogo, out Color?[] overrideColor) {
1658  List<TooltipLine> tooltips = new List<TooltipLine>();
1659  for (int k = 0; k < numTooltips; k++) {
1660  TooltipLine tooltip = new TooltipLine(names[k], text[k]);
1661  tooltip.isModifier = modifier[k];
1662  tooltip.isModifierBad = badModifier[k];
1663  if (k == oneDropLogo) {
1664  tooltip.oneDropLogo = true;
1665  }
1666  tooltips.Add(tooltip);
1667  }
1668  item.modItem?.ModifyTooltips(tooltips);
1669  foreach (var g in HookModifyTooltips.arr)
1670  g.Instance(item).ModifyTooltips(item, tooltips);
1671 
1672  numTooltips = tooltips.Count;
1673  text = new string[numTooltips];
1674  modifier = new bool[numTooltips];
1675  badModifier = new bool[numTooltips];
1676  oneDropLogo = -1;
1677  overrideColor = new Color?[numTooltips];
1678  for (int k = 0; k < numTooltips; k++) {
1679  text[k] = tooltips[k].text;
1680  modifier[k] = tooltips[k].isModifier;
1681  badModifier[k] = tooltips[k].isModifierBad;
1682  if (tooltips[k].oneDropLogo) {
1683  oneDropLogo = k;
1684  }
1685  overrideColor[k] = tooltips[k].overrideColor;
1686  }
1687 
1688  return tooltips;
1689  }
1690 
1691  private static HookList HookNeedsSaving = AddHook<Func<Item, bool>>(g => g.NeedsSaving);
1692  public static bool NeedsModSaving(Item item) {
1693  return item.type != 0 && (item.modItem != null || item.prefix >= PrefixID.Count || HookNeedsSaving.arr.Count(g => g.Instance(item).NeedsSaving(item)) > 0);
1694  }
1695 
1696  internal static void WriteNetGlobalOrder(BinaryWriter w) {
1697  w.Write((short)NetGlobals.Length);
1698  foreach (var globalItem in NetGlobals) {
1699  w.Write(globalItem.mod.netID);
1700  w.Write(globalItem.Name);
1701  }
1702  }
1703 
1704  internal static void ReadNetGlobalOrder(BinaryReader r) {
1705  short n = r.ReadInt16();
1706  NetGlobals = new GlobalItem[n];
1707  for (short i = 0; i < n; i++)
1708  NetGlobals[i] = ModNet.GetMod(r.ReadInt16()).GetGlobalItem(r.ReadString());
1709  }
1710 
1711  private static bool HasMethod(Type t, string method, params Type[] args) {
1712  return t.GetMethod(method, args).DeclaringType != typeof(GlobalItem);
1713  }
1714 
1715  internal static void VerifyGlobalItem(GlobalItem item) {
1716  var type = item.GetType();
1717  int saveMethods = 0;
1718  if (HasMethod(type, "NeedsSaving", typeof(Item))) saveMethods++;
1719  if (HasMethod(type, "Save", typeof(Item))) saveMethods++;
1720  if (HasMethod(type, "Load", typeof(Item), typeof(TagCompound))) saveMethods++;
1721  if (saveMethods > 0 && saveMethods < 3)
1722  throw new Exception(type + " must override all of (NeedsSaving/Save/Load) or none");
1723 
1724  int netMethods = 0;
1725  if (HasMethod(type, "NetSend", typeof(Item), typeof(BinaryWriter))) netMethods++;
1726  if (HasMethod(type, "NetReceive", typeof(Item), typeof(BinaryReader))) netMethods++;
1727  if (netMethods == 1)
1728  throw new Exception(type + " must override both of (NetSend/NetReceive) or none");
1729 
1730  bool hasInstanceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
1731  .Any(f => f.DeclaringType != typeof(GlobalItem));
1732 
1733  if (hasInstanceFields) {
1734  if (!item.InstancePerEntity)
1735  throw new Exception(type + " has instance fields but does not set InstancePerEntity to true. Either use static fields, or per instance globals");
1736 
1737  if (!item.CloneNewInstances &&
1738  !HasMethod(type, "NewInstance", typeof(Item)) &&
1739  !HasMethod(type, "Clone", typeof(Item), typeof(Item)))
1740  throw new Exception(type + " has InstancePerEntity but must either set CloneNewInstances to true, or override NewInstance(Item) or Clone(Item, Item)");
1741  }
1742  }
1743  }
1744 }
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:413
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:573
static bool CanPickup(Item item, Player player)
Definition: ItemLoader.cs:1381
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:968
static void HoldItem(Item item, Player player)
Calls ModItem.HoldItem and all GlobalItem.HoldItem hooks.
Definition: ItemLoader.cs:318
virtual bool IsAnglerQuestAvailable()
Whether or not specific conditions have been satisfied for the Angler to be able to request this item...
Definition: ModItem.cs:948
static void OnConsumeItem(Item item, Player player)
Calls ModItem.OnConsumeItem and all GlobalItem.OnConsumeItem hooks.
Definition: ItemLoader.cs:751
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:1050
static void IsAnglerQuestAvailable(int itemID, ref bool notAvailable)
Definition: ItemLoader.cs:1587
static void UseItemHitbox(Item item, Player player, ref Rectangle hitbox, ref bool noHitbox)
Calls ModItem.UseItemHitbox, then all GlobalItem.UseItemHitbox hooks.
Definition: ItemLoader.cs:591
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:463
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:52
static void GetWeaponCrit(Item item, Player player, ref int crit)
Calls ModItem.GetWeaponCrit, then all GlobalItem.GetWeaponCrit hooks.
Definition: ItemLoader.cs:483
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:1238
static void MeleeEffects(Item item, Player player, Rectangle hitbox)
Calls ModItem.MeleeEffects and all GlobalItem.MeleeEffects hooks.
Definition: ItemLoader.cs:604
static void OnHitPvp(Item item, Player player, Player target, int damage, bool crit)
Calls ModItem.OnHitPvp and all GlobalItem.OnHitPvp hooks.
Definition: ItemLoader.cs:702
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:953
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:1442
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:1312
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:496
static bool CanRightClick(Item item)
Calls ModItem.CanRightClick, then all GlobalItem.CanRightClick hooks, until one of the returns true...
Definition: ItemLoader.cs:992
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:526
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:508
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:1631
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:893
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:272
static float UseTimeMultiplier(Item item, Player player)
Definition: ItemLoader.cs:329
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:24
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:1564
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:1395
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:1160
static void Update(Item item, ref float gravity, ref float maxFallSpeed)
Calls ModItem.Update, then all GlobalItem.Update hooks.
Definition: ItemLoader.cs:1332
static void OnMissingMana(Item item, Player player, int neededMana)
Calls ModItem.OnMissingMana, then all GlobalItem.OnMissingMana hooks.
Definition: ItemLoader.cs:404
static bool ReforgePrice(Item item, ref int reforgePrice, ref bool canApplyDiscount)
Call all ModItem.ReforgePrice, then GlobalItem.ReforgePrice hooks.
Definition: ItemLoader.cs:1094
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:689
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:648
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:1492
static void HorizontalWingSpeeds(Player player)
If the player is using wings, this uses the result of GetWing, and calls ModItem.HorizontalWingSpeeds...
Definition: ItemLoader.cs:1294
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:622
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:714
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:1649
static void UpdateEquip(Item item, Player player)
Calls ModItem.UpdateEquip and all GlobalItem.UpdateEquip hooks.
Definition: ItemLoader.cs:838
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:544
static void GetHealMana(Item item, Player player, bool quickHeal, ref int healValue)
Calls ModItem.GetHealMana, then all GlobalItem.GetHealMana hooks.
Definition: ItemLoader.cs:374
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:674
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:1422
static void CaughtFishStack(Item item)
Definition: ItemLoader.cs:1579
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:661
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:1082
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:1213
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:902
static string AnglerChat(int type)
Definition: ItemLoader.cs:1598
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:1176
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:767
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:423
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:1227
static bool NeedsModSaving(Item item)
Definition: ItemLoader.cs:1692
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:880
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:1268
static bool GrabStyle(Item item, Player player)
Calls all GlobalItem.GrabStyle hooks then ModItem.GrabStyle, until one of them returns true...
Definition: ItemLoader.cs:1370
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:1128
static void RightClick(Item item, Player player)
If Main.mouseRightRelease is true, the following steps are taken:
Definition: ItemLoader.cs:1019
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:467
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:303
static bool CanEquipAccessory(Item item, int slot)
Definition: ItemLoader.cs:1543
static void ModifyManaCost(Item item, Player player, ref float reduce, ref float mult)
Calls ModItem.ModifyManaCost, then all GlobalItem.ModifyManaCost hooks.
Definition: ItemLoader.cs:389
static bool AltFunctionUse(Item item, Player player)
Calls ModItem.AltFunctionUse, then all GlobalItem.AltFunctionUse hooks, until one of them returns tru...
Definition: ItemLoader.cs:802
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 ModifyWeaponDamage(Item item, Player player, ref float add, ref float mult)
Calls ModItem.HookModifyWeaponDamage, then all GlobalItem.HookModifyWeaponDamage hooks.
Definition: ItemLoader.cs:452
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:927
static bool ItemSpace(Item item, Player player)
Definition: ItemLoader.cs:1406
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:455
static void GetWeaponDamage(Item item, Player player, ref int damage)
Calls ModItem.GetWeaponDamage, then all GlobalItem.GetWeaponDamage hooks.
Definition: ItemLoader.cs:437
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:1656
static void OnConsumeMana(Item item, Player player, int manaConsumed)
Calls ModItem.OnConsumeMana, then all GlobalItem.OnConsumeMana hooks.
Definition: ItemLoader.cs:419
static bool PreReforge(Item item)
Calls ModItem.PreReforge, then all GlobalItem.PreReforge hooks.
Definition: ItemLoader.cs:1106
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:1473
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:1520
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:41
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:822
static bool HasMethod(Type t, string method, params Type[] args)
Definition: ItemLoader.cs:1711
static float MeleeSpeedMultiplier(Item item, Player player)
Definition: ItemLoader.cs:342
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:640
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:23
static bool PreDrawTooltipLine(Item item, DrawableTooltipLine line, ref int yOffset)
Definition: ItemLoader.cs:1639
static void UseStyle(Item item, Player player)
Calls ModItem.UseStyle and all GlobalItem.UseStyle hooks.
Definition: ItemLoader.cs:288
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:1557
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:359
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:1041
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:734
static void OnCraft(Item item, Recipe recipe)
Definition: ItemLoader.cs:1613
static void UpdateVanity(Player player)
Calls each of the item&#39;s equipment texture&#39;s UpdateVanity hook.
Definition: ItemLoader.cs:867
static void UpdateAccessory(Item item, Player player, bool hideVisual)
Calls ModItem.UpdateAccessory and all GlobalItem.UpdateAccessory hooks.
Definition: ItemLoader.cs:854
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:1066
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:472
static void HoldoutOffset(float gravDir, int type, ref Vector2 offset)
Definition: ItemLoader.cs:1501
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:1145
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:1459
static bool HoldItemFrame(Item item, Player player)
Calls ModItem.HoldItemFrame, then all GlobalItem.HoldItemFrame hooks, until one of them returns true...
Definition: ItemLoader.cs:784
static void PostUpdate(Item item)
Calls ModItem.PostUpdate and all GlobalItem.PostUpdate hooks.
Definition: ItemLoader.cs:1343
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:1621
static void GrabRange(Item item, Player player, ref int grabRange)
Calls ModItem.GrabRange, then all GlobalItem.GrabRange hooks.
Definition: ItemLoader.cs:1357
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:1192
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:433
static void PostReforge(Item item)
Calls ModItem.PostReforge, then all GlobalItem.PostReforge hooks.
Definition: ItemLoader.cs:1117
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:978