-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathItemHooks.cs
More file actions
49 lines (41 loc) · 1.38 KB
/
ItemHooks.cs
File metadata and controls
49 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using OTAPI;
using Terraria;
namespace TerrariaApi.Server.Hooking;
internal static class ItemHooks
{
private static HookManager _hookManager;
/// <summary>
/// Attaches any of the OTAPI Item hooks to the existing <see cref="HookManager"/> implementation
/// </summary>
/// <param name="hookManager">HookManager instance which will receive the events</param>
public static void AttachTo(HookManager hookManager)
{
_hookManager = hookManager;
HookEvents.Terraria.Item.SetDefaults += OnSetDefaults;
HookEvents.Terraria.Item.netDefaults += OnNetDefaults;
Hooks.Chest.QuickStack += OnQuickStack;
}
private static void OnNetDefaults(Item item, HookEvents.Terraria.Item.netDefaultsEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeItemNetDefaults(ref args.type, item))
args.ContinueExecution = false;
}
private static void OnSetDefaults(Item item, HookEvents.Terraria.Item.SetDefaultsEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeItemSetDefaultsInt(ref args.Type, item, args.variant))
args.ContinueExecution = false;
}
private static void OnQuickStack(object sender, Hooks.Chest.QuickStackEventArgs e)
{
if (e.Result == HookResult.Cancel)
{
return;
}
if (_hookManager.InvokeItemForceIntoChest(Main.chest[e.ChestIndex], e.Item, Main.player[e.PlayerId]))
{
e.Result = HookResult.Cancel;
}
}
}