Class GameTests
java.lang.Object
net.ixdarklord.coolcatcore.api.gametest.GameTests
Game tests from common code, the same on every loader: a test is a function given a
GameTestHelper, run in
a structure built for it, and it passes or fails. Register them while your mod constructs, by class (methods marked
GameTest) or one by one:
GameTests.register(MOD_ID, WandTests.class);
GameTests.register(MyMod.id("crate/keeps_items"), GameTestOptions.DEFAULT.withMaxTicks(40), helper -> {
helper.setBlock(1, 1, 1, MyBlocks.CRATE.get());
...
helper.succeed();
});
Tests are added to the game only when it's run to test (isEnabled()): in a development environment, or
with -Dcoolcatlib.gametest=true (or the loader's own switch, -Dfabric-api.gametest or
-Dforge.enableGameTest=true). On Forge, -Dforge.enabledGameTestNamespaces=mymod,othermod keeps only
those mods' tests, as it does for Forge's own. Then:
- in game,
/test run <test>runs one by its name, which on this version is its id with dots (mymod:wand_tests/zaps_a_zombieismymod.wand_tests.zaps_a_zombie);/test runallruns them all,/test runall mymodall of a mod's (/test runall mymod.wand_testsone class's), and/test runfailedthose that failed. The/testcommand is there in a development environment and on Fabric clients; on Forge it's only in a development environment, where the loader allows it; - a game test server runs them all and exits, failing if a required one did: on Fabric a dedicated server with
-Dfabric-api.gametest, on Forge a development server with-Dforge.gameTestServer=true(and-Dforge.enableGameTest=true).
data/<ns>/structures/<path>.nbt, saved with a structure block);
without one, tests run on GameTestOptions.PLATFORM. The helper's positions count from the structure's
corner, (0, 0, 0) being its lowest block, as on newer versions, so a test reads the same on every version
(the game's own tests on this version count from the structure block, one below).-
Method Summary
Modifier and TypeMethodDescriptionstatic List<net.minecraft.resources.ResourceLocation>all()Every test registered so far.static booleanWhether tests are added to the game this run (see the class description).static List<net.minecraft.resources.ResourceLocation>Registers everyGameTestmethod of a class, as<modid>:<class>/<method>.static voidregister(net.minecraft.resources.ResourceLocation id, Consumer<net.minecraft.gametest.framework.GameTestHelper> test) Registers one test.static voidregister(net.minecraft.resources.ResourceLocation id, GameTestOptions options, Consumer<net.minecraft.gametest.framework.GameTestHelper> test) Registers one test with its options.
-
Method Details
-
register
public static void register(net.minecraft.resources.ResourceLocation id, Consumer<net.minecraft.gametest.framework.GameTestHelper> test) Registers one test. Call while your mod constructs; its id's namespace must be your mod id. -
register
public static void register(net.minecraft.resources.ResourceLocation id, GameTestOptions options, Consumer<net.minecraft.gametest.framework.GameTestHelper> test) Registers one test with its options. Call while your mod constructs; its id's namespace must be your mod id. -
register
public static List<net.minecraft.resources.ResourceLocation> register(String modId, Class<?> holder) Registers everyGameTestmethod of a class, as<modid>:<class>/<method>. Call while your mod constructs.- Returns:
- the tests' ids
-
isEnabled
public static boolean isEnabled()Whether tests are added to the game this run (see the class description). -
all
Every test registered so far.
-