-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Destructor gametests
- Loading branch information
Showing
3 changed files
with
291 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
...com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.constructordestructor; | ||
|
||
import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; | ||
import com.refinedmods.refinedstorage2.platform.common.Platform; | ||
import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; | ||
|
||
import java.util.Set; | ||
|
||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.neoforged.neoforge.gametest.GameTestHolder; | ||
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; | ||
|
||
import static com.refinedmods.refinedstorage2.platform.common.constructordestructor.DestructorTestPlots.preparePlot; | ||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.asResource; | ||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.insert; | ||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.networkIsAvailable; | ||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.storageContainsExactly; | ||
import static net.minecraft.world.item.Items.DIRT; | ||
import static net.minecraft.world.item.Items.STONE; | ||
import static net.minecraft.world.level.material.Fluids.LAVA; | ||
import static net.minecraft.world.level.material.Fluids.WATER; | ||
|
||
@GameTestHolder(IdentifierUtil.MOD_ID) | ||
@PrefixGameTestTemplate(false) | ||
public final class DestructorTest { | ||
private DestructorTest() { | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldBreakBlock(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
helper.setBlock(pos.east(), Blocks.DIRT); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.DIRT, pos.east())) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 11), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldBreakBlockAllowlist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.ALLOW); | ||
destructor.setFilters(Set.of(asResource(DIRT))); | ||
|
||
helper.setBlock(pos.east(), Blocks.DIRT); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.DIRT, pos.east())) | ||
.thenExecute(() -> helper.setBlock(pos.east(), Blocks.STONE)) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertBlockPresent(Blocks.STONE, pos.east())) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 11), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldBreakBlockBlocklist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.BLOCK); | ||
destructor.setFilters(Set.of(asResource(STONE))); | ||
|
||
helper.setBlock(pos.east(), Blocks.DIRT); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.DIRT, pos.east())) | ||
.thenExecute(() -> helper.setBlock(pos.east(), Blocks.STONE)) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertBlockPresent(Blocks.STONE, pos.east())) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 11), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPickupItemAllowlist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.ALLOW); | ||
destructor.setPickupItems(true); | ||
destructor.setFilters(Set.of(asResource(DIRT))); | ||
|
||
helper.spawnItem(DIRT, pos.east()); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertItemEntityNotPresent(DIRT, pos.east(), 1)) | ||
.thenExecute(() -> helper.spawnItem(STONE, pos.east())) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertItemEntityPresent(STONE, pos.east(), 1)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 11), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPickupItemBlocklist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.BLOCK); | ||
destructor.setPickupItems(true); | ||
destructor.setFilters(Set.of(asResource(STONE))); | ||
|
||
helper.spawnItem(DIRT, pos.east()); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertItemEntityNotPresent(DIRT, pos.east(), 1)) | ||
.thenExecute(() -> helper.spawnItem(STONE, pos.east())) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertItemEntityPresent(STONE, pos.east(), 1)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 11), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldDrainFluidAllowlist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.ALLOW); | ||
destructor.setFilters(Set.of(asResource(WATER))); | ||
|
||
helper.setBlock(pos.east(), Blocks.WATER); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.WATER, pos.east())) | ||
.thenExecute(() -> helper.setBlock(pos.east(), Blocks.DIRT)) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertBlockPresent(Blocks.DIRT, pos.east())) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount()) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldDrainFluidBlocklist(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
destructor.setFilterMode(FilterMode.BLOCK); | ||
destructor.setFilters(Set.of(asResource(LAVA))); | ||
|
||
helper.setBlock(pos.east(), Blocks.WATER); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> helper.assertBlockNotPresent(Blocks.WATER, pos.east())) | ||
.thenExecute(() -> helper.setBlock(pos.east(), Blocks.LAVA)) | ||
.thenIdle(20) | ||
.thenWaitUntil(() -> helper.assertBlockPresent(Blocks.LAVA, pos.east())) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount()) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...efinedmods/refinedstorage2/platform/common/constructordestructor/DestructorTestPlots.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.constructordestructor; | ||
|
||
import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; | ||
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.gametest.framework.GameTestSequence; | ||
import org.apache.commons.lang3.function.TriConsumer; | ||
|
||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.RSBLOCKS; | ||
import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.requireBlockEntity; | ||
import static net.minecraft.core.BlockPos.ZERO; | ||
|
||
final class DestructorTestPlots { | ||
private DestructorTestPlots() { | ||
} | ||
|
||
static void preparePlot(final GameTestHelper helper, | ||
final Direction direction, | ||
final TriConsumer<DestructorBlockEntity, BlockPos, GameTestSequence> consumer) { | ||
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); | ||
helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageType.Variant.ONE_K)); | ||
helper.setBlock( | ||
ZERO.above().above().north(), | ||
RSBLOCKS.getFluidStorageBlock(FluidStorageType.Variant.SIXTY_FOUR_B) | ||
); | ||
final BlockPos destructorPos = ZERO.above().above().above(); | ||
helper.setBlock(destructorPos, RSBLOCKS.getDestructor().getDefault().rotated(direction)); | ||
consumer.accept( | ||
requireBlockEntity(helper, destructorPos, DestructorBlockEntity.class), | ||
destructorPos, | ||
helper.startSequence() | ||
); | ||
} | ||
} |