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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
package gtPlusPlus.xmod.thaumcraft.util;
import static gtPlusPlus.xmod.thaumcraft.HANDLER_Thaumcraft.sItemsToGetAspects;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ConfigCategories;
import gregtech.api.enums.TC_Aspects;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.thaumcraft.HANDLER_Thaumcraft;
import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_AspectStack;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_AspectList_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.aspect.TC_Aspect_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_CrucibleRecipe_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_IArcaneRecipe_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionEnchantmentRecipe_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.recipe.TC_InfusionRecipe_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchCategories_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchCategoryList_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchItem_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchNoteData_Wrapper;
import gtPlusPlus.xmod.thaumcraft.objects.wrapper.research.TC_ResearchPage_Wrapper;
public class ThaumcraftUtils {
private static Class<?> mClass_Aspect;
private static Field mField_Aspects;
static {
mClass_Aspect = ReflectionUtils.getClass("thaumcraft.api.aspects.Aspect");
if (mClass_Aspect != null) {
Field aTagF = ReflectionUtils.getField(mClass_Aspect, "tag");
if (aTagF != null) {
mField_Aspects = aTagF;
}
}
}
public static boolean addAspectToItem(ItemStack item, TC_Aspect_Wrapper aspect, int amount) {
return addAspectToItem(item, new TC_Aspect_Wrapper[] { aspect }, new Integer[] { amount });
}
public static boolean addAspectToItem(ItemStack item, TC_Aspect_Wrapper[] aspect, Integer[] amounts) {
GTPP_AspectStack[] aspects = new GTPP_AspectStack[aspect.length];
for (int g = 0; g < aspect.length; g++) {
if (amounts[g] != null && amounts[g] > 0) {
// aspects[g] = new GTPP_AspectStack(aspect[g], amounts[g]);
}
}
Pair<ItemStack, GTPP_AspectStack[]> k = new Pair<ItemStack, GTPP_AspectStack[]>(item, aspects);
int mSizeA = sItemsToGetAspects.size();
sItemsToGetAspects.put(k);
if (sItemsToGetAspects.size() > mSizeA) {
Logger.MATERIALS("[Aspect] Successfully queued an ItemStack for Aspect addition.");
return true;
}
Logger.MATERIALS("[Aspect] Failed to queue an ItemStack for Aspect addition.");
// Logger.INFO("[Aspect] ");
return false;
}
public static TC_Aspect_Wrapper getAspect(String name) {
return TC_Aspect_Wrapper.getAspect(name);
}
public static TC_Aspects getEnumAspect(String name) {
TC_Aspect_Wrapper r = getAspect(name);
return r.mGtEnumField;
}
public static Object addResearch(String aResearch, String aName, String aText, String[] aParentResearches,
String aCategory, ItemStack aIcon, int aComplexity, int aType, int aX, int aY,
List<GTPP_AspectStack> aAspects, ItemStack[] aResearchTriggers, Object[] aPages) {
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) {
return null;
}
TC_ResearchCategoryList_Wrapper tCategory = TC_ResearchCategories_Wrapper.getResearchList(aCategory);
if (tCategory == null) {
return null;
}
for (Iterator<TC_ResearchItem_Wrapper> i$ = tCategory.research.values().iterator(); i$.hasNext();) {
TC_ResearchItem_Wrapper tResearch = (TC_ResearchItem_Wrapper) i$.next();
if ((tResearch.displayColumn == aX) && (tResearch.displayRow == aY)) {
aX += (aX > 0 ? 5 : -5);
aY += (aY > 0 ? 5 : -5);
}
}
TC_ResearchItem_Wrapper rResearch = new TC_ResearchItem_Wrapper(
aResearch,
aCategory,
getAspectList_Ex(aAspects),
aX,
aY,
aComplexity,
aIcon);
ArrayList<Object> tPages = new ArrayList<Object>(aPages.length);
GT_LanguageManager.addStringLocalization("tc.research_name." + aResearch, aName);
GT_LanguageManager.addStringLocalization("tc.research_text." + aResearch, "[GT++] " + aText);
for (Object tPage : aPages) {
if ((tPage instanceof String)) {
tPages.add(new TC_ResearchPage_Wrapper((String) tPage));
} else if ((tPage instanceof IRecipe)) {
tPages.add(new TC_ResearchPage_Wrapper((IRecipe) tPage));
} else if ((tPage instanceof TC_IArcaneRecipe_Wrapper)) {
tPages.add(new TC_ResearchPage_Wrapper((TC_IArcaneRecipe_Wrapper) tPage));
} else if ((tPage instanceof TC_CrucibleRecipe_Wrapper)) {
tPages.add(new TC_ResearchPage_Wrapper((TC_CrucibleRecipe_Wrapper) tPage));
} else if ((tPage instanceof TC_InfusionRecipe_Wrapper)) {
tPages.add(new TC_ResearchPage_Wrapper((TC_InfusionRecipe_Wrapper) tPage));
} else if ((tPage instanceof TC_InfusionEnchantmentRecipe_Wrapper)) {
tPages.add(new TC_ResearchPage_Wrapper((TC_InfusionEnchantmentRecipe_Wrapper) tPage));
}
}
if ((aType & 0x40) != 0) {
rResearch.setAutoUnlock();
}
if ((aType & 0x1) != 0) {
rResearch.setSecondary();
}
if ((aType & 0x20) != 0) {
rResearch.setSpecial();
}
if ((aType & 0x8) != 0) {
rResearch.setVirtual();
}
if ((aType & 0x4) != 0) {
rResearch.setHidden();
}
if ((aType & 0x10) != 0) {
rResearch.setRound();
}
if ((aType & 0x2) != 0) {
rResearch.setStub();
}
if (aParentResearches != null) {
ArrayList<String> tParentResearches = new ArrayList<String>();
for (String tParent : aParentResearches) {
if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.researches, aResearch, true)) {
tParentResearches.add(tParent);
}
}
if (tParentResearches.size() > 0) {
rResearch.setParents((String[]) tParentResearches.toArray(new String[tParentResearches.size()]));
rResearch.setConcealed();
}
}
if (aResearchTriggers != null) {
rResearch.setItemTriggers(aResearchTriggers);
rResearch.setHidden();
}
Object[] aVarArgs = (TC_ResearchPage_Wrapper[]) tPages.toArray(new TC_ResearchPage_Wrapper[tPages.size()]);
rResearch.setPages(aVarArgs);
return rResearch.registerResearchItem();
}
public static Object addCrucibleRecipe(final String aResearch, final Object aInput, final ItemStack aOutput,
final List<GTPP_AspectStack> aAspects) {
if (GT_Utility.isStringInvalid((Object) aResearch) || aInput == null
|| aOutput == null
|| aAspects == null
|| aAspects.isEmpty()) {
return null;
}
return addCrucibleRecipe(
aResearch,
GT_Utility.copy(new Object[] { aOutput }),
(aInput instanceof ItemStack || aInput instanceof ArrayList) ? aInput : aInput.toString(),
getAspectList_Ex(aAspects));
}
public static Object addInfusionRecipe(final String aResearch, final ItemStack aMainInput,
final ItemStack[] aSideInputs, final ItemStack aOutput, final int aInstability,
final List<GTPP_AspectStack> aAspects) {
if (GT_Utility.isStringInvalid((Object) aResearch) || aMainInput == null
|| aSideInputs == null
|| aOutput == null
|| aAspects == null
|| aAspects.isEmpty()) {
return null;
}
return addInfusionCraftingRecipe(
aResearch,
(Object) GT_Utility.copy(new Object[] { aOutput }),
aInstability,
getAspectList_Ex(aAspects),
aMainInput,
aSideInputs);
}
public static boolean registerThaumcraftAspectsToItem(final ItemStack aExampleStack,
final List<GTPP_AspectStack> aAspects, final String aOreDict) {
if (aAspects.isEmpty()) {
return false;
}
registerObjectTag(aOreDict, getAspectList_Ex(aAspects));
return true;
}
public static boolean registerThaumcraftAspectsToItem(final ItemStack aStack, final List<GTPP_AspectStack> aAspects,
final boolean aAdditive) {
try {
if (aAspects.isEmpty()) {
return false;
}
TC_AspectList_Wrapper h = getAspectList_Ex(aAspects);
if (aAdditive && (h != null && h.size() > 0)) {
registerComplexObjectTag(aStack, getAspectList_Ex(aAspects));
return true;
} else {
Logger.MATERIALS("[Aspect] Failed adding aspects to " + aStack.getDisplayName() + ".");
}
final TC_AspectList_Wrapper tAlreadyRegisteredAspects = getObjectAspects(aStack);
if (tAlreadyRegisteredAspects == null || tAlreadyRegisteredAspects.size() <= 0) {
registerObjectTag(aStack, getAspectList_Ex(aAspects));
}
return true;
} catch (Throwable t) {
Logger.MATERIALS("[Aspect] Failed adding aspects to " + aStack.getDisplayName() + ".");
t.printStackTrace();
return false;
}
}
private static final Class<?> mClass_ThaumcraftApi;
private static final Class<?> mClass_ThaumcraftApiHelper;
private static final Class<?> mClass_AspectList;
private static final Class<?> mClass_ResearchManager;
private static final Method mMethod_registerObjectTag1;
private static final Method mMethod_registerObjectTag2;
private static final Method mMethod_registerComplexObjectTag;
private static final Method mMethod_addInfusionCraftingRecipe;
private static final Method mMethod_addCrucibleRecipe;
private static final Method mMethod_getObjectAspects;
private static final Method mMethod_updateData;
private static final Method mMethod_getData;
private static final Field mField_PortholeBlacklist;
static {
/*
* Classes
*/
mClass_ThaumcraftApi = ReflectionUtils.getClass("thaumcraft.api.ThaumcraftApi");
mClass_ThaumcraftApiHelper = ReflectionUtils.getClass("thaumcraft.api.ThaumcraftApiHelper");
mClass_AspectList = ReflectionUtils.getClass("thaumcraft.api.aspects.AspectList");
mClass_ResearchManager = ReflectionUtils.getClass("thaumcraft.common.lib.research.ResearchManager");
/*
* Methods
*/
mMethod_registerObjectTag1 = ReflectionUtils
.getMethod(mClass_ThaumcraftApi, "registerObjectTag", ItemStack.class, mClass_AspectList);
mMethod_registerObjectTag2 = ReflectionUtils
.getMethod(mClass_ThaumcraftApi, "registerObjectTag", String.class, mClass_AspectList);
mMethod_registerComplexObjectTag = ReflectionUtils
.getMethod(mClass_ThaumcraftApi, "registerComplexObjectTag", ItemStack.class, mClass_AspectList);
mMethod_addInfusionCraftingRecipe = ReflectionUtils.getMethod(
mClass_ThaumcraftApi,
"addInfusionCraftingRecipe",
String.class,
Object.class,
int.class,
mClass_AspectList,
ItemStack.class,
ItemStack[].class);
mMethod_addCrucibleRecipe = ReflectionUtils.getMethod(
mClass_ThaumcraftApi,
"addCrucibleRecipe",
String.class,
ItemStack.class,
Object.class,
mClass_AspectList);
mMethod_getObjectAspects = ReflectionUtils
.getMethod(mClass_ThaumcraftApiHelper, "getObjectAspects", ItemStack.class);
mMethod_updateData = ReflectionUtils.getMethod(
mClass_ResearchManager,
"updateData",
ItemStack.class,
ReflectionUtils.getClass("thaumcraft.common.lib.research.ResearchNoteData"));
mMethod_getData = ReflectionUtils.getMethod(mClass_ResearchManager, "getData", ItemStack.class);
/*
* Fields
*/
mField_PortholeBlacklist = ReflectionUtils.getField(mClass_ThaumcraftApi, "portableHoleBlackList");
}
public static void registerObjectTag(ItemStack aStack, TC_AspectList_Wrapper aAspectList) {
try {
mMethod_registerObjectTag1.invoke(null, aStack, aAspectList.getVanillaAspectList());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static void registerObjectTag(String aOreDict, TC_AspectList_Wrapper aAspectList) {
try {
mMethod_registerObjectTag2.invoke(null, aOreDict, aAspectList.getVanillaAspectList());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static void registerComplexObjectTag(ItemStack aStack, TC_AspectList_Wrapper aAspectList) {
try {
mMethod_registerComplexObjectTag.invoke(null, aStack, aAspectList.getVanillaAspectList());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static TC_AspectList_Wrapper getObjectAspects(ItemStack aStack) {
try {
return new TC_AspectList_Wrapper(mMethod_getObjectAspects.invoke(null, aStack));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public static Object addCrucibleRecipe(String aResearch, ItemStack copy, Object aOutput,
TC_AspectList_Wrapper aAspectList) {
try {
return mMethod_addCrucibleRecipe.invoke(null, aResearch, copy, aOutput, aAspectList);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public static Object addInfusionCraftingRecipe(String aResearch, Object copy, int aInstability,
TC_AspectList_Wrapper aAspectList, ItemStack aMainInput, ItemStack[] aSideInputs) {
try {
return mMethod_addInfusionCraftingRecipe
.invoke(null, aResearch, copy, aInstability, aAspectList, aMainInput, aSideInputs);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public static boolean registerPortholeBlacklistedBlock(final Block aBlock) {
try {
((ArrayList<Block>) mField_PortholeBlacklist.get(null)).add(aBlock);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
return false;
}
return true;
}
public static String getTagFromAspectObject(Object aAspect) {
try {
if (mClass_Aspect == null || mField_Aspects == null) {
return null;
}
String aTafB = (String) mField_Aspects.get(aAspect);
if (aTafB == null) {
return null;
}
String aTag = aTafB.toLowerCase();
return aTag;
} catch (IllegalArgumentException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}
public static void updateResearchNote(ItemStack a, TC_ResearchNoteData_Wrapper b) {
// updateData(a, b.getResearchNoteData());
try {
mMethod_updateData.invoke(a, b.getResearchNoteData());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static Object getResearchNoteData(ItemStack a) {
// getData(a);
try {
return mMethod_getData.invoke(a);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public static boolean isItemResearchNotes(ItemStack aStack) {
if (aStack != null && aStack.getItem() == HANDLER_Thaumcraft.mResearchNotes
&& HANDLER_Thaumcraft.mResearchNotes.getClass().isInstance(aStack.getItem())) {
return true;
}
return false;
}
public static boolean isItemStackValidResearchNotes(ItemStack aStack) {
if (isItemResearchNotes(aStack) && aStack.getItemDamage() < 64) {
return true;
}
return false;
}
public static TC_ResearchNoteData_Wrapper gatherResults(ItemStack note) {
TC_ResearchNoteData_Wrapper research = null;
if (isItemResearchNotes(note)) {
research = new TC_ResearchNoteData_Wrapper(getResearchNoteData(note));
}
return research;
}
public static void completeResearchNote(World aWorld, ItemStack aStack) {
if (!aWorld.isRemote) {
if (isItemResearchNotes(aStack)) {
aStack.setItemDamage(64);
}
}
}
public static final synchronized TC_AspectList_Wrapper getAspectList_Ex(final List<GTPP_AspectStack> aAspects) {
final TC_AspectList_Wrapper rAspects = new TC_AspectList_Wrapper();
for (final GTPP_AspectStack tAspect : aAspects) {
rAspects.add(tAspect.mAspect, tAspect.mAmount);
}
return rAspects;
}
public static void addResearch(TC_ResearchItem_Wrapper tc_ResearchItem_Wrapper) {
// TODO Auto-generated method stub
}
}
|