|
21 | 21 | import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties; |
22 | 22 | import org.cyclops.integrateddynamics.api.part.write.IPartStateWriter; |
23 | 23 | import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus; |
| 24 | +import org.cyclops.integrateddynamics.core.evaluate.operator.CurriedOperator; |
| 25 | +import org.cyclops.integrateddynamics.core.evaluate.operator.Operators; |
24 | 26 | import org.cyclops.integrateddynamics.core.evaluate.variable.*; |
25 | 27 | import org.cyclops.integrateddynamics.core.helper.PartHelpers; |
26 | 28 | import org.cyclops.integratedtunnels.Reference; |
@@ -571,4 +573,202 @@ public void testItemsImporterToInterfaceItemListBlacklist(GameTestHelper helper) |
571 | 573 | }); |
572 | 574 | } |
573 | 575 |
|
| 576 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 577 | + public void testItemsInterfaceToExporterPredicateValidSingle(GameTestHelper helper) { |
| 578 | + // Place cable |
| 579 | + helper.setBlock(POS, RegistryEntries.BLOCK_CABLE.value()); |
| 580 | + helper.setBlock(POS.east(), RegistryEntries.BLOCK_CABLE.value()); |
| 581 | + |
| 582 | + // Place item interface |
| 583 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS), Direction.WEST, PartTypes.INTERFACE_ITEM, new ItemStack(PartTypes.INTERFACE_ITEM.getItem())); |
| 584 | + |
| 585 | + // Place item exporter |
| 586 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST, PartTypes.EXPORTER_ITEM, new ItemStack(PartTypes.EXPORTER_ITEM.getItem())); |
| 587 | + |
| 588 | + // Place chests |
| 589 | + helper.setBlock(POS.west(), Blocks.CHEST); |
| 590 | + helper.setBlock(POS.east().east(), Blocks.CHEST); |
| 591 | + |
| 592 | + // Insert items in interface chest |
| 593 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.west()); |
| 594 | + chestIn.setItem(0, new ItemStack(Items.WHITE_WOOL)); |
| 595 | + chestIn.setItem(1, new ItemStack(Items.ACACIA_LEAVES)); |
| 596 | + chestIn.setItem(2, new ItemStack(Items.DIAMOND_PICKAXE)); |
| 597 | + |
| 598 | + // Place empty variable in exporter |
| 599 | + ItemStack variableAspect = createVariableForValue(helper.getLevel(), ValueTypes.OPERATOR, ValueTypeOperator.ValueOperator.of(new CurriedOperator( |
| 600 | + Operators.RELATIONAL_EQUALS, |
| 601 | + new Variable<>(ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.WHITE_WOOL))) |
| 602 | + ))); |
| 603 | + placeVariableInWriter(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST), TunnelAspects.Write.Item.PREDICATE_EXPORT, variableAspect); |
| 604 | + |
| 605 | + helper.succeedWhen(() -> { |
| 606 | + // Check if items are moved |
| 607 | + ChestBlockEntity chestOut = helper.getBlockEntity(POS.east().east()); |
| 608 | + helper.assertTrue(chestIn.getItem(0).isEmpty(), "Incorrect input item was moved"); |
| 609 | + helper.assertFalse(chestIn.getItem(1).isEmpty(), "Incorrect input item was moved"); |
| 610 | + helper.assertFalse(chestIn.getItem(2).isEmpty(), "Incorrect input item was moved"); |
| 611 | + helper.assertFalse(chestOut.getItem(0).isEmpty(), "Incorrect output item was moved"); |
| 612 | + helper.assertTrue(chestOut.getItem(1).isEmpty(), "Incorrect output item was moved"); |
| 613 | + helper.assertTrue(chestOut.getItem(2).isEmpty(), "Incorrect output item was moved"); |
| 614 | + helper.assertContainerContains(POS.east().east(), Items.WHITE_WOOL); |
| 615 | + helper.assertContainerContains(POS.west(), Items.ACACIA_LEAVES); |
| 616 | + helper.assertContainerContains(POS.west(), Items.DIAMOND_PICKAXE); |
| 617 | + }); |
| 618 | + } |
| 619 | + |
| 620 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 621 | + public void testItemsInterfaceToExporterPredicateInvalidMultiple(GameTestHelper helper) { |
| 622 | + // Place cable |
| 623 | + helper.setBlock(POS, RegistryEntries.BLOCK_CABLE.value()); |
| 624 | + helper.setBlock(POS.east(), RegistryEntries.BLOCK_CABLE.value()); |
| 625 | + |
| 626 | + // Place item interface |
| 627 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS), Direction.WEST, PartTypes.INTERFACE_ITEM, new ItemStack(PartTypes.INTERFACE_ITEM.getItem())); |
| 628 | + |
| 629 | + // Place item exporter |
| 630 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST, PartTypes.EXPORTER_ITEM, new ItemStack(PartTypes.EXPORTER_ITEM.getItem())); |
| 631 | + |
| 632 | + // Place chests |
| 633 | + helper.setBlock(POS.west(), Blocks.CHEST); |
| 634 | + helper.setBlock(POS.east().east(), Blocks.CHEST); |
| 635 | + |
| 636 | + // Insert items in interface chest |
| 637 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.west()); |
| 638 | + chestIn.setItem(0, new ItemStack(Items.WHITE_WOOL)); |
| 639 | + chestIn.setItem(1, new ItemStack(Items.ACACIA_LEAVES)); |
| 640 | + chestIn.setItem(2, new ItemStack(Items.DIAMOND_PICKAXE)); |
| 641 | + chestIn.setItem(3, new ItemStack(Items.WHITE_WOOL)); |
| 642 | + |
| 643 | + // Place empty variable in exporter |
| 644 | + ItemStack variableAspect = createVariableForValue(helper.getLevel(), ValueTypes.OPERATOR, ValueTypeOperator.ValueOperator.of(new CurriedOperator( |
| 645 | + Operators.RELATIONAL_EQUALS, |
| 646 | + new Variable<>(ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.WHITE_WOOL))) |
| 647 | + ))); |
| 648 | + placeVariableInWriter(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST), TunnelAspects.Write.Item.PREDICATE_EXPORT, variableAspect); |
| 649 | + |
| 650 | + helper.succeedWhen(() -> { |
| 651 | + // Check if items are moved |
| 652 | + ChestBlockEntity chestOut = helper.getBlockEntity(POS.east().east()); |
| 653 | + helper.assertFalse(chestIn.getItem(0).isEmpty(), "Incorrect input item was moved"); |
| 654 | + helper.assertFalse(chestIn.getItem(1).isEmpty(), "Incorrect input item was moved"); |
| 655 | + helper.assertFalse(chestIn.getItem(2).isEmpty(), "Incorrect input item was moved"); |
| 656 | + helper.assertFalse(chestIn.getItem(3).isEmpty(), "Incorrect input item was moved"); |
| 657 | + helper.assertTrue(chestOut.getItem(0).isEmpty(), "Incorrect output item was moved"); |
| 658 | + helper.assertTrue(chestOut.getItem(1).isEmpty(), "Incorrect output item was moved"); |
| 659 | + helper.assertTrue(chestOut.getItem(2).isEmpty(), "Incorrect output item was moved"); |
| 660 | + helper.assertTrue(chestOut.getItem(3).isEmpty(), "Incorrect output item was moved"); |
| 661 | + helper.assertTrue(chestIn.getItem(0).getItem() == Items.WHITE_WOOL, "Incorrect output item type was moved"); |
| 662 | + helper.assertContainerContains(POS.west(), Items.ACACIA_LEAVES); |
| 663 | + helper.assertContainerContains(POS.west(), Items.DIAMOND_PICKAXE); |
| 664 | + helper.assertTrue(chestIn.getItem(3).getItem() == Items.WHITE_WOOL, "Incorrect output item type was moved"); |
| 665 | + }); |
| 666 | + } |
| 667 | + |
| 668 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 669 | + public void testItemsInterfaceToExporterPredicateSlotBasedValid(GameTestHelper helper) { |
| 670 | + // Place cable |
| 671 | + helper.setBlock(POS, RegistryEntries.BLOCK_CABLE.value()); |
| 672 | + helper.setBlock(POS.east(), RegistryEntries.BLOCK_CABLE.value()); |
| 673 | + |
| 674 | + // Place item interface |
| 675 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS), Direction.WEST, PartTypes.INTERFACE_ITEM, new ItemStack(PartTypes.INTERFACE_ITEM.getItem())); |
| 676 | + |
| 677 | + // Place item exporter |
| 678 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST, PartTypes.EXPORTER_ITEM, new ItemStack(PartTypes.EXPORTER_ITEM.getItem())); |
| 679 | + |
| 680 | + // Place chests |
| 681 | + helper.setBlock(POS.west(), Blocks.CHEST); |
| 682 | + helper.setBlock(POS.east().east(), Blocks.CHEST); |
| 683 | + |
| 684 | + // Insert items in interface chest |
| 685 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.west()); |
| 686 | + chestIn.setItem(0, new ItemStack(Items.WHITE_WOOL)); |
| 687 | + chestIn.setItem(1, new ItemStack(Items.ACACIA_LEAVES)); |
| 688 | + chestIn.setItem(2, new ItemStack(Items.DIAMOND_PICKAXE)); |
| 689 | + chestIn.setItem(3, new ItemStack(Items.WHITE_WOOL)); |
| 690 | + |
| 691 | + // Place empty variable in exporter |
| 692 | + ItemStack variableAspect = createVariableForValue(helper.getLevel(), ValueTypes.OPERATOR, ValueTypeOperator.ValueOperator.of(new CurriedOperator( |
| 693 | + Operators.RELATIONAL_EQUALS, |
| 694 | + new Variable<>(ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.WHITE_WOOL))) |
| 695 | + ))); |
| 696 | + placeVariableInWriter(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST), TunnelAspects.Write.Item.PREDICATE_EXPORT, variableAspect); |
| 697 | + |
| 698 | + // Enable slot-based |
| 699 | + PartPos posExporter = PartPos.of(DimPos.of(helper.getLevel(), helper.absolutePos(POS.east())), Direction.EAST); |
| 700 | + PartHelpers.PartStateHolder partStateHolder = PartHelpers.getPart(posExporter); |
| 701 | + IAspectProperties properties = TunnelAspects.Write.Item.PREDICATE_EXPORT.getProperties(partStateHolder.getPart(), PartTarget.fromCenter(posExporter), partStateHolder.getState()); |
| 702 | + properties.setValue(TunnelAspectWriteBuilders.Item.PROP_PREDICATE_SLOTBASED, ValueTypeBoolean.ValueBoolean.of(true)); |
| 703 | + partStateHolder.getState().setAspectProperties(TunnelAspects.Write.Item.PREDICATE_EXPORT, properties); |
| 704 | + |
| 705 | + helper.succeedWhen(() -> { |
| 706 | + // Check if items are moved |
| 707 | + ChestBlockEntity chestOut = helper.getBlockEntity(POS.east().east()); |
| 708 | + helper.assertTrue(chestIn.getItem(0).isEmpty(), "Incorrect input item was moved"); |
| 709 | + helper.assertFalse(chestIn.getItem(1).isEmpty(), "Incorrect input item was moved"); |
| 710 | + helper.assertFalse(chestIn.getItem(2).isEmpty(), "Incorrect input item was moved"); |
| 711 | + helper.assertTrue(chestIn.getItem(3).isEmpty(), "Incorrect input item was moved"); |
| 712 | + helper.assertFalse(chestOut.getItem(0).isEmpty(), "Incorrect output item was moved"); |
| 713 | + helper.assertTrue(chestOut.getItem(1).isEmpty(), "Incorrect output item was moved"); |
| 714 | + helper.assertTrue(chestOut.getItem(2).isEmpty(), "Incorrect output item was moved"); |
| 715 | + helper.assertTrue(chestOut.getItem(0).getItem() == Items.WHITE_WOOL, "Incorrect output item type was moved"); |
| 716 | + helper.assertTrue(chestOut.getItem(0).getCount() == 2, "Incorrect output item size was moved"); |
| 717 | + helper.assertContainerContains(POS.west(), Items.ACACIA_LEAVES); |
| 718 | + helper.assertContainerContains(POS.west(), Items.DIAMOND_PICKAXE); |
| 719 | + }); |
| 720 | + } |
| 721 | + |
| 722 | + @GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT) |
| 723 | + public void testItemsInterfaceToExporterPredicateSlotBasedInvalid(GameTestHelper helper) { |
| 724 | + // Place cable |
| 725 | + helper.setBlock(POS, RegistryEntries.BLOCK_CABLE.value()); |
| 726 | + helper.setBlock(POS.east(), RegistryEntries.BLOCK_CABLE.value()); |
| 727 | + |
| 728 | + // Place item interface |
| 729 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS), Direction.WEST, PartTypes.INTERFACE_ITEM, new ItemStack(PartTypes.INTERFACE_ITEM.getItem())); |
| 730 | + |
| 731 | + // Place item exporter |
| 732 | + PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST, PartTypes.EXPORTER_ITEM, new ItemStack(PartTypes.EXPORTER_ITEM.getItem())); |
| 733 | + |
| 734 | + // Place chests |
| 735 | + helper.setBlock(POS.west(), Blocks.CHEST); |
| 736 | + helper.setBlock(POS.east().east(), Blocks.CHEST); |
| 737 | + |
| 738 | + // Insert items in interface chest |
| 739 | + ChestBlockEntity chestIn = helper.getBlockEntity(POS.west()); |
| 740 | + chestIn.setItem(0, new ItemStack(Items.WHITE_WOOL, 2)); |
| 741 | + chestIn.setItem(1, new ItemStack(Items.ACACIA_LEAVES)); |
| 742 | + chestIn.setItem(2, new ItemStack(Items.DIAMOND_PICKAXE)); |
| 743 | + |
| 744 | + // Place empty variable in exporter |
| 745 | + ItemStack variableAspect = createVariableForValue(helper.getLevel(), ValueTypes.OPERATOR, ValueTypeOperator.ValueOperator.of(new CurriedOperator( |
| 746 | + Operators.RELATIONAL_EQUALS, |
| 747 | + new Variable<>(ValueObjectTypeItemStack.ValueItemStack.of(new ItemStack(Items.WHITE_WOOL))) |
| 748 | + ))); |
| 749 | + placeVariableInWriter(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.east()), Direction.EAST), TunnelAspects.Write.Item.PREDICATE_EXPORT, variableAspect); |
| 750 | + |
| 751 | + // Enable slot-based |
| 752 | + PartPos posExporter = PartPos.of(DimPos.of(helper.getLevel(), helper.absolutePos(POS.east())), Direction.EAST); |
| 753 | + PartHelpers.PartStateHolder partStateHolder = PartHelpers.getPart(posExporter); |
| 754 | + IAspectProperties properties = TunnelAspects.Write.Item.PREDICATE_EXPORT.getProperties(partStateHolder.getPart(), PartTarget.fromCenter(posExporter), partStateHolder.getState()); |
| 755 | + properties.setValue(TunnelAspectWriteBuilders.Item.PROP_PREDICATE_SLOTBASED, ValueTypeBoolean.ValueBoolean.of(true)); |
| 756 | + partStateHolder.getState().setAspectProperties(TunnelAspects.Write.Item.PREDICATE_EXPORT, properties); |
| 757 | + |
| 758 | + helper.succeedWhen(() -> { |
| 759 | + // Check if items are moved |
| 760 | + ChestBlockEntity chestOut = helper.getBlockEntity(POS.east().east()); |
| 761 | + helper.assertFalse(chestIn.getItem(0).isEmpty(), "Incorrect input item was moved"); |
| 762 | + helper.assertFalse(chestIn.getItem(1).isEmpty(), "Incorrect input item was moved"); |
| 763 | + helper.assertFalse(chestIn.getItem(2).isEmpty(), "Incorrect input item was moved"); |
| 764 | + helper.assertTrue(chestOut.getItem(0).isEmpty(), "Incorrect output item was moved"); |
| 765 | + helper.assertTrue(chestOut.getItem(1).isEmpty(), "Incorrect output item was moved"); |
| 766 | + helper.assertTrue(chestOut.getItem(2).isEmpty(), "Incorrect output item was moved"); |
| 767 | + helper.assertTrue(chestIn.getItem(0).getItem() == Items.WHITE_WOOL, "Incorrect output item type was moved"); |
| 768 | + helper.assertTrue(chestIn.getItem(0).getCount() == 2, "Incorrect output item size was moved"); |
| 769 | + helper.assertContainerContains(POS.west(), Items.ACACIA_LEAVES); |
| 770 | + helper.assertContainerContains(POS.west(), Items.DIAMOND_PICKAXE); |
| 771 | + }); |
| 772 | + } |
| 773 | + |
574 | 774 | } |
0 commit comments