Skip to content

Commit 139307c

Browse files
authored
Fix #106: Extractor limits are for the entire inventory, not per slot (#124)
1 parent b1941fe commit 139307c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/main/java/dev/technici4n/moderndynamics/network/TickHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import java.util.List;
2323

2424
public class TickHelper {
25-
private static long tickCounter = 0;
25+
// Start counter way above 0 so that newly placed pipes (with a last tick of 0) always do work on their first tick.
26+
private static long tickCounter = 1000;
2627
private static List<Runnable> delayedActions = new ArrayList<>();
2728
private static List<Runnable> delayedActions2 = new ArrayList<>();
2829

src/main/java/dev/technici4n/moderndynamics/network/item/ItemHost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public void tickAttractor(Direction side, ItemAttachedIo attractor) {
278278
private int move(IItemHandler from, IItemHandler to, Predicate<ItemVariant> predicate, int maxAmount) {
279279
var moved = 0;
280280
for (int i = 0; i < from.getSlots(); i++) {
281-
var extracted = from.extractItem(i, maxAmount, true);
281+
var extracted = from.extractItem(i, maxAmount - moved, true);
282282
if (!extracted.isEmpty()) {
283283
var variant = ItemVariant.of(extracted);
284284
if (predicate.test(variant)) {

src/main/java/dev/technici4n/moderndynamics/test/ItemTransferTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
package dev.technici4n.moderndynamics.test;
2020

2121
import dev.technici4n.moderndynamics.init.MdBlocks;
22+
import dev.technici4n.moderndynamics.init.MdItems;
2223
import dev.technici4n.moderndynamics.test.framework.MdGameTestHelper;
2324
import net.minecraft.core.BlockPos;
25+
import net.minecraft.core.Direction;
2426
import net.minecraft.world.item.ItemStack;
2527
import net.minecraft.world.item.Items;
2628
import net.minecraft.world.level.block.Blocks;
@@ -55,4 +57,38 @@ public void testHopperInsertingDamagedItem(MdGameTestHelper helper) {
5557
})
5658
.thenSucceed();
5759
}
60+
61+
@MdGameTest
62+
public void testExtractorLimitIsForEntireInventory(MdGameTestHelper helper) {
63+
var sourceChest = new BlockPos(0, 1, 0);
64+
helper.setBlock(sourceChest, Blocks.CHEST.defaultBlockState());
65+
var chest = (ChestBlockEntity) helper.getBlockEntity(sourceChest);
66+
67+
helper.pipe(new BlockPos(1, 1, 0), MdBlocks.ITEM_PIPE)
68+
.attachment(Direction.WEST, MdItems.EXTRACTOR)
69+
.configureItemIo(Direction.WEST, io -> {
70+
io.setMaxItemsExtracted(2);
71+
});
72+
73+
var targetChest = new BlockPos(2, 1, 0);
74+
helper.setBlock(targetChest, Blocks.CHEST.defaultBlockState());
75+
76+
for (int i = 0; i < 9; ++i) {
77+
chest.setItem(i, new ItemStack(Items.DIAMOND, 7));
78+
}
79+
80+
helper.startSequence()
81+
.thenIdle(1)
82+
.thenExecute(() -> {
83+
if (!ItemStack.matches(new ItemStack(Items.DIAMOND, 5), chest.getItem(0))) {
84+
helper.fail("Expected 6 diamonds in slot 0", targetChest);
85+
}
86+
for (int i = 1; i < 9; ++i) {
87+
if (!ItemStack.matches(new ItemStack(Items.DIAMOND, 7), chest.getItem(i))) {
88+
helper.fail("Expected 16 diamonds in slot " + i, targetChest);
89+
}
90+
}
91+
})
92+
.thenSucceed();
93+
}
5894
}

0 commit comments

Comments
 (0)