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
|
package gregtech.api.util;
import static gregtech.api.enums.GT_Values.*;
import java.util.*;
import net.minecraft.item.ItemStack;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.api.objects.GT_ItemStack;
import gtPlusPlus.api.objects.Logger;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
public class CustomRecipeMap/* extends GTPP_Recipe_Map*/{
/**
* Contains all Recipe Maps
*/
public static final Collection<CustomRecipeMap> sMappings = new ArrayList<>();
//public static final CustomRecipeMap sOreWasherRecipes = new GTPP_Recipe_Map_OreWasher(new HashSet<GTPP_Recipe>(0), "ic.recipe.orewasher", "Ore Washer", "ic2.blockOreWashingPlant", RES_PATH_GUI + "basicmachines/OreWasher", 1, 3, 1, 1, 1, E, 1, E, true, false);
//Fission Fuel Plant Recipes
public static final CustomRecipeMap sFissionFuelProcessing = new CustomRecipeMap(new HashSet<GTPP_Recipe>(50), "gt.recipe.fissionfuel", "Nuclear Fuel Processing", null, RES_PATH_GUI + "basicmachines/FissionFuel", 0, 0, 0, 4, 1, E, 1, E, true, true);
public static final CustomRecipeMap mMultiWireMill = new CustomRecipeMap(new HashSet<GTPP_Recipe>(500), "gt.recipe.multi.wiremill", "Multiblock Wiremill", null, RES_PATH_GUI + "basicmachines/FissionFuel", 1, 1, 0, 0, 1, E, 1, E, true, true);
public static final CustomRecipeMap mMultiMacerator = new CustomRecipeMap(new HashSet<GTPP_Recipe>(500), "gt.recipe.multi.macerator", "Maceration Stack", null, RES_PATH_GUI + "basicmachines/FissionFuel", 1, 3, 0, 0, 1, E, 1, E, true, true);
public static final CustomRecipeMap mMultiCentrifuge = new CustomRecipeMap(new HashSet<GTPP_Recipe>(500), "gt.recipe.multi.centrifuge", "Multiblock Centrifuge", null, RES_PATH_GUI + "basicmachines/FissionFuel", 2, 6, 0, 0, 1, E, 1, E, true, true);
public static final CustomRecipeMap mMultiElectrolyzer = new CustomRecipeMap(new HashSet<GTPP_Recipe>(500), "gt.recipe.multi.electrolyzer", "Multiblock Electrolyzer", null, RES_PATH_GUI + "basicmachines/FissionFuel", 2, 6, 0, 0, 1, E, 1, E, true, true);
/**
* HashMap of Recipes based on their Items
*/
public final Map<GT_ItemStack, Collection<GTPP_Recipe>> mRecipeItemMap = new HashMap<>();
/**
* HashMap of Recipes based on their Fluids
*/
public final Map<Fluid, Collection<GTPP_Recipe>> mRecipeFluidMap = new HashMap<>();
/**
* The List of all Recipes
*/
public final Collection<GTPP_Recipe> mRecipeList;
/**
* String used as an unlocalised Name.
*/
public final String mUnlocalizedName;
/**
* String used in NEI for the Recipe Lists. If null it will use the unlocalised Name instead
*/
public final String mNEIName;
/**
* GUI used for NEI Display. Usually the GUI of the Machine itself
*/
public final String mNEIGUIPath;
public final String mNEISpecialValuePre, mNEISpecialValuePost;
public final int mUsualInputCount, mUsualOutputCount, mNEISpecialValueMultiplier, mMinimalInputItems, mMinimalInputFluids, mAmperage;
public final boolean mNEIAllowed, mShowVoltageAmperageInNEI;
/**
* Initialises a new type of Recipe Handler.
*
* @param aRecipeList a List you specify as Recipe List. Usually just an ArrayList with a pre-initialised Size.
* @param aUnlocalizedName the unlocalised Name of this Recipe Handler, used mainly for NEI.
* @param aLocalName the displayed Name inside the NEI Recipe GUI.
* @param aNEIGUIPath the displayed GUI Texture, usually just a Machine GUI. Auto-Attaches ".png" if forgotten.
* @param aUsualInputCount the usual amount of Input Slots this Recipe Class has.
* @param aUsualOutputCount the usual amount of Output Slots this Recipe Class has.
* @param aNEISpecialValuePre the String in front of the Special Value in NEI.
* @param aNEISpecialValueMultiplier the Value the Special Value is getting Multiplied with before displaying
* @param aNEISpecialValuePost the String after the Special Value. Usually for a Unit or something.
* @param aNEIAllowed if NEI is allowed to display this Recipe Handler in general.
*/
public CustomRecipeMap(final Collection<GTPP_Recipe> aRecipeList, final String aUnlocalizedName, final String aLocalName, final String aNEIName, final String aNEIGUIPath, final int aUsualInputCount, final int aUsualOutputCount, final int aMinimalInputItems, final int aMinimalInputFluids, final int aAmperage, final String aNEISpecialValuePre, final int aNEISpecialValueMultiplier, final String aNEISpecialValuePost, final boolean aShowVoltageAmperageInNEI, final boolean aNEIAllowed) {
//super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed);
sMappings.add(this);
this.mNEIAllowed = aNEIAllowed;
this.mShowVoltageAmperageInNEI = aShowVoltageAmperageInNEI;
this.mRecipeList = aRecipeList;
this.mNEIName = aNEIName == null ? aUnlocalizedName : aNEIName;
this.mNEIGUIPath = aNEIGUIPath.endsWith(".png") ? aNEIGUIPath : aNEIGUIPath + ".png";
this.mNEISpecialValuePre = aNEISpecialValuePre;
this.mNEISpecialValueMultiplier = aNEISpecialValueMultiplier;
this.mNEISpecialValuePost = aNEISpecialValuePost;
this.mAmperage = aAmperage;
this.mUsualInputCount = aUsualInputCount;
this.mUsualOutputCount = aUsualOutputCount;
this.mMinimalInputItems = aMinimalInputItems;
this.mMinimalInputFluids = aMinimalInputFluids;
GregTech_API.sFluidMappings.add(this.mRecipeFluidMap);
GregTech_API.sItemStackMappings.add(this.mRecipeItemMap);
GT_LanguageManager.addStringLocalization(this.mUnlocalizedName = aUnlocalizedName, aLocalName);
}
public GTPP_Recipe addRecipe(final boolean aOptimize, final ItemStack[] aInputs, final ItemStack[] aOutputs, final Object aSpecial, final int[] aOutputChances, final FluidStack[] aFluidInputs, final FluidStack[] aFluidOutputs, final int aDuration, final int aEUt, final int aSpecialValue) {
return this.addRecipe(new GTPP_Recipe(aOptimize, aInputs, aOutputs, aSpecial, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue));
}
public GTPP_Recipe addRecipe(final int[] aOutputChances, final FluidStack[] aFluidInputs, final FluidStack[] aFluidOutputs, final int aDuration, final int aEUt, final int aSpecialValue) {
return this.addRecipe(new GTPP_Recipe(false, null, null, null, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue), false, false, false);
}
public GTPP_Recipe addRecipe(final boolean aOptimize, final ItemStack[] aInputs, final ItemStack[] aOutputs, final Object aSpecial, final FluidStack[] aFluidInputs, final FluidStack[] aFluidOutputs, final int aDuration, final int aEUt, final int aSpecialValue) {
return this.addRecipe(new GTPP_Recipe(aOptimize, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue));
}
public GTPP_Recipe addRecipe(final GTPP_Recipe aRecipe) {
return this.addRecipe(aRecipe, true, false, false);
}
public GTPP_Recipe addRecipe(final GTPP_Recipe aRecipe, final boolean aCheckForCollisions, final boolean aFakeRecipe, final boolean aHidden) {
aRecipe.mHidden = aHidden;
aRecipe.mFakeRecipe = aFakeRecipe;
if ((aRecipe.mFluidInputs.length < this.mMinimalInputFluids) && (aRecipe.mInputs.length < this.mMinimalInputItems)) {
return null;
}
if (aCheckForCollisions && (this.findRecipe(null, false, Long.MAX_VALUE, aRecipe.mFluidInputs, aRecipe.mInputs) != null)) {
return null;
}
return this.add(aRecipe);
}
/**
* Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes
*/
public GTPP_Recipe addFakeRecipe(final boolean aCheckForCollisions, final ItemStack[] aInputs, final ItemStack[] aOutputs, final Object aSpecial, final int[] aOutputChances, final FluidStack[] aFluidInputs, final FluidStack[] aFluidOutputs, final int aDuration, final int aEUt, final int aSpecialValue) {
return this.addFakeRecipe(aCheckForCollisions, new GTPP_Recipe(false, aInputs, aOutputs, aSpecial, aOutputChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue));
}
/**
* Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes
*/
public GTPP_Recipe addFakeRecipe(final boolean aCheckForCollisions, final ItemStack[] aInputs, final ItemStack[] aOutputs, final Object aSpecial, final FluidStack[] aFluidInputs, final FluidStack[] aFluidOutputs, final int aDuration, final int aEUt, final int aSpecialValue) {
return this.addFakeRecipe(aCheckForCollisions, new GTPP_Recipe(false, aInputs, aOutputs, aSpecial, null, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue));
}
/**
* Only used for fake Recipe Handlers to show something in NEI, do not use this for adding actual Recipes! findRecipe wont find fake Recipes, containsInput WILL find fake Recipes
*/
public GTPP_Recipe addFakeRecipe(final boolean aCheckForCollisions, final GTPP_Recipe aRecipe) {
return this.addRecipe(aRecipe, aCheckForCollisions, true, false);
}
public GTPP_Recipe add(final GTPP_Recipe aRecipe) {
this.mRecipeList.add(aRecipe);
for (final FluidStack aFluid : aRecipe.mFluidInputs) {
if (aFluid != null) {
Collection<GTPP_Recipe> tList = this.mRecipeFluidMap.get(aFluid.getFluid());
if (tList == null) {
this.mRecipeFluidMap.put(aFluid.getFluid(), tList = new HashSet<>(1));
}
tList.add(aRecipe);
}
}
return this.addToItemMap(aRecipe);
}
public void reInit() {
final Map<GT_ItemStack, Collection<GTPP_Recipe>> tMap = this.mRecipeItemMap;
if (tMap != null) {
tMap.clear();
}
for (final GTPP_Recipe tRecipe : this.mRecipeList) {
GT_OreDictUnificator.setStackArray(true, tRecipe.mInputs);
GT_OreDictUnificator.setStackArray(true, tRecipe.mOutputs);
if (tMap != null) {
this.addToItemMap(tRecipe);
}
}
}
/**
* @return if this Item is a valid Input for any for the Recipes
*/
public boolean containsInput(final ItemStack aStack) {
return (aStack != null) && (this.mRecipeItemMap.containsKey(new GT_ItemStack(aStack)) || this.mRecipeItemMap.containsKey(new GT_ItemStack(GT_Utility.copyMetaData(W, aStack))));
}
/**
* @return if this Fluid is a valid Input for any for the Recipes
*/
public boolean containsInput(final FluidStack aFluid) {
return (aFluid != null) && this.containsInput(aFluid.getFluid());
}
/**
* @return if this Fluid is a valid Input for any for the Recipes
*/
public boolean containsInput(final Fluid aFluid) {
return (aFluid != null) && this.mRecipeFluidMap.containsKey(aFluid);
}
public GTPP_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final boolean aNotUnificated, final long aVoltage, final FluidStack[] aFluids, final ItemStack... aInputs) {
return this.findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, null, aInputs);
}
public GTPP_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GTPP_Recipe aRecipe, final boolean aNotUnificated, final long aVoltage, final FluidStack[] aFluids, final ItemStack... aInputs) {
return this.findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, null, aInputs);
}
/**
* finds a Recipe matching the aFluid and ItemStack Inputs.
*
* @param aTileEntity an Object representing the current coordinates of the executing Block/Entity/Whatever. This may be null, especially during Startup.
* @param aRecipe in case this is != null it will try to use this Recipe first when looking things up.
* @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs
* @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param aFluids the Fluid Inputs
* @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with this, but some custom ones do.
* @param aInputs the Item Inputs
* @return the Recipe it has found or null for no matching Recipe
*/
public GTPP_Recipe findRecipe(final IHasWorldObjectAndCoords aTileEntity, final GTPP_Recipe aRecipe, final boolean aNotUnificated, final long aVoltage, final FluidStack[] aFluids, final ItemStack aSpecialSlot, ItemStack... aInputs) {
// No Recipes? Well, nothing to be found then.
if (this.mRecipeList.isEmpty()) {
Logger.WARNING("BAD RECIPE");
return null;
}
// Some Recipe Classes require a certain amount of Inputs of certain kinds. Like "at least 1 Fluid + 1 Stack" or "at least 2 Stacks" before they start searching for Recipes.
// This improves Performance massively, especially if people leave things like Circuits, Molds or Shapes in their Machines to select Sub Recipes.
if (GregTech_API.sPostloadFinished) {
if (this.mMinimalInputFluids > 0) {
if (aFluids == null) {
Logger.WARNING("BAD RECIPE [1]");
return null;
}
int tAmount = 0;
for (final FluidStack aFluid : aFluids) {
if (aFluid != null) {
tAmount++;
}
}
if (tAmount < this.mMinimalInputFluids) {
Logger.WARNING("BAD RECIPE [2]");
return null;
}
}
if (this.mMinimalInputItems > 0) {
if (aInputs == null) {
Logger.WARNING("BAD RECIPE [3]");
return null;
}
int tAmount = 0;
for (final ItemStack aInput : aInputs) {
if (aInput != null) {
tAmount++;
}
}
if (tAmount < this.mMinimalInputItems) {
Logger.WARNING("BAD RECIPE [4]");
return null;
}
}
}
// Unification happens here in case the Input isn't already unificated.
if (aNotUnificated) {
aInputs = GT_OreDictUnificator.getStackArray(true, (Object[]) aInputs);
}
// Check the Recipe which has been used last time in order to not have to search for it again, if possible.
if (aRecipe != null) {
if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) {
Logger.WARNING("BAD RECIPE [a]");
return aRecipe.mEnabled && ((aVoltage * this.mAmperage) >= aRecipe.mEUt) ? aRecipe : null;
}
}
// Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items.
if ((this.mUsualInputCount > 0) && (aInputs != null)) {
Logger.WARNING("BAD RECIPE [b0]");
for (final ItemStack tStack : aInputs) {
Logger.WARNING("BAD RECIPE [b1]");
if (tStack != null) {
Logger.WARNING("BAD RECIPE [b2] | "+tStack.getDisplayName());
Collection<GTPP_Recipe>
tRecipes = this.mRecipeItemMap.get(new GT_ItemStack(tStack));
if (tRecipes != null) {
Logger.WARNING("BAD RECIPE [b3]");
for (final GTPP_Recipe tRecipe : tRecipes) {
Logger.WARNING("BAD RECIPE [b4]");
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) {
Logger.WARNING("BAD RECIPE [b5]");
return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null;
}
}
}
Logger.WARNING("BAD RECIPE [b6]");
tRecipes = this.mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(W, tStack)));
if (tRecipes != null) {
Logger.WARNING("BAD RECIPE [b7]");
for (final GTPP_Recipe tRecipe : tRecipes) {
Logger.WARNING("BAD RECIPE [b8]");
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) {
Logger.WARNING("BAD RECIPE [b9]");
return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null;
}
}
}
}
}
}
// If the minimal Amount of Items for the Recipe is 0, then it could be a Fluid-Only Recipe, so check that Map too.
if ((this.mMinimalInputItems == 0) && (aFluids != null && aFluids.length > 0)) {
Logger.WARNING("BAD RECIPE [c0] "+aFluids.length);
for (final FluidStack aFluid : aFluids) {
Logger.WARNING("BAD RECIPE [c1]");
if (aFluid != null) {
Logger.WARNING("BAD RECIPE [c2]");
final Collection<GTPP_Recipe>
tRecipes = this.mRecipeFluidMap.get(aFluid.getFluid());
if (tRecipes != null) {
Logger.WARNING("BAD RECIPE [c3]");
for (final GTPP_Recipe tRecipe : tRecipes) {
Logger.WARNING("BAD RECIPE [c4]");
if (!tRecipe.mFakeRecipe && tRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) {
Logger.WARNING("BAD RECIPE [c5]");
return tRecipe.mEnabled && ((aVoltage * this.mAmperage) >= tRecipe.mEUt) ? tRecipe : null;
}
}
}
}
}
}
// And nothing has been found.
Logger.WARNING("BAD RECIPE [5]");
return null;
}
protected GTPP_Recipe addToItemMap(final GTPP_Recipe aRecipe) {
for (final ItemStack aStack : aRecipe.mInputs) {
if (aStack != null) {
final GT_ItemStack tStack = new GT_ItemStack(aStack);
Collection<GTPP_Recipe> tList = this.mRecipeItemMap.get(tStack);
if (tList == null) {
this.mRecipeItemMap.put(tStack, tList = new HashSet<>(1));
}
tList.add(aRecipe);
}
}
return aRecipe;
}
}
|