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
455
456
457
458
459
460
461
462
463
464
465
466
467
|
package gtPlusPlus.xmod.gregtech.api.util;
import static gregtech.api.enums.GT_Values.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import gregtech.api.GregTech_API;
import gregtech.api.enums.*;
import gregtech.api.objects.GT_HashSet;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.util.*;
import gregtech.common.GT_Proxy.OreDictEventContainer;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
import gtPlusPlus.xmod.gregtech.api.objects.GregtechItemData;
import gtPlusPlus.xmod.gregtech.api.objects.GregtechMaterialStack;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
* This is the Core of my OreDict Unification Code
* <p/>
* If you just want to use this to unificate your Items, then use the Function in the GregTech_API File
* <p/>
* P.S. It is intended to be named "Unificator" and not "Unifier", because that sounds more awesome.
*/
public class GregtechOreDictUnificator {
private static final HashMap<String, ItemStack> sName2StackMap = new HashMap<>();
private static final HashMap<GT_ItemStack, GregtechItemData> sItemStack2DataMap = new HashMap<>();
private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<>();
public static volatile int VERSION = 508;
private static int isRegisteringOre = 0, isAddingOre = 0;
private static boolean mRunThroughTheList = true;
static {
GregTech_API.sItemStackMappings.add(sItemStack2DataMap);
}
/**
* The Blacklist just prevents the Item from being unificated into something else.
* Useful if you have things like the Industrial Diamond, which is better than regular Diamond, but also usable in absolutely all Diamond Recipes.
*/
public static void addToBlacklist(final ItemStack aStack) {
if (GT_Utility.isStackValid(aStack) && !GT_Utility.isStackInList(aStack, sNoUnificationList)) {
sNoUnificationList.add(aStack);
}
}
public static boolean isBlacklisted(final ItemStack aStack) {
return GT_Utility.isStackInList(aStack, sNoUnificationList);
}
public static void add(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack) {
set(aPrefix, aMaterial, aStack, false, false);
}
public static void set(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack) {
set(aPrefix, aMaterial, aStack, true, false);
}
public static void set(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, ItemStack aStack, final boolean aOverwrite, final boolean aAlreadyRegistered) {
if ((aMaterial == null) || (aPrefix == null) || GT_Utility.isStackInvalid(aStack) || (Items.feather.getDamage(aStack) == W)) {
return;
}
isAddingOre++;
aStack = GT_Utility.copyAmount(1, aStack);
if (!aAlreadyRegistered) {
registerOre(aPrefix.get(aMaterial), aStack);
}
addAssociation(aPrefix, aMaterial, aStack, isBlacklisted(aStack));
if (aOverwrite || GT_Utility.isStackInvalid(sName2StackMap.get(aPrefix.get(aMaterial).toString()))) {
sName2StackMap.put(aPrefix.get(aMaterial).toString(), aStack);
}
isAddingOre--;
}
public static ItemStack getFirstOre(final Object aName, final long aAmount) {
if (GT_Utility.isStringInvalid(aName)) {
return null;
}
final ItemStack tStack = sName2StackMap.get(aName.toString());
if (GT_Utility.isStackValid(tStack)) {
return GT_Utility.copyAmount(aAmount, tStack);
}
return GT_Utility.copyAmount(aAmount, getOres(aName).toArray());
}
public static ItemStack get(final Object aName, final long aAmount) {
return get(aName, null, aAmount, true, true);
}
public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount) {
return get(aName, aReplacement, aAmount, true, true);
}
public static ItemStack get(final GregtechOrePrefixes aPrefix, final Object aMaterial, final long aAmount) {
return get(aPrefix, aMaterial, null, aAmount);
}
public static ItemStack get(final GregtechOrePrefixes aPrefix, final Object aMaterial, final ItemStack aReplacement, final long aAmount) {
return get(aPrefix.get(aMaterial), aReplacement, aAmount, false, true);
}
public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount, final boolean aMentionPossibleTypos, final boolean aNoInvalidAmounts) {
if (aNoInvalidAmounts && (aAmount < 1)) {
return null;
}
if (!sName2StackMap.containsKey(aName.toString()) && aMentionPossibleTypos) {
GT_Log.err.println("Unknown Key for Unification, Typo? " + aName);
}
return GT_Utility.copyAmount(aAmount, sName2StackMap.get(aName.toString()), getFirstOre(aName, aAmount), aReplacement);
}
public static ItemStack[] setStackArray(final boolean aUseBlackList, final ItemStack... aStacks) {
for (int i = 0; i < aStacks.length; i++) {
aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i]));
}
return aStacks;
}
public static ItemStack[] getStackArray(final boolean aUseBlackList, final Object... aStacks) {
final ItemStack[] rStacks = new ItemStack[aStacks.length];
for (int i = 0; i < aStacks.length; i++) {
rStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i]));
}
return rStacks;
}
public static ItemStack setStack(final ItemStack aStack) {
return setStack(true, aStack);
}
public static ItemStack setStack(final boolean aUseBlackList, final ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) {
return aStack;
}
final ItemStack tStack = get(aUseBlackList, aStack);
if (GT_Utility.areStacksEqual(aStack, tStack)) {
return aStack;
}
aStack.func_150996_a(tStack.getItem());
Items.feather.setDamage(aStack, Items.feather.getDamage(tStack));
return aStack;
}
public static ItemStack get(final ItemStack aStack) {
return get(true, aStack);
}
public static ItemStack get(final boolean aUseBlackList, final ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) {
return null;
}
final GregtechItemData tPrefixMaterial = getAssociation(aStack);
ItemStack rStack = null;
if ((tPrefixMaterial == null) || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed)) {
return GT_Utility.copy(aStack);
}
if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) {
tPrefixMaterial.mBlackListed = true;
return GT_Utility.copy(aStack);
}
if (tPrefixMaterial.mUnificationTarget == null) {
tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString());
}
rStack = tPrefixMaterial.mUnificationTarget;
if (GT_Utility.isStackInvalid(rStack)) {
return GT_Utility.copy(aStack);
}
assert rStack != null;
rStack.setTagCompound(aStack.getTagCompound());
return GT_Utility.copyAmount(aStack.stackSize, rStack);
}
public static void addItemData(final ItemStack aStack, final GregtechItemData aData) {
if (GT_Utility.isStackValid(aStack) && (getItemData(aStack) == null) && (aData != null)) {
setItemData(aStack, aData);
}
}
public static void setItemData(ItemStack aStack, final GregtechItemData aData) {
if (GT_Utility.isStackInvalid(aStack) || (aData == null)) {
return;
}
final GregtechItemData tData = getItemData(aStack);
if ((tData == null) || !tData.hasValidPrefixMaterialData()) {
if (tData != null) {
for (final Object tObject : tData.mExtraData) {
if (!aData.mExtraData.contains(tObject)) {
aData.mExtraData.add(tObject);
}
}
}
if (aStack.stackSize > 1) {
if (aData.mMaterial != null) {
aData.mMaterial.mAmount /= aStack.stackSize;
}
for (final GregtechMaterialStack tMaterial : aData.mByProducts) {
tMaterial.mAmount /= aStack.stackSize;
}
aStack = GT_Utility.copyAmount(1, aStack);
}
sItemStack2DataMap.put(new GT_ItemStack(aStack), aData);
if (aData.hasValidMaterialData()) {
long tValidMaterialAmount = aData.mMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : aData.mMaterial.mAmount >= 0 ? aData.mMaterial.mAmount : M;
for (final GregtechMaterialStack tMaterial : aData.mByProducts) {
tValidMaterialAmount += tMaterial.mMaterial.contains(SubTag.NO_RECYCLING) ? 0 : tMaterial.mAmount >= 0 ? tMaterial.mAmount : M;
}
if (tValidMaterialAmount < M) {
GT_ModHandler.addToRecyclerBlackList(aStack);
}
}
if (mRunThroughTheList) {
if (GregTech_API.sLoadStarted) {
mRunThroughTheList = false;
for (final Entry<GT_ItemStack, GregtechItemData> tEntry : sItemStack2DataMap.entrySet()) {
if (!tEntry.getValue().hasValidPrefixData() || tEntry.getValue().mPrefix.mAllowNormalRecycling) {
GregtechRecipeRegistrator.registerMaterialRecycling(tEntry.getKey().toStack(), tEntry.getValue());
}
}
}
} else {
if (!aData.hasValidPrefixData() || aData.mPrefix.mAllowNormalRecycling) {
GregtechRecipeRegistrator.registerMaterialRecycling(aStack, aData);
}
}
} else {
for (final Object tObject : aData.mExtraData) {
if (!tData.mExtraData.contains(tObject)) {
tData.mExtraData.add(tObject);
}
}
}
}
public static void addAssociation(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final ItemStack aStack, final boolean aBlackListed) {
if ((aPrefix == null) || (aMaterial == null) || GT_Utility.isStackInvalid(aStack)) {
return;
}
if (Items.feather.getDamage(aStack) == W) {
for (byte i = 0; i < 16; i++) {
setItemData(GT_Utility.copyAmountAndMetaData(1, i, aStack), new GregtechItemData(aPrefix, aMaterial, aBlackListed));
}
}
setItemData(aStack, new GregtechItemData(aPrefix, aMaterial, aBlackListed));
}
public static GregtechItemData getItemData(final ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) {
return null;
}
GregtechItemData rData = sItemStack2DataMap.get(new GT_ItemStack(aStack));
if (rData == null) {
rData = sItemStack2DataMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack)));
}
return rData;
}
public static GregtechItemData getAssociation(final ItemStack aStack) {
final GregtechItemData rData = getItemData(aStack);
return (rData != null) && rData.hasValidPrefixMaterialData() ? rData : null;
}
public static boolean isItemStackInstanceOf(final ItemStack aStack, final Object aName) {
if (GT_Utility.isStringInvalid(aName) || GT_Utility.isStackInvalid(aStack)) {
return false;
}
for (final ItemStack tOreStack : getOres(aName.toString())) {
if (GT_Utility.areStacksEqual(tOreStack, aStack, true)) {
return true;
}
}
return false;
}
public static boolean isItemStackDye(final ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) {
return false;
}
for (final Dyes tDye : Dyes.VALUES) {
if (isItemStackInstanceOf(aStack, tDye.toString())) {
return true;
}
}
return false;
}
public static boolean registerOre(final GregtechOrePrefixes aPrefix, final Object aMaterial, final ItemStack aStack) {
return registerOre(aPrefix.get(aMaterial), aStack);
}
public static boolean registerOre(final Object aName, final ItemStack aStack) {
if ((aName == null) || GT_Utility.isStackInvalid(aStack)) {
return false;
}
final String tName = aName.toString();
if (GT_Utility.isStringInvalid(tName)) {
return false;
}
final ArrayList<ItemStack> tList = getOres(tName);
for (int i = 0; i < tList.size(); i++) {
if (GT_Utility.areStacksEqual(tList.get(i), aStack, true)) {
return false;
}
}
isRegisteringOre++;
OreDictionary.registerOre(tName, GT_Utility.copyAmount(1, aStack));
isRegisteringOre--;
return true;
}
public static boolean isRegisteringOres() {
return isRegisteringOre > 0;
}
public static boolean isAddingOres() {
return isAddingOre > 0;
}
public static void resetUnificationEntries() {
for (final GregtechItemData tPrefixMaterial : sItemStack2DataMap.values()) {
tPrefixMaterial.mUnificationTarget = null;
}
}
public static ItemStack getGem(final GregtechMaterialStack aMaterial) {
return aMaterial == null ? null : getGem(aMaterial.mMaterial, aMaterial.mAmount);
}
public static ItemStack getGem(final GT_Materials aMaterial, final OrePrefixes aPrefix) {
return aMaterial == null ? null : getGem(aMaterial, aPrefix.mMaterialAmount);
}
public static ItemStack getGem(final GT_Materials aMaterial, final long aMaterialAmount) {
ItemStack rStack = null;
if (((aMaterialAmount >= M) || (aMaterialAmount >= (M * 32)))) {
rStack = get(GregtechOrePrefixes.gem, aMaterial, aMaterialAmount / M);
}
if ((rStack == null) && ((((aMaterialAmount * 2) % M) == 0) || (aMaterialAmount >= (M * 16)))) {
rStack = get(GregtechOrePrefixes.gemFlawed, aMaterial, (aMaterialAmount * 2) / M);
}
if ((rStack == null) && (((aMaterialAmount * 4) >= M))) {
rStack = get(GregtechOrePrefixes.gemChipped, aMaterial, (aMaterialAmount * 4) / M);
}
return rStack;
}
public static ItemStack getDust(final GregtechMaterialStack aMaterial) {
return aMaterial == null ? null : getDust(aMaterial.mMaterial, aMaterial.mAmount);
}
public static ItemStack getDust(final GT_Materials aMaterial, final OrePrefixes aPrefix) {
return aMaterial == null ? null : getDust(aMaterial, aPrefix.mMaterialAmount);
}
public static ItemStack getDust(final GT_Materials aMaterial, final long aMaterialAmount) {
if (aMaterialAmount <= 0) {
return null;
}
ItemStack rStack = null;
if ((((aMaterialAmount % M) == 0) || (aMaterialAmount >= (M * 16)))) {
rStack = get(GregtechOrePrefixes.dust, aMaterial, aMaterialAmount / M);
}
if ((rStack == null) && ((((aMaterialAmount * 4) % M) == 0) || (aMaterialAmount >= (M * 8)))) {
rStack = get(GregtechOrePrefixes.dustSmall, aMaterial, (aMaterialAmount * 4) / M);
}
if ((rStack == null) && (((aMaterialAmount * 9) >= M))) {
rStack = get(GregtechOrePrefixes.dustTiny, aMaterial, (aMaterialAmount * 9) / M);
}
return rStack;
}
public static ItemStack getIngot(final GregtechMaterialStack aMaterial) {
return aMaterial == null ? null : getIngot(aMaterial.mMaterial, aMaterial.mAmount);
}
public static ItemStack getIngot(final GT_Materials aMaterial, final OrePrefixes aPrefix) {
return aMaterial == null ? null : getIngot(aMaterial, aPrefix.mMaterialAmount);
}
public static ItemStack getIngot(final GT_Materials aMaterial, final long aMaterialAmount) {
if (aMaterialAmount <= 0) {
return null;
}
ItemStack rStack = null;
if (((((aMaterialAmount % (M * 9)) == 0) && ((aMaterialAmount / (M * 9)) > 1)) || (aMaterialAmount >= (M * 72)))) {
rStack = get(GregtechOrePrefixes.block, aMaterial, aMaterialAmount / (M * 9));
}
if ((rStack == null) && (((aMaterialAmount % M) == 0) || (aMaterialAmount >= (M * 8)))) {
rStack = get(GregtechOrePrefixes.ingot, aMaterial, aMaterialAmount / M);
}
if ((rStack == null) && (((aMaterialAmount * 9) >= M))) {
rStack = get(GregtechOrePrefixes.nugget, aMaterial, (aMaterialAmount * 9) / M);
}
return rStack;
}
public static ItemStack getIngotOrDust(final GT_Materials aMaterial, final long aMaterialAmount) {
if (aMaterialAmount <= 0) {
return null;
}
ItemStack rStack = getIngot(aMaterial, aMaterialAmount);
if (rStack == null) {
rStack = getDust(aMaterial, aMaterialAmount);
}
return rStack;
}
public static ItemStack getIngotOrDust(final GregtechMaterialStack aMaterial) {
ItemStack rStack = getIngot(aMaterial);
if((aMaterial!=null)&&(aMaterial.mMaterial!=null)) {
rStack = getDust(aMaterial);
}
if (rStack == null) {
rStack = getDust(aMaterial);
}
return rStack;
}
public static ItemStack getDustOrIngot(final GT_Materials aMaterial, final long aMaterialAmount) {
if (aMaterialAmount <= 0) {
return null;
}
ItemStack rStack = getDust(aMaterial, aMaterialAmount);
if (rStack == null) {
rStack = getIngot(aMaterial, aMaterialAmount);
}
return rStack;
}
public static ItemStack getDustOrIngot(final GregtechMaterialStack aMaterial) {
ItemStack rStack = getDust(aMaterial);
if (rStack == null) {
rStack = getIngot(aMaterial);
}
return rStack;
}
/**
* @return a Copy of the OreDictionary.getOres() List
*/
public static ArrayList<ItemStack> getOres(final OrePrefixes aPrefix, final Object aMaterial) {
return getOres(aPrefix.get(aMaterial));
}
/**
* @return a Copy of the OreDictionary.getOres() List
*/
public static ArrayList<ItemStack> getOres(final Object aOreName) {
final String aName = aOreName == null ? E : aOreName.toString();
final ArrayList<ItemStack> rList = new ArrayList<>();
if (GT_Utility.isStringValid(aName)) {
rList.addAll(OreDictionary.getOres(aName));
}
return rList;
}
public static void registerRecipes(final OreDictEventContainer tOre) {
// TODO Auto-generated method stub
}
}
|