Skip to content

Commit

Permalink
feat: relay gametest
Browse files Browse the repository at this point in the history
  • Loading branch information
starforcraft committed Dec 14, 2024
1 parent 5bc8e39 commit 97baf46
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@

@FunctionalInterface
public interface RelayConsumer {
void accept(RelayBlockEntity relayBlockEntity, BlockPos pos, BlockPos gridPos, GameTestSequence gameTestSequence);
void accept(RelayBlockEntity relayBlockEntity,
BlockPos pos,
BlockPos subnetworkPos,
GameTestSequence gameTestSequence);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private RelayTest() {

@GameTest(template = "empty_15x15")
public static void shouldPassThrough(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -42,11 +42,11 @@ public static void shouldPassThrough(final GameTestHelper helper) {

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> stored))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> stored))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -62,7 +62,7 @@ public static void shouldPassThrough(final GameTestHelper helper) {

@GameTest(template = "empty_15x15")
public static void shouldNotPassThrough(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -74,9 +74,9 @@ public static void shouldNotPassThrough(final GameTestHelper helper) {

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, false))
.thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> 0L))
.thenWaitUntil(storageContainsExactly(helper, gridPos))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, false))
.thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> 0L))
.thenWaitUntil(storageContainsExactly(helper, subnetworkPos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
Expand All @@ -89,7 +89,7 @@ public static void shouldNotPassThrough(final GameTestHelper helper) {

@GameTest(template = "empty_15x15")
public static void shouldPassThroughEnergy(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -102,9 +102,9 @@ public static void shouldPassThroughEnergy(final GameTestHelper helper) {

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> stored))
.thenWaitUntil(storageContainsExactly(helper, gridPos))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> stored))
.thenWaitUntil(storageContainsExactly(helper, subnetworkPos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
Expand All @@ -117,7 +117,7 @@ public static void shouldPassThroughEnergy(final GameTestHelper helper) {

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorage(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -131,10 +131,10 @@ public static void shouldPassThroughStorage(final GameTestHelper helper) {

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -150,7 +150,7 @@ public static void shouldPassThroughStorage(final GameTestHelper helper) {

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -165,10 +165,10 @@ public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
Expand All @@ -183,7 +183,7 @@ public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
Expand All @@ -203,10 +203,10 @@ public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper h

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -224,7 +224,7 @@ public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper h

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -240,10 +240,10 @@ public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10)
))
.thenWaitUntil(storageContainsExactly(
Expand All @@ -258,7 +258,7 @@ public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
Expand All @@ -278,10 +278,10 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
Expand All @@ -299,7 +299,7 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -314,12 +314,12 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
insert(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -329,11 +329,11 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
extract(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -349,7 +349,7 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -364,12 +364,12 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
insert(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -379,11 +379,11 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
extract(helper, network, DIRT, 10, false)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -399,7 +399,7 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndExtract(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> {
RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
Expand All @@ -414,12 +414,12 @@ public static void shouldPassThroughStorageAndExtract(final GameTestHelper helpe

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true))
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
insert(helper, network, DIRT, 10, false)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
Expand All @@ -429,11 +429,11 @@ public static void shouldPassThroughStorageAndExtract(final GameTestHelper helpe
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, gridPos, network ->
.thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network ->
extract(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
gridPos,
subnetworkPos,
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ static void preparePlot(final GameTestHelper helper,
final BlockPos relayPos = ZERO.above().above().above();
helper.setBlock(relayPos, RSBLOCKS.getRelay().getDefault().rotated(Direction.UP));

final BlockPos gridPos = relayPos.above();
helper.setBlock(gridPos, RSBLOCKS.getGrid().getDefault());
final BlockPos subnetworkPos = relayPos.above();
helper.setBlock(subnetworkPos, RSBLOCKS.getGrid().getDefault());

consumer.accept(
requireBlockEntity(helper, relayPos, RelayBlockEntity.class),
relayPos,
gridPos,
subnetworkPos,
helper.startSequence()
);
}
Expand Down

0 comments on commit 97baf46

Please sign in to comment.