-
Notifications
You must be signed in to change notification settings - Fork 497
/
NBTAwareShapedOreRecipe.java
64 lines (52 loc) · 2.24 KB
/
NBTAwareShapedOreRecipe.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
package buildcraft.core.lib.recipe;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
public class NBTAwareShapedOreRecipe extends ShapedOreRecipe {
public NBTAwareShapedOreRecipe(ItemStack result, Object[] recipe) {
super(result, recipe);
}
@Override
protected boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) {
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) {
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) {
int subX = x - startX;
int subY = y - startY;
Object target = null;
if (subX >= 0 && subY >= 0 && subX < width && subY < height) {
if (mirror) {
target = input[width - subX - 1 + subY * width];
} else {
target = input[subX + subY * width];
}
}
ItemStack slot = inv.getStackInRowAndColumn(x, y);
if (target instanceof ItemStack) {
ItemStack targetStack = (ItemStack) target;
if (!OreDictionary.itemMatches(targetStack, slot, false)) {
return false;
}
if (targetStack.hasTagCompound()) {
if (!slot.hasTagCompound()) return false;
if (!targetStack.getTagCompound().equals(slot.getTagCompound())) return false;
}
} else if (target instanceof List) {
boolean matched = false;
Iterator<ItemStack> itr = ((List<ItemStack>) target).iterator();
while (itr.hasNext() && !matched) {
matched = OreDictionary.itemMatches(itr.next(), slot, false);
}
if (!matched) {
return false;
}
} else if (target == null && slot != null) {
return false;
}
}
}
return true;
}
}