For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server-gametest/classes/RegistrationBuilder.md.

Class: RegistrationBuilder

Beta

用于为测试设置 GameTest 参数的工具类。可以将多个方法链式 调用以设置多个属性。

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

Methods

batch()

batch(batchName): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

batchName

string

测试所属批次的名称。

Name of the batch for the test.

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

设置测试所运行的批次。

Sets the batch for the test to run in.


maxAttempts()

maxAttempts(attemptCount): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

attemptCount

number

Returns

RegistrationBuilder

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.


maxTicks()

maxTicks(tickCount): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

tickCount

number

Returns

RegistrationBuilder

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.


padding()

padding(paddingBlocks): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

paddingBlocks

number

GameTest 周围不应创建其他 GameTest 的空间大小(以方块为 单位)。

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

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

在同时运行多个测试时,应为该 GameTest 预留的周围空间大小 (以方块为单位)。

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


required()

required(isRequired): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

isRequired

boolean

若设为 true,则该测试必须通过,整个测试运行才能通过。

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

Returns

RegistrationBuilder

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.


requiredSuccessfulAttempts()

requiredSuccessfulAttempts(attemptCount): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

attemptCount

number

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

设置视为成功所需的测试成功运行次数。

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


rotateTest()

rotateTest(rotate): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

rotate

boolean

Returns

RegistrationBuilder

Remarks

若为 true,则通过 /gametest runset 运行时会以全部四个旋转方 向运行该测试。

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


setupTicks()

setupTicks(tickCount): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

tickCount

number

Returns

RegistrationBuilder

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.


structureLocation()

structureLocation(structureLocation, structureDimension?): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

structureLocation

Vector3

structureDimension?

any

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

以指定的位置和维度覆盖默认的结构放置。若高度(y)设为 Dimension.heightRange.max,则结构将吸附到地面。若未指定维 度,则将在运行命令所在的维度中运行。

Overrides the default structure placement with a specific location and dimension. If height (y) is set to Dimension.heightRange.max, the structure will snap to the ground. If the dimension is not specified, it will run in the dimension the command was run from.

Throws

This function can throw errors.

EngineError

InvalidArgumentError


structureName()

structureName(structureName): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

structureName

string

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

设置测试要使用的结构名称。"xyz:bar" 将从行为包栈中加载 /structures/xyz/bar.mcstructure

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

Example

phantomsShouldFlyFromCats.ts

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

World Mutation Early Execution Beta

Parameters

tag

string

Returns

RegistrationBuilder

RegistrationBuilder 对象,可在其上调用其他配置方法。

RegistrationBuilder object where additional configuration methods can be called.

Remarks

为测试添加一个标签。你可以使用 /gametest runset <tag> 运行 具有指定标签的所有测试。

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

Example

phantomsShouldFlyFromCats.ts

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'
);