|
36 | 36 | import org.cyclops.integratedcrafting.part.aspect.CraftingAspectWriteBuilders; |
37 | 37 | import org.cyclops.integratedcrafting.part.aspect.CraftingAspects; |
38 | 38 | import org.cyclops.integrateddynamics.RegistryEntries; |
| 39 | +import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator; |
39 | 40 | import org.cyclops.integrateddynamics.api.part.PartPos; |
40 | 41 | import org.cyclops.integrateddynamics.api.part.write.IPartStateWriter; |
41 | 42 | import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus; |
| 43 | +import org.cyclops.integrateddynamics.core.evaluate.operator.CurriedOperator; |
| 44 | +import org.cyclops.integrateddynamics.core.evaluate.operator.Operators; |
42 | 45 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack; |
43 | 46 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeRecipe; |
44 | 47 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean; |
| 48 | +import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeOperator; |
45 | 49 | import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; |
| 50 | +import org.cyclops.integrateddynamics.core.evaluate.variable.Variable; |
46 | 51 | import org.cyclops.integrateddynamics.core.helper.NetworkHelpers; |
47 | 52 | import org.cyclops.integrateddynamics.core.helper.PartHelpers; |
48 | 53 | import org.cyclops.integratedtunnels.part.aspect.TunnelAspects; |
@@ -100,6 +105,80 @@ public void testItemsCraftChestOne(GameTestHelper helper) { |
100 | 105 | }); |
101 | 106 | } |
102 | 107 |
|
| 108 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 109 | + public void testItemsCraftChestOneOperator(GameTestHelper helper) { |
| 110 | + GameTestHelpersIntegratedCrafting.INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS); |
| 111 | + |
| 112 | + // Insert items in interface chest |
| 113 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.east()); |
| 114 | + chestIn.setItem(0, new ItemStack(Items.OAK_PLANKS, 64)); |
| 115 | + |
| 116 | + // Add chest recipe to crafting interface |
| 117 | + ResourceLocation recipeName = ResourceLocation.fromNamespaceAndPath("minecraft", "chest"); |
| 118 | + positions.interfaceRecipeAdders().get(0).accept(Triple.of(0, RecipeType.CRAFTING, recipeName)); |
| 119 | + |
| 120 | + // Enable operator crafting aspect in crafting writer, with an operator that returns the chest recipe |
| 121 | + placeOperatorInWriter(helper, positions.writer(), new CurriedOperator(Operators.GENERAL_IDENTITY, |
| 122 | + new Variable<>(ValueTypes.OBJECT_RECIPE, ValueObjectTypeRecipe.ValueRecipe.of(createRecipeDefinition(helper.getLevel(), RecipeType.CRAFTING, recipeName))))); |
| 123 | + |
| 124 | + helper.succeedWhen(() -> { |
| 125 | + IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(positions.writer()).getState(); |
| 126 | + helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.OPERATOR_CRAFT, "Active aspect is incorrect"); |
| 127 | + helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.OPERATOR_CRAFT).isEmpty(), "Active aspect has errors"); |
| 128 | + |
| 129 | + // Check if items have been crafted |
| 130 | + helper.assertValueEqual(chestIn.getItem(0).getItem(), Items.OAK_PLANKS, "Slot 0 item is incorrect"); |
| 131 | + helper.assertValueEqual(chestIn.getItem(0).getCount(), 56, "Slot 0 amount is incorrect"); |
| 132 | + helper.assertValueEqual(chestIn.getItem(1).getItem(), Items.CHEST, "Slot 1 item is incorrect"); |
| 133 | + helper.assertValueEqual(chestIn.getItem(1).getCount(), 1, "Slot 1 amount is incorrect"); |
| 134 | + }); |
| 135 | + } |
| 136 | + |
| 137 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 138 | + public void testItemsCraftChestOneOperatorEmptyRecipe(GameTestHelper helper) { |
| 139 | + GameTestHelpersIntegratedCrafting.INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS); |
| 140 | + |
| 141 | + // Insert items in interface chest |
| 142 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.east()); |
| 143 | + chestIn.setItem(0, new ItemStack(Items.OAK_PLANKS, 64)); |
| 144 | + |
| 145 | + // Add chest recipe to crafting interface |
| 146 | + positions.interfaceRecipeAdders().get(0).accept(Triple.of(0, RecipeType.CRAFTING, ResourceLocation.fromNamespaceAndPath("minecraft", "chest"))); |
| 147 | + |
| 148 | + // Enable operator crafting aspect in crafting writer, with an operator that returns an empty recipe |
| 149 | + placeOperatorInWriter(helper, positions.writer(), new CurriedOperator(Operators.GENERAL_IDENTITY, |
| 150 | + new Variable<>(ValueTypes.OBJECT_RECIPE, ValueObjectTypeRecipe.ValueRecipe.of(null)))); |
| 151 | + |
| 152 | + helper.runAfterDelay(100, () -> { |
| 153 | + IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(positions.writer()).getState(); |
| 154 | + helper.assertValueEqual(partStateWriter.getActiveAspect(), CraftingAspects.Write.OPERATOR_CRAFT, "Active aspect is incorrect"); |
| 155 | + helper.assertTrue(partStateWriter.getErrors(CraftingAspects.Write.OPERATOR_CRAFT).isEmpty(), "Active aspect has errors"); |
| 156 | + |
| 157 | + // Check that nothing has been crafted |
| 158 | + helper.assertValueEqual(chestIn.getItem(0).getCount(), 64, "Slot 0 amount is incorrect"); |
| 159 | + helper.assertTrue(chestIn.getItem(1).isEmpty(), "Slot 1 is not empty"); |
| 160 | + helper.succeed(); |
| 161 | + }); |
| 162 | + } |
| 163 | + |
| 164 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 165 | + public void testItemsCraftOperatorWithInputs(GameTestHelper helper) { |
| 166 | + GameTestHelpersIntegratedCrafting.INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS); |
| 167 | + |
| 168 | + // Enable operator crafting aspect in crafting writer, with an operator that still requires an input |
| 169 | + placeOperatorInWriter(helper, positions.writer(), Operators.GENERAL_IDENTITY); |
| 170 | + |
| 171 | + helper.succeedWhen(() -> { |
| 172 | + IPartStateWriter partStateWriter = (IPartStateWriter) PartHelpers.getPart(positions.writer()).getState(); |
| 173 | + helper.assertFalse(partStateWriter.getErrors(CraftingAspects.Write.OPERATOR_CRAFT).isEmpty(), "Active aspect has no errors"); |
| 174 | + }); |
| 175 | + } |
| 176 | + |
| 177 | + private static void placeOperatorInWriter(GameTestHelper helper, PartPos writerPos, IOperator operator) { |
| 178 | + placeVariableInWriter(helper.getLevel(), writerPos, CraftingAspects.Write.OPERATOR_CRAFT, |
| 179 | + createVariableForValue(helper.getLevel(), ValueTypes.OPERATOR, ValueTypeOperator.ValueOperator.of(operator))); |
| 180 | + } |
| 181 | + |
103 | 182 | @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
104 | 183 | public void testItemsCraftChestOneRecipeDuration(GameTestHelper helper) { |
105 | 184 | GameTestHelpersIntegratedCrafting.INetworkPositions<PartTypeInterfaceCrafting.State> positions = createBasicNetwork(helper, POS); |
|
0 commit comments