-
Notifications
You must be signed in to change notification settings - Fork 497
/
ListMatchHandlerArmor.java
49 lines (41 loc) · 1.5 KB
/
ListMatchHandlerArmor.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
package buildcraft.core.list;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraftforge.common.DimensionManager;
import buildcraft.api.lists.ListMatchHandler;
import buildcraft.core.proxy.CoreProxy;
public class ListMatchHandlerArmor extends ListMatchHandler {
private int getArmorTypeID(ItemStack stack) {
EntityPlayer player = CoreProxy.proxy.getClientPlayer();
if (player == null) {
player = CoreProxy.proxy.getBuildCraftPlayer(DimensionManager.getWorld(0), BlockPos.ORIGIN).get();
}
int atID = 0;
for (int i = 0; i <= 3; i++) {
if (stack.getItem().isValidArmor(stack, i, player)) {
atID |= 1 << i;
}
}
return atID;
}
@Override
public boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise) {
if (type == Type.TYPE) {
int armorTypeIDSource = getArmorTypeID(stack);
if (armorTypeIDSource > 0) {
int armorTypeIDTarget = getArmorTypeID(target);
if (precise) {
return armorTypeIDSource == armorTypeIDTarget;
} else {
return (armorTypeIDSource & armorTypeIDTarget) != 0;
}
}
}
return false;
}
@Override
public boolean isValidSource(Type type, ItemStack stack) {
return getArmorTypeID(stack) > 0;
}
}