-
Notifications
You must be signed in to change notification settings - Fork 101
/
DecraftingGUI.cs
63 lines (49 loc) · 1.9 KB
/
DecraftingGUI.cs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using MagicStorage.Components;
using System.Collections.Generic;
using Terraria.ID;
using Terraria.ModLoader.IO;
using Terraria.ModLoader;
using Terraria;
namespace MagicStorage {
public static partial class DecraftingGUI {
internal static readonly List<int> viewingItems = new();
internal static readonly List<bool> itemAvailable = new();
internal static int selectedItem = -1;
internal static void Unload() => ClearAllCollections(unloading: true);
private static void ClearAllCollections(bool unloading) {
if (!unloading)
CraftingGUI.ClearAllCollections();
ResetRefreshCache();
viewingItems.Clear();
itemAvailable.Clear();
resultItems.Clear();
resultItemsFromModules.Clear();
resultItemInfo.Clear();
selectedItem = -1;
}
internal static TEStorageHeart GetHeart() => StoragePlayer.LocalPlayer.GetStorageHeart();
internal static TEDecraftingAccess GetDecraftingEntity() => StoragePlayer.LocalPlayer.GetDecraftingAccess();
internal static Item DoWithdraw(Item toWithdraw, bool toInventory = false) {
TEStorageHeart heart = GetHeart();
if (heart is null)
return new Item();
if (Main.netMode == NetmodeID.MultiplayerClient) {
ModPacket packet = heart.PrepareClientRequest(toInventory ? TEStorageHeart.Operation.WithdrawToInventoryThenTryModuleInventory : TEStorageHeart.Operation.WithdrawThenTryModuleInventory);
ItemIO.Send(toWithdraw, packet, true, true);
packet.Send();
return new Item();
}
Item withdrawn = heart.Withdraw(toWithdraw, false);
if (withdrawn.IsAir)
withdrawn = CraftingGUI.TryToWithdrawFromModuleItems(toWithdraw, false);
return withdrawn;
}
internal static void SetSelectedItem(int item) {
NetHelper.Report(true, "Reassigning current item...");
selectedItem = item;
RefreshStorageItems();
CraftingGUI.blockStorageItems.Clear();
NetHelper.Report(true, "Successfully reassigned current item!");
}
}
}