Skip to content

Commit

Permalink
Make health check more lenient to work around inconsistent fall damage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Dec 13, 2024
1 parent 7ed82d6 commit 3b909f5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/net/wurstclient/test/NoFallHackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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<Float> 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);
}
}

0 comments on commit 3b909f5

Please sign in to comment.