Skip to content

Commit 4ab774e

Browse files
committed
Added game tests
1 parent ad04016 commit 4ab774e

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ repositories {
7575
}
7676
}
7777

78+
fabricApi {
79+
configureTests {
80+
modId = "${base.archivesName}-tests"
81+
eula = true
82+
createSourceSet = true
83+
84+
enableGameTests = false
85+
enableClientGameTests = true
86+
clearRunDirectory = false
87+
}
88+
}
89+
7890
loom {
7991
accessWidenerPath = file("src/main/resources/$modId.accesswidener")
8092

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda
19+
20+
import com.lambda.context.SafeContext
21+
import com.lambda.threading.runSafe
22+
import com.lambda.util.combat.DamageUtils.isFallDeadly
23+
import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest
24+
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext
25+
import net.minecraft.client.gui.screen.world.WorldCreator
26+
27+
@Suppress("UnstableApiUsage")
28+
object LambdaTest : FabricClientGameTest {
29+
override fun runTest(context: ClientGameTestContext) {
30+
val singleplayerContext = context.worldBuilder()
31+
.adjustSettings {
32+
it.gameMode = WorldCreator.Mode.CREATIVE
33+
}
34+
.create()
35+
36+
val world = singleplayerContext.clientWorld
37+
val server = singleplayerContext.server
38+
39+
world.waitForChunksDownload()
40+
41+
server.runCommand("/tp Steve ~ ~30 ~")
42+
context.unit("assert deadly fall") { isFallDeadly() }
43+
44+
server.runCommand("/tp Steve ~ -50 ~")
45+
context.unit("assert safe fall") { !isFallDeadly() }
46+
server.runCommand("/tp Steve ~ -60 ~")
47+
48+
// All the tests passed
49+
singleplayerContext.close()
50+
}
51+
52+
inline fun ClientGameTestContext.unit(label: String, crossinline block: SafeContext.() -> Boolean) {
53+
waitTick()
54+
55+
runOnClient<IllegalStateException> {
56+
val asserted = runSafe(block)
57+
?: throw IllegalStateException("Could not run in a safe context")
58+
59+
check(asserted) { "Assertion failed: $label" }
60+
}
61+
}
62+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schemaVersion": 1,
3+
"id": "lambda-tests",
4+
"version": "1.0.0",
5+
"name": "Lambda Fabric gametest entrypoint",
6+
"environment": "*",
7+
"entrypoints": {
8+
"fabric-client-gametest": [
9+
{
10+
"adapter": "kotlin",
11+
"value": "com.lambda.LambdaTest"
12+
}
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)