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

    • 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');
    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");
  • Beta

    Parameters

    • blockType: string | BlockType

      Type of block to set.

    • blockLocation: Vector3

      Location of the block to set.

    Returns void

    Sets a block to a particular type at the specified block location.

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

    This function can throw errors.

    GameTestError

    import { EntityComponentTypes } from "@minecraft/server";
    import { Test, register } from "@minecraft/server-gametest";
    import { MinecraftBlockTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function minibiomes(test: Test) {
    const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 });
    const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 });

    test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 });

    const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable);

    minecartRideableComp?.addRider(pig);

    test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true);
    }
    register("ChallengeTests", "minibiomes", minibiomes).structureName("gametests:minibiomes").maxTicks(160);
  • 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');
    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");
    import { Test, register } from "@minecraft/server-gametest";
    import { MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function phantomsShouldFlyFromCats(test: Test) {
    test.spawn(MinecraftEntityTypes.Cat, { x: 4, y: 3, z: 3 });
    test.spawn(MinecraftEntityTypes.Phantom, { x: 4, y: 3, z: 3 });

    test.succeedWhenEntityPresent(MinecraftEntityTypes.Phantom, { x: 4, y: 6, z: 3 }, true);
    }

    register("MobBehaviorTests", "phantoms_should_fly_from_cats", phantomsShouldFlyFromCats)
    .structureName("gametests:glass_cells");
    import { EntityComponentTypes } from "@minecraft/server";
    import { Test, register } from "@minecraft/server-gametest";
    import { MinecraftBlockTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function minibiomes(test: Test) {
    const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 });
    const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 });

    test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 });

    const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable);

    minecartRideableComp?.addRider(pig);

    test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true);
    }
    register("ChallengeTests", "minibiomes", minibiomes).structureName("gametests:minibiomes").maxTicks(160);
  • 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 { 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");
  • 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.

    import { Test, register } from "@minecraft/server-gametest";
    import { MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function phantomsShouldFlyFromCats(test: Test) {
    test.spawn(MinecraftEntityTypes.Cat, { x: 4, y: 3, z: 3 });
    test.spawn(MinecraftEntityTypes.Phantom, { x: 4, y: 3, z: 3 });

    test.succeedWhenEntityPresent(MinecraftEntityTypes.Phantom, { x: 4, y: 6, z: 3 }, true);
    }

    register("MobBehaviorTests", "phantoms_should_fly_from_cats", phantomsShouldFlyFromCats)
    .structureName("gametests:glass_cells");
    import { EntityComponentTypes } from "@minecraft/server";
    import { Test, register } from "@minecraft/server-gametest";
    import { MinecraftBlockTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data";

    function minibiomes(test: Test) {
    const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 });
    const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 });

    test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 });

    const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable);

    minecartRideableComp?.addRider(pig);

    test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true);
    }
    register("ChallengeTests", "minibiomes", minibiomes).structureName("gametests:minibiomes").maxTicks(160);