Skip to content

Commit d00ea56

Browse files
committed
Add game tests for mechanical machine crafting, #197
1 parent c4af59c commit d00ea56

5 files changed

Lines changed: 232 additions & 1 deletion

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ org.gradle.caching=true
3030

3131
# Dependencies
3232
cyclopscore_version=1.29.5-1012
33-
integrateddynamics_version=1.32.11-1809
33+
integrateddynamics_version=1.32.13-1822
3434
commoncapabilities_version=2.11.4-344
3535
integratedtunnels_version=1.9.4-621

src/main/java/org/cyclops/integratedcrafting/IntegratedCrafting.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.cyclops.integratedcrafting.core.CraftingProcessOverrides;
2222
import org.cyclops.integratedcrafting.gametest.GameTestsAdvancements;
2323
import org.cyclops.integratedcrafting.gametest.GameTestsItemsCraft;
24+
import org.cyclops.integratedcrafting.gametest.GameTestsItemsMechanicalDryingBasin;
25+
import org.cyclops.integratedcrafting.gametest.GameTestsItemsMechanicalSqueezer;
2426
import org.cyclops.integratedcrafting.gametest.GameTestsItemsSmithing;
2527
import org.cyclops.integratedcrafting.gametest.GameTestsItemsStonecutting;
2628
import org.cyclops.integratedcrafting.inventory.container.ContainerPartInterfaceCraftingConfig;
@@ -127,7 +129,9 @@ public Class<?>[] getGameTestClasses() {
127129
return new Class<?>[]{
128130
GameTestsAdvancements.class,
129131
GameTestsItemsCraft.class,
132+
GameTestsItemsMechanicalDryingBasin.class,
130133
GameTestsItemsSmithing.class,
134+
GameTestsItemsMechanicalSqueezer.class,
131135
GameTestsItemsStonecutting.class
132136
};
133137
}

src/main/java/org/cyclops/integratedcrafting/gametest/GameTestHelpersIntegratedCrafting.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ public static INetworkPositions<PartTypeInterfaceCrafting.State> createBasicNetw
120120
helper.setBlock(posi.below().west(), RegistryEntries.BLOCK_CABLE.value());
121121
PartHelpers.addPart(helper.getLevel(), helper.absolutePos(posi.below().west()), Direction.UP, org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM, new ItemStack(org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM.getItem()));
122122
placeVariableInWriter(helper, helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(posi.below().west()), Direction.UP), TunnelAspects.Write.Item.BOOLEAN_IMPORT, new ItemStack(RegistryEntries.ITEM_VARIABLE));
123+
} else if (crafter instanceof org.cyclops.integrateddynamics.block.BlockMechanicalDryingBasin
124+
|| crafter instanceof org.cyclops.integrateddynamics.block.BlockMechanicalSqueezer) {
125+
// Add energy battery adjacent to the mechanical machine
126+
helper.setBlock(posi.west().north(), RegistryEntries.BLOCK_ENERGY_BATTERY.value());
127+
org.cyclops.integrateddynamics.blockentity.BlockEntityEnergyBattery battery = helper.getBlockEntity(posi.west().north(), org.cyclops.integrateddynamics.blockentity.BlockEntityEnergyBattery.class);
128+
battery.setEnergyStored(100_000);
129+
130+
// Extract result from output slots via the DOWN face
131+
helper.setBlock(posi.below(), RegistryEntries.BLOCK_CABLE.value());
132+
helper.setBlock(posi.below().west(), RegistryEntries.BLOCK_CABLE.value());
133+
PartHelpers.addPart(helper.getLevel(), helper.absolutePos(posi.below().west()), Direction.UP, org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM, new ItemStack(org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM.getItem()));
134+
placeVariableInWriter(helper, helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(posi.below().west()), Direction.UP), TunnelAspects.Write.Item.BOOLEAN_IMPORT, new ItemStack(RegistryEntries.ITEM_VARIABLE));
123135
}
124136

125137
interfaces.add(PartPos.of(helper.getLevel(), helper.absolutePos(posi.above().west()), Direction.DOWN));
@@ -215,6 +227,29 @@ public static ItemStack createVariableForRecipe(Level level, RecipeType<?> recip
215227
}
216228
recipeIn.put(IngredientComponents.ITEMSTACK, alternatives);
217229
recipeOut.put(IngredientComponents.ITEMSTACK, Lists.newArrayList(result));
230+
} else if (recipeUnknown.value() instanceof org.cyclops.integrateddynamics.core.recipe.type.RecipeDryingBasin recipeDryingBasin) {
231+
recipeDryingBasin.getInputIngredient().ifPresent(ingredient ->
232+
alternatives.add(new PrototypedIngredientAlternativesList<>(Lists.newArrayList(
233+
new PrototypedIngredient<>(IngredientComponents.ITEMSTACK, new ItemStack(ingredient.items().findFirst().get()), ItemMatch.ITEM | ItemMatch.DATA)
234+
)))
235+
);
236+
recipeIn.put(IngredientComponents.ITEMSTACK, alternatives);
237+
recipeDryingBasin.getOutputItemFirst().ifPresent(outputItem ->
238+
recipeOut.put(IngredientComponents.ITEMSTACK, Lists.newArrayList(outputItem))
239+
);
240+
} else if (recipeUnknown.value() instanceof org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer recipeSqueezer) {
241+
alternatives.add(new PrototypedIngredientAlternativesList<>(Lists.newArrayList(
242+
new PrototypedIngredient<>(IngredientComponents.ITEMSTACK, new ItemStack(recipeSqueezer.getInputIngredient().items().findFirst().get()), ItemMatch.ITEM | ItemMatch.DATA)
243+
)));
244+
recipeIn.put(IngredientComponents.ITEMSTACK, alternatives);
245+
java.util.List<ItemStack> squeezerOutputItems = recipeSqueezer.getOutputItems().stream()
246+
.filter(ic -> ic.getChance() == 1.0F)
247+
.map(ic -> ic.getIngredientFirst().copy())
248+
.filter(stack -> !stack.isEmpty())
249+
.collect(java.util.stream.Collectors.toList());
250+
if (!squeezerOutputItems.isEmpty()) {
251+
recipeOut.put(IngredientComponents.ITEMSTACK, squeezerOutputItems);
252+
}
218253
} else {
219254
throw new IllegalStateException("Unknown recipe type " + recipeType);
220255
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package org.cyclops.integratedcrafting.gametest;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
5+
import net.minecraft.gametest.framework.GameTestHelper;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.resources.Identifier;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
10+
import net.minecraft.world.level.block.entity.ChestBlockEntity;
11+
import org.apache.commons.lang3.tuple.Triple;
12+
import org.cyclops.cyclopscore.gametest.GameTest;
13+
import org.cyclops.integratedcrafting.Reference;
14+
import org.cyclops.integratedcrafting.part.PartTypeInterfaceCrafting;
15+
import org.cyclops.integratedcrafting.part.PartTypeInterfaceCraftingAttuned;
16+
import org.cyclops.integratedcrafting.part.PartTypes;
17+
import org.cyclops.integratedcrafting.part.aspect.CraftingAspects;
18+
import org.cyclops.integrateddynamics.RegistryEntries;
19+
import org.cyclops.integrateddynamics.api.part.PartPos;
20+
import org.cyclops.integrateddynamics.api.part.write.IPartStateWriter;
21+
import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus;
22+
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
23+
24+
import static org.cyclops.integratedcrafting.gametest.GameTestHelpersIntegratedCrafting.*;
25+
26+
public class GameTestsItemsMechanicalDryingBasin {
27+
28+
public static final String TEMPLATE_EMPTY = Reference.MOD_ID + ":empty10";
29+
public static final int TIMEOUT = 2000;
30+
public static final BlockPos POS = BlockPos.ZERO.offset(2, 0, 2);
31+
32+
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
33+
public void testItemsMechanicalDryingBasinDriedKelp(GameTestHelper helper) {
34+
INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS, RegistryEntries.BLOCK_MECHANICAL_DRYING_BASIN.value());
35+
36+
// Insert items in interface chest
37+
ChestBlockEntity chestIn = helper.getBlockEntity(POS.east(), ChestBlockEntity.class);
38+
chestIn.setItem(0, new ItemStack(Items.KELP, 1));
39+
40+
// Add dried kelp recipe to crafting interface
41+
positions.interfaceRecipeAdders().get(0).accept(Triple.of(0, RegistryEntries.RECIPETYPE_MECHANICAL_DRYING_BASIN.get(), Identifier.fromNamespaceAndPath("integrateddynamics", "mechanical_drying_basin/convenience/minecraft_dried_kelp")));
42+
43+
// Enable crafting aspect in crafting writer
44+
enableRecipeInWriter(helper, positions.writer(), new ItemStack(Items.DRIED_KELP));
45+
46+
helper.succeedWhen(() -> {
47+
// Check crafting interface state
48+
helper.assertTrue(positions.interfaceStates().get(0).isRecipeSlotValid(0), Component.literal("Recipe in crafting interface is not valid"));
49+
50+
// Check crafting writer state
51+
IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)).getState();
52+
helper.assertFalse(partStateWriter.isDeactivated(), Component.literal("Crafting writer is deactivated"));
53+
helper.assertValueEqual(
54+
PartTypes.CRAFTING_WRITER.getBlockState(PartHelpers.getPartContainerChecked(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)), Direction.NORTH).getValue(IgnoredBlockStatus.STATUS),
55+
IgnoredBlockStatus.Status.ACTIVE,
56+
Component.literal("Block status is incorrect")
57+
);
58+
helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.ITEMSTACK_CRAFT, Component.literal("Active aspect is incorrect"));
59+
helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.ITEMSTACK_CRAFT).isEmpty(), Component.literal("Active aspect has errors"));
60+
61+
// Check if items have been crafted
62+
helper.assertValueEqual(chestIn.getItem(0).getItem(), Items.DRIED_KELP, Component.literal("Slot 0 item is incorrect"));
63+
helper.assertValueEqual(chestIn.getItem(0).getCount(), 1, Component.literal("Slot 0 amount is incorrect"));
64+
});
65+
}
66+
67+
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
68+
public void testItemsMechanicalDryingBasinAttunedDriedKelp(GameTestHelper helper) {
69+
INetworkPositions<PartTypeInterfaceCraftingAttuned.State> positions = createBasicNetwork(helper, POS, true, RegistryEntries.BLOCK_MECHANICAL_DRYING_BASIN.value());
70+
71+
// Insert items in interface chest
72+
ChestBlockEntity chestIn = helper.getBlockEntity(POS.east(), ChestBlockEntity.class);
73+
chestIn.setItem(0, new ItemStack(Items.KELP, 1));
74+
75+
// Enable crafting aspect in crafting writer (attuned interface auto-discovers recipes)
76+
enableRecipeInWriter(helper, positions.writer(), new ItemStack(Items.DRIED_KELP));
77+
78+
helper.succeedWhen(() -> {
79+
// Check crafting writer state
80+
IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)).getState();
81+
helper.assertFalse(partStateWriter.isDeactivated(), Component.literal("Crafting writer is deactivated"));
82+
helper.assertValueEqual(
83+
PartTypes.CRAFTING_WRITER.getBlockState(PartHelpers.getPartContainerChecked(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)), Direction.NORTH).getValue(IgnoredBlockStatus.STATUS),
84+
IgnoredBlockStatus.Status.ACTIVE,
85+
Component.literal("Block status is incorrect")
86+
);
87+
helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.ITEMSTACK_CRAFT, Component.literal("Active aspect is incorrect"));
88+
helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.ITEMSTACK_CRAFT).isEmpty(), Component.literal("Active aspect has errors"));
89+
90+
// Check if items have been crafted
91+
helper.assertValueEqual(chestIn.getItem(0).getItem(), Items.DRIED_KELP, Component.literal("Slot 0 item is incorrect"));
92+
helper.assertValueEqual(chestIn.getItem(0).getCount(), 1, Component.literal("Slot 0 amount is incorrect"));
93+
});
94+
}
95+
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package org.cyclops.integratedcrafting.gametest;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
5+
import net.minecraft.gametest.framework.GameTestHelper;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.resources.Identifier;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
10+
import net.minecraft.world.level.block.entity.ChestBlockEntity;
11+
import org.apache.commons.lang3.tuple.Triple;
12+
import org.cyclops.cyclopscore.gametest.GameTest;
13+
import org.cyclops.integratedcrafting.Reference;
14+
import org.cyclops.integratedcrafting.part.PartTypeInterfaceCrafting;
15+
import org.cyclops.integratedcrafting.part.PartTypeInterfaceCraftingAttuned;
16+
import org.cyclops.integratedcrafting.part.PartTypes;
17+
import org.cyclops.integratedcrafting.part.aspect.CraftingAspects;
18+
import org.cyclops.integrateddynamics.RegistryEntries;
19+
import org.cyclops.integrateddynamics.api.part.PartPos;
20+
import org.cyclops.integrateddynamics.api.part.write.IPartStateWriter;
21+
import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus;
22+
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
23+
24+
import static org.cyclops.integratedcrafting.gametest.GameTestHelpersIntegratedCrafting.*;
25+
26+
public class GameTestsItemsMechanicalSqueezer {
27+
28+
public static final String TEMPLATE_EMPTY = Reference.MOD_ID + ":empty10";
29+
public static final int TIMEOUT = 2000;
30+
public static final BlockPos POS = BlockPos.ZERO.offset(2, 0, 2);
31+
32+
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
33+
public void testItemsMechanicalSqueezerBricks(GameTestHelper helper) {
34+
INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS, RegistryEntries.BLOCK_MECHANICAL_SQUEEZER.value());
35+
36+
// Insert items in interface chest
37+
ChestBlockEntity chestIn = helper.getBlockEntity(POS.east(), ChestBlockEntity.class);
38+
chestIn.setItem(0, new ItemStack(Items.BRICKS, 1));
39+
40+
// Add brick recipe to crafting interface
41+
positions.interfaceRecipeAdders().get(0).accept(Triple.of(0, RegistryEntries.RECIPETYPE_MECHANICAL_SQUEEZER.get(), Identifier.fromNamespaceAndPath("integrateddynamics", "mechanical_squeezer/convenience/minecraft_brick")));
42+
43+
// Enable crafting aspect in crafting writer
44+
enableRecipeInWriter(helper, positions.writer(), new ItemStack(Items.BRICK, 4));
45+
46+
helper.succeedWhen(() -> {
47+
// Check crafting interface state
48+
helper.assertTrue(positions.interfaceStates().get(0).isRecipeSlotValid(0), Component.literal("Recipe in crafting interface is not valid"));
49+
50+
// Check crafting writer state
51+
IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)).getState();
52+
helper.assertFalse(partStateWriter.isDeactivated(), Component.literal("Crafting writer is deactivated"));
53+
helper.assertValueEqual(
54+
PartTypes.CRAFTING_WRITER.getBlockState(PartHelpers.getPartContainerChecked(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)), Direction.NORTH).getValue(IgnoredBlockStatus.STATUS),
55+
IgnoredBlockStatus.Status.ACTIVE,
56+
Component.literal("Block status is incorrect")
57+
);
58+
helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.ITEMSTACK_CRAFT, Component.literal("Active aspect is incorrect"));
59+
helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.ITEMSTACK_CRAFT).isEmpty(), Component.literal("Active aspect has errors"));
60+
61+
// Check if items have been crafted
62+
helper.assertValueEqual(chestIn.getItem(0).getItem(), Items.BRICK, Component.literal("Slot 0 item is incorrect"));
63+
helper.assertValueEqual(chestIn.getItem(0).getCount(), 4, Component.literal("Slot 0 amount is incorrect"));
64+
});
65+
}
66+
67+
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
68+
public void testItemsMechanicalSqueezerAttunedBricks(GameTestHelper helper) {
69+
INetworkPositions<PartTypeInterfaceCraftingAttuned.State> positions = createBasicNetwork(helper, POS, true, RegistryEntries.BLOCK_MECHANICAL_SQUEEZER.value());
70+
71+
// Insert items in interface chest
72+
ChestBlockEntity chestIn = helper.getBlockEntity(POS.east(), ChestBlockEntity.class);
73+
chestIn.setItem(0, new ItemStack(Items.BRICKS, 1));
74+
75+
// Enable crafting aspect in crafting writer (attuned interface auto-discovers recipes)
76+
enableRecipeInWriter(helper, positions.writer(), new ItemStack(Items.BRICK, 4));
77+
78+
helper.succeedWhen(() -> {
79+
// Check crafting writer state
80+
IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)).getState();
81+
helper.assertFalse(partStateWriter.isDeactivated(), Component.literal("Crafting writer is deactivated"));
82+
helper.assertValueEqual(
83+
PartTypes.CRAFTING_WRITER.getBlockState(PartHelpers.getPartContainerChecked(PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.NORTH)), Direction.NORTH).getValue(IgnoredBlockStatus.STATUS),
84+
IgnoredBlockStatus.Status.ACTIVE,
85+
Component.literal("Block status is incorrect")
86+
);
87+
helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.ITEMSTACK_CRAFT, Component.literal("Active aspect is incorrect"));
88+
helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.ITEMSTACK_CRAFT).isEmpty(), Component.literal("Active aspect has errors"));
89+
90+
// Check if items have been crafted
91+
helper.assertValueEqual(chestIn.getItem(0).getItem(), Items.BRICK, Component.literal("Slot 0 item is incorrect"));
92+
helper.assertValueEqual(chestIn.getItem(0).getCount(), 4, Component.literal("Slot 0 amount is incorrect"));
93+
});
94+
}
95+
96+
}

0 commit comments

Comments
 (0)