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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
package gtPlusPlus.xmod.gregtech.common;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.Textures.BlockIcons;
import gregtech.api.interfaces.ITexture;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.common.GT_Proxy;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.reflect.ProxyFinder;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
public class StaticFields59 {
public static boolean mGT6StylePipes;
public static final Field mGtBlockCasings5;
public static final Field mPreventableComponents;
public static final Field mDisabledItems;
public static final Field mMultiblockChemicalRecipes;
public static final Field mDescriptionArray;
public static final Field mCasingTexturePages;
public static final Field mAssLineVisualMapNEI;
public static final GT_Recipe_Map sAssemblylineVisualRecipes;
public static final Method mCalculatePollutionReduction;
public static final Method mAddFurnaceRecipe;
private static final Map<String, Materials> mMaterialCache = new LinkedHashMap<String, Materials>();
//OrePrefixes
static {
Logger.INFO("[SH] Creating Static Helper for various fields which require reflective access.");
mGtBlockCasings5 = getField(GregTech_API.class, "sBlockCasings5");
Logger.INFO("[SH] Got Field: sBlockCasings5");
mPreventableComponents = getField(OrePrefixes.class, "mPreventableComponents");
Logger.INFO("[SH] Got Field: mPreventableComponents");
mDisabledItems = getField(OrePrefixes.class, "mDisabledItems");
Logger.INFO("[SH] Got Field: mDisabledItems");
mDescriptionArray = getField(GT_MetaTileEntity_TieredMachineBlock.class, "mDescriptionArray");
Logger.INFO("[SH] Got Field: mDescriptionArray");
mCasingTexturePages = getField(BlockIcons.class, "casingTexturePages");
Logger.INFO("[SH] Got Field: casingTexturePages");
mAssLineVisualMapNEI = getField(GT_Recipe_Map.class, "sAssemblylineVisualRecipes");
Logger.INFO("[SH] Got Field: mAssLineVisualMapNEI");
GT_Recipe_Map aTemp;
if (mAssLineVisualMapNEI != null) {
try {
aTemp = (GT_Recipe_Map) mAssLineVisualMapNEI.get(null);
Logger.INFO("[SH] Got Field: sAssemblylineVisualRecipes");
} catch (IllegalArgumentException | IllegalAccessException e) {
aTemp = null;
}
} else {
aTemp = null;
}
sAssemblylineVisualRecipes = aTemp;
mMultiblockChemicalRecipes = getField(GT_Recipe_Map.class, "sMultiblockChemicalRecipes");
Logger.INFO("[SH] Got Field: sMultiblockChemicalRecipes");
mCalculatePollutionReduction = getMethod(GT_MetaTileEntity_Hatch_Muffler.class, "calculatePollutionReduction",
int.class);
Logger.INFO("[SH] Got Method: calculatePollutionReduction");
// Yep...
if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) {
mAddFurnaceRecipe = getMethod(GT_ModHandler.class, "addSmeltingAndAlloySmeltingRecipe", ItemStack.class,
ItemStack.class);
Logger.INFO("[SH] Got Method: addSmeltingAndAlloySmeltingRecipe");
} else {
mAddFurnaceRecipe = getMethod(GT_ModHandler.class, "addSmeltingAndAlloySmeltingRecipe", ItemStack.class,
ItemStack.class, boolean.class);
Logger.INFO("[SH] Got Method: addSmeltingAndAlloySmeltingRecipe");
}
}
public static synchronized final Block getBlockCasings5() {
try {
return (Block) mGtBlockCasings5.get(GregTech_API.class);
} catch (IllegalArgumentException | IllegalAccessException e) {
return null;
}
}
public static int calculatePollutionReducation(GT_MetaTileEntity_Hatch_Muffler h, int i) {
try {
return (int) mCalculatePollutionReduction.invoke(h, i);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
return 0;
}
}
public static Field getField(Class a, String b) {
return ReflectionUtils.getField(a, b);
}
public static Method getMethod(Class a, String b, Class... params) {
return ReflectionUtils.getMethod(a, b, params);
}
public static synchronized final Collection<Materials> getOrePrefixesBooleanDisabledItems() {
try {
return (Collection<Materials>) mDisabledItems.get(OrePrefixes.class);
} catch (IllegalArgumentException | IllegalAccessException e) {
return new ArrayList<Materials>();
}
}
public static synchronized final List<OrePrefixes> geOrePrefixesBooleanPreventableComponents() {
try {
return (List<OrePrefixes>) mPreventableComponents.get(OrePrefixes.class);
} catch (IllegalArgumentException | IllegalAccessException e) {
return new ArrayList<OrePrefixes>();
}
}
public static synchronized final GT_Recipe_Map getLargeChemicalReactorRecipeMap() {
try {
return (GT_Recipe_Map) mMultiblockChemicalRecipes.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
return null;
}
}
public static Materials getMaterial(String aMaterialName) {
Materials m = mMaterialCache.get(aMaterialName);
if (m != null) {
return m;
}
else {
m = Materials.get(aMaterialName);
if (m != null) {
mMaterialCache.put(aMaterialName, m);
return m;
}
return null;
}
}
public static String[] getDescriptionArray(GT_MetaTileEntity_TieredMachineBlock aTile) {
try {
return (String[]) mDescriptionArray.get(aTile);
} catch (IllegalArgumentException | IllegalAccessException e) {
return new String[] {aTile.mDescription};
}
}
public static ITexture getCasingTexturePages(int a, int b) {
try {
ITexture[][] g = (ITexture[][]) mCasingTexturePages.get(null);
if (g != null) {
return g[a][b];
}
}
catch (Throwable t) {
}
return null;
}
public static Object getFieldFromGregtechProxy(String fieldName) {
return getFieldFromGregtechProxy(Utils.isServer() ? false : true, fieldName);
}
public static Object getFieldFromGregtechProxy(boolean client, String fieldName) {
Object proxyGT;
if (Meta_GT_Proxy.mProxies[0] != null && client) {
proxyGT = Meta_GT_Proxy.mProxies[0];
} else if (Meta_GT_Proxy.mProxies[1] != null && !client) {
proxyGT = Meta_GT_Proxy.mProxies[1];
} else {
try {
proxyGT = (client ? ProxyFinder.getClientProxy(GT_Mod.instance)
: ProxyFinder.getServerProxy(GT_Mod.instance));
} catch (final ReflectiveOperationException e1) {
proxyGT = null;
Logger.INFO("Failed to obtain instance of GT " + (client ? "Client" : "Server") + " proxy.");
}
if (Meta_GT_Proxy.mProxies[0] == null && client) {
Meta_GT_Proxy.mProxies[0] = (GT_Proxy) proxyGT;
} else if (Meta_GT_Proxy.mProxies[1] == null && !client) {
Meta_GT_Proxy.mProxies[1] = (GT_Proxy) proxyGT;
}
}
if (proxyGT != null && proxyGT instanceof GT_Proxy) {
try {
return ReflectionUtils.getField(proxyGT.getClass(), fieldName).get(proxyGT);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
}
return null;
}
}
|