|
| 1 | +package mrtjp.projectred.transmission.gametests; |
| 2 | + |
| 3 | +import mrtjp.projectred.transmission.ProjectRedTransmission; |
| 4 | +import net.minecraft.core.BlockPos; |
| 5 | +import net.minecraft.gametest.framework.GameTest; |
| 6 | +import net.minecraft.gametest.framework.GameTestHelper; |
| 7 | +import net.minecraft.world.level.block.LeverBlock; |
| 8 | +import net.minecraft.world.level.block.RedstoneLampBlock; |
| 9 | +import net.neoforged.neoforge.gametest.GameTestHolder; |
| 10 | +import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; |
| 11 | + |
| 12 | +@GameTestHolder(ProjectRedTransmission.MOD_ID) |
| 13 | +@PrefixGameTestTemplate(false) |
| 14 | +public class RedwirePropagationTests { |
| 15 | + |
| 16 | + @GameTest(template = "alloy_rw_wraparound_rs_block") |
| 17 | + public static void redAlloyPropagatesAroundRSBlock(GameTestHelper helper) { |
| 18 | + // Red alloy wires should propagate signal around a redsone block, |
| 19 | + // and also power the lamp underneath |
| 20 | + |
| 21 | + // Positions |
| 22 | + var lever = new BlockPos(0, 2, 1); |
| 23 | + var lampA = new BlockPos(3, 2, 1); |
| 24 | + var lampB = new BlockPos(6, 2, 1); |
| 25 | + |
| 26 | + // Assert start condition |
| 27 | + helper.assertBlockState(lever, state -> !state.getValue(LeverBlock.POWERED), () -> "Lever should be off!"); |
| 28 | + helper.assertBlockState(lampA, state -> !state.getValue(RedstoneLampBlock.LIT), () -> "Lamp should be off!"); |
| 29 | + helper.assertBlockState(lampB, state -> !state.getValue(RedstoneLampBlock.LIT), () -> "Lamp should be off!"); |
| 30 | + |
| 31 | + // Pull lever, wait 2 ticks, then check lamp states |
| 32 | + helper.startSequence() |
| 33 | + .thenExecute(() -> helper.setBlock(lever, helper.getBlockState(lever).setValue(LeverBlock.POWERED, true))) |
| 34 | + .thenIdle(2) |
| 35 | + .thenExecute(() -> { |
| 36 | + helper.assertBlockState(lever, state -> state.getValue(LeverBlock.POWERED), () -> "Lever should be on!"); |
| 37 | + helper.assertBlockState(lampA, state -> state.getValue(RedstoneLampBlock.LIT), () -> "Lamp A should be on!"); |
| 38 | + helper.assertBlockState(lampB, state -> state.getValue(RedstoneLampBlock.LIT), () -> "Lamp B should be on!"); |
| 39 | + }).thenSucceed(); |
| 40 | + } |
| 41 | + |
| 42 | + @GameTest(template = "insulated_rw_wraparound_rs_block") |
| 43 | + public static void insulatedWirePropagatesAroundRSBlock(GameTestHelper helper) { |
| 44 | + // Insulated wires should propagate signal around a redsone block, |
| 45 | + // but NOT power the lamp underneath |
| 46 | + |
| 47 | + // Positions |
| 48 | + var lever = new BlockPos(0, 2, 1); |
| 49 | + var lampA = new BlockPos(3, 2, 1); |
| 50 | + var lampB = new BlockPos(6, 2, 1); |
| 51 | + |
| 52 | + // Assert start condition |
| 53 | + helper.assertBlockState(lever, state -> !state.getValue(LeverBlock.POWERED), () -> "Lever should be off!"); |
| 54 | + helper.assertBlockState(lampA, state -> !state.getValue(RedstoneLampBlock.LIT), () -> "Lamp should be off!"); |
| 55 | + helper.assertBlockState(lampB, state -> !state.getValue(RedstoneLampBlock.LIT), () -> "Lamp should be off!"); |
| 56 | + |
| 57 | + // Pull lever, wait 2 ticks, then check lamp states |
| 58 | + helper.startSequence() |
| 59 | + .thenExecute(() -> helper.setBlock(lever, helper.getBlockState(lever).setValue(LeverBlock.POWERED, true))) |
| 60 | + .thenIdle(2) |
| 61 | + .thenExecute(() -> { |
| 62 | + helper.assertBlockState(lever, state -> state.getValue(LeverBlock.POWERED), () -> "Lever should be on!"); |
| 63 | + helper.assertBlockState(lampA, state -> !state.getValue(RedstoneLampBlock.LIT), () -> "Lamp A should be off!"); |
| 64 | + helper.assertBlockState(lampB, state -> state.getValue(RedstoneLampBlock.LIT), () -> "Lamp B should be on!"); |
| 65 | + }).thenSucceed(); |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments