11package mekanism .common .tests .network ;
22
3+ import static mekanism .common .tests .network .TransmitterTestUtils .useConfigurator ;
34import static mekanism .common .tests .util .TransporterTestUtils .colored ;
45import static mekanism .common .tests .util .TransporterTestUtils .configured ;
56import static mekanism .common .tests .util .TransporterTestUtils .containing ;
1617import net .minecraft .core .BlockPos ;
1718import net .minecraft .core .Direction ;
1819import net .minecraft .gametest .framework .GameTest ;
19- import net .minecraft .world .entity .player .Player ;
2020import net .minecraft .world .item .ItemStack ;
2121import net .minecraft .world .item .Items ;
2222import net .minecraft .world .level .block .Blocks ;
@@ -52,6 +52,18 @@ public class InventoryNetworkTest {
5252 .fill (0 , 0 , 2 , 9 , 0 , 2 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState ())
5353 .fill (9 , 0 , 0 , 9 , 0 , 1 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState ())
5454 );
55+ private static final String SIMPLE_PATH = MekanismTests .MODID + ":simple_path" ;
56+ //Note: Our template is lazy so that we ensure the transporters are registered
57+ @ RegisterStructureTemplate (SIMPLE_PATH )
58+ public static final Supplier <StructureTemplate > SIMPLE_PATH_TEMPLATE = StructureTemplateBuilder .lazy (1 , 1 , 6 , builder -> builder
59+ //Start barrel
60+ .set (0 , 0 , 0 , Blocks .BARREL .defaultBlockState (), containing (Items .STONE ))
61+ //End barrel
62+ .set (0 , 0 , 5 , Blocks .BARREL .defaultBlockState ())
63+
64+ .set (0 , 0 , 1 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState (), configured (Direction .NORTH ))
65+ .fill (0 , 0 , 2 , 0 , 0 , 4 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState ())
66+ );
5567
5668 //TODO: Do we want to somehow test the case of when we add a shorter path to the same destination, as the newly pulled items go via the new shorter path
5769 // but any already en-route ones continue the original way
@@ -61,39 +73,77 @@ public class InventoryNetworkTest {
6173 // - Cutting off an existing path -> recalculating pathfinding of currently travelling stacks, for example when setting a side to none or breaking a transporter
6274 // - Color changing on an existing path??
6375 // - Diversion transporters?? Might basically be just the same as the cutting off existing path
64- // - destination becomes inaccessible due to side changes
65- // - base path becomes disabled but there is a different path to the same destination
66- // - Remove destination and source and let it idle for a bit in the transporter then add a new spot and validate it all enters it??
6776 // - Make destination no longer able to accept item, validate input doesn't contain stack, and then validate it made its way back to the input
6877 // - Make destination no longer able to accept item, fill input fully, wait a little, and then allow for room in the destination, validate it makes it there
6978 // - Single transporter with no destination stays in the transporter, it fails and pops out if there is only a single connection point
7079 // Note: We may want to change that behavior so even with a single connection point it just stays idling and only pops out if there are zero connection points
7180
81+ @ GameTest (template = SIMPLE_PATH , setupTicks = SETUP_TICKS , timeoutTicks = TIMEOUT_TICKS )
82+ @ TestHolder (description = "Tests that items will properly be sent back and inserted into their home if the destination is removed while the stacks are en-route." )
83+ public static void sendsBackToHome (final ExtendedGameTestHelper helper ) {
84+ helper .startSequence ()
85+ //Wait a second for it to pull the item out, and remove the destination
86+ .thenExecuteAfter (SharedConstants .TICKS_PER_SECOND , () -> helper .setBlock (0 , 1 , 5 , Blocks .AIR ))
87+ //Make sure the start container is empty
88+ .thenExecute (() -> helper .assertContainerEmpty (0 , 1 , 0 ))
89+ //And then after a few seconds that the item has transferred back into the destination it was pulled from
90+ .thenExecuteAfter (6 * SharedConstants .TICKS_PER_SECOND , () -> helper .assertContainerContains (0 , 1 , 0 , Items .STONE ))
91+ .thenSucceed ();
92+ }
93+
94+ @ GameTest (template = SIMPLE_PATH , setupTicks = SETUP_TICKS , timeoutTicks = TIMEOUT_TICKS )
95+ @ TestHolder (description = "Tests that items will properly be sent back and inserted into their home if the destination becomes inaccessible "
96+ + "due to side changes while the stacks are en-route." )
97+ public static void sendsBackToHomeDisabled (final ExtendedGameTestHelper helper ) {
98+ helper .startSequence ()
99+ //Wait a second for it to pull the item out, and disable the path to the destination
100+ .thenExecuteAfter (SharedConstants .TICKS_PER_SECOND , () -> useConfigurator (helper , 0 , 1 , 4 , Direction .SOUTH , 3 ))
101+ //Make sure the start container is empty
102+ .thenExecute (() -> helper .assertContainerEmpty (0 , 1 , 0 ))
103+ //And then after a few seconds that the item has transferred back into the destination it was pulled from
104+ .thenExecuteAfter (6 * SharedConstants .TICKS_PER_SECOND , () -> helper .assertContainerContains (0 , 1 , 0 , Items .STONE ))
105+ .thenSucceed ();
106+ }
107+
72108 @ GameTest (setupTicks = SETUP_TICKS , timeoutTicks = TIMEOUT_TICKS )
73- @ TestHolder (description = "Tests that newly pulled items will go to the new destination that has a shorter path, "
74- + "but any items that were already en-route will continue to the destination they had already calculated." )
75- public static void sendsBackToHome (final DynamicTest test ) {
76- test .registerGameTestTemplate (() -> StructureTemplateBuilder .withSize (1 , 1 , 6 )
109+ @ TestHolder (description = "Tests that items will properly get to their destination, even if one of the paths to them is disabled, but another exists." )
110+ public static void pathDisabledButStillHasPath (final DynamicTest test ) {
111+ test .registerGameTestTemplate (() -> StructureTemplateBuilder .withSize (3 , 1 , 6 )
77112 //Start barrel
78113 .set (0 , 0 , 0 , Blocks .BARREL .defaultBlockState (), containing (Items .STONE ))
79- //End barrel
114+ //End barrels
80115 .set (0 , 0 , 5 , Blocks .BARREL .defaultBlockState ())
81116
82117 .set (0 , 0 , 1 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState (), configured (Direction .NORTH ))
83118 .fill (0 , 0 , 2 , 0 , 0 , 4 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState ())
119+ .fill (1 , 0 , 4 , 1 , 0 , 5 , MekanismBlocks .BASIC_LOGISTICAL_TRANSPORTER .defaultState ())
84120 );
85121
86122 test .onGameTest (helper -> helper .startSequence ()
87- //Wait a second for it to pull the item out, and remove the destination
88- .thenExecuteAfter (SharedConstants .TICKS_PER_SECOND , () -> helper . setBlock ( 0 , 1 , 5 , Blocks . AIR ))
123+ //Wait a second for it to pull the item out, and disable the base path to the destination
124+ .thenExecuteAfter (SharedConstants .TICKS_PER_SECOND , () -> useConfigurator ( helper , 0 , 1 , 4 , Direction . SOUTH , 3 ))
89125 //Make sure the start container is empty
90126 .thenExecute (() -> helper .assertContainerEmpty (0 , 1 , 0 ))
91127 //And then after a few seconds that the item has transferred back into the destination it was pulled from
92- .thenExecuteAfter (6 * SharedConstants .TICKS_PER_SECOND , () -> helper .assertContainerContains (0 , 1 , 0 , Items .STONE ))
128+ .thenExecuteAfter (6 * SharedConstants .TICKS_PER_SECOND , () -> helper .assertContainerContains (0 , 1 , 5 , Items .STONE ))
93129 .thenSucceed ()
94130 );
95131 }
96132
133+ @ GameTest (template = SIMPLE_PATH , setupTicks = SETUP_TICKS , timeoutTicks = TIMEOUT_TICKS )
134+ @ TestHolder (description = "Tests that idling items will properly find a destination if both the destination and source are removed "
135+ + "and then later a new destination is added." )
136+ public static void findPathFromIdle (final ExtendedGameTestHelper helper ) {
137+ helper .startSequence ()
138+ //Wait a second for it to pull the item out, and remove the destination
139+ .thenExecuteAfter (SharedConstants .TICKS_PER_SECOND , () -> helper .setBlock (0 , 1 , 5 , Blocks .AIR ))
140+ .thenExecute (() -> helper .setBlock (0 , 1 , 0 , Blocks .AIR ))
141+ .thenExecuteAfter (10 * SharedConstants .TICKS_PER_SECOND , () -> helper .setBlock (0 , 1 , 5 , Blocks .BARREL ))
142+ //And then after a few seconds that the item has transferred back into the destination it was pulled from
143+ .thenExecuteAfter (5 * SharedConstants .TICKS_PER_SECOND , () -> helper .assertContainerContains (0 , 1 , 5 , Items .STONE ))
144+ .thenSucceed ();
145+ }
146+
97147 @ GameTest (setupTicks = SETUP_TICKS , timeoutTicks = TIMEOUT_TICKS )
98148 @ TestHolder (description = "Tests that newly pulled items will go to the new destination that has a shorter path, "
99149 + "but any items that were already en-route will continue to the destination they had already calculated." )
@@ -143,11 +193,8 @@ public static void shorterEnabledPath(final DynamicTest test) {
143193
144194 test .onGameTest (helper -> helper .startSequence ()
145195 //Wait a few seconds for it to pull some items out, re-enable a disabled path to make there be a shorter destination
146- .thenExecuteAfter (4 * SharedConstants .TICKS_PER_SECOND , () -> {
147- Player player = helper .makeMockPlayer ();
148- player .setShiftKeyDown (true );
149- helper .useOn (new BlockPos (1 , 1 , 2 ), MekanismItems .CONFIGURATOR .getItemStack (), player , Direction .WEST );
150- }).thenExecuteAfter (10 * SharedConstants .TICKS_PER_SECOND , () -> {
196+ .thenExecuteAfter (4 * SharedConstants .TICKS_PER_SECOND , () -> useConfigurator (helper , 1 , 1 , 2 , Direction .WEST ))
197+ .thenExecuteAfter (10 * SharedConstants .TICKS_PER_SECOND , () -> {
151198 //Validate original destination has expected count
152199 GameTestUtils .validateContainerHas (helper , new BlockPos (0 , 1 , 5 ), 0 , new ItemStack (Items .STONE , 8 ));
153200 //Validate new destination has expected count
0 commit comments