From 9af40eabc19dff7237100d6ababb49ad734ee346 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 10 Dec 2024 14:55:49 +0000 Subject: [PATCH] Move client auto tests to new module fabric-client-gametest-api-v1 --- build.gradle | 16 ++- .../src/testmod/resources/fabric.mod.json | 11 +- fabric-client-gametest-api-v1/build.gradle | 6 + .../ClientGameTestMixinConfigPlugin.java | 59 ++++++++++ .../client/FabricClientTestHelper.java | 8 +- .../gametest}/client/TestDedicatedServer.java | 2 +- .../impl/gametest}/client/ThreadingImpl.java | 2 +- .../client}/CyclingButtonWidgetAccessor.java | 2 +- .../client}/MinecraftClientMixin.java | 103 ++++++++---------- .../MinecraftDedicatedServerMixin.java | 4 +- .../client}/MinecraftServerMixin.java | 65 +++++------ .../gametest/client}/ScreenAccessor.java | 2 +- .../gametest/client}/TitleScreenAccessor.java | 2 +- .../fabric-client-gametest-api-v1/icon.png | Bin 0 -> 1579 bytes .../fabric-client-gametest-api-v1.mixins.json | 17 +-- .../src/client/resources/fabric.mod.json | 29 +++++ .../client/ClientGameTestTestMod.java | 40 +++---- .../testmodClient/resources/fabric.mod.json | 13 +++ gradle.properties | 1 + settings.gradle | 1 + 20 files changed, 235 insertions(+), 148 deletions(-) create mode 100644 fabric-client-gametest-api-v1/build.gradle create mode 100644 fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ClientGameTestMixinConfigPlugin.java rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest}/client/FabricClientTestHelper.java (96%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest}/client/TestDedicatedServer.java (98%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest}/client/ThreadingImpl.java (99%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/CyclingButtonWidgetAccessor.java (94%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/MinecraftClientMixin.java (60%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/MinecraftDedicatedServerMixin.java (93%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/MinecraftServerMixin.java (54%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/ScreenAccessor.java (94%) rename {fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin => fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client}/TitleScreenAccessor.java (94%) create mode 100644 fabric-client-gametest-api-v1/src/client/resources/assets/fabric-client-gametest-api-v1/icon.png rename fabric-api-base/src/testmodClient/resources/fabric-api-base-testmod.client.mixins.json => fabric-client-gametest-api-v1/src/client/resources/fabric-client-gametest-api-v1.mixins.json (68%) create mode 100644 fabric-client-gametest-api-v1/src/client/resources/fabric.mod.json rename fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricApiAutoTestClient.java => fabric-client-gametest-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/gametest/client/ClientGameTestTestMod.java (72%) create mode 100644 fabric-client-gametest-api-v1/src/testmodClient/resources/fabric.mod.json diff --git a/build.gradle b/build.gradle index 7e71f6b344..b9b44f79c8 100644 --- a/build.gradle +++ b/build.gradle @@ -420,7 +420,7 @@ loom { autoTestClient { inherit testmodClient name "Auto Test Client" - vmArg "-Dfabric.autoTest" + vmArg "-Dfabric.client.gametest" vmArg "-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail" vmArg "-Dfabric-tag-conventions-v1.legacyTagWarning=fail" } @@ -498,6 +498,9 @@ import net.fabricmc.loom.util.Platform // This is very far beyond loom's API if you copy this, you're on your own. tasks.register('runProductionAutoTestClient', JavaExec) { dependsOn remapJar, remapTestmodJar, downloadAssets + afterEvaluate { + dependsOn project(':fabric-client-gametest-api-v1').remapJar + } classpath.from configurations.productionRuntime mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient" workingDir = file("run") @@ -518,9 +521,11 @@ tasks.register('runProductionAutoTestClient', JavaExec) { ) } + afterEvaluate { + jvmArgs "-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${project(':fabric-client-gametest-api-v1').remapJar.archiveFile.get().asFile.absolutePath}" + } jvmArgs( - "-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}", - "-Dfabric.autoTest", + "-Dfabric.gametest.client", "-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail", "-Dfabric-tag-conventions-v1.legacyTagWarning=fail" ) @@ -726,7 +731,10 @@ subprojects.each { } // These modules are not included in the fat jar, maven will resolve them via the pom. -def devOnlyModules = ["fabric-gametest-api-v1",] +def devOnlyModules = [ + "fabric-client-gametest-api-v1", + "fabric-gametest-api-v1", +] dependencies { afterEvaluate { diff --git a/fabric-api-base/src/testmod/resources/fabric.mod.json b/fabric-api-base/src/testmod/resources/fabric.mod.json index 05db3dc8f3..fc1240a71a 100644 --- a/fabric-api-base/src/testmod/resources/fabric.mod.json +++ b/fabric-api-base/src/testmod/resources/fabric.mod.json @@ -9,20 +9,11 @@ "main": [ "net.fabricmc.fabric.test.base.FabricApiBaseTestInit" ], - "client": [ - "net.fabricmc.fabric.test.base.client.FabricApiAutoTestClient" - ], "server": [ "net.fabricmc.fabric.test.base.FabricApiAutoTestServer" ], "fabric-gametest" : [ "net.fabricmc.fabric.test.base.FabricApiBaseGameTest" ] - }, - "mixins": [ - { - "config": "fabric-api-base-testmod.client.mixins.json", - "environment": "client" - } - ] + } } diff --git a/fabric-client-gametest-api-v1/build.gradle b/fabric-client-gametest-api-v1/build.gradle new file mode 100644 index 0000000000..f2db1b51aa --- /dev/null +++ b/fabric-client-gametest-api-v1/build.gradle @@ -0,0 +1,6 @@ +version = getSubprojectVersion(project) + +moduleDependencies(project, [ + 'fabric-api-base', + 'fabric-resource-loader-v0' +]) diff --git a/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ClientGameTestMixinConfigPlugin.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ClientGameTestMixinConfigPlugin.java new file mode 100644 index 0000000000..79c0c68778 --- /dev/null +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ClientGameTestMixinConfigPlugin.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.impl.gametest.client; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +public class ClientGameTestMixinConfigPlugin implements IMixinConfigPlugin { + private static final boolean ENABLED = System.getProperty("fabric.client.gametest") != null; + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return ENABLED; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricClientTestHelper.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/FabricClientTestHelper.java similarity index 96% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricClientTestHelper.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/FabricClientTestHelper.java index 79e194fb77..299663fffd 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricClientTestHelper.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/FabricClientTestHelper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client; +package net.fabricmc.fabric.impl.gametest.client; import java.util.Objects; import java.util.function.Function; @@ -45,9 +45,9 @@ import net.minecraft.client.util.ScreenshotRecorder; import net.minecraft.text.Text; -import net.fabricmc.fabric.test.base.client.mixin.CyclingButtonWidgetAccessor; -import net.fabricmc.fabric.test.base.client.mixin.ScreenAccessor; -import net.fabricmc.fabric.test.base.client.mixin.TitleScreenAccessor; +import net.fabricmc.fabric.mixin.gametest.client.CyclingButtonWidgetAccessor; +import net.fabricmc.fabric.mixin.gametest.client.ScreenAccessor; +import net.fabricmc.fabric.mixin.gametest.client.TitleScreenAccessor; import net.fabricmc.loader.api.FabricLoader; public final class FabricClientTestHelper { diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/TestDedicatedServer.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/TestDedicatedServer.java similarity index 98% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/TestDedicatedServer.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/TestDedicatedServer.java index 58796eb6e2..7cc62379c6 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/TestDedicatedServer.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/TestDedicatedServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client; +package net.fabricmc.fabric.impl.gametest.client; import java.io.Closeable; import java.io.IOException; diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/ThreadingImpl.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ThreadingImpl.java similarity index 99% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/ThreadingImpl.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ThreadingImpl.java index ee13bcf40b..87da7f9264 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/ThreadingImpl.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/impl/gametest/client/ThreadingImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client; +package net.fabricmc.fabric.impl.gametest.client; import java.util.concurrent.Phaser; import java.util.concurrent.Semaphore; diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/CyclingButtonWidgetAccessor.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/CyclingButtonWidgetAccessor.java similarity index 94% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/CyclingButtonWidgetAccessor.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/CyclingButtonWidgetAccessor.java index cca8b118b2..2b8fd4a9d6 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/CyclingButtonWidgetAccessor.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/CyclingButtonWidgetAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftClientMixin.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftClientMixin.java similarity index 60% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftClientMixin.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftClientMixin.java index 137d4defa5..d5ddd343cb 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftClientMixin.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftClientMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import com.google.common.base.Preconditions; import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; @@ -32,8 +32,7 @@ import net.minecraft.server.SaveLoader; import net.minecraft.world.level.storage.LevelStorage; -import net.fabricmc.fabric.test.base.client.FabricApiAutoTestClient; -import net.fabricmc.fabric.test.base.client.ThreadingImpl; +import net.fabricmc.fabric.impl.gametest.client.ThreadingImpl; @Mixin(MinecraftClient.class) public class MinecraftClientMixin { @@ -42,71 +41,63 @@ public class MinecraftClientMixin { @WrapMethod(method = "run") private void onRun(Operation original) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - if (ThreadingImpl.isClientRunning) { - throw new IllegalStateException("Client is already running"); - } - - ThreadingImpl.isClientRunning = true; - ThreadingImpl.PHASER.register(); + if (ThreadingImpl.isClientRunning) { + throw new IllegalStateException("Client is already running"); } + ThreadingImpl.isClientRunning = true; + ThreadingImpl.PHASER.register(); + try { original.call(); } finally { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.clientCanAcceptTasks = false; - ThreadingImpl.PHASER.arriveAndDeregister(); - ThreadingImpl.isClientRunning = false; - } + ThreadingImpl.clientCanAcceptTasks = false; + ThreadingImpl.PHASER.arriveAndDeregister(); + ThreadingImpl.isClientRunning = false; } } @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;runTasks()V")) private void preRunTasks(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_SERVER_TASKS); - // server tasks happen here - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_CLIENT_TASKS); - } + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_SERVER_TASKS); + // server tasks happen here + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_CLIENT_TASKS); } @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;runTasks()V", shift = At.Shift.AFTER)) private void postRunTasks(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.clientCanAcceptTasks = true; - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TEST); - - if (ThreadingImpl.testThread != null) { - while (true) { - try { - ThreadingImpl.CLIENT_SEMAPHORE.acquire(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - if (ThreadingImpl.taskToRun != null) { - ThreadingImpl.taskToRun.run(); - } else { - break; - } + ThreadingImpl.clientCanAcceptTasks = true; + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TEST); + + if (ThreadingImpl.testThread != null) { + while (true) { + try { + ThreadingImpl.CLIENT_SEMAPHORE.acquire(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + if (ThreadingImpl.taskToRun != null) { + ThreadingImpl.taskToRun.run(); + } else { + break; } } + } - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TICK); + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TICK); - Runnable deferredTask = this.deferredTask; - this.deferredTask = null; + Runnable deferredTask = this.deferredTask; + this.deferredTask = null; - if (deferredTask != null) { - deferredTask.run(); - } + if (deferredTask != null) { + deferredTask.run(); } } @Inject(method = "startIntegratedServer", at = @At("HEAD"), cancellable = true) private void deferStartIntegratedServer(LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, boolean newWorld, CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST && ThreadingImpl.taskToRun != null) { + if (ThreadingImpl.taskToRun != null) { // don't start the integrated server (which busywaits) inside a task deferredTask = () -> MinecraftClient.getInstance().startIntegratedServer(session, dataPackManager, saveLoader, newWorld); ci.cancel(); @@ -115,16 +106,14 @@ private void deferStartIntegratedServer(LevelStorage.Session session, ResourcePa @Inject(method = "startIntegratedServer", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;sleep(J)V", remap = false)) private void onStartIntegratedServerBusyWait(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - // give the server a chance to tick too - preRunTasks(ci); - postRunTasks(ci); - } + // give the server a chance to tick too + preRunTasks(ci); + postRunTasks(ci); } @Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At("HEAD"), cancellable = true) private void deferDisconnect(Screen disconnectionScreen, boolean transferring, CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST && MinecraftClient.getInstance().getServer() != null && ThreadingImpl.taskToRun != null) { + if (MinecraftClient.getInstance().getServer() != null && ThreadingImpl.taskToRun != null) { // don't disconnect (which busywaits) inside a task deferredTask = () -> MinecraftClient.getInstance().disconnect(disconnectionScreen, transferring); ci.cancel(); @@ -133,18 +122,14 @@ private void deferDisconnect(Screen disconnectionScreen, boolean transferring, C @Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;render(Z)V", shift = At.Shift.AFTER)) private void onDisconnectBusyWait(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - // give the server a chance to tick too - preRunTasks(ci); - postRunTasks(ci); - } + // give the server a chance to tick too + preRunTasks(ci); + postRunTasks(ci); } @Inject(method = "getInstance", at = @At("HEAD")) private static void checkThreadOnGetInstance(CallbackInfoReturnable cir) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - // TODO: add suggestion of runOnClient etc when API methods are added - Preconditions.checkState(Thread.currentThread() != ThreadingImpl.testThread, "MinecraftClient.getInstance() cannot be called from the test thread"); - } + // TODO: add suggestion of runOnClient etc when API methods are added + Preconditions.checkState(Thread.currentThread() != ThreadingImpl.testThread, "MinecraftClient.getInstance() cannot be called from the test thread"); } } diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftDedicatedServerMixin.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftDedicatedServerMixin.java similarity index 93% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftDedicatedServerMixin.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftDedicatedServerMixin.java index e53a5256ed..c5e7ece359 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftDedicatedServerMixin.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftDedicatedServerMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; @@ -25,7 +25,7 @@ import net.minecraft.server.dedicated.MinecraftDedicatedServer; -import net.fabricmc.fabric.test.base.client.TestDedicatedServer; +import net.fabricmc.fabric.impl.gametest.client.TestDedicatedServer; @Mixin(MinecraftDedicatedServer.class) public abstract class MinecraftDedicatedServerMixin { diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftServerMixin.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftServerMixin.java similarity index 54% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftServerMixin.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftServerMixin.java index 9b044be19b..702cd87efe 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/MinecraftServerMixin.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/MinecraftServerMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; @@ -25,66 +25,57 @@ import net.minecraft.server.MinecraftServer; -import net.fabricmc.fabric.test.base.client.FabricApiAutoTestClient; -import net.fabricmc.fabric.test.base.client.ThreadingImpl; +import net.fabricmc.fabric.impl.gametest.client.ThreadingImpl; @Mixin(MinecraftServer.class) public class MinecraftServerMixin { @WrapMethod(method = "runServer") private void onRunServer(Operation original) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - if (ThreadingImpl.isServerRunning) { - throw new IllegalStateException("Server is already running"); - } - - ThreadingImpl.isServerRunning = true; - ThreadingImpl.PHASER.register(); + if (ThreadingImpl.isServerRunning) { + throw new IllegalStateException("Server is already running"); } + ThreadingImpl.isServerRunning = true; + ThreadingImpl.PHASER.register(); + try { original.call(); } finally { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.serverCanAcceptTasks = false; - ThreadingImpl.PHASER.arriveAndDeregister(); - ThreadingImpl.isServerRunning = false; - } + ThreadingImpl.serverCanAcceptTasks = false; + ThreadingImpl.PHASER.arriveAndDeregister(); + ThreadingImpl.isServerRunning = false; } } @Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;runTasksTillTickEnd()V")) private void preRunTasks(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_SERVER_TASKS); - } + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_SERVER_TASKS); } @Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;runTasksTillTickEnd()V", shift = At.Shift.AFTER)) private void postRunTasks(CallbackInfo ci) { - if (FabricApiAutoTestClient.IS_AUTO_TEST) { - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_CLIENT_TASKS); - // client tasks happen here + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_CLIENT_TASKS); + // client tasks happen here - ThreadingImpl.serverCanAcceptTasks = true; - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TEST); + ThreadingImpl.serverCanAcceptTasks = true; + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TEST); - if (ThreadingImpl.testThread != null) { - while (true) { - try { - ThreadingImpl.SERVER_SEMAPHORE.acquire(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + if (ThreadingImpl.testThread != null) { + while (true) { + try { + ThreadingImpl.SERVER_SEMAPHORE.acquire(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } - if (ThreadingImpl.taskToRun != null) { - ThreadingImpl.taskToRun.run(); - } else { - break; - } + if (ThreadingImpl.taskToRun != null) { + ThreadingImpl.taskToRun.run(); + } else { + break; } } - - ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TICK); } + + ThreadingImpl.enterPhase(ThreadingImpl.PHASE_TICK); } } diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/ScreenAccessor.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/ScreenAccessor.java similarity index 94% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/ScreenAccessor.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/ScreenAccessor.java index fd444c43cf..7497af6df1 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/ScreenAccessor.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/ScreenAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import java.util.List; diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/TitleScreenAccessor.java b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/TitleScreenAccessor.java similarity index 94% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/TitleScreenAccessor.java rename to fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/TitleScreenAccessor.java index 6b2696aa7b..f621101e6d 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/mixin/TitleScreenAccessor.java +++ b/fabric-client-gametest-api-v1/src/client/java/net/fabricmc/fabric/mixin/gametest/client/TitleScreenAccessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client.mixin; +package net.fabricmc.fabric.mixin.gametest.client; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/fabric-client-gametest-api-v1/src/client/resources/assets/fabric-client-gametest-api-v1/icon.png b/fabric-client-gametest-api-v1/src/client/resources/assets/fabric-client-gametest-api-v1/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2931efbf610873c0084debb8690902b0103d27fe GIT binary patch literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ literal 0 HcmV?d00001 diff --git a/fabric-api-base/src/testmodClient/resources/fabric-api-base-testmod.client.mixins.json b/fabric-client-gametest-api-v1/src/client/resources/fabric-client-gametest-api-v1.mixins.json similarity index 68% rename from fabric-api-base/src/testmodClient/resources/fabric-api-base-testmod.client.mixins.json rename to fabric-client-gametest-api-v1/src/client/resources/fabric-client-gametest-api-v1.mixins.json index fb5cc068d0..e7d83cfb49 100644 --- a/fabric-api-base/src/testmodClient/resources/fabric-api-base-testmod.client.mixins.json +++ b/fabric-client-gametest-api-v1/src/client/resources/fabric-client-gametest-api-v1.mixins.json @@ -1,18 +1,19 @@ { "required": true, - "package": "net.fabricmc.fabric.test.base.client.mixin", + "package": "net.fabricmc.fabric.mixin.gametest.client", "compatibilityLevel": "JAVA_21", - "client": [ - "CyclingButtonWidgetAccessor", - "MinecraftClientMixin", + "mixins": [ "MinecraftDedicatedServerMixin", - "ScreenAccessor", - "TitleScreenAccessor" + "MinecraftServerMixin" ], + "plugin": "net.fabricmc.fabric.impl.gametest.client.ClientGameTestMixinConfigPlugin", "injectors": { "defaultRequire": 1 }, - "mixins": [ - "MinecraftServerMixin" + "client": [ + "CyclingButtonWidgetAccessor", + "MinecraftClientMixin", + "ScreenAccessor", + "TitleScreenAccessor" ] } diff --git a/fabric-client-gametest-api-v1/src/client/resources/fabric.mod.json b/fabric-client-gametest-api-v1/src/client/resources/fabric.mod.json new file mode 100644 index 0000000000..66b17600a4 --- /dev/null +++ b/fabric-client-gametest-api-v1/src/client/resources/fabric.mod.json @@ -0,0 +1,29 @@ +{ + "schemaVersion": 1, + "id": "fabric-client-gametest-api-v1", + "name": "Fabric Client Game Test API (v1)", + "version": "${version}", + "environment": "client", + "license": "Apache-2.0", + "icon": "assets/fabric-client-gametest-api-v1/icon.png", + "contact": { + "homepage": "https://fabricmc.net", + "irc": "irc://irc.esper.net:6667/fabric", + "issues": "https://github.com/FabricMC/fabric/issues", + "sources": "https://github.com/FabricMC/fabric" + }, + "authors": [ + "FabricMC" + ], + "depends": { + "fabricloader": ">=0.16.9", + "fabric-resource-loader-v0": "*" + }, + "description": "Allows registration of client game tests.", + "mixins": [ + "fabric-client-gametest-api-v1.mixins.json" + ], + "custom": { + "fabric-api:module-lifecycle": "experimental" + } +} diff --git a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricApiAutoTestClient.java b/fabric-client-gametest-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/gametest/client/ClientGameTestTestMod.java similarity index 72% rename from fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricApiAutoTestClient.java rename to fabric-client-gametest-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/gametest/client/ClientGameTestTestMod.java index 60de59e2a3..aafa68b94e 100644 --- a/fabric-api-base/src/testmodClient/java/net/fabricmc/fabric/test/base/client/FabricApiAutoTestClient.java +++ b/fabric-client-gametest-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/gametest/client/ClientGameTestTestMod.java @@ -14,22 +14,22 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.base.client; - -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.clickScreenButton; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.closeScreen; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.computeOnClient; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.connectToServer; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.enableDebugHud; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.openGameMenu; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.openInventory; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.setPerspective; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.takeScreenshot; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.waitForLoadingComplete; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.waitForScreen; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.waitForServerStop; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.waitForTitleScreenFade; -import static net.fabricmc.fabric.test.base.client.FabricClientTestHelper.waitForWorldTicks; +package net.fabricmc.fabric.test.gametest.client; + +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.clickScreenButton; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.closeScreen; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.computeOnClient; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.connectToServer; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.enableDebugHud; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.openGameMenu; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.openInventory; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.setPerspective; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.takeScreenshot; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.waitForLoadingComplete; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.waitForScreen; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.waitForServerStop; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.waitForTitleScreenFade; +import static net.fabricmc.fabric.impl.gametest.client.FabricClientTestHelper.waitForWorldTicks; import java.io.IOException; import java.io.UncheckedIOException; @@ -51,14 +51,16 @@ import net.minecraft.client.option.Perspective; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.impl.gametest.client.TestDedicatedServer; +import net.fabricmc.fabric.impl.gametest.client.ThreadingImpl; import net.fabricmc.loader.api.FabricLoader; -public class FabricApiAutoTestClient implements ClientModInitializer { - public static final boolean IS_AUTO_TEST = System.getProperty("fabric.autoTest") != null; +public class ClientGameTestTestMod implements ClientModInitializer { + public static final boolean ENABLED = System.getProperty("fabric.client.gametest") != null; @Override public void onInitializeClient() { - if (!IS_AUTO_TEST) { + if (!ENABLED) { return; } diff --git a/fabric-client-gametest-api-v1/src/testmodClient/resources/fabric.mod.json b/fabric-client-gametest-api-v1/src/testmodClient/resources/fabric.mod.json new file mode 100644 index 0000000000..c2f5ca1eb0 --- /dev/null +++ b/fabric-client-gametest-api-v1/src/testmodClient/resources/fabric.mod.json @@ -0,0 +1,13 @@ +{ + "schemaVersion": 1, + "id": "fabric-client-gametest-api-v1-testmod", + "name": "Fabric Client Game Test API (v1) Test Mod", + "version": "1.0.0", + "environment": "*", + "license": "Apache-2.0", + "entrypoints": { + "client": [ + "net.fabricmc.fabric.test.gametest.client.ClientGameTestTestMod" + ] + } +} diff --git a/gradle.properties b/gradle.properties index a506d15251..e3857cb064 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,7 @@ fabric-biome-api-v1-version=15.0.4 fabric-block-api-v1-version=1.0.31 fabric-block-view-api-v2-version=1.0.19 fabric-blockrenderlayer-v1-version=2.0.7 +fabric-client-gametest-api-v1-version=0.0.1 fabric-command-api-v1-version=1.2.61 fabric-command-api-v2-version=2.2.40 fabric-commands-v0-version=0.2.78 diff --git a/settings.gradle b/settings.gradle index 4e3df4ebb1..150664dc37 100644 --- a/settings.gradle +++ b/settings.gradle @@ -30,6 +30,7 @@ include 'fabric-biome-api-v1' include 'fabric-block-api-v1' include 'fabric-block-view-api-v2' include 'fabric-blockrenderlayer-v1' +include 'fabric-client-gametest-api-v1' include 'fabric-client-tags-api-v1' include 'fabric-command-api-v2' include 'fabric-content-registries-v0'