Skip to content

Commit

Permalink
Fix #106: Extractor limits are for the entire inventory, not per slot (
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Sep 17, 2024
1 parent b1941fe commit 139307c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.List;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void tickAttractor(Direction side, ItemAttachedIo attractor) {
private int move(IItemHandler from, IItemHandler to, Predicate<ItemVariant> predicate, int maxAmount) {
var moved = 0;
for (int i = 0; i < from.getSlots(); i++) {
var extracted = from.extractItem(i, maxAmount, true);
var extracted = from.extractItem(i, maxAmount - moved, true);
if (!extracted.isEmpty()) {
var variant = ItemVariant.of(extracted);
if (predicate.test(variant)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package dev.technici4n.moderndynamics.test;

import dev.technici4n.moderndynamics.init.MdBlocks;
import dev.technici4n.moderndynamics.init.MdItems;
import dev.technici4n.moderndynamics.test.framework.MdGameTestHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -55,4 +57,38 @@ public void testHopperInsertingDamagedItem(MdGameTestHelper helper) {
})
.thenSucceed();
}

@MdGameTest
public void testExtractorLimitIsForEntireInventory(MdGameTestHelper helper) {
var sourceChest = new BlockPos(0, 1, 0);
helper.setBlock(sourceChest, Blocks.CHEST.defaultBlockState());
var chest = (ChestBlockEntity) helper.getBlockEntity(sourceChest);

helper.pipe(new BlockPos(1, 1, 0), MdBlocks.ITEM_PIPE)
.attachment(Direction.WEST, MdItems.EXTRACTOR)
.configureItemIo(Direction.WEST, io -> {
io.setMaxItemsExtracted(2);
});

var targetChest = new BlockPos(2, 1, 0);
helper.setBlock(targetChest, Blocks.CHEST.defaultBlockState());

for (int i = 0; i < 9; ++i) {
chest.setItem(i, new ItemStack(Items.DIAMOND, 7));
}

helper.startSequence()
.thenIdle(1)
.thenExecute(() -> {
if (!ItemStack.matches(new ItemStack(Items.DIAMOND, 5), chest.getItem(0))) {
helper.fail("Expected 6 diamonds in slot 0", targetChest);
}
for (int i = 1; i < 9; ++i) {
if (!ItemStack.matches(new ItemStack(Items.DIAMOND, 7), chest.getItem(i))) {
helper.fail("Expected 16 diamonds in slot " + i, targetChest);
}
}
})
.thenSucceed();
}
}

0 comments on commit 139307c

Please sign in to comment.