This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
549 additions
and
368 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
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
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,7 @@ | ||
[libraries] | ||
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version = "0.16.0" } | ||
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.92.1+1.20.1" } | ||
|
||
[plugins] | ||
fabric-loom = { id = "fabric-loom", version = "1.7.2" } | ||
spotless = { id = "com.diffplug.spotless", version = "6.25.0" } |
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
153 changes: 78 additions & 75 deletions
153
src/main/java/me/melontini/handytests/client/ClientTestContext.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 |
---|---|---|
@@ -1,86 +1,89 @@ | ||
package me.melontini.handytests.client; | ||
|
||
import me.melontini.handytests.util.TestContext; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.option.Perspective; | ||
import static me.melontini.handytests.client.FabricClientTestHelper.submit; | ||
|
||
import java.time.Duration; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
import static me.melontini.handytests.client.FabricClientTestHelper.submit; | ||
import me.melontini.handytests.util.TestContext; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.option.Perspective; | ||
|
||
public record ClientTestContext(MinecraftClient client) implements TestContext<MinecraftClient> { | ||
|
||
public void sendCommand(String command) { | ||
FabricClientTestHelper.submitAndWait(client -> { | ||
client.player.networkHandler.sendCommand(command); | ||
return null; | ||
}); | ||
} | ||
|
||
public void waitForLoadingComplete() { | ||
FabricClientTestHelper.waitForLoadingComplete(); | ||
} | ||
|
||
public void waitForScreen(Class<? extends Screen> screenClass) { | ||
FabricClientTestHelper.waitForScreen(screenClass); | ||
} | ||
|
||
public <T, S extends Screen> T executeForScreen(Class<S> screenClass, BiFunction<MinecraftClient, S, T> function) { | ||
return FabricClientTestHelper.submitAndWait(client -> { | ||
if (screenClass.isInstance(client.currentScreen)) { | ||
return function.apply(client, screenClass.cast(client.currentScreen)); | ||
} | ||
throw new IllegalStateException("Expected: %s, got: %s".formatted(screenClass.getName(), client.currentScreen != null ? client.currentScreen.getClass().getName() : "null")); | ||
}); | ||
} | ||
|
||
public void openGameMenu() { | ||
FabricClientTestHelper.openGameMenu(); | ||
} | ||
|
||
public void openInventory() { | ||
FabricClientTestHelper.openInventory(); | ||
} | ||
|
||
public void closeScreen() { | ||
setScreen((client) -> null); | ||
} | ||
|
||
public void setScreen(Function<MinecraftClient, Screen> screenSupplier) { | ||
FabricClientTestHelper.setScreen(screenSupplier); | ||
} | ||
|
||
public void takeScreenshot(String name) { | ||
FabricClientTestHelper.takeScreenshot(name); | ||
} | ||
|
||
public void waitForWorldTicks(long ticks) { | ||
FabricClientTestHelper.waitForWorldTicks(ticks); | ||
} | ||
|
||
public void enableDebugHud() { | ||
FabricClientTestHelper.enableDebugHud(); | ||
} | ||
|
||
public void setPerspective(Perspective perspective) { | ||
FabricClientTestHelper.setPerspective(perspective); | ||
} | ||
|
||
@Override | ||
public void waitFor(String what, Predicate<MinecraftClient> predicate, Duration timeout) { | ||
FabricClientTestHelper.waitFor(what, predicate, timeout); | ||
} | ||
|
||
public <T> T submitAndWait(Function<MinecraftClient, T> function) { | ||
return submit(function).join(); | ||
} | ||
|
||
@Override | ||
public MinecraftClient context() { | ||
return client(); | ||
} | ||
public void sendCommand(String command) { | ||
FabricClientTestHelper.submitAndWait(client -> { | ||
client.player.networkHandler.sendCommand(command); | ||
return null; | ||
}); | ||
} | ||
|
||
public void waitForLoadingComplete() { | ||
FabricClientTestHelper.waitForLoadingComplete(); | ||
} | ||
|
||
public void waitForScreen(Class<? extends Screen> screenClass) { | ||
FabricClientTestHelper.waitForScreen(screenClass); | ||
} | ||
|
||
public <T, S extends Screen> T executeForScreen( | ||
Class<S> screenClass, BiFunction<MinecraftClient, S, T> function) { | ||
return FabricClientTestHelper.submitAndWait(client -> { | ||
if (screenClass.isInstance(client.currentScreen)) { | ||
return function.apply(client, screenClass.cast(client.currentScreen)); | ||
} | ||
throw new IllegalStateException("Expected: %s, got: %s" | ||
.formatted( | ||
screenClass.getName(), | ||
client.currentScreen != null ? client.currentScreen.getClass().getName() : "null")); | ||
}); | ||
} | ||
|
||
public void openGameMenu() { | ||
FabricClientTestHelper.openGameMenu(); | ||
} | ||
|
||
public void openInventory() { | ||
FabricClientTestHelper.openInventory(); | ||
} | ||
|
||
public void closeScreen() { | ||
setScreen((client) -> null); | ||
} | ||
|
||
public void setScreen(Function<MinecraftClient, Screen> screenSupplier) { | ||
FabricClientTestHelper.setScreen(screenSupplier); | ||
} | ||
|
||
public void takeScreenshot(String name) { | ||
FabricClientTestHelper.takeScreenshot(name); | ||
} | ||
|
||
public void waitForWorldTicks(long ticks) { | ||
FabricClientTestHelper.waitForWorldTicks(ticks); | ||
} | ||
|
||
public void enableDebugHud() { | ||
FabricClientTestHelper.enableDebugHud(); | ||
} | ||
|
||
public void setPerspective(Perspective perspective) { | ||
FabricClientTestHelper.setPerspective(perspective); | ||
} | ||
|
||
@Override | ||
public void waitFor(String what, Predicate<MinecraftClient> predicate, Duration timeout) { | ||
FabricClientTestHelper.waitFor(what, predicate, timeout); | ||
} | ||
|
||
public <T> T submitAndWait(Function<MinecraftClient, T> function) { | ||
return submit(function).join(); | ||
} | ||
|
||
@Override | ||
public MinecraftClient context() { | ||
return client(); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
src/main/java/me/melontini/handytests/client/ClientTestEntrypoint.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package me.melontini.handytests.client; | ||
|
||
public interface ClientTestEntrypoint { | ||
void onClientTest(ClientTestContext context); | ||
default void onClientTest(ClientTestContext context) { | ||
context.runAllForEntrypoint(this); | ||
} | ||
} |
Oops, something went wrong.