/
RecipeMapper.java
185 lines (158 loc) · 3.77 KB
/
RecipeMapper.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package moze_intel.projecte.emc;
import moze_intel.projecte.utils.PELogger;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.*;
public final class RecipeMapper
{
private static LinkedHashMap<SimpleStack, LinkedList<RecipeInput>> recipes = new LinkedHashMap<SimpleStack, LinkedList<RecipeInput>>();
public static void map()
{
Iterator<IRecipe> iter = CraftingManager.getInstance().getRecipeList().iterator();
while (iter.hasNext())
{
IRecipe recipe = iter.next();
ItemStack output = recipe.getRecipeOutput();
if (output == null || output.getItem() == null || output.stackSize < 1)
{
continue;
}
SimpleStack outStack = new SimpleStack(output);
if (!outStack.isValid())
{
continue;
}
List<Object> inputs = new ArrayList<Object>();
if (recipe instanceof ShapedRecipes)
{
inputs.addAll(Arrays.asList(((ShapedRecipes) recipe).recipeItems));
}
else if (recipe instanceof ShapelessRecipes)
{
inputs.addAll(((ShapelessRecipes) recipe).recipeItems);
}
else if (recipe instanceof ShapedOreRecipe)
{
for (Object obj : ((ShapedOreRecipe) recipe).getInput())
{
if (obj == null)
{
continue;
}
if (obj instanceof ItemStack)
{
inputs.add(obj);
}
else if (obj instanceof ArrayList)
{
inputs.add(obj);
}
else
{
PELogger.logInfo("Uknown object for shaped recipe: " + obj);
}
}
}
else if (recipe instanceof ShapelessOreRecipe)
{
for (Object obj : ((ShapelessOreRecipe) recipe).getInput())
{
if (obj == null)
{
continue;
}
if (obj instanceof ItemStack)
{
inputs.add(obj);
}
else if (obj instanceof ArrayList)
{
inputs.add(obj);
}
else
{
PELogger.logInfo("Uknown object for shapeless recipe: " + obj);
}
}
}
try
{
RecipeInput rInput = new RecipeInput();
for (Object obj : inputs)
{
if (obj == null)
{
continue;
}
if (obj instanceof ItemStack)
{
try {
ItemStack stack = ((ItemStack) obj).copy();
if (stack == null)
{
continue;
}
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
stack.setItemDamage(0);
}
if (stack.getItem().doesContainerItemLeaveCraftingGrid(stack))
{
rInput.addToInputs(stack);
}
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
ArrayList<ItemStack> listCopy = new ArrayList<ItemStack>();
for (ItemStack stack : (ArrayList<ItemStack>) obj)
{
if (stack == null)
{
continue;
}
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
ItemStack copy = stack.copy();
copy.setItemDamage(0);
listCopy.add(copy);
}
else
{
listCopy.add(stack);
}
}
rInput.addToInput(listCopy);
}
}
LinkedList<RecipeInput> currentInputs;
if (recipes.containsKey(outStack))
{
currentInputs = recipes.get(outStack);
}
else
{
currentInputs = new LinkedList<RecipeInput>();
}
currentInputs.add(rInput);
recipes.put(outStack, currentInputs);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public static Set<Map.Entry<SimpleStack, LinkedList<RecipeInput>>> getEntrySet()
{
return recipes.entrySet();
}
}