Skip to content

Commit 33e72ba

Browse files
committed
Add a test and fix not being able to actually insert items back home when the destination stops being willing to accept them
1 parent 89e70aa commit 33e72ba

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/gameTest/java/mekanism/common/tests/network/InventoryNetworkTest.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,38 @@ public class InventoryNetworkTest {
6161
// - Cutting off an existing path -> recalculating pathfinding of currently travelling stacks, for example when setting a side to none or breaking a transporter
6262
// - Color changing on an existing path??
6363
// - Diversion transporters?? Might basically be just the same as the cutting off existing path
64-
// - destination is removed
6564
// - destination becomes inaccessible due to side changes
6665
// - base path becomes disabled but there is a different path to the same destination
6766
// - 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??
6867
// - 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
6968
// - 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
7069
// - Single transporter with no destination stays in the transporter, it fails and pops out if there is only a single connection point
7170
// 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
72-
// -
71+
72+
@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)
77+
//Start barrel
78+
.set(0, 0, 0, Blocks.BARREL.defaultBlockState(), containing(Items.STONE))
79+
//End barrel
80+
.set(0, 0, 5, Blocks.BARREL.defaultBlockState())
81+
82+
.set(0, 0, 1, MekanismBlocks.BASIC_LOGISTICAL_TRANSPORTER.defaultState(), configured(Direction.NORTH))
83+
.fill(0, 0, 2, 0, 0, 4, MekanismBlocks.BASIC_LOGISTICAL_TRANSPORTER.defaultState())
84+
);
85+
86+
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))
89+
//Make sure the start container is empty
90+
.thenExecute(() -> helper.assertContainerEmpty(0, 1, 0))
91+
//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))
93+
.thenSucceed()
94+
);
95+
}
7396

7497
@GameTest(setupTicks = SETUP_TICKS, timeoutTicks = TIMEOUT_TICKS)
7598
@TestHolder(description = "Tests that newly pulled items will go to the new destination that has a shorter path, "
@@ -88,7 +111,7 @@ public static void shorterNewDestination(final DynamicTest test) {
88111

89112
test.onGameTest(helper -> helper.startSequence()
90113
//Wait a few seconds for it to pull some items out, and add a transporter to create a shorter destination
91-
.thenExecuteAfter(4 * SharedConstants.TICKS_PER_SECOND, () -> helper.setBlock(new BlockPos(1, 1, 2), MekanismBlocks.BASIC_LOGISTICAL_TRANSPORTER.getBlock()))
114+
.thenExecuteAfter(4 * SharedConstants.TICKS_PER_SECOND, () -> helper.setBlock(1, 1, 2, MekanismBlocks.BASIC_LOGISTICAL_TRANSPORTER.getBlock()))
92115
.thenExecuteAfter(10 * SharedConstants.TICKS_PER_SECOND, () -> {
93116
//Validate original destination has expected count
94117
GameTestUtils.validateContainerHas(helper, new BlockPos(0, 1, 5), 0, new ItemStack(Items.STONE, 8));

src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ public void onUpdateServer() {
180180
} else if (stack.getPathType().hasTarget()) {
181181
//Otherwise, try to insert it into the destination inventory
182182
//Get the handler we are trying to insert into from the network's acceptor cache
183-
IItemHandler acceptor = network.getCachedAcceptor(next, stack.getSide(this).getOpposite());
183+
Direction side = stack.getSide(this).getOpposite();
184+
IItemHandler acceptor = network.getCachedAcceptor(next, side);
185+
if (acceptor == null && stack.getPathType().isHome()) {
186+
//TODO: Cache this capability. The issue is that when we are sending it back home
187+
// if it pulled the item itself, then it isn't in our cached acceptors, and thus won't be able to insert it
188+
acceptor = Capabilities.ITEM.getCapabilityIfLoaded(getLevel(), next, side);
189+
}
184190
TransitResponse response = TransitRequest.simple(stack.itemStack).addToInventory(getLevel(), next, acceptor, 0,
185191
stack.getPathType().isHome());
186192
if (!response.isEmpty()) {

0 commit comments

Comments
 (0)