-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Detector gametest
- Loading branch information
Showing
3 changed files
with
281 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
233 changes: 233 additions & 0 deletions
233
...e-neoforge/src/test/java/com/refinedmods/refinedstorage/common/detector/DetectorTest.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,233 @@ | ||
package com.refinedmods.refinedstorage.common.detector; | ||
|
||
import com.refinedmods.refinedstorage.api.network.impl.node.detector.DetectorMode; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.common.util.IdentifierUtil; | ||
|
||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.RedStoneWireBlock; | ||
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.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 com.refinedmods.refinedstorage.common.detector.DetectorTestPlots.preparePlot; | ||
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 DetectorTest { | ||
private DetectorTest() { | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldNotEmitRedstone(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
})); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldEmitRedstoneUnder(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
detector.setConfiguredResource(asResource(DIRT)); | ||
detector.setMode(DetectorMode.UNDER); | ||
detector.setAmount(5); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(4)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(5)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(6)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(10)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(15)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldUseEqualModeByDefault(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
detector.setConfiguredResource(asResource(DIRT)); | ||
detector.setAmount(9); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(8)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(10)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenExecute(() -> { | ||
detector.setConfiguredResource(asResource(damagedDiamondChestplate)); | ||
detector.setAmount(1); | ||
}) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(networkIsAvailable(helper, pos, network -> | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1))) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldEmitRedstoneEquals(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
detector.setConfiguredResource(asResource(DIRT)); | ||
detector.setMode(DetectorMode.EQUAL); | ||
detector.setAmount(9); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(8)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(10)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenExecute(() -> { | ||
detector.setConfiguredResource(asResource(damagedDiamondChestplate)); | ||
detector.setAmount(1); | ||
}) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(networkIsAvailable(helper, pos, network -> | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1))) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldEmitRedstoneAbove(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
detector.setConfiguredResource(asResource(DIRT)); | ||
detector.setMode(DetectorMode.ABOVE); | ||
detector.setAmount(15); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(16)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(14)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(10)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(5)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldEmitRedstoneFuzzy(final GameTestHelper helper) { | ||
preparePlot(helper, Direction.DOWN, (detector, pos, sequence) -> { | ||
// Arrange | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
|
||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, asResource(DIAMOND_CHESTPLATE.getDefaultInstance()), 1); | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1); | ||
})); | ||
|
||
// Act | ||
detector.setFuzzyMode(true); | ||
detector.setConfiguredResource(asResource(DIAMOND_CHESTPLATE.getDefaultInstance())); | ||
detector.setMode(DetectorMode.EQUAL); | ||
detector.setAmount(1); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()), 1), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 0)) | ||
.thenExecute(() -> detector.setAmount(2)) | ||
.thenWaitUntil(() -> helper.assertBlockProperty(pos.north(), RedStoneWireBlock.POWER, 15)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...forge/src/test/java/com/refinedmods/refinedstorage/common/detector/DetectorTestPlots.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,39 @@ | ||
package com.refinedmods.refinedstorage.common.detector; | ||
|
||
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 net.minecraft.world.level.block.Blocks; | ||
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 DetectorTestPlots { | ||
private DetectorTestPlots() { | ||
} | ||
|
||
static void preparePlot(final GameTestHelper helper, | ||
final Direction direction, | ||
final TriConsumer<DetectorBlockEntity, 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) | ||
); | ||
helper.setBlock(ZERO.above().above().above().north(), Blocks.REDSTONE_WIRE); | ||
final BlockPos detectorPos = ZERO.above().above().above(); | ||
helper.setBlock(detectorPos, RSBLOCKS.getDetector().getDefault().rotated(direction)); | ||
consumer.accept( | ||
requireBlockEntity(helper, detectorPos, DetectorBlockEntity.class), | ||
detectorPos, | ||
helper.startSequence() | ||
); | ||
} | ||
} |