|
| 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