diff --git a/src/main/java/net/wurstclient/test/NoFallHackTest.java b/src/main/java/net/wurstclient/test/NoFallHackTest.java index 9361c02cc2..dc8d96b17c 100644 --- a/src/main/java/net/wurstclient/test/NoFallHackTest.java +++ b/src/main/java/net/wurstclient/test/NoFallHackTest.java @@ -10,6 +10,7 @@ import static net.wurstclient.test.WurstClientTestHelper.*; import java.time.Duration; +import java.util.function.Predicate; import net.minecraft.client.option.Perspective; @@ -23,7 +24,7 @@ public static void testNoFallHack() setPerspective(Perspective.THIRD_PERSON_BACK); runChatCommand("gamemode survival"); assertOnGround(); - assertPlayerHealth(20); + assertPlayerHealth(health -> health == 20); // Fall 10 blocks with NoFall enabled runWurstCommand("t NoFall on"); @@ -32,7 +33,7 @@ public static void testNoFallHack() waitUntil("player is on ground", mc -> mc.player.isOnGround()); waitForWorldTicks(5); takeScreenshot("nofall_on_10_blocks", Duration.ZERO); - assertPlayerHealth(20); + assertPlayerHealth(health -> health == 20); // Fall 10 blocks with NoFall disabled runWurstCommand("t NoFall off"); @@ -41,7 +42,7 @@ public static void testNoFallHack() waitUntil("player is on ground", mc -> mc.player.isOnGround()); waitForWorldTicks(5); takeScreenshot("nofall_off_10_blocks", Duration.ZERO); - assertPlayerHealth(13); + assertPlayerHealth(health -> Math.abs(health - 13) <= 1); // Clean up submitAndWait(mc -> mc.player.heal(20)); @@ -55,11 +56,12 @@ private static void assertOnGround() throw new RuntimeException("Player is not on ground"); } - private static void assertPlayerHealth(float expectedHealth) + private static void assertPlayerHealth(Predicate healthCheck) { - float actualHealth = submitAndGet(mc -> mc.player.getHealth()); - if(actualHealth != expectedHealth) - throw new RuntimeException("Player's health is wrong. Expected: " - + expectedHealth + ", actual: " + actualHealth); + float health = submitAndGet(mc -> mc.player.getHealth()); + if(healthCheck.test(health)) + System.out.println("Player's health is correct: " + health); + else + throw new RuntimeException("Player's health is wrong: " + health); } }