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