Skip to content

Commit

Permalink
refactor: constructor item drop test
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed May 26, 2024
1 parent b6162d5 commit f0ec6ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ boolean isDropItems() {
return dropItems;
}

void setDropItems(final boolean dropItems) {
public void setDropItems(final boolean dropItems) {
this.dropItems = dropItems;
setChanged();
if (level instanceof ServerLevel serverLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.gametest.framework.GameTestSequence;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
Expand Down Expand Up @@ -72,4 +73,31 @@ public static void shouldPlaceBlock(final GameTestHelper helper) {
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldDropItem(final GameTestHelper helper) {
prepareConstructorPlot(helper, Direction.EAST, (constructor, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insertItem(helper, network, DIRT, 10);
insertItem(helper, network, STONE, 15);
}));

// Act
constructor.setDropItems(true);
constructor.setFilters(List.of(DIRT));

// Assert
sequence
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.DIRT, pos.east()))
.thenWaitUntil(() -> helper.assertItemEntityPresent(Items.DIRT, pos.east(), 1))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(DIRT, 9),
new ResourceAmount(STONE, 15)
))
.thenSucceed();
});
}
}

0 comments on commit f0ec6ca

Please sign in to comment.