Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The @minecraft/server-gametest module provides scriptable APIs for scaffolding and testing content experiences in Minecraft.
Caution
This module is still in pre-release. It may change or it may be removed in future releases.
Changelog
Manifest Details
{
"module_name": "@minecraft/server-gametest",
"version": "1.0.0-beta"
}
This is version 1.x.x of this module, which is the latest as of version 1.26.10-beta.23 of Minecraft.
Available Versions
1.0.0-beta
Enumerations
Classes
- FenceConnectivity
- GameTestSequence
- NavigationResult
- RegistrationBuilder
- SculkSpreader
- SimulatedPlayer
- Tags
- Test
Interfaces
Errors
Functions
getPlayerSkin
getPlayerSkin(player: minecraftserver.Player): PlayerSkinData
Returns data about a player's skin.
Parameters
player: @minecraft/server.Player
The player who's skin is returned.
Returns PlayerSkinData
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.
register
register(testClassName: string, testName: string, testFunction: (arg0: Test) => void): RegistrationBuilder
Registers a new GameTest function. This GameTest will become available in Minecraft via /gametest run [testClassName]:[testName].
Parameters
testClassName: string
Name of the class of tests this test should be a part of.
testName: string
Name of this specific test.
testFunction: (arg0: Test) => void
Implementation of the test function.
Returns RegistrationBuilder - Returns a @minecraft/server-gametest.RegistrationBuilder object where additional options for this test can be specified via builder methods.
Notes:
- This function can't be called in restricted-execution mode.
- This function can be called in early-execution mode.
Examples
simpleMobGameTest.ts
import { Test, register } from "@minecraft/server-gametest";
import { MinecraftEntityTypes } from "@minecraft/vanilla-data";
function simpleMobGameTest(test: Test) {
const attackerId = MinecraftEntityTypes.Fox;
const victimId = MinecraftEntityTypes.Chicken;
test.spawn(attackerId, { x: 5, y: 2, z: 5 });
test.spawn(victimId, { x: 2, y: 2, z: 2 });
test.assertEntityPresentInArea(victimId, true);
test.succeedWhen(() => {
test.assertEntityPresentInArea(victimId, false);
});
}
register("StarterTests", "simpleMobTest", simpleMobGameTest).maxTicks(400).structureName("gametests:mediumglass");
(preview) Work with this sample on the MCTools.dev code sandbox.
registerAsync
registerAsync(testClassName: string, testName: string, testFunction: (arg0: Test) => Promise<void>): RegistrationBuilder
Registers a new GameTest function that is designed for asynchronous execution. This GameTest will become available in Minecraft via /gametest run [testClassName]:[testName].
Parameters
testClassName: string
Name of the class of tests this test should be a part of.
testName: string
Name of this specific test.
testFunction: (arg0: Test) => Promise<void>
Implementation of the test function.
Returns RegistrationBuilder - Returns a @minecraft/server-gametest.RegistrationBuilder object where additional options for this test can be specified via builder methods.
Notes:
- This function can't be called in restricted-execution mode.
- This function can be called in early-execution mode.
Examples
simpleMobAsyncTest.ts
import * as gameTest from '@minecraft/server-gametest';
gameTest
.registerAsync('StarterTests', 'simpleMobTest', async (test: gameTest.Test) => {
const attackerId = 'fox';
const victimId = 'chicken';
test.spawn(attackerId, { x: 5, y: 2, z: 5 });
test.spawn(victimId, { x: 2, y: 2, z: 2 });
test.assertEntityPresentInArea(victimId, true);
test.succeedWhen(() => {
test.assertEntityPresentInArea(victimId, false);
});
})
.maxTicks(400)
.structureName('gametests:mediumglass');
(preview) Work with this sample on the MCTools.dev code sandbox.
setAfterBatchCallback
setAfterBatchCallback(batchName: string, batchCallback: () => void): void
Sets a callback that is called after the batch gets called. This will overwrite previously set callbacks for this batch.
Parameters
batchName: string
Name of the batch of tests the callback will run after.
batchCallback: () => void
Notes:
- This function can't be called in restricted-execution mode.
- This function can be called in early-execution mode.
- This function can throw errors.
- Throws GameTestError
setBeforeBatchCallback
setBeforeBatchCallback(batchName: string, batchCallback: () => void): void
Sets a callback that is called before the batch gets called. This will overwrite previously set callbacks for this batch.
Parameters
batchName: string
Name of the batch of tests the callback will run before.
batchCallback: () => void
Notes:
- This function can't be called in restricted-execution mode.
- This function can be called in early-execution mode.
- This function can throw errors.
- Throws GameTestError
spawnSimulatedPlayer
spawnSimulatedPlayer(location: minecraftserver.DimensionLocation, name: string, gameMode: minecraftserver.GameMode): SimulatedPlayer
Spawns a simulated player that isn't associated to a specific {@link Test}. You can use {@link SimulatedPlayer.remove} to remove the player from the world.
Parameters
location: @minecraft/server.DimensionLocation
The location in which to spawn the player.
name: string
The name for the player.
gameMode: @minecraft/server.GameMode
The game mode for the player.
Returns SimulatedPlayer
Notes:
- This function can't be called in restricted-execution mode.
- This function can throw errors.