From b6a1cb27a55916e462b42c5746c8585ef6ca80eb Mon Sep 17 00:00:00 2001 From: melontini <104443436+melontini@users.noreply.github.com> Date: Sat, 13 Apr 2024 17:23:56 +0700 Subject: [PATCH] Add simple testmod. --- .github/workflows/build.yml | 33 ++++++++++++++- build.gradle | 42 +++++++++++++++++-- gradle.properties | 2 +- src/main/resources/fabric.mod.json | 3 +- .../test/InventoryScreenAccessor.java | 5 +++ .../test/RecipeBookIsPainTest.java | 36 ++++++++++++++++ .../test/mixin/InventoryScreenMixin.java | 31 ++++++++++++++ src/testmod/resources/fabric.mod.json | 15 +++++++ .../recipe-book-is-pain-testmod.mixins.json | 14 +++++++ 9 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 src/testmod/java/me/melontini/recipebookispain/test/InventoryScreenAccessor.java create mode 100644 src/testmod/java/me/melontini/recipebookispain/test/RecipeBookIsPainTest.java create mode 100644 src/testmod/java/me/melontini/recipebookispain/test/mixin/InventoryScreenMixin.java create mode 100644 src/testmod/resources/fabric.mod.json create mode 100644 src/testmod/resources/recipe-book-is-pain-testmod.mixins.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88b094c..918deb6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,9 +48,36 @@ jobs: name: Artifacts path: build/libs/ - packages: + client_test: needs: build runs-on: ubuntu-latest + steps: + - name: checkout repository + uses: actions/checkout@v4.1.1 + - name: validate gradle wrapper + uses: gradle/wrapper-validation-action@v2.1.1 + - name: setup jdk 17 + uses: actions/setup-java@v4.1.0 + 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 runTestClient --stacktrace --warning-mode=fail + - uses: actions/upload-artifact@v4.3.1 + with: + name: Test Screenshots + path: run/screenshots + + packages: + needs: + - build + - client_test + runs-on: ubuntu-latest steps: - name: checkout repository uses: actions/checkout@v4.1.1 @@ -69,7 +96,9 @@ jobs: ./gradlew publish publish: - needs: build + needs: + - build + - client_test runs-on: ubuntu-latest if: ${{ github.event_name == 'workflow_dispatch' }} steps: diff --git a/build.gradle b/build.gradle index b7476ff..d2e84c1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import net.fabricmc.loom.api.RemapConfigurationSettings + plugins { id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' @@ -26,6 +28,22 @@ repositories { maven { url 'https://maven.wispforest.io' } } +sourceSets { + testmod { + compileClasspath += main.compileClasspath + runtimeClasspath += main.runtimeClasspath + } +} + +loom { + addRemapConfiguration("testmodRemapImplementation", (RemapConfigurationSettings configuration) -> { + configuration.getTargetConfigurationName().convention("testmodImplementation") + configuration.getOnCompileClasspath().convention(true) + configuration.getOnRuntimeClasspath().convention(true) + configuration.getPublishingMode().convention(RemapConfigurationSettings.PublishingMode.COMPILE_AND_RUNTIME) + }) +} + dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -39,6 +57,26 @@ dependencies { modApi("me.melontini:dark-matter-item-group:${project.dark_matter}") modCompileOnly("io.wispforest:owo-lib:${project.owo_version}") + + testmodImplementation sourceSets.main.output + testmodRemapImplementation "me.melontini:handy-tests:0.1.0-1.20.1-build.2" +} + +loom { + runs { + testClient { + client() + source sourceSets.testmod + } + } +} + +loom.mods.register(project.name) { + sourceSet project.sourceSets.main +} + +loom.mods.register(project.name + "-testmod") { + sourceSet project.sourceSets.testmod } processResources { @@ -72,10 +110,6 @@ java { if (JavaVersion.current() < javaVersion) { toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) } - archivesBaseName = project.archives_base_name - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. withSourcesJar() } diff --git a/gradle.properties b/gradle.properties index 739c305..e4ae459 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # check these on https://modmuss50.me/fabric.html minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 -loader_version=0.15.7 +loader_version=0.15.10 # Mod Properties mod_version=0.11.1 maven_group=me.melontini diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index bc3fead..3c10583 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,6 +21,7 @@ ], "depends": { "fabricloader": ">=${loader_version}", - "minecraft": ">=${minecraft_version}" + "minecraft": ">=${minecraft_version}", + "dark-matter-base": "*" } } diff --git a/src/testmod/java/me/melontini/recipebookispain/test/InventoryScreenAccessor.java b/src/testmod/java/me/melontini/recipebookispain/test/InventoryScreenAccessor.java new file mode 100644 index 0000000..ac5a501 --- /dev/null +++ b/src/testmod/java/me/melontini/recipebookispain/test/InventoryScreenAccessor.java @@ -0,0 +1,5 @@ +package me.melontini.recipebookispain.test; + +public interface InventoryScreenAccessor { + void rbip$pressRecipeBookButton(); +} diff --git a/src/testmod/java/me/melontini/recipebookispain/test/RecipeBookIsPainTest.java b/src/testmod/java/me/melontini/recipebookispain/test/RecipeBookIsPainTest.java new file mode 100644 index 0000000..fa80b27 --- /dev/null +++ b/src/testmod/java/me/melontini/recipebookispain/test/RecipeBookIsPainTest.java @@ -0,0 +1,36 @@ +package me.melontini.recipebookispain.test; + +import me.melontini.handytests.client.ClientTestContext; +import me.melontini.handytests.client.ClientTestEntrypoint; +import net.minecraft.client.gui.screen.ingame.InventoryScreen; + +public class RecipeBookIsPainTest implements ClientTestEntrypoint { + + @Override + public void onClientTest(ClientTestContext context) { + context.sendCommand("gamemode survival"); + context.sendCommand("difficulty peaceful"); + context.sendCommand("recipe give @s *"); + context.openInventory(); + context.waitForWorldTicks(40); + + context.openInventory(); + context.executeForScreen(InventoryScreen.class, (client, screen) -> { + if (!screen.getRecipeBookWidget().isOpen()) { + ((InventoryScreenAccessor) screen).rbip$pressRecipeBookButton(); + } + return null; + }); + context.takeScreenshot("recipe-book-open"); + context.executeForScreen(InventoryScreen.class, (client, screen) -> { + if (screen.getRecipeBookWidget().isOpen()) { + ((InventoryScreenAccessor) screen).rbip$pressRecipeBookButton(); + } + return null; + }); + context.closeScreen(); + + context.sendCommand("gamemode creative"); + context.waitForWorldTicks(20); + } +} diff --git a/src/testmod/java/me/melontini/recipebookispain/test/mixin/InventoryScreenMixin.java b/src/testmod/java/me/melontini/recipebookispain/test/mixin/InventoryScreenMixin.java new file mode 100644 index 0000000..226729f --- /dev/null +++ b/src/testmod/java/me/melontini/recipebookispain/test/mixin/InventoryScreenMixin.java @@ -0,0 +1,31 @@ +package me.melontini.recipebookispain.test.mixin; + +import me.melontini.recipebookispain.test.InventoryScreenAccessor; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.gui.widget.TexturedButtonWidget; +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.ModifyArg; + +@Mixin(InventoryScreen.class) +public class InventoryScreenMixin implements InventoryScreenAccessor { + + @Unique + private TexturedButtonWidget recipeBookButton; + + @ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/InventoryScreen;addDrawableChild(Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element;")) + private Element steal(Element par1) { + if (par1 instanceof TexturedButtonWidget widget) { + this.recipeBookButton = widget; + return widget; + } + return par1; + } + + @Override + public void rbip$pressRecipeBookButton() { + this.recipeBookButton.onPress(); + } +} diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json new file mode 100644 index 0000000..de28837 --- /dev/null +++ b/src/testmod/resources/fabric.mod.json @@ -0,0 +1,15 @@ +{ + "schemaVersion": 1, + "id": "recipe-book-is-pain-testmod", + "version": "1.0.0", + "license": "MIT", + "environment": "*", + "mixins": [ + "recipe-book-is-pain-testmod.mixins.json" + ], + "entrypoints": { + "handy:client_test": [ + "me.melontini.recipebookispain.test.RecipeBookIsPainTest" + ] + } +} diff --git a/src/testmod/resources/recipe-book-is-pain-testmod.mixins.json b/src/testmod/resources/recipe-book-is-pain-testmod.mixins.json new file mode 100644 index 0000000..f22b4a9 --- /dev/null +++ b/src/testmod/resources/recipe-book-is-pain-testmod.mixins.json @@ -0,0 +1,14 @@ +{ + "required": false, + "minVersion": "0.8", + "package": "me.melontini.recipebookispain.test.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "InventoryScreenMixin" + ], + "injectors": { + "defaultRequire": 0 + } +} -- 2.51.2