22
33import com .google .gson .JsonElement ;
44import com .mojang .serialization .JsonOps ;
5- import dev .compactmods .crafting .CompactCrafting ;
65import dev .compactmods .crafting .api .components .IRecipeComponents ;
76import dev .compactmods .crafting .api .field .MiniaturizationFieldSize ;
87import dev .compactmods .crafting .api .recipe .layers .IRecipeBlocks ;
1110import dev .compactmods .crafting .recipes .components .MiniaturizationRecipeComponents ;
1211import dev .compactmods .crafting .recipes .layers .FilledComponentRecipeLayer ;
1312import 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 ;
1615import dev .compactmods .crafting .util .BlockSpaceUtil ;
1716import net .minecraft .core .BlockPos ;
1817import net .minecraft .gametest .framework .GameTest ;
1918import net .minecraft .gametest .framework .GameTestHelper ;
2019import net .minecraft .world .level .block .Blocks ;
2120import net .minecraft .world .phys .AABB ;
22- import net .neoforged .neoforge .gametest .GameTestHolder ;
23- import net .neoforged .neoforge .gametest .PrefixGameTestTemplate ;
2421import net .neoforged .testframework .annotation .ForEachTest ;
22+ import net .neoforged .testframework .annotation .TestHolder ;
2523import net .neoforged .testframework .gametest .EmptyTemplate ;
2624
2725import java .util .Objects ;
3230@ ForEachTest (groups = "layers" )
3331public 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