-
Notifications
You must be signed in to change notification settings - Fork 755
/
ArmorModTypeFilter.java
117 lines (106 loc) · 3.46 KB
/
ArmorModTypeFilter.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package tconstruct.library.armor;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.item.ItemStack;
public abstract class ArmorModTypeFilter extends ArmorMod
{
public final List<Integer> increase;
public ArmorModTypeFilter(int effect, String dataKey, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items, int[] values)
{
super(effect, dataKey, armorTypes, items);
assert items.length == values.length : "Itemstacks and their values for armor modifiers must be the same length";
this.increase = new ArrayList<Integer>();
for (int i = 0; i < values.length; i++)
{
increase.add(values[i]);
}
}
/** Checks to see if the inputs match the stored items
* Note: Filters types, doesn't care about amount
*
* @param input The ItemStacks to compare against
* @param tool Item to modify, used for restrictions
* @return Whether the recipe matches the input
*/
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
if (!canModify(tool, input))
return false;
boolean minimumMatch = false;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
boolean match = false;
for (Object check : stacks)
{
ItemStack stack = (ItemStack) check;
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (this.areItemsEquivalent(inputStack, stack))
match = true;
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
match = true;
}
}
if (!match)
return false;
minimumMatch = true;
}
return minimumMatch;
}
public int matchingAmount (ItemStack[] input)
{
int amount = 0;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
else
{
for (int iter = 0; iter < stacks.size(); iter++)
{
ItemStack stack = (ItemStack) stacks.get(iter);
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (this.areItemsEquivalent(inputStack, stack))
amount += increase.get(iter);
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
amount += increase.get(iter);
}
}
}
}
return amount;
}
public int matchingItems (ItemStack[] input)
{
int amount = 0;
for (ItemStack inputStack : input)
{
if (inputStack != null)
amount++;
}
return amount;
}
/** Adds a new itemstack to the list for increases
*
* @param stack ItemStack to compare against
* @param amount Amount to increase
*/
public void addStackToMatchList (ItemStack stack, int amount)
{
if (stack == null)
throw new NullPointerException("ItemStack added to " + this.getClass().getSimpleName() + " cannot be null.");
stacks.add(stack);
increase.add(amount);
}
}