Skip to content

Commit 2117210

Browse files
committed
Start filled layer tests
1 parent 803af09 commit 2117210

File tree

6 files changed

+83
-50
lines changed

6 files changed

+83
-50
lines changed

src/api/java/dev/compactmods/crafting/api/recipe/layers/dim/IDynamicSizedRecipeLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public interface IDynamicSizedRecipeLayer {
1313
* Used to recalculate dynamic-sized recipe layers. Expected to be called
1414
* any time components or base recipe dimensions change.
1515
*/
16-
void recalculateRequirements();
16+
default void recalculateRequirements() {}
1717
}

src/main/java/dev/compactmods/crafting/recipes/layers/FilledComponentRecipeLayer.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class FilledComponentRecipeLayer implements IRecipeLayer, IDynamicSizedRe
2828
).apply(in, FilledComponentRecipeLayer::new));
2929

3030
public FilledComponentRecipeLayer(String component) {
31+
this.recipeDimensions = AxisAlignedBB.ofSize(0, 0, 0);
3132
this.componentKey = component;
3233
}
3334

@@ -92,14 +93,5 @@ public void setComponent(String component) {
9293
*/
9394
public void setRecipeDimensions(AxisAlignedBB dimensions) {
9495
this.recipeDimensions = dimensions;
95-
this.recalculateRequirements();
96-
}
97-
98-
/**
99-
* Used to recalculate dynamic-sized recipe layers. Expected to be called
100-
* any time components or base recipe dimensions change.
101-
*/
102-
public void recalculateRequirements() {
103-
10496
}
10597
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package dev.compactmods.crafting.tests.recipes.layers;
2+
3+
import com.google.gson.JsonElement;
4+
import com.mojang.serialization.JsonOps;
5+
import dev.compactmods.crafting.recipes.layers.FilledComponentRecipeLayer;
6+
import dev.compactmods.crafting.tests.util.FileHelper;
7+
import net.minecraft.util.math.AxisAlignedBB;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Tag;
10+
import org.junit.jupiter.api.Test;
11+
12+
public class FilledLayerTests {
13+
14+
private FilledComponentRecipeLayer getLayerFromFile(String filename) {
15+
JsonElement layerJson = FileHelper.INSTANCE.getJsonFromFile(filename);
16+
17+
return FilledComponentRecipeLayer.CODEC.parse(JsonOps.INSTANCE, layerJson)
18+
.getOrThrow(false, Assertions::fail);
19+
}
20+
21+
@Test
22+
@Tag("minecraft")
23+
void CanCreateLayerInstance() {
24+
getLayerFromFile("layers/filled/basic.json");
25+
}
26+
27+
@Test
28+
@Tag("minecraft")
29+
void ReturnsNoFilledIfDimensionsNull() {
30+
final FilledComponentRecipeLayer layer = getLayerFromFile("layers/filled/basic.json");
31+
32+
int filled = Assertions.assertDoesNotThrow(layer::getNumberFilledPositions);
33+
Assertions.assertEquals(0, filled);
34+
}
35+
36+
@Test
37+
@Tag("minecraft")
38+
void CanUpdateDimensions() {
39+
final FilledComponentRecipeLayer layer = getLayerFromFile("layers/filled/basic.json");
40+
41+
int filledBefore = layer.getNumberFilledPositions();
42+
43+
AxisAlignedBB newDims = new AxisAlignedBB(0, 0, 0, 5, 1, 5);
44+
Assertions.assertDoesNotThrow(() -> layer.setRecipeDimensions(newDims));
45+
46+
int filledAfter = layer.getNumberFilledPositions();
47+
48+
Assertions.assertNotEquals(filledBefore, filledAfter, "Expected component count to change after growing layer dimensions.");
49+
}
50+
51+
52+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "compactcrafting:filled",
3+
"component":"Gl"
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"world": {
3+
"type": "compactcrafting:filled",
4+
"component": "Gl"
5+
},
6+
7+
"worldBlocks": {
8+
"Gl": {
9+
"type": "compactcrafting:block",
10+
"block": "minecraft:glass"
11+
}
12+
},
13+
14+
"layer": {
15+
"type": "compactcrafting:filled",
16+
"component":"Gl"
17+
},
18+
19+
"components": {
20+
"Gl": {
21+
"type": "compactcrafting:block",
22+
"block": "minecraft:glass"
23+
}
24+
}
25+
}

src/test/resources/layers/mixed/mixed_basic.json

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)