forked from blushiemagic/MagicStorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemData.cs
60 lines (52 loc) · 1.12 KB
/
ItemData.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
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
namespace MagicStorage
{
public struct ItemData
{
public readonly int Type;
public readonly int Prefix;
public ItemData(int type, int prefix = 0)
{
this.Type = type;
this.Prefix = prefix;
}
public ItemData(Item item)
{
this.Type = item.netID;
this.Prefix = item.prefix;
}
public override bool Equals(Object other)
{
if (!(other is ItemData))
{
return false;
}
return Matches(this, (ItemData)other);
}
public override int GetHashCode()
{
return 100 * Type + Prefix;
}
public static bool Matches(Item item1, Item item2)
{
return Matches(new ItemData(item1), new ItemData(item2));
}
public static bool Matches(ItemData data1, ItemData data2)
{
return data1.Type == data2.Type && data1.Prefix == data2.Prefix;
}
public static int Compare(Item item1, Item item2)
{
ItemData data1 = new ItemData(item1);
ItemData data2 = new ItemData(item2);
if (data1.Type != data2.Type)
{
return data1.Type - data2.Type;
}
return data1.Prefix - data2.Prefix;
}
}
}