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
|
package gregtech.test;
import static gregtech.api.GregTechAPI.sBlockOres1;
import static gregtech.api.enums.GTValues.RA;
import static gregtech.api.enums.ItemList.Circuit_Parts_Crystal_Chip_Master;
import static gregtech.api.enums.ItemList.IC2_LapotronCrystal;
import static gregtech.api.enums.OrePrefixes.circuit;
import static gregtech.api.enums.OrePrefixes.lens;
import static gregtech.api.util.GTOreDictUnificator.get;
import static gregtech.api.util.GTUtility.copyAmount;
import static net.minecraft.init.Blocks.chest;
import static net.minecraft.init.Blocks.iron_ore;
import static net.minecraft.init.Blocks.lapis_block;
import static net.minecraft.init.Blocks.log;
import static net.minecraft.init.Blocks.planks;
import static net.minecraft.init.Blocks.stone;
import static net.minecraft.init.Blocks.stone_slab;
import static net.minecraft.init.Items.glass_bottle;
import static net.minecraft.init.Items.iron_ingot;
import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.RecipeMapBuilder;
import gregtech.api.util.GTRecipe;
class GTRecipeTest {
static RecipeMap<?> recipeMap;
static GTRecipe lapotronChipRecipe;
@BeforeAll
static void setup() {
recipeMap = RecipeMapBuilder.of("__test__")
.maxIO(9, 1, 1, 0)
.build();
RA.stdBuilder()
.itemInputs(new ItemStack(log, 2, WILDCARD_VALUE), new ItemStack(planks, 2, WILDCARD_VALUE))
.itemOutputs(new ItemStack(chest, 1))
.duration(0)
.eut(0)
.addTo(recipeMap);
RA.stdBuilder()
.itemInputs(new ItemStack(lapis_block, 1), get(circuit, Materials.HV, 1))
.itemOutputs(IC2_LapotronCrystal.get(1))
.duration(0)
.eut(0)
.addTo(recipeMap);
lapotronChipRecipe = RA.stdBuilder()
.itemInputs(IC2_LapotronCrystal.getWildcard(1), copyAmount(0, get(lens, Materials.BlueTopaz, 1)))
.itemOutputs(Circuit_Parts_Crystal_Chip_Master.get(3))
.duration(0)
.eut(0)
.addTo(recipeMap)
.toArray(new GTRecipe[0])[0];
RA.stdBuilder()
.itemInputs(new ItemStack(sBlockOres1, 1, 32))
.itemOutputs(new ItemStack(iron_ingot, 1))
.duration(0)
.eut(0)
.addTo(recipeMap);
RA.stdBuilder()
.itemInputs(new ItemStack(stone_slab, 64), new ItemStack(stone_slab, 64))
.itemOutputs(new ItemStack(stone, 2))
.duration(0)
.eut(0)
.addTo(recipeMap);
ItemStack dataStick = ItemList.Tool_DataStick.get(0);
NBTTagCompound dataStickTag = new NBTTagCompound();
dataStickTag.setInteger("integer", 123456);
dataStick.setTagCompound(dataStickTag);
RA.stdBuilder()
.itemInputs(dataStick)
.itemOutputs(new ItemStack(chest, 1))
.duration(0)
.eut(0)
.addTo(recipeMap);
ItemStack glass = new ItemStack(glass_bottle, 2);
NBTTagCompound glassTag = new NBTTagCompound();
glassTag.setInteger("integer", 123456);
glass.setTagCompound(glassTag);
RA.stdBuilder()
.itemInputs(glass)
.itemOutputs(new ItemStack(chest, 1))
.duration(0)
.eut(0)
.nbtSensitive()
.addTo(recipeMap);
}
@Test
void ensureRecipesAdded() {
assertEquals(
recipeMap.getAllRecipes()
.size(),
7);
}
@Test
void findWithExactSameInputs() {
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(new ItemStack(lapis_block, 1), get(circuit, Materials.HV, 1))
.find();
assertNotNull(recipe);
GTRecipe stoneRecipe = recipeMap.findRecipeQuery()
.items(new ItemStack(stone_slab, 128))
.find();
assertNotNull(stoneRecipe);
}
@Test
void findWildcardWithExactSameInputs() {
GTRecipe chestRecipe = recipeMap.findRecipeQuery()
.items(new ItemStack(log, 2, WILDCARD_VALUE), new ItemStack(planks, 2, WILDCARD_VALUE))
.find();
assertNotNull(chestRecipe);
GTRecipe lapotronChipRecipe = recipeMap.findRecipeQuery()
.items(IC2_LapotronCrystal.getWildcard(1), copyAmount(0, get(lens, Materials.BlueTopaz, 1)))
.find();
assertNotNull(lapotronChipRecipe);
}
@Test
void findWildcardWithDifferentMeta() {
// https://github.com/GTNewHorizons/GT5-Unofficial/pull/2364/commits/e7112fce5f24431f3a4ad19288d662b93cbb91f2
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(new ItemStack(log, 2, 0), new ItemStack(planks, 2, 1))
.find();
assertNotNull(recipe);
}
@Test
void findWithNBT() {
// https://github.com/GTNewHorizons/GT5-Unofficial/pull/2364/commits/844a38662b05494b42a4439bbc0e6d4d7df1a683
ItemStack lapisBlock = new ItemStack(lapis_block, 1);
NBTTagCompound tag = new NBTTagCompound();
tag.setFloat("charge", 123456);
lapisBlock.stackTagCompound = tag;
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(lapisBlock, get(circuit, Materials.HV, 1))
.find();
assertNotNull(recipe);
// For NBT sensitive recipes
ItemStack glass = new ItemStack(glass_bottle, 2);
NBTTagCompound glassTag = new NBTTagCompound();
glassTag.setInteger("integer", 123456);
glass.setTagCompound(glassTag);
GTRecipe nbtSensitiveRecipe = recipeMap.findRecipeQuery()
.items(glass)
.find();
assertNotNull(nbtSensitiveRecipe);
// For items that need to check NBT, e.g. data sticks
ItemStack dataStick = ItemList.Tool_DataStick.get(0);
NBTTagCompound dataStickTag = new NBTTagCompound();
dataStickTag.setInteger("integer", 123456);
dataStick.setTagCompound(dataStickTag);
GTRecipe checkNBTRecipe = recipeMap.findRecipeQuery()
.items(dataStick)
.find();
assertNotNull(checkNBTRecipe);
}
@Test
void rejectWithInsufficientAmount() {
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(new ItemStack(log, 1, 0), new ItemStack(planks, 1, 0))
.find();
assertNull(recipe);
GTRecipe stoneRecipe = recipeMap.findRecipeQuery()
.items(new ItemStack(stone_slab, 127))
.find();
assertNull(stoneRecipe);
}
@Test
void rejectWithoutNonConsumable() {
// https://github.com/GTNewHorizons/GT5-Unofficial/pull/2364/commits/bfc93bff7ed34616021e8c5b6dbdc50dd7096af5
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(IC2_LapotronCrystal.get(1))
.cachedRecipe(lapotronChipRecipe)
.find();
assertNull(recipe);
}
@Test
void rejectWithoutCorrectNBT() {
// For NBT sensitive recipes
GTRecipe nbtSensitiveRecipe = recipeMap.findRecipeQuery()
.items(new ItemStack(glass_bottle, 2))
.find();
assertNull(nbtSensitiveRecipe);
// For items that need to check NBT, e.g. data sticks
GTRecipe checkNBTRecipe = recipeMap.findRecipeQuery()
.items(ItemList.Tool_DataStick.get(0))
.find();
assertNull(checkNBTRecipe);
}
@Test
void findWithSpecificOreDictionary() {
// https://github.com/GTNewHorizons/GT5-Unofficial/pull/2379
// We cannot use circuit assembling recipe like the issue mentioned above,
// as mUnificationTarget is not set for circuits in GT5.
// But it works in the same way; specific circuit -> GT ore block, unificated circuit -> vanilla ore block
GTRecipe recipeCorrectOre = recipeMap.findRecipeQuery()
.items(new ItemStack(sBlockOres1, 1, 32))
.find();
assertNotNull(recipeCorrectOre);
GTRecipe recipeWrongOre = recipeMap.findRecipeQuery()
.items(new ItemStack(iron_ore, 1))
.find();
assertNull(recipeWrongOre);
}
}
|