forked from Towdium/JustEnoughCalculation
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Adapter.java
107 lines (97 loc) · 4.03 KB
/
Adapter.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
package me.towdium.jecalculation.nei;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import cpw.mods.fml.common.Loader;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.nei.adapter.AE2;
import me.towdium.jecalculation.nei.adapter.Avaritia;
import me.towdium.jecalculation.nei.adapter.EnderIO;
import me.towdium.jecalculation.nei.adapter.Forestry;
import me.towdium.jecalculation.nei.adapter.GTPP;
import me.towdium.jecalculation.nei.adapter.GregTech;
import me.towdium.jecalculation.nei.adapter.GregTech6;
import me.towdium.jecalculation.nei.adapter.IAdapter;
import me.towdium.jecalculation.nei.adapter.Thaum;
import me.towdium.jecalculation.utils.Utilities;
public class Adapter {
public static List<IAdapter> adapters = new ArrayList<>();
public static Object convertFluid(ItemStack itemStack) {
String name = Utilities.getName(itemStack);
String modId = name.substring(0, name.indexOf(":"));
String itemId = name.substring(name.indexOf(":") + 1);
if (Loader.isModLoaded("gregtech")) {
if (GregTech6.isGT6()) {
return GregTech6.convertFluid(itemStack);
} else {
return GregTech.convertFluid(itemStack);
}
}
return itemStack;
}
public static void init() {
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Start=====");
if (Loader.isModLoaded("Forestry")) {
JustEnoughCalculation.logger.info("Forestry detected");
adapters.add(new Forestry());
}
if (Loader.isModLoaded("appliedenergistics2")) {
JustEnoughCalculation.logger.info("ae2 detected");
adapters.add(new AE2());
}
if (Loader.isModLoaded("gregtech")) {
if (GregTech6.isGT6()) {
JustEnoughCalculation.logger.info("gregtech6 detected");
adapters.add(new GregTech6());
} else {
JustEnoughCalculation.logger.info("gregtech5 detected");
adapters.add(new GregTech());
}
}
try {
if (Loader.isModLoaded("miscutils")) {
adapters.add(new GTPP());
JustEnoughCalculation.logger.info("gt++ detected");
}
} catch (Exception e) {
JustEnoughCalculation.logger.error("Init error with gt++");
e.printStackTrace();
}
if (Loader.isModLoaded("Avaritia")) {
JustEnoughCalculation.logger.info("Avaritia detected");
adapters.add(new Avaritia());
}
if (Loader.isModLoaded("EnderIO")) {
JustEnoughCalculation.logger.info("EnderIO detected");
adapters.add(new EnderIO());
}
if (Loader.isModLoaded("thaumcraftneiplugin")) {
adapters.add(new Thaum());
JustEnoughCalculation.logger.info("Thaumcraft detected");
}
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Finish=====");
}
public static void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
// raw inputs
recipe.getIngredientStacks(index)
.stream()
.map((positionedStack) -> (Object[]) positionedStack.items)
.forEach(inputs::add);
// raw outputs
PositionedStack resultStack = recipe.getResultStack(index);
if (resultStack != null) outputs.add(resultStack.items);
try {
for (IAdapter adapter : adapters) {
adapter.handleRecipe(recipe, index, inputs, outputs);
}
} catch (Exception e) {
Utilities.addChatMessage(Utilities.ChatMessage.RECIPE_TRANSFER_ERROR);
JustEnoughCalculation.logger.error(
"Exception when handling recipe: " + recipe.getClass()
.getName());
e.printStackTrace();
}
}
}