Skip to content

Commit 50c62e3

Browse files
committed
Gametests passing again :D
1 parent cca1768 commit 50c62e3

35 files changed

+219
-167
lines changed

neoforge-main/src/main/java/dev/compactmods/crafting/CompactCrafting.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ public CompactCrafting(IEventBus modBus, ModContainer modContainer) {
4343
public static ResourceLocation modRL(String path) {
4444
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
4545
}
46+
47+
public static String rlPrefix(String path) {
48+
return CompactCrafting.MOD_ID + ":" + path;
49+
}
4650
}

neoforge-main/src/test/java/dev/compactmods/crafting/test/ServerEventListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.compactmods.crafting.test;
22

33
import java.io.File;
4+
import java.nio.file.Path;
45
import java.util.concurrent.ExecutionException;
56
import com.google.common.collect.ImmutableSet;
67
import dev.compactmods.crafting.CompactCrafting;
@@ -30,7 +31,7 @@ public static void onServerStarted(final ServerStartedEvent evt) {
3031

3132
final String cc_test_resources = System.getenv("CC_TEST_RESOURCES");
3233
if(cc_test_resources != null) {
33-
final var testPack = new FolderRepositorySource(new File(cc_test_resources).toPath(),
34+
final var testPack = new FolderRepositorySource(Path.of(cc_test_resources).resolve("test_datapacks"),
3435
PackType.SERVER_DATA,
3536
PackSource.BUILT_IN,
3637
new DirectoryValidator(path -> true));

neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/TestFrameworkTemplates.java renamed to neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/CMTestStructures.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
import net.neoforged.testframework.annotation.RegisterStructureTemplate;
77
import net.neoforged.testframework.gametest.StructureTemplateBuilder;
88

9-
public class TestFrameworkTemplates {
9+
public class CMTestStructures {
1010

1111
public static final String ONE_CUBED = "1x1x1";
1212
public static final String FIVE_CUBED = "5x5x5";
1313
public static final String FIFTEEN_CUBED = "15x15x15";
1414

15+
public static final String MEDIUM_GLASS_FILLED = CompactCrafting.MOD_ID + ":medium_glass_filled";
16+
public static final String MEDIUM_GLASS_WALLS = CompactCrafting.MOD_ID + ":medium_glass_walls";
17+
public static final String MEDIUM_GLASS_WALLS_OBSIDIAN_CENTER = CompactCrafting.MOD_ID + ":medium_glass_walls_obsidian_center";
18+
1519
@RegisterStructureTemplate(CompactCrafting.MOD_ID + ":empty_1_cubed")
1620
public static final StructureTemplate empty_1 = StructureTemplateBuilder.empty(1, 1, 1);
1721

neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/CompactCraftingGametests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package dev.compactmods.crafting.test.gametests;
22

33
import dev.compactmods.crafting.CompactCrafting;
4+
import dev.compactmods.crafting.test.gametests.util.CompactGameTestHelper;
45
import net.minecraft.commands.Commands;
56
import net.neoforged.bus.api.IEventBus;
67
import net.neoforged.fml.ModContainer;
78
import net.neoforged.fml.common.Mod;
89
import net.neoforged.testframework.conf.Feature;
910
import net.neoforged.testframework.conf.FrameworkConfiguration;
11+
import net.neoforged.testframework.impl.GameTestHelperFactory;
1012

1113
@Mod(CompactCrafting.MOD_ID)
1214
public class CompactCraftingGametests {
1315

1416
public CompactCraftingGametests(ModContainer container, IEventBus modBus) {
17+
18+
// GameTestHelperFactory.CONSTRUCTORS.put(CompactGameTestHelper.class, CompactGameTestHelper::new);
19+
1520
final var config = FrameworkConfiguration.builder(CompactCrafting.modRL("tests"))
1621
.enable(Feature.GAMETEST)
1722
.enable(Feature.MAGIC_ANNOTATIONS)

neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/recipes/MiniaturizationRecipeTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import dev.compactmods.crafting.api.recipe.layers.IRecipeBlocks;
66
import dev.compactmods.crafting.recipes.MiniaturizationRecipe;
77
import dev.compactmods.crafting.recipes.blocks.RecipeBlocks;
8-
import dev.compactmods.crafting.test.gametests.util.RecipeTestUtil;
8+
import dev.compactmods.crafting.test.gametests.util.CompactGameTestHelper;
99
import dev.compactmods.crafting.util.BlockSpaceUtil;
1010
import net.minecraft.core.BlockPos;
1111
import net.minecraft.gametest.framework.GameTest;
@@ -31,10 +31,10 @@ private static MiniaturizationRecipe getRecipe(GameTestHelper testHelper, String
3131
}
3232

3333
@GameTest(template = "recipes/ender_crystal")
34-
public void MatchesExactStructure(final GameTestHelper test) {
34+
public void MatchesExactStructure(final CompactGameTestHelper test) {
3535
final MiniaturizationRecipe enderCrystal = getRecipe(test, "ender_crystal");
3636
final IRecipeBlocks blocks = RecipeBlocks
37-
.create(test.getLevel(), enderCrystal.getComponents(), RecipeTestUtil.getFieldBounds(MiniaturizationFieldSize.MEDIUM, test))
37+
.create(test.getLevel(), enderCrystal.getComponents(), test.getFieldBounds(MiniaturizationFieldSize.MEDIUM))
3838
.normalize();
3939

4040
try {
@@ -52,15 +52,15 @@ public void MatchesExactStructure(final GameTestHelper test) {
5252
}
5353

5454
@GameTest(template = "recipes/ender_crystal")
55-
public void RecipeFailsIfUnidentifiedBlock(final GameTestHelper test) {
55+
public void RecipeFailsIfUnidentifiedBlock(final CompactGameTestHelper test) {
5656
final MiniaturizationRecipe enderCrystal = getRecipe(test, "ender_crystal");
5757
Objects.requireNonNull(enderCrystal);
5858

5959
// Force an unknown component in the exact center
6060
test.setBlock(new BlockPos(2, 2, 2), Blocks.GOLD_BLOCK.defaultBlockState());
6161

6262
final IRecipeBlocks blocks = RecipeBlocks
63-
.create(test.getLevel(), enderCrystal.getComponents(), RecipeTestUtil.getFieldBounds(MiniaturizationFieldSize.MEDIUM, test))
63+
.create(test.getLevel(), enderCrystal.getComponents(), test.getFieldBounds(MiniaturizationFieldSize.MEDIUM))
6464
.normalize();
6565

6666
try {
@@ -77,12 +77,12 @@ public void RecipeFailsIfUnidentifiedBlock(final GameTestHelper test) {
7777
}
7878

7979
@GameTest(template = "recipes/ender_crystal")
80-
public void RecipeFailsIfDifferentDimensions(final GameTestHelper test) {
80+
public void RecipeFailsIfDifferentDimensions(final CompactGameTestHelper test) {
8181
final MiniaturizationRecipe recipe = getRecipe(test, "compact_walls");
8282
Objects.requireNonNull(recipe);
8383

8484
final IRecipeBlocks blocks = RecipeBlocks
85-
.create(test.getLevel(), recipe.getComponents(), RecipeTestUtil.getFieldBounds(MiniaturizationFieldSize.MEDIUM, test))
85+
.create(test.getLevel(), recipe.getComponents(), test.getFieldBounds(MiniaturizationFieldSize.MEDIUM))
8686
.normalize();
8787

8888
final boolean matched = recipe.matches(blocks);
@@ -93,7 +93,7 @@ public void RecipeFailsIfDifferentDimensions(final GameTestHelper test) {
9393
}
9494

9595
@GameTest(template = "recipes/empty_medium")
96-
public void RecipeFailsIfNoRotationsMatched(final GameTestHelper test) {
96+
public void RecipeFailsIfNoRotationsMatched(final CompactGameTestHelper test) {
9797
final MiniaturizationRecipe recipe = getRecipe(test, "ender_crystal");
9898
Objects.requireNonNull(recipe);
9999

@@ -102,7 +102,7 @@ public void RecipeFailsIfNoRotationsMatched(final GameTestHelper test) {
102102
BlockSpaceUtil.getCornersOfBounds(MiniaturizationFieldSize.MEDIUM).forEach(p -> test.setBlock(p, glass));
103103

104104
final IRecipeBlocks blocks = RecipeBlocks
105-
.create(test.getLevel(), recipe.getComponents(), RecipeTestUtil.getFieldBounds(MiniaturizationFieldSize.MEDIUM, test))
105+
.create(test.getLevel(), recipe.getComponents(), test.getFieldBounds(MiniaturizationFieldSize.MEDIUM))
106106
.normalize();
107107

108108
final boolean matched = recipe.matches(blocks);

neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/recipes/layers/EmptyLayerTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22

33
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
44
import dev.compactmods.crafting.recipes.layers.EmptyRecipeLayer;
5-
import dev.compactmods.crafting.test.gametests.TestFrameworkTemplates;
5+
import dev.compactmods.crafting.test.gametests.CMTestStructures;
66
import dev.compactmods.crafting.test.testers.TestHelper;
77
import net.minecraft.core.BlockPos;
88
import net.minecraft.gametest.framework.GameTest;
99
import net.minecraft.gametest.framework.GameTestHelper;
1010
import net.minecraft.world.level.block.Blocks;
1111
import net.neoforged.testframework.annotation.ForEachTest;
12+
import net.neoforged.testframework.annotation.TestHolder;
1213
import net.neoforged.testframework.gametest.EmptyTemplate;
1314

1415
@ForEachTest(groups = "layers")
1516
public class EmptyLayerTests {
1617

17-
@GameTest @EmptyTemplate
18+
@GameTest
19+
@EmptyTemplate
20+
@TestHolder
1821
public static void CanCreateLayerInstance(final GameTestHelper test) {
1922
final var layer = new EmptyRecipeLayer();
2023
test.succeed();
2124
}
2225

2326
@GameTest
24-
@EmptyTemplate(TestFrameworkTemplates.FIVE_CUBED)
27+
@TestHolder
28+
@EmptyTemplate(CMTestStructures.FIVE_CUBED)
2529
public static void fails_match_if_any_blocks_present(final GameTestHelper test) {
2630
final var testHelper = TestHelper.forTest(test)
2731
.forComponents()

neoforge-main/src/test/java/dev/compactmods/crafting/test/gametests/recipes/layers/FilledLayerTests.java

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.gson.JsonElement;
44
import com.mojang.serialization.JsonOps;
5-
import dev.compactmods.crafting.CompactCrafting;
65
import dev.compactmods.crafting.api.components.IRecipeComponents;
76
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
87
import dev.compactmods.crafting.api.recipe.layers.IRecipeBlocks;
@@ -11,17 +10,16 @@
1110
import dev.compactmods.crafting.recipes.components.MiniaturizationRecipeComponents;
1211
import dev.compactmods.crafting.recipes.layers.FilledComponentRecipeLayer;
1312
import dev.compactmods.crafting.test.FileHelper;
14-
import dev.compactmods.crafting.test.gametests.TestFrameworkTemplates;
15-
import dev.compactmods.crafting.test.gametests.util.RecipeTestUtil;
13+
import dev.compactmods.crafting.test.gametests.CMTestStructures;
14+
import dev.compactmods.crafting.test.gametests.util.CompactGameTestHelper;
1615
import dev.compactmods.crafting.util.BlockSpaceUtil;
1716
import net.minecraft.core.BlockPos;
1817
import net.minecraft.gametest.framework.GameTest;
1918
import net.minecraft.gametest.framework.GameTestHelper;
2019
import net.minecraft.world.level.block.Blocks;
2120
import net.minecraft.world.phys.AABB;
22-
import net.neoforged.neoforge.gametest.GameTestHolder;
23-
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
2421
import net.neoforged.testframework.annotation.ForEachTest;
22+
import net.neoforged.testframework.annotation.TestHolder;
2523
import net.neoforged.testframework.gametest.EmptyTemplate;
2624

2725
import java.util.Objects;
@@ -32,18 +30,15 @@
3230
@ForEachTest(groups = "layers")
3331
public class FilledLayerTests {
3432

35-
private static FilledComponentRecipeLayer getLayerFromFile(GameTestHelper test, String filename) {
36-
JsonElement layerJson = FileHelper.getJsonFromFile(filename);
33+
@GameTest
34+
@TestHolder
35+
@EmptyTemplate(CMTestStructures.ONE_CUBED)
36+
public static void null_dimensions_have_zero_blocks_filled(final GameTestHelper test) {
37+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
3738

38-
return FilledComponentRecipeLayer.CODEC.codec()
39+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
3940
.parse(JsonOps.INSTANCE, layerJson)
4041
.getOrThrow();
41-
}
42-
43-
@GameTest
44-
@EmptyTemplate(TestFrameworkTemplates.ONE_CUBED)
45-
public static void null_dimensions_have_zero_blocks_filled(final GameTestHelper test) {
46-
final FilledComponentRecipeLayer layer = getLayerFromFile(test,"layers/filled/basic.json");
4742

4843
// We force the dimensions null here
4944
layer.setRecipeDimensions((AABB) null);
@@ -55,9 +50,14 @@ public static void null_dimensions_have_zero_blocks_filled(final GameTestHelper
5550
}
5651

5752
@GameTest
58-
@EmptyTemplate(TestFrameworkTemplates.ONE_CUBED)
53+
@TestHolder
54+
@EmptyTemplate(CMTestStructures.ONE_CUBED)
5955
public static void CanUpdateDimensions(final GameTestHelper test) {
60-
final FilledComponentRecipeLayer layer = getLayerFromFile(test, "layers/filled/basic.json");
56+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
57+
58+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
59+
.parse(JsonOps.INSTANCE, layerJson)
60+
.getOrThrow();
6161

6262
int filledBefore = layer.getNumberFilledPositions();
6363

@@ -72,9 +72,14 @@ public static void CanUpdateDimensions(final GameTestHelper test) {
7272
}
7373

7474
@GameTest
75-
@EmptyTemplate(TestFrameworkTemplates.ONE_CUBED)
75+
@TestHolder
76+
@EmptyTemplate(CMTestStructures.ONE_CUBED)
7677
public static void ComponentPositionsAreCorrect(final GameTestHelper test) {
77-
final FilledComponentRecipeLayer layer = getLayerFromFile(test, "layers/filled/basic.json");
78+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
79+
80+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
81+
.parse(JsonOps.INSTANCE, layerJson)
82+
.getOrThrow();
7883
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
7984

8085
test.assertValueEqual(layer.getNumberFilledPositions(), 25, "filled positions");
@@ -92,9 +97,14 @@ public static void ComponentPositionsAreCorrect(final GameTestHelper test) {
9297
}
9398

9499
@GameTest
95-
@EmptyTemplate(TestFrameworkTemplates.ONE_CUBED)
100+
@TestHolder
101+
@EmptyTemplate(CMTestStructures.ONE_CUBED)
96102
public static void CanFetchComponentByPosition(final GameTestHelper test) {
97-
final FilledComponentRecipeLayer layer = getLayerFromFile(test, "layers/filled/basic.json");
103+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
104+
105+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
106+
.parse(JsonOps.INSTANCE, layerJson)
107+
.getOrThrow();
98108
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
99109

100110
final Optional<String> componentForPosition = layer.getComponentForPosition(BlockPos.ZERO);
@@ -107,9 +117,14 @@ public static void CanFetchComponentByPosition(final GameTestHelper test) {
107117
}
108118

109119
@GameTest
110-
@EmptyTemplate(TestFrameworkTemplates.ONE_CUBED)
120+
@TestHolder
121+
@EmptyTemplate(CMTestStructures.ONE_CUBED)
111122
public static void oob_position_returns_empty(final GameTestHelper test) {
112-
final FilledComponentRecipeLayer layer = getLayerFromFile(test, "layers/filled/basic.json");
123+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
124+
125+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
126+
.parse(JsonOps.INSTANCE, layerJson)
127+
.getOrThrow();
113128
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
114129

115130
// Y = 1 should never happen, in any layer, ever
@@ -119,11 +134,15 @@ public static void oob_position_returns_empty(final GameTestHelper test) {
119134
test.succeed();
120135
}
121136

122-
// note - we use the empty medium here just to let the gametest system run our test
123-
// we create an actual blocks instance inside the test
124-
@GameTest(template = "empty_medium")
137+
@GameTest
138+
@TestHolder
139+
@EmptyTemplate(CMTestStructures.FIVE_CUBED)
125140
public static void FilledFailsMatchWithEmptyBlockList(final GameTestHelper test) {
126-
final FilledComponentRecipeLayer layer = getLayerFromFile(test, "layers/filled/basic.json");
141+
JsonElement layerJson = FileHelper.getJsonFromFile("layers/filled/basic.json");
142+
143+
final FilledComponentRecipeLayer layer = FilledComponentRecipeLayer.CODEC.codec()
144+
.parse(JsonOps.INSTANCE, layerJson)
145+
.getOrThrow();
127146
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
128147

129148
MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
@@ -136,13 +155,13 @@ public static void FilledFailsMatchWithEmptyBlockList(final GameTestHelper test)
136155
test.succeed();
137156
}
138157

139-
140-
@GameTest(template = "medium_glass_filled")
141-
public static void FilledLayerMatchesWorldInExactMatchScenario(GameTestHelper test) {
158+
@TestHolder
159+
@GameTest(template = CMTestStructures.MEDIUM_GLASS_FILLED)
160+
public static void FilledLayerMatchesWorldInExactMatchScenario(CompactGameTestHelper test) {
142161
final MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
143162
components.registerBlock("G", new BlockComponent(Blocks.GLASS));
144163

145-
final AABB bounds = RecipeTestUtil.getFloorLayerBounds(MiniaturizationFieldSize.MEDIUM, test);
164+
final AABB bounds = test.getFloorLayerBounds(MiniaturizationFieldSize.MEDIUM);
146165
final IRecipeBlocks blocks = RecipeBlocks.create(test.getLevel(), components, bounds).normalize();
147166

148167
// Set up a 5x5x1 filled layer, using "G" component
@@ -162,8 +181,8 @@ public static void FilledLayerMatchesWorldInExactMatchScenario(GameTestHelper te
162181
test.succeed();
163182
}
164183

165-
166-
@GameTest(template = "medium_glass_walls_obsidian_center")
184+
@TestHolder
185+
@GameTest(template = CMTestStructures.MEDIUM_GLASS_WALLS_OBSIDIAN_CENTER)
167186
public static void FailsMatchIfAllBlocksNotIdentified(final GameTestHelper test) {
168187
final IRecipeComponents components = new MiniaturizationRecipeComponents();
169188
// note the lack of a G component here, missing "GLASS"
@@ -183,9 +202,9 @@ public static void FailsMatchIfAllBlocksNotIdentified(final GameTestHelper test)
183202
test.succeed();
184203
}
185204

186-
187-
@GameTest(template = "medium_glass_walls_obsidian_center")
188-
public static void FailsMatchIfMoreThanOneBlockFound(final GameTestHelper test) {
205+
@TestHolder
206+
@GameTest(template = CMTestStructures.MEDIUM_GLASS_WALLS_OBSIDIAN_CENTER)
207+
public static void FailsMatchIfMoreThanOneBlockFound(GameTestHelper test) {
189208
final MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
190209
components.registerBlock("G", new BlockComponent(Blocks.GLASS));
191210
components.registerBlock("O", new BlockComponent(Blocks.OBSIDIAN));
@@ -203,9 +222,9 @@ public static void FailsMatchIfMoreThanOneBlockFound(final GameTestHelper test)
203222
test.succeed();
204223
}
205224

206-
207-
@GameTest(template = "medium_glass_filled")
208-
public static void FailsMatchIfComponentKeyNotFound(final GameTestHelper test) {
225+
@TestHolder
226+
@GameTest(template = CMTestStructures.MEDIUM_GLASS_FILLED)
227+
public static void FailsMatchIfComponentKeyNotFound(CompactGameTestHelper test) {
209228
final MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
210229

211230
/*
@@ -214,7 +233,7 @@ public static void FailsMatchIfComponentKeyNotFound(final GameTestHelper test) {
214233
*/
215234
components.registerBlock("Gl", new BlockComponent(Blocks.GLASS));
216235

217-
final AABB bounds = RecipeTestUtil.getFloorLayerBounds(MiniaturizationFieldSize.MEDIUM, test);
236+
final AABB bounds = test.getFloorLayerBounds(MiniaturizationFieldSize.MEDIUM);
218237
final RecipeBlocks blocks = RecipeBlocks.create(test.getLevel(), components, bounds);
219238

220239
// Set up a 5x5x1 filled layer, using "G" component

0 commit comments

Comments
 (0)