-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathPatternBufferTest.java
More file actions
231 lines (196 loc) · 11.4 KB
/
PatternBufferTest.java
File metadata and controls
231 lines (196 loc) · 11.4 KB
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
package com.gregtechceu.gtceu.integration.ae2.machine;
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
import com.gregtechceu.gtceu.common.machine.multiblock.part.FluidHatchPartMachine;
import com.gregtechceu.gtceu.common.machine.multiblock.part.ItemBusPartMachine;
import com.gregtechceu.gtceu.gametest.util.TestUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.gametest.framework.BeforeBatch;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.gametest.GameTestHolder;
import net.minecraftforge.gametest.PrefixGameTestTemplate;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.CalculationStrategy;
import appeng.api.networking.crafting.ICraftingPlan;
import appeng.api.networking.crafting.ICraftingService;
import appeng.api.networking.crafting.ICraftingSubmitResult;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEItemKey;
import appeng.blockentity.networking.CableBusBlockEntity;
import appeng.parts.encoding.PatternEncodingTerminalPart;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@PrefixGameTestTemplate(false)
@GameTestHolder(GTCEu.MOD_ID)
public class PatternBufferTest {
private static GTRecipeType LCR_RECIPE_TYPE;
@BeforeBatch(batch = "PatternBuffer")
public static void prepare(ServerLevel level) {
LCR_RECIPE_TYPE = TestUtils.createRecipeTypeAndInsertRecipe("pattern_buffer_tests",
GTRecipeTypes.LARGE_CHEMICAL_RECIPES);
LCR_RECIPE_TYPE.getAdditionHandler().addStaging(LCR_RECIPE_TYPE
.recipeBuilder(GTCEu.id("test_recipe_pattern_buffer"))
.id(GTCEu.id("test_recipe_pattern_buffer"))
.inputItems(new ItemStack(Items.RED_BED))
.outputItems(new ItemStack(Blocks.BROWN_BED))
.EUt(GTValues.V[GTValues.EV])
.duration(1).buildRawRecipe());
LCR_RECIPE_TYPE.getAdditionHandler().completeStaging();
}
private record BusHolder(ItemBusPartMachine inputBus1, ItemBusPartMachine inputBus2, ItemBusPartMachine outputBus1,
FluidHatchPartMachine outputHatch1, MEPatternBufferPartMachine patternBuffer,
WorkableMultiblockMachine controller) {}
/**
* Retrieves the busses for this specific template and force a multiblock structure check
*
* @param helper the GameTestHelper
* @return the busses, in the BusHolder record.
*/
private static BusHolder getBussesAndForm(GameTestHelper helper) {
WorkableMultiblockMachine controller = (WorkableMultiblockMachine) helper.getBlockEntity(new BlockPos(1, 2, 0));
assert controller != null;
TestUtils.formMultiblock(controller);
controller.setRecipeType(LCR_RECIPE_TYPE);
ItemBusPartMachine inputBus1 = (ItemBusPartMachine) helper.getBlockEntity(new BlockPos(2, 1, 0));
ItemBusPartMachine inputBus2 = (ItemBusPartMachine) helper.getBlockEntity(new BlockPos(2, 2, 0));
ItemBusPartMachine outputBus1 = (ItemBusPartMachine) helper.getBlockEntity(new BlockPos(0, 1, 0));
FluidHatchPartMachine outputHatch1 = (FluidHatchPartMachine) helper.getBlockEntity(new BlockPos(0, 2, 0));
MEPatternBufferPartMachine patternBuffer = (MEPatternBufferPartMachine) helper
.getBlockEntity(new BlockPos(2, 2, 1));
return new BusHolder(inputBus1, inputBus2, outputBus1, outputHatch1, patternBuffer, controller);
}
// Test for putting ingredient on the normal input bus when the pattern buffer exists on machine
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
public static void patternBufferNormalInputBusTest(GameTestHelper helper) {
BusHolder busHolder = getBussesAndForm(helper);
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
// placement structure bug
busHolder.inputBus1.getInventory().setStackInSlot(0, new ItemStack(Blocks.COBBLESTONE));
helper.succeedWhen(() -> {
helper.assertTrue(
TestUtils.isItemStackEqual(busHolder.outputBus1.getInventory().getStackInSlot(0),
new ItemStack(Blocks.STONE)),
"Crafting items in same bus failed, expected STONE but was " +
busHolder.outputBus1.getInventory().getStackInSlot(0).getDisplayName());
});
}
// Test for checking if pattern buffers work at all
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
public static void patternBufferBasicRequestTest(GameTestHelper helper) {
BusHolder busHolder = getBussesAndForm(helper);
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
// placement structure bug
IGrid grid = busHolder.patternBuffer.getGrid();
ICraftingService craftingService = grid.getCraftingService();
CableBusBlockEntity cbbe = (CableBusBlockEntity) helper.getBlockEntity(new BlockPos(3, 2, 1));
PatternEncodingTerminalPart terminal = (PatternEncodingTerminalPart) cbbe.getCableBus()
.getPart(Direction.NORTH);
Future<ICraftingPlan> plan = craftingService.beginCraftingCalculation(
helper.getLevel(),
() -> IActionSource.ofMachine(terminal),
AEItemKey.of(Items.STONE),
1,
CalculationStrategy.REPORT_MISSING_ITEMS);
helper.runAfterDelay(40, () -> {
ICraftingPlan job;
try {
job = plan.get(5, TimeUnit.SECONDS);
} catch (Exception e) {
helper.fail("Job didn't get queued in 40 ticks");
throw new RuntimeException("Oopsie, could not get job to start craft");
}
ICraftingSubmitResult result = craftingService.submitJob(job, null, null, true, IActionSource.empty());
helper.assertTrue(result.successful(), "Could not queue crafting job");
helper.succeedWhen(() -> {
helper.assertTrue(
TestUtils.isItemStackEqual(busHolder.outputBus1.getInventory().getStackInSlot(0),
new ItemStack(Blocks.STONE)),
"Crafting items in same bus failed, expected STONE but was " +
busHolder.outputBus1.getInventory().getStackInSlot(0).getDisplayName());
});
});
}
// Test for checking if pattern buffers work if you set distinct
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
public static void patternBufferDistinctDoesNothingTest(GameTestHelper helper) {
BusHolder busHolder = getBussesAndForm(helper);
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
// placement structure bug
busHolder.patternBuffer.setDistinct(true);
IGrid grid = busHolder.patternBuffer.getGrid();
ICraftingService craftingService = grid.getCraftingService();
CableBusBlockEntity cbbe = (CableBusBlockEntity) helper.getBlockEntity(new BlockPos(3, 2, 1));
PatternEncodingTerminalPart terminal = (PatternEncodingTerminalPart) cbbe.getCableBus()
.getPart(Direction.NORTH);
Future<ICraftingPlan> plan = craftingService.beginCraftingCalculation(
helper.getLevel(),
() -> IActionSource.ofMachine(terminal),
AEItemKey.of(Items.STONE),
1,
CalculationStrategy.REPORT_MISSING_ITEMS);
helper.runAfterDelay(40, () -> {
ICraftingPlan job;
try {
job = plan.get(5, TimeUnit.SECONDS);
} catch (Exception e) {
helper.fail("Job didn't get queued in 40 ticks");
throw new RuntimeException("Oopsie, could not get job to start craft");
}
ICraftingSubmitResult result = craftingService.submitJob(job, null, null, true, IActionSource.empty());
helper.assertTrue(result.successful(), "Could not queue crafting job");
helper.succeedWhen(() -> {
helper.assertTrue(
TestUtils.isItemStackEqual(busHolder.outputBus1.getInventory().getStackInSlot(0),
new ItemStack(Blocks.STONE)),
"Crafting items in same bus failed, expected STONE but was " +
busHolder.outputBus1.getInventory().getStackInSlot(0).getDisplayName());
});
});
}
// Test for checking if pattern buffers work if you dye them
@GameTest(template = "patternbuffertest", batch = "PatternBuffer", setupTicks = 40, timeoutTicks = 200)
public static void patternBufferDyeingDoesNothingTest(GameTestHelper helper) {
BusHolder busHolder = getBussesAndForm(helper);
busHolder.patternBuffer.onPatternChange(0); // Jank forced pattern update, likely needed because of NBT
// placement structure bug
busHolder.patternBuffer.setPaintingColor(0xff);
IGrid grid = busHolder.patternBuffer.getGrid();
ICraftingService craftingService = grid.getCraftingService();
CableBusBlockEntity cbbe = (CableBusBlockEntity) helper.getBlockEntity(new BlockPos(3, 2, 1));
PatternEncodingTerminalPart terminal = (PatternEncodingTerminalPart) cbbe.getCableBus()
.getPart(Direction.NORTH);
Future<ICraftingPlan> plan = craftingService.beginCraftingCalculation(
helper.getLevel(),
() -> IActionSource.ofMachine(terminal),
AEItemKey.of(Items.STONE),
1,
CalculationStrategy.REPORT_MISSING_ITEMS);
helper.runAfterDelay(40, () -> {
ICraftingPlan job;
try {
job = plan.get(5, TimeUnit.SECONDS);
} catch (Exception e) {
helper.fail("Job didn't get queued in 40 ticks");
throw new RuntimeException("Oopsie, could not get job to start craft");
}
ICraftingSubmitResult result = craftingService.submitJob(job, null, null, true, IActionSource.empty());
helper.assertTrue(result.successful(), "Could not queue crafting job");
helper.succeedWhen(() -> {
helper.assertTrue(
TestUtils.isItemStackEqual(busHolder.outputBus1.getInventory().getStackInSlot(0),
new ItemStack(Blocks.STONE)),
"Crafting items in same bus failed, expected STONE but was " +
busHolder.outputBus1.getInventory().getStackInSlot(0).getDisplayName());
});
});
}
}