|
| 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 | +} |
0 commit comments