Skip to content

@minecraft/server-gametest


@minecraft/server-gametest / RegistrationBuilder

Class: RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:216

Beta

A utility class to set GameTest parameters for a test. Methods can be chained together to set multiple properties.

Methods

batch()

batch(batchName): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:232

Beta

Parameters

batchName

string

Name of the batch for the test.

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the batch for the test to run in.

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

This function can be called in early-execution mode.


maxAttempts()

maxAttempts(attemptCount): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:246

Beta

Parameters

attemptCount

number

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the maximum number of times a test will try to rerun if it fails.

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

This function can be called in early-execution mode.


maxTicks()

maxTicks(tickCount): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:260

Beta

Parameters

tickCount

number

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the maximum number of ticks a test will run for before timing out and failing.

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

This function can be called in early-execution mode.


padding()

padding(paddingBlocks): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:277

Beta

Parameters

paddingBlocks

number

Size, in blocks, around the GameTest where additional GameTests should not be created.

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Size around the GameTest, in blocks, that should be reserved for the test when running multiple tests together.

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

This function can be called in early-execution mode.


required()

required(isRequired): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:294

Beta

Parameters

isRequired

boolean

If set to true, the test must pass in order for the entire run of tests to pass.

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Whether this test is required to pass as part of its broader set of tests.

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

This function can be called in early-execution mode.


requiredSuccessfulAttempts()

requiredSuccessfulAttempts(attemptCount): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:308

Beta

Parameters

attemptCount

number

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the number of successful test runs to be considered successful.

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

This function can be called in early-execution mode.


rotateTest()

rotateTest(rotate): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:319

Beta

Parameters

rotate

boolean

Returns

RegistrationBuilder

Remarks

If true, runs the test in all four rotations when run via /gametest runset.

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

This function can be called in early-execution mode.


setupTicks()

setupTicks(tickCount): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:333

Beta

Parameters

tickCount

number

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the number of ticks for a test to wait before executing when the structure is spawned.

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

This function can be called in early-execution mode.


structureLocation()

structureLocation(structureLocation): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:348

Beta

Parameters

structureLocation

Vector3

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Overrides the default structure placement with a specific location. If height (y) is set to Dimension.heightRange.max, the structure will snap to the ground.

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

This function can be called in early-execution mode.


structureName()

structureName(structureName): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:378

Beta

Parameters

structureName

string

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Sets the name of the structure for a test to use. "xyz:bar" will load /structures/xyz/bar.mcstructure from the behavior pack stack.

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

This function can be called in early-execution mode.

Example

phantomsShouldFlyFromCats.ts

typescript
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");

tag()

tag(tag): RegistrationBuilder

Defined in: @minecraft/server-gametest/index.d.ts:407

Beta

Parameters

tag

string

Returns

RegistrationBuilder

RegistrationBuilder object where additional configuration methods can be called.

Remarks

Adds a tag to a test. You can run all tests with a given tag with /gametest runset <tag>.

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

This function can be called in early-execution mode.

Example

phantomsShouldFlyFromCats.ts

typescript
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");