Skip to content

Commit

Permalink
Add a test for NoFall
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Dec 12, 2024
1 parent d6fb0d3 commit 4c74e1e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/main/java/net/wurstclient/test/NoFallHackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.test;

import static net.wurstclient.test.WurstClientTestHelper.*;

import java.time.Duration;

import net.minecraft.client.option.Perspective;

public enum NoFallHackTest
{
;

public static void testNoFallHack()
{
System.out.println("Testing NoFall hack");
setPerspective(Perspective.THIRD_PERSON_BACK);
runChatCommand("gamemode survival");
assertOnGround();
assertPlayerHealth(20);

// Fall 10 blocks with NoFall enabled
runWurstCommand("t NoFall on");
runChatCommand("tp ~ ~10 ~");
waitUntil("player is on ground", mc -> mc.player.isOnGround());
waitForWorldTicks(1);
takeScreenshot("nofall_on_10_blocks", Duration.ZERO);
assertPlayerHealth(20);

// Fall 10 blocks with NoFall disabled
runWurstCommand("t NoFall off");
runChatCommand("tp ~ ~10 ~");
waitUntil("player is on ground", mc -> mc.player.isOnGround());
waitForWorldTicks(1);
takeScreenshot("nofall_off_10_blocks", Duration.ZERO);
assertPlayerHealth(13);

// Clean up
submitAndWait(mc -> mc.player.heal(20));
runChatCommand("gamemode creative");
setPerspective(Perspective.FIRST_PERSON);
}

private static void assertOnGround()
{
if(!submitAndGet(mc -> mc.player.isOnGround()))
throw new RuntimeException("Player is not on ground");
}

private static void assertPlayerHealth(float expectedHealth)
{
float actualHealth = submitAndGet(mc -> mc.player.getHealth());
if(actualHealth != expectedHealth)
throw new RuntimeException("Player's health is wrong. Expected: "
+ expectedHealth + ", actual: " + actualHealth);
}
}
11 changes: 10 additions & 1 deletion src/main/java/net/wurstclient/test/WurstE2ETestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,23 @@ private void runTests()

// TODO: Open ClickGUI and Navigator

// Build a test platform and clear out the space above it
runChatCommand("fill ~-5 ~-1 ~-5 ~5 ~-1 ~5 stone");
runChatCommand("fill ~-5 ~ ~-5 ~5 ~30 ~5 air");

// Clear inventory and chat before running tests
runChatCommand("clear");
clearChat();

// Test Wurst hacks
NoFallHackTest.testNoFallHack();

// Test Wurst commands
CopyItemCmdTest.testCopyItemCmd();
GiveCmdTest.testGiveCmd();
ModifyCmdTest.testModifyCmd();
// TODO: Test more Wurst hacks

// TODO: Test more Wurst features

System.out.println("Opening game menu");
openGameMenu();
Expand Down

0 comments on commit 4c74e1e

Please sign in to comment.