Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

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:
#	src/main/java/me/melontini/handytests/mixin/client/MinecraftClientMixin.java
  • Loading branch information
melontini committed Jun 1, 2024
2 parents f1c2004 + 11f1c88 commit 88418bd
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 164 deletions.
49 changes: 0 additions & 49 deletions .github/ISSUE_TEMPLATE/bug_report.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

41 changes: 0 additions & 41 deletions .github/ISSUE_TEMPLATE/crash_report.yml

This file was deleted.

52 changes: 7 additions & 45 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,17 @@ 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

packages:
needs:
- build
- client_test
- server_test
- run_tests
runs-on: ubuntu-latest
steps:
- name: checkout repository
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# handy-tests

Based on the internal testing framework of Fabric API.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ dependencies {
}
}

loom {
runs {
client {
property("handy-tests.auto-test", "true")
}
server {
property("handy-tests.auto-test", "true")
}
}
}

processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.10
# Mod Properties
mod_version=0.1.0
mod_version=0.2.0
maven_group=me.melontini
archives_base_name=handy-tests
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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 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;

public record ClientTestContext(MinecraftClient client) {
public record ClientTestContext(MinecraftClient client) implements TestContext<MinecraftClient> {

public void sendCommand(String command) {
FabricClientTestHelper.submitAndWait(client -> {
Expand All @@ -31,7 +34,7 @@ public <T, S extends Screen> T executeForScreen(Class<S> screenClass, BiFunction
if (screenClass.isInstance(client.currentScreen)) {
return function.apply(client, screenClass.cast(client.currentScreen));
}
throw new IllegalStateException();
throw new IllegalStateException("Expected: %s, got: %s".formatted(screenClass.getName(), client.currentScreen != null ? client.currentScreen.getClass().getName() : "null"));
});
}

Expand Down Expand Up @@ -67,7 +70,17 @@ 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();
}
}
3 changes: 3 additions & 0 deletions src/main/java/me/melontini/handytests/client/HandyClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.melontini.handytests.client;

import me.melontini.handytests.server.HandyServer;
import me.melontini.handytests.util.Utils;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
Expand All @@ -10,6 +11,8 @@ public class HandyClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
if (!Utils.ENABLED) return;

var thread = new Thread(() -> {
try {
HandyServer.LOGGER.info("Started client test.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.melontini.handytests.mixin;
package me.melontini.handytests.mixin.client;

import me.melontini.handytests.util.Utils;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.registry.RegistryKeys;
Expand All @@ -12,26 +15,40 @@
import net.minecraft.world.gen.WorldPresets;
import net.minecraft.world.level.LevelInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.regex.Pattern;

@Mixin(value = MinecraftClient.class, priority = 1200)
public class MinecraftClientMixin {

@Unique
private static final Pattern RESERVED_WINDOWS_NAMES = Pattern.compile(".*\\.|(?:COM|CLOCK\\$|CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\\..*)?", 2);

@Inject(method = "method_29338", at = @At("TAIL"), require = 0)
private void handy$init(CallbackInfo ci) {
if (!Utils.ENABLED) return;

MinecraftClient.getInstance().send(() -> {
try {
MinecraftClient client = MinecraftClient.getInstance();
String levelName = "handy_test_" + FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion().getFriendlyString();

for (char c : SharedConstants.INVALID_CHARS_LEVEL_NAME) levelName = levelName.replace(c, '_');
levelName = levelName.replaceAll("[./\"]", "_");
if (RESERVED_WINDOWS_NAMES.matcher(levelName).matches()) levelName = "_" + levelName + "_";

if (!client.getLevelStorage().levelExists("handy_tests_world")) {
client.createIntegratedServerLoader().createAndStart("handy_tests_world",
new LevelInfo("handy_tests_world", GameMode.CREATIVE, false, Difficulty.EASY, true,
if (!client.getLevelStorage().levelExists(levelName)) {
client.createIntegratedServerLoader().createAndStart(levelName,
new LevelInfo(levelName, GameMode.CREATIVE, false, Difficulty.PEACEFUL, true,
new GameRules(), DataConfiguration.SAFE_MODE),
new GeneratorOptions(0, true, false),
registryManager -> registryManager.get(RegistryKeys.WORLD_PRESET).entryOf(WorldPresets.FLAT).value().createDimensionsRegistryHolder(), null);
} else {
client.createIntegratedServerLoader().start("handy_tests_world", () -> client.setScreen(new TitleScreen()));
client.createIntegratedServerLoader().start(levelName, () -> client.setScreen(new TitleScreen()));
}
} catch (Throwable t) {
CrashReport report = CrashReport.create(t, "Setting tests world");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.melontini.handytests.mixin;
package me.melontini.handytests.mixin.server;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.melontini.handytests.util.Utils;
import net.minecraft.server.Main;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -9,6 +10,6 @@
public class ServerMainMixin {
@ModifyExpressionValue(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/EulaReader;isEulaAgreedTo()Z"))
private static boolean isEulaAgreedTo(boolean original) {
return true;
return original || Utils.ENABLED;
}
}
7 changes: 3 additions & 4 deletions src/main/java/me/melontini/handytests/server/HandyServer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.melontini.handytests.server;

import com.mojang.logging.LogUtils;
import me.melontini.handytests.util.Utils;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
Expand All @@ -14,10 +15,8 @@ public class HandyServer implements DedicatedServerModInitializer {

@Override
public void onInitializeServer() {
if (System.getProperty("fabric-api.gametest") != null) {
LOGGER.info("Skipping handy server test, as gametest is enabled!");
return;
}
if (!Utils.ENABLED) return;

MutableInt ticks = new MutableInt(0);
ServerTickEvents.END_SERVER_TICK.register(server -> ticks.add(1));

Expand Down
Loading

0 comments on commit 88418bd

Please sign in to comment.