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
|
package gtPlusPlus.xmod.gregtech.api.objects;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import gregtech.api.objects.GTArrayList;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
public class GregtechItemData {
private static final GregtechMaterialStack[] EMPTY_GT_MaterialStack_ARRAY = new GregtechMaterialStack[0];
public final List<Object> mExtraData = new GTArrayList<>(false, 1);
public final GregtechOrePrefixes mPrefix;
public final GregtechMaterialStack mMaterial;
public final GregtechMaterialStack[] mByProducts;
public boolean mBlackListed = false;
public ItemStack mUnificationTarget = null;
public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial,
final boolean aBlackListed) {
this.mPrefix = aPrefix;
this.mMaterial = aMaterial == null ? null : new GregtechMaterialStack(aMaterial, aPrefix.mMaterialAmount);
this.mBlackListed = aBlackListed;
this.mByProducts = (aPrefix.mSecondaryMaterial == null) || (aPrefix.mSecondaryMaterial.mMaterial == null)
? EMPTY_GT_MaterialStack_ARRAY
: new GregtechMaterialStack[] { aPrefix.mSecondaryMaterial.clone() };
}
public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial) {
this(aPrefix, aMaterial, false);
}
public GregtechItemData(final GregtechMaterialStack aMaterial, final GregtechMaterialStack... aByProducts) {
this.mPrefix = null;
this.mMaterial = aMaterial.mMaterial == null ? null : aMaterial.clone();
this.mBlackListed = true;
if (aByProducts == null) {
this.mByProducts = EMPTY_GT_MaterialStack_ARRAY;
} else {
final GregtechMaterialStack[] tByProducts = aByProducts.length < 1 ? EMPTY_GT_MaterialStack_ARRAY
: new GregtechMaterialStack[aByProducts.length];
int j = 0;
for (GregtechMaterialStack aByProduct : aByProducts) {
if ((aByProduct != null) && (aByProduct.mMaterial != null)) {
tByProducts[j++] = aByProduct.clone();
}
}
this.mByProducts = j > 0 ? new GregtechMaterialStack[j] : EMPTY_GT_MaterialStack_ARRAY;
for (int i = 0; i < this.mByProducts.length; i++) {
this.mByProducts[i] = tByProducts[i];
}
}
}
public GregtechItemData(final GT_Materials aMaterial, final long aAmount,
final GregtechMaterialStack... aByProducts) {
this(new GregtechMaterialStack(aMaterial, aAmount), aByProducts);
}
public GregtechItemData(final GT_Materials aMaterial, final long aAmount, final GT_Materials aByProduct,
final long aByProductAmount) {
this(new GregtechMaterialStack(aMaterial, aAmount), new GregtechMaterialStack(aByProduct, aByProductAmount));
}
public GregtechItemData(final GregtechItemData... aData) {
this.mPrefix = null;
this.mBlackListed = true;
final ArrayList<GregtechMaterialStack> aList = new ArrayList<>(), rList = new ArrayList<>();
for (final GregtechItemData tData : aData) {
if (tData != null) {
if (tData.hasValidMaterialData() && (tData.mMaterial.mAmount > 0)) {
aList.add(tData.mMaterial.clone());
}
for (final GregtechMaterialStack tMaterial : tData.mByProducts) {
if (tMaterial.mAmount > 0) {
aList.add(tMaterial.clone());
}
}
}
}
for (final GregtechMaterialStack aMaterial : aList) {
boolean temp = true;
for (final GregtechMaterialStack tMaterial : rList) {
if (aMaterial.mMaterial == tMaterial.mMaterial) {
tMaterial.mAmount += aMaterial.mAmount;
temp = false;
break;
}
}
if (temp) {
rList.add(aMaterial.clone());
}
}
rList.sort((a, b) -> Long.compare(b.mAmount, a.mAmount));
if (rList.isEmpty()) {
this.mMaterial = null;
} else {
this.mMaterial = rList.get(0);
rList.remove(0);
}
this.mByProducts = rList.toArray(new GregtechMaterialStack[0]);
}
public boolean hasValidPrefixMaterialData() {
return (this.mPrefix != null) && (this.mMaterial != null) && (this.mMaterial.mMaterial != null);
}
public boolean hasValidPrefixData() {
return this.mPrefix != null;
}
public boolean hasValidMaterialData() {
return (this.mMaterial != null) && (this.mMaterial.mMaterial != null);
}
public ArrayList<GregtechMaterialStack> getAllGT_MaterialStacks() {
final ArrayList<GregtechMaterialStack> rList = new ArrayList<>();
if (this.hasValidMaterialData()) {
rList.add(this.mMaterial);
}
rList.addAll(Arrays.asList(this.mByProducts));
return rList;
}
public GregtechMaterialStack getByProduct(final int aIndex) {
return (aIndex >= 0) && (aIndex < this.mByProducts.length) ? this.mByProducts[aIndex] : null;
}
@Override
public String toString() {
if ((this.mPrefix == null) || (this.mMaterial == null) || (this.mMaterial.mMaterial == null)) {
return "";
}
return this.mPrefix.name() + this.mMaterial.mMaterial.name();
}
}
|