From d03bb16d41946aeff25cc0c46d1a1d4f7a9848b3 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Thu, 19 Dec 2024 15:40:56 +0100 Subject: [PATCH] Add game tests for issue #81 --- .../GameTestHelpersIntegratedCrafting.java | 3 +- .../gametest/GameTestsItemsCraft.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestHelpersIntegratedCrafting.java b/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestHelpersIntegratedCrafting.java index 1b0edea5..a229af46 100644 --- a/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestHelpersIntegratedCrafting.java +++ b/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestHelpersIntegratedCrafting.java @@ -114,7 +114,7 @@ public static NetworkPositions createBasicNetwork(GameTestHelper helper, BlockPo posi = posi.south(); } - return new NetworkPositions(PartPos.of(helper.getLevel(), helper.absolutePos(pos), Direction.NORTH), interfaces, interfaceStates, interfaceRecipeAdders); + return new NetworkPositions(pos.east(), PartPos.of(helper.getLevel(), helper.absolutePos(pos), Direction.NORTH), interfaces, interfaceStates, interfaceRecipeAdders); } public static ItemStack createVariableForRecipe(Level level, RecipeType recipeType, ResourceLocation recipeName) { @@ -195,6 +195,7 @@ public static , V extends IValue> void setCraftingInterf } public static record NetworkPositions( + BlockPos chest, PartPos writer, List interfaces, List interfaceStates, diff --git a/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestsItemsCraft.java b/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestsItemsCraft.java index 9a91f1f1..d0ecd231 100644 --- a/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestsItemsCraft.java +++ b/src/main/java/org/cyclops/integratedcrafting/gametest/GameTestsItemsCraft.java @@ -28,19 +28,23 @@ import org.cyclops.integratedcrafting.part.PartTypes; import org.cyclops.integratedcrafting.part.aspect.CraftingAspectWriteBuilders; import org.cyclops.integratedcrafting.part.aspect.CraftingAspects; +import org.cyclops.integrateddynamics.RegistryEntries; import org.cyclops.integrateddynamics.api.part.PartPos; import org.cyclops.integrateddynamics.api.part.write.IPartStateWriter; import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus; +import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeRecipe; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; import org.cyclops.integrateddynamics.core.helper.PartHelpers; +import org.cyclops.integratedtunnels.part.aspect.TunnelAspects; import java.util.List; import java.util.Map; import static org.cyclops.integratedcrafting.gametest.GameTestHelpersIntegratedCrafting.*; import static org.cyclops.integrateddynamics.gametest.GameTestHelpersIntegratedDynamics.createVariableForValue; +import static org.cyclops.integrateddynamics.gametest.GameTestHelpersIntegratedDynamics.placeVariableInWriter; @GameTestHolder(Reference.MOD_ID) @PrefixGameTestTemplate(false) @@ -351,4 +355,37 @@ public void testItemsCraftCrafterComplex(GameTestHelper helper) { }); } + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) + public void testItemsCraftPlanksAndExtractFromStorage(GameTestHelper helper) { + GameTestHelpersIntegratedCrafting.NetworkPositions positions = createBasicNetwork(helper, POS); + + // Insert items in interface chest + ChestBlockEntity chestIn = helper.getBlockEntity(POS.east()); + chestIn.setItem(0, new ItemStack(Items.OAK_LOG, 64)); + + // Add chest recipe to crafting interface + positions.interfaceRecipeAdders().get(0).accept(Triple.of(0, RecipeType.CRAFTING, ResourceLocation.fromNamespaceAndPath("minecraft", "oak_planks"))); + + // Enable crafting aspect in crafting writer + enableRecipeInWriter(helper, positions.writer(), new ItemStack(Items.OAK_PLANKS)); + + // Set aspect to ignore storage contents + setWriterAspectProperty(positions.writer(), CraftingAspects.Write.ITEMSTACK_CRAFT, CraftingAspectWriteBuilders.PROP_IGNORE_STORAGE, ValueTypeBoolean.ValueBoolean.of(true)); + + // Extract all items from storage chest + helper.setBlock(positions.chest().south(), RegistryEntries.BLOCK_CABLE.value()); + helper.setBlock(positions.chest().south().south(), Blocks.CHEST); + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(positions.chest().south()), Direction.SOUTH, org.cyclops.integratedtunnels.part.PartTypes.INTERFACE_ITEM, new ItemStack(org.cyclops.integratedtunnels.part.PartTypes.INTERFACE_ITEM.getItem())); + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(positions.chest().south()), Direction.NORTH, org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM, new ItemStack(org.cyclops.integratedtunnels.part.PartTypes.IMPORTER_ITEM.getItem())); + placeVariableInWriter(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(positions.chest().south()), Direction.NORTH), TunnelAspects.Write.Item.ITEMSTACK_IMPORT, createVariableForValue(helper.getLevel(), ValueTypes.OBJECT_ITEMSTACK, ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.OAK_PLANKS)))); + + helper.succeedWhen(() -> { + // Check crafting interface state + helper.assertTrue(positions.interfaceStates().get(0).isRecipeSlotValid(0), "Recipe in crafting interface is not valid"); + + // Check if items have been crafted + helper.assertTrue(chestIn.getItem(0).isEmpty(), "Slot 0 item is incorrect"); + }); + } + }