Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/1.20.1-fabric' into…
Browse files Browse the repository at this point in the history
… 1.20.4-fabric

# Conflicts:
#	gradle.properties
#	src/main/java/me/melontini/handytests/client/FabricClientTestHelper.java
#	src/main/java/me/melontini/handytests/mixin/client/MinecraftClientMixin.java
#	src/main/java/me/melontini/handytests/server/ServerTestContext.java
  • Loading branch information
melontini committed Jul 27, 2024
2 parents 3b67ea9 + 2cf038a commit e016053
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 410 deletions.
49 changes: 6 additions & 43 deletions .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,9 @@ jobs:
run: |
./gradlew build
client_test:
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/[email protected]
- name: validate gradle wrapper
uses: gradle/[email protected]
- name: setup jdk 17
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: 17
cache: gradle
- name: make gradle wrapper executable
run: chmod +x ./gradlew
- name: run testmod
uses: modmuss50/xvfb-action@v1
with:
run: ./gradlew runClient --stacktrace --warning-mode=fail
#- uses: actions/[email protected]
# with:
# name: Test Screenshots
# path: run/screenshots

server_test:
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/[email protected]
- name: validate gradle wrapper
uses: gradle/[email protected]
- name: setup jdk 17
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: 17
cache: gradle
- name: make gradle wrapper executable
run: chmod +x ./gradlew
- name: run testmod
run: ./gradlew runServer --stacktrace --warning-mode=fail
run_tests:
uses: constellation-mc/actions/.github/workflows/mc-tests.yml@main
with:
java: 17
client_task: runClient
server_task: runServer
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
alias libs.plugins.fabric.loom
id 'maven-publish'
alias libs.plugins.spotless
}

def local = !System.getenv().containsKey("GITHUB_RUN_NUMBER")
Expand All @@ -24,15 +25,24 @@ dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation libs.fabric.loader

// Fabric API. This is technically optional, but you probably want it anyway.
def fabricModules = [
"fabric-api-base",
"fabric-lifecycle-events-v1"
]
fabricModules.each {
modImplementation include(fabricApi.module(it, project.fabric_version))
modImplementation include(fabricApi.module(it, libs.fabric.api.get().version))
}
}

spotless {
java {
removeUnusedImports()
palantirJavaFormat('2.47.0').style("GOOGLE")
trimTrailingWhitespace()
formatAnnotations()
}
}

Expand All @@ -50,13 +60,13 @@ loom {
processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
inputs.property "loader_version", project.loader_version
inputs.property "loader_version", libs.fabric.loader.get().version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version
"loader_version": libs.fabric.loader.get().version
}
}

Expand Down
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.10
# Mod Properties
mod_version=0.2.0
mod_version=0.3.0
maven_group=me.melontini
archives_base_name=handy-tests
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.97.0+1.20.4
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
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" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
153 changes: 78 additions & 75 deletions src/main/java/me/melontini/handytests/client/ClientTestContext.java
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();
}
}
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);
}
}
Loading

0 comments on commit e016053

Please sign in to comment.