/
Ingredients.java
100 lines (84 loc) · 3.42 KB
/
Ingredients.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
package mezz.jei.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mezz.jei.IngredientRegistry;
import mezz.jei.Internal;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.ingredients.IIngredients;
public class Ingredients implements IIngredients {
private final Map<Class, List<List>> inputs = new HashMap<Class, List<List>>();
private final Map<Class, List> outputs = new HashMap<Class, List>();
private boolean used = false; // check that the addon used this at all. legacy addons will not
@Override
public <T> void setInputLists(Class<T> ingredientClass, List<List<T>> inputs) {
this.used = true;
IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry();
IIngredientHelper<T> ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass);
List<List<T>> expandedInputs = new ArrayList<List<T>>();
for (List<T> input : inputs) {
List<T> itemStacks = ingredientHelper.expandSubtypes(input);
expandedInputs.add(itemStacks);
}
//noinspection unchecked
this.inputs.put(ingredientClass, (List<List>) (Object) expandedInputs);
}
@Override
public <T> void setInputs(Class<T> ingredientClass, List<T> input) {
this.used = true;
IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry();
IIngredientHelper<T> ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass);
List<List<T>> expandedInputs = new ArrayList<List<T>>();
for (T input1 : input) {
List<T> itemStacks = ingredientHelper.expandSubtypes(Collections.singletonList(input1));
expandedInputs.add(itemStacks);
}
//noinspection unchecked
this.inputs.put(ingredientClass, (List<List>) (Object) expandedInputs);
}
@Override
public <T> void setOutput(Class<T> ingredientClass, T output) {
this.used = true;
IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry();
IIngredientHelper<T> ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass);
List<T> expandedOutputs = ingredientHelper.expandSubtypes(Collections.singletonList(output));
this.outputs.put(ingredientClass, expandedOutputs);
}
@Override
public <T> void setOutputs(Class<T> ingredientClass, List<T> outputs) {
this.used = true;
IngredientRegistry ingredientRegistry = Internal.getIngredientRegistry();
IIngredientHelper<T> ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass);
List<T> expandedOutputs = ingredientHelper.expandSubtypes(outputs);
this.outputs.put(ingredientClass, expandedOutputs);
}
@Override
public <T> List<List<T>> getInputs(Class<T> ingredientClass) {
//noinspection unchecked
return (List<List<T>>) (Object) this.inputs.get(ingredientClass);
}
@Override
public <T> List<T> getOutputs(Class<T> ingredientClass) {
//noinspection unchecked
return this.outputs.get(ingredientClass);
}
public Map<Class, List> getInputIngredients() {
Map<Class, List> inputIngredients = new HashMap<Class, List>();
for (Map.Entry<Class, List<List>> entry : inputs.entrySet()) {
List<Object> flatIngredients = new ArrayList<Object>();
for (List ingredients : entry.getValue()) {
flatIngredients.addAll(ingredients);
}
inputIngredients.put(entry.getKey(), flatIngredients);
}
return inputIngredients;
}
public Map<Class, List> getOutputIngredients() {
return outputs;
}
public boolean isUsed() {
return used;
}
}