From f0ec6ca98f5736978ac545c723c2201543b3c12f Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 26 May 2024 10:42:45 +0200 Subject: [PATCH] refactor: constructor item drop test --- .../ConstructorBlockEntity.java | 2 +- .../platform/forge/ConstructorTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java index 45cf2e459..08090a30c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java @@ -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) { diff --git a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java index a8b22f16d..b5f52b618 100644 --- a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java +++ b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java @@ -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; @@ -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(); + }); + } }