-
-
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.
- Loading branch information
1 parent
102ae60
commit 26b7632
Showing
5 changed files
with
358 additions
and
3 deletions.
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
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
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
304 changes: 304 additions & 0 deletions
304
...ge-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.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,304 @@ | ||
package com.refinedmods.refinedstorage.common.networking; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.api.resource.filter.FilterMode; | ||
import com.refinedmods.refinedstorage.common.util.IdentifierUtil; | ||
|
||
import java.util.Set; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.gametest.GameTestHolder; | ||
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; | ||
|
||
import static com.refinedmods.refinedstorage.common.GameTestUtil.asResource; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.checkBlockEntityActiveness; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.getItemAsDamaged; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.insert; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.storageContainsExactly; | ||
import static net.minecraft.world.item.Items.DIAMOND_CHESTPLATE; | ||
import static net.minecraft.world.item.Items.DIRT; | ||
import static net.minecraft.world.item.Items.STONE; | ||
|
||
@GameTestHolder(IdentifierUtil.MOD_ID) | ||
@PrefixGameTestTemplate(false) | ||
public final class RelayTest { | ||
private RelayTest() { | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThrough(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(true); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldNotPassThrough(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, false)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughEnergy(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly(helper, pos2)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughStorage(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
relay.setPassStorage(true); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
relay.setPassStorage(true); | ||
relay.setFilters(Set.of(asResource(DIRT))); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
insert(helper, network, DIAMOND_CHESTPLATE, 1); | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
relay.setPassStorage(true); | ||
relay.setFuzzyMode(true); | ||
relay.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); | ||
relay.setFilterMode(FilterMode.BLOCK); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
relay.setPassStorage(true); | ||
relay.setFilters(Set.of(asResource(DIRT))); | ||
relay.setFilterMode(FilterMode.ALLOW); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(DIRT), 10) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper helper) { | ||
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { | ||
// Arrange | ||
final BlockPos pos2 = pos.above(); | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
insert(helper, network, DIAMOND_CHESTPLATE, 1); | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1); | ||
})); | ||
|
||
// Act | ||
relay.setPassThrough(false); | ||
relay.setPassEnergy(true); | ||
relay.setPassStorage(true); | ||
relay.setFuzzyMode(true); | ||
relay.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); | ||
relay.setFilterMode(FilterMode.ALLOW); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos2, | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...oforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTestPlots.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.refinedstorage.common.networking; | ||
|
||
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; | ||
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; | ||
|
||
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.refinedstorage.common.GameTestUtil.RSBLOCKS; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.requireBlockEntity; | ||
import static net.minecraft.core.BlockPos.ZERO; | ||
|
||
final class RelayTestPlots { | ||
private RelayTestPlots() { | ||
} | ||
|
||
static void preparePlot(final GameTestHelper helper, | ||
final TriConsumer<RelayBlockEntity, BlockPos, GameTestSequence> consumer) { | ||
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); | ||
helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K)); | ||
helper.setBlock( | ||
ZERO.above().above().north(), | ||
RSBLOCKS.getFluidStorageBlock(FluidStorageVariant.SIXTY_FOUR_B) | ||
); | ||
final BlockPos relayPos = ZERO.above().above().above(); | ||
helper.setBlock(relayPos, RSBLOCKS.getRelay().getDefault().rotated(Direction.UP)); | ||
helper.setBlock(relayPos.above(), RSBLOCKS.getGrid().getDefault()); | ||
consumer.accept( | ||
requireBlockEntity(helper, relayPos, RelayBlockEntity.class), | ||
relayPos, | ||
helper.startSequence() | ||
); | ||
} | ||
} |