11package dev .compactmods .crafting .tests .recipes .layers ;
22
3+ import java .util .Optional ;
4+ import java .util .Set ;
5+ import java .util .stream .Collectors ;
36import com .google .gson .JsonElement ;
47import com .mojang .serialization .JsonOps ;
8+ import dev .compactmods .crafting .api .field .MiniaturizationFieldSize ;
9+ import dev .compactmods .crafting .recipes .components .CCMiniRecipeComponents ;
510import dev .compactmods .crafting .recipes .layers .FilledComponentRecipeLayer ;
11+ import dev .compactmods .crafting .tests .recipes .util .RecipeTestUtil ;
612import dev .compactmods .crafting .tests .util .FileHelper ;
13+ import dev .compactmods .crafting .util .BlockSpaceUtil ;
714import net .minecraft .util .math .AxisAlignedBB ;
15+ import net .minecraft .util .math .BlockPos ;
816import org .junit .jupiter .api .Assertions ;
917import org .junit .jupiter .api .Tag ;
1018import org .junit .jupiter .api .Test ;
@@ -29,6 +37,9 @@ void CanCreateLayerInstance() {
2937 void ReturnsNoFilledIfDimensionsNull () {
3038 final FilledComponentRecipeLayer layer = getLayerFromFile ("layers/filled/basic.json" );
3139
40+ // We force the dimensions null here
41+ layer .setRecipeDimensions ((AxisAlignedBB ) null );
42+
3243 int filled = Assertions .assertDoesNotThrow (layer ::getNumberFilledPositions );
3344 Assertions .assertEquals (0 , filled );
3445 }
@@ -40,13 +51,109 @@ void CanUpdateDimensions() {
4051
4152 int filledBefore = layer .getNumberFilledPositions ();
4253
43- AxisAlignedBB newDims = new AxisAlignedBB (0 , 0 , 0 , 5 , 1 , 5 );
44- Assertions .assertDoesNotThrow (() -> layer .setRecipeDimensions (newDims ));
54+ Assertions .assertDoesNotThrow (() -> layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM ));
4555
4656 int filledAfter = layer .getNumberFilledPositions ();
4757
4858 Assertions .assertNotEquals (filledBefore , filledAfter , "Expected component count to change after growing layer dimensions." );
4959 }
5060
61+ @ Test
62+ @ Tag ("minecraft" )
63+ void ComponentPositionsAreCorrect () {
64+ final FilledComponentRecipeLayer layer = getLayerFromFile ("layers/filled/basic.json" );
65+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
66+
67+ Assertions .assertEquals (25 , layer .getNumberFilledPositions ());
68+
69+ final Set <BlockPos > expected = BlockSpaceUtil .getBlocksIn (MiniaturizationFieldSize .MEDIUM , 0 )
70+ .map (BlockPos ::immutable )
71+ .collect (Collectors .toSet ());
72+
73+ final Set <BlockPos > actual = layer .getPositionsForComponent ("G" )
74+ .map (BlockPos ::immutable )
75+ .collect (Collectors .toSet ());
76+
77+ Assertions .assertEquals (expected , actual );
78+ }
79+
80+ @ Test
81+ @ Tag ("minecraft" )
82+ void CanFetchComponentByPosition () {
83+ final FilledComponentRecipeLayer layer = getLayerFromFile ("layers/filled/basic.json" );
84+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
85+
86+ final Optional <String > componentForPosition = layer .getComponentForPosition (BlockPos .ZERO );
87+ Assertions .assertTrue (componentForPosition .isPresent ());
88+ componentForPosition .ifPresent (comp -> {
89+ Assertions .assertEquals ("G" , comp );
90+ });
91+ }
92+
93+ @ Test
94+ @ Tag ("minecraft" )
95+ void ReturnsEmptyWhenFetchingOOBPosition () {
96+ final FilledComponentRecipeLayer layer = getLayerFromFile ("layers/filled/basic.json" );
97+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
98+
99+ // Y = 1 should never happen, in any layer, ever
100+ final Optional <String > componentForPosition = layer .getComponentForPosition (BlockPos .ZERO .above ());
101+ Assertions .assertFalse (componentForPosition .isPresent ());
102+ }
103+
104+ @ Test
105+ @ Tag ("minecraft" )
106+ void LayerMatchesWorldInExactMatchScenario () {
107+ final TestRecipeLayerBlocks blocks = RecipeTestUtil .getLayerHarness ("worlds/basic_filled_harness_5x.json" );
108+ final CCMiniRecipeComponents components = RecipeTestUtil .getComponentsFromHarness ("worlds/basic_filled_harness_5x.json" );
109+
110+ // Set up a 5x5x1 filled layer, using "G" component
111+ final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer ("G" );
112+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
113+
114+ boolean matched = Assertions .assertDoesNotThrow (() -> layer .matches (components , blocks ));
115+ Assertions .assertTrue (matched );
116+ }
117+
118+ @ Test
119+ @ Tag ("minecraft" )
120+ void FailsMatchIfAllBlocksNotIdentified () {
121+ final TestRecipeLayerBlocks blocks = RecipeTestUtil .getLayerHarness ("worlds/basic_harness_5x.json" );
122+ final CCMiniRecipeComponents components = RecipeTestUtil .getComponentsFromHarness ("worlds/basic_harness_5x.json" );
123+
124+ // Set up a 5x5x1 filled layer, using "G" component
125+ final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer ("G" );
126+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
127+
128+ boolean matched = Assertions .assertDoesNotThrow (() -> layer .matches (components , blocks ));
129+ Assertions .assertFalse (matched );
130+ }
51131
132+ @ Test
133+ @ Tag ("minecraft" )
134+ void FailsMatchIfMoreThanOneBlockFound () {
135+ final TestRecipeLayerBlocks blocks = RecipeTestUtil .getLayerHarness ("worlds/basic_harness_allmatched_5x.json" );
136+ final CCMiniRecipeComponents components = RecipeTestUtil .getComponentsFromHarness ("worlds/basic_harness_allmatched_5x.json" );
137+
138+ // Set up a 5x5x1 filled layer, using "G" component
139+ final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer ("G" );
140+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
141+
142+ boolean matched = Assertions .assertDoesNotThrow (() -> layer .matches (components , blocks ));
143+ Assertions .assertFalse (matched );
144+ }
145+
146+ @ Test
147+ @ Tag ("minecraft" )
148+ void FailsMatchIfComponentKeyNotFound () {
149+ final TestRecipeLayerBlocks blocks = RecipeTestUtil .getLayerHarness ("worlds/basic_filled_harness_alt_5x.json" );
150+ final CCMiniRecipeComponents components = RecipeTestUtil .getComponentsFromHarness ("worlds/basic_filled_harness_alt_5x.json" );
151+
152+ // Set up a 5x5x1 filled layer, using "G" component
153+ final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer ("G" );
154+ layer .setRecipeDimensions (MiniaturizationFieldSize .MEDIUM );
155+
156+ boolean matched = Assertions .assertDoesNotThrow (() -> layer .matches (components , blocks ));
157+ Assertions .assertFalse (matched );
158+ }
52159}
0 commit comments