From 80468faa1c85f74d5b70bb46ea072588ccd60ab1 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 29 Nov 2022 21:15:15 +0100 Subject: [PATCH] Add gametest setup --- README.md | 14 +- build.gradle | 30 ++++ .../example_mod/test/ExampleModTests.java | 14 ++ .../assets/example_mod_test/icon.png | Bin 0 -> 207 bytes .../examplemodtests.examplestructuretest.snbt | 138 ++++++++++++++++++ src/gametest/resources/quilt.mod.json | 40 +++++ 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 src/gametest/java/com/example/example_mod/test/ExampleModTests.java create mode 100644 src/gametest/resources/assets/example_mod_test/icon.png create mode 100644 src/gametest/resources/data/example_mod_test/gametest/structures/examplemodtests.examplestructuretest.snbt create mode 100644 src/gametest/resources/quilt.mod.json diff --git a/README.md b/README.md index 08db1bb..e0f66cd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ My personalized Quilt template Mod. You can use it as a template for your own mo ## Differences from the Official Mod - Added a build github action - +- Added gametest support (See ##Usage###Gametest Support) ## Usage In order to use this mod as a template: @@ -14,7 +14,7 @@ In order to use this mod as a template: 3. Make the necessary changes in order to make it yours: - Update `gradle.properties` in order to use your Maven group and mod ID - If you don't know which Maven group to use, and you are planning to host the mod's source code on GitHub, use `io.github.` - - Update `quilt.mod.json` in order to reflect your mod's metadata + - Update `quilt.mod.json` in `src/main/resources` in order to reflect your mod's metadata - If you are planning to include (jar-in-jar) a mod, don't forget to declare its dependency on it! - The icon provided here is a placeholder one. If you aren't able to replace it yet, you can delete it and remove the "icon" property - Create a LICENSE file for this mod! If you don't know which license to use, check out [here](https://choosealicense.com/). @@ -24,6 +24,16 @@ In order to use this mod as a template: - If the dependencies on `gradle/libs.versions.toml` isn't up-to-date, feel free to update them! The [linked utility](https://lambdaurora.dev/tools/import_quilt.html) should help you in this easy and quick process. 4. The mod is now ready to be worked on! +### Gametest Support +1. Update `quilt.mod.json` in `src/gametest/resources` and the rest of the naming in order to reflect your testmod's metadata + +> [WARNING] +> +> make sure to change the dependency on `example_mod` to your modid and to not reuse the modid of your main project, e.g. suffix your project's modid with `_test` +> + +2. Now testing should be available using the test gradle task + ## License This template on the QuiltMC GitHub is licensed under the [Creative Common Zero v1.0 license](./LICENSE-TEMPLATE.md). diff --git a/build.gradle b/build.gradle index 6d2c0d6..c6aeee3 100644 --- a/build.gradle +++ b/build.gradle @@ -69,6 +69,36 @@ jar { } } +// Gametest stuff +sourceSets { + gametest { + compileClasspath += sourceSets.main.compileClasspath + runtimeClasspath += sourceSets.main.runtimeClasspath + compileClasspath += sourceSets.main.output + runtimeClasspath += sourceSets.main.output + } +} + +loom { + runs { + gametest { + server() + name = "Headless Game Test Server" + vmArg "-Dfabric-api.gametest" + runDir "build/gametest" + source = project.sourceSets.gametest + } + + gametestClient { + client() + name = "Game Test Client" + source = project.sourceSets.gametest + } + } +} + +test.dependsOn runGametest + // Configure the maven publication publishing { publications { diff --git a/src/gametest/java/com/example/example_mod/test/ExampleModTests.java b/src/gametest/java/com/example/example_mod/test/ExampleModTests.java new file mode 100644 index 0000000..80caff9 --- /dev/null +++ b/src/gametest/java/com/example/example_mod/test/ExampleModTests.java @@ -0,0 +1,14 @@ +package com.example.example_mod.test; + +import net.minecraft.block.Blocks; +import net.minecraft.test.GameTest; +import net.minecraft.test.TestContext; +import net.minecraft.util.math.BlockPos; + +public class ExampleModTests { + @GameTest() + public void exampleStructureTest (TestContext context) { + context.setBlockState(new BlockPos(0, 2, 0), Blocks.DIAMOND_BLOCK.getDefaultState()); + context.addInstantFinalTask(() -> context.checkBlock(new BlockPos(0,2,0), block -> block == Blocks.DIAMOND_BLOCK, "Expect block to be a Diamond Block")); + } +} diff --git a/src/gametest/resources/assets/example_mod_test/icon.png b/src/gametest/resources/assets/example_mod_test/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d42fc1ea554d071d2007278d85a81e4d807ae490 GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?I3?vN&YJLDI#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;R0X`wFK>7#6kG0nxb^=+P1s;*b3=DjSK$uZf!>a)(806{V7?N@C?X``( z3<^BV8$L1q`LAOfDIm>}?h|@`rH6F(xpP2eK#<3<=;gH(aAM6Bv=06JYUG|cH!pvuXvOr>=0.17.0-" + }, + { + "id": "quilted_fabric_api", + "versions": ">=4.0.0-" + }, + { + "id": "minecraft", + "versions": ">=1.19.2" + } + ] + } +}