Main class for GameTest functions, with helpers and data for manipulating the respective test. Note that all methods of this class expect BlockLocations and Locations relative to the GameTest structure block.

Constructors

Methods

  • Beta

    Parameters

    • entityTypeIdentifier: string

      Identifier of the entity to match (e.g., 'minecraft:skeleton').

    • armorSlot: number

      Container slot index to test.

    • armorName: string

      Name of the armor to look for.

    • armorData: number

      Data value integer to look for.

    • blockLocation: Vector3

      Location of the entity with armor to test for.

    • OptionalhasArmor: boolean

      Whether or not the entity is expected to have the specified armor equipped.

    Returns void

    Tests that an entity has a specific piece of armor equipped. If not, an error is thrown.

    This function can throw errors.

    GameTestError

    test.assertEntityHasArmor("minecraft:horse", armorSlotTorso, "diamond_horse_armor", 0, horseLocation, true);
    
  • Beta

    Parameters

    • entityTypeIdentifier: string

      Identifier of the specified entity (e.g., 'minecraft:skeleton'). If the namespace is not specified, 'minecraft:' is assumed.

    • componentIdentifier: string

      Identifier of the component to check for. If the namespace is not specified, 'minecraft:' is assumed.

    • blockLocation: Vector3

      Location of the block with a container (for example, a chest.)

    • OptionalhasComponent: boolean

      Determines whether to test that the component exists, or does not.

    Returns void

    Tests that an entity has a particular component. If not, an exception is thrown.

    This function can throw errors.

    GameTestError

    test.assertEntityHasComponent("minecraft:sheep", "minecraft:is_sheared", entityLoc, false);
    
  • Beta

    Parameters

    • entity: Entity

      Entity instance to test for.

    • OptionalisPresent: boolean

      If true, this function tests whether the specified entity is present in the GameTest area. If false, tests that the specified entity is not present.

    Returns void

    Tests that an entity instance is present within the GameTest area. If not, an exception is thrown.

    This function can throw errors.

    GameTestError

    import * as gameTest from '@minecraft/server-gametest';

    gameTest
    .register('StarterTests', 'simpleMobTest', (test: gameTest.Test) => {
    const attackerId = 'fox';
    const victimId = 'chicken';

    test.spawn(attackerId, { x: 5, y: 2, z: 5 });
    const victim = test.spawn(victimId, { x: 2, y: 2, z: 2 });

    test.assertEntityInstancePresentInArea(victim, true);

    test.succeedWhen(() => {
    test.assertEntityInstancePresentInArea(victim, false);
    });
    })
    .maxTicks(400)
    .structureName('gametests:mediumglass');
  • Beta

    Parameters

    • entityTypeIdentifier: string

      Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.

    • blockLocation: Vector3

      Location of the entity to test for.

    • OptionalsearchDistance: number

      The distance to search for the entity from the blockLocation.

    • OptionalisPresent: boolean

      If true, this function tests whether an entity of the specified type is present. If false, tests that an entity of the specified type is not present.

    Returns void

    Depending on the value of isPresent, tests for the presence or non-presence of entity of a specified type at a particular location. If the condition is not met, an exception is thrown.

    This function can throw errors.

    GameTestError

  • Beta

    Parameters

    • entityTypeIdentifier: string

      Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.

    • OptionalisPresent: boolean

      If true, this function tests whether an entity of the specified type is present in the GameTest area. If false, tests that an entity of the specified type is not present.

    Returns void

    Tests that an entity of a specified type is present within the GameTest area. If not, an exception is thrown.

    This function can throw errors.

    GameTestError

    import * as gameTest from '@minecraft/server-gametest';

    gameTest
    .register('StarterTests', 'simpleMobTest', (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');
  • Beta

    Parameters

    • blockLocation: Vector3

      Location of the entity to look for.

    • entityTypeIdentifier: string

      Identifier of the entity (e.g., 'minecraft:skeleton') to look for. Note if no namespace is specified, 'minecraft:' is assumed.

    • callback: (arg: Entity) => boolean

      Callback function where facets of the selected entity can be tested for. If this callback function returns false or no entity with the specified identifier is found, an exception is thrown.

    Returns void

    Tests that an entity (e.g., a skeleton) at the specified location has a particular piece of data. If not, an error is thrown.

    This function can throw errors.

    GameTestError

    test.assertEntityState(
    villagerPos,
    "minecraft:villager_v2",
    (entity) => entity.getEffect(MinecraftEffectTypes.Regeneration).duration > 120
    ); // At least 6 seconds remaining in the villagers' effect
  • Beta

    Parameters

    • entityTypeIdentifier: string

      Type of entity to create. If no namespace is provided, 'minecraft:' is assumed. Note that an optional initial spawn event can be specified between less than/greater than signs (e.g., namespace:entityType).

    • blockLocation: Vector3

    Returns Entity

    The spawned entity. If the entity cannot be spawned, returns undefined.

    Spawns an entity at a location.

    This function can't be called in read-only mode.

    This function can throw errors.

    minecraftserver.GameTestError

    import * as gameTest from '@minecraft/server-gametest';

    gameTest
    .register('StarterTests', 'simpleMobTest', (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');
    test.spawn("minecraft:pig<minecraft:ageable_grow_up>", { x: 1, y: 2, z: 1 });
  • Beta

    Parameters

    • callback: () => void

      Testing callback function that runs. If the function runs successfully, the test is marked as a success.

    Returns void

    Runs the given callback every tick. When the callback successfully executes, the test is marked as a success. Specifically, the test will succeed when the callback does not throw an exception.

    This function can't be called in read-only mode.

    This function can throw errors.

    import * as gameTest from '@minecraft/server-gametest';

    gameTest
    .register('StarterTests', 'simpleMobTest', (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');
  • Beta

    Parameters

    • entityTypeIdentifier: string

      Type of entity to look for. If no namespace is specified, 'minecraft:' is assumed.

    • componentIdentifier: string

      Type of component to test for the presence of. If no namespace is specified, 'minecraft:' is assumed.

    • blockLocation: Vector3

      Block location of the entity to test.

    • hasComponent: boolean

      If true, this function tests for the presence of a component. If false, this function tests for the lack of a component.

    Returns void

    Tests for the presence of a component on every tick. Depending on the value of hasComponent, when the specified component is found, the test is marked as a success.

    This function can't be called in read-only mode.

    This function can throw errors.

  • Beta

    Parameters

    • entityTypeIdentifier: string

      Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.

    • blockLocation: Vector3

      Location of the entity to test for.

    • OptionalisPresent: boolean

      If true, this function tests whether an entity of the specified type is present. If false, tests that an entity of the specified type is not present.

    Returns void

    Depending on the value of isPresent, tests for the presence of an entity on every tick. When an entity of the specified type is found or not found (depending on isPresent), the test is marked as a success.

    This function can't be called in read-only mode.

    This function can throw errors.