Class: Test
Beta
GameTest 函数的主类,附带用于操作相应测试的辅助工具和数据。请注意,该类的所有方法都期望传入相对于 GameTest 结构方块的位置(BlockLocation 与 Location)。
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.
Methods
assert()
assert(
condition,message):void
Beta
Parameters
condition
boolean
待求值条件表达式。
Expression of the condition to evaluate.
message
string
当 condition 求值结果不为真时所传递的消息。
Message that is passed if the condition does not evaluate to true.
Returns
void
Remarks
断言 condition 所指定的条件为真。如果不为真,则抛出带有指定 message 的错误。
Tests that the condition specified in condition is true. If not, an error with the specified message is thrown.
Throws
This function can throw errors.
assertBlockPresent()
assertBlockPresent(
blockType,blockLocation,isPresent?):void
Beta
Parameters
blockType
any
期望的方块类型。
Expected block type.
blockLocation
Vector3
待检查的方块位置。
Location of the block to test at.
isPresent?
boolean
若为 true,此函数检查指定位置上是否存在指定类型的方块;若为 false,则检查指定位置上不存在指定类型的方块。
If true, this function tests whether a block of the specified type is at the location. If false, tests that a block of the specified type is not present. Defaults to: true
Returns
void
Remarks
断言在指定位置上存在指定类型的方块。如果不存在,则抛出异常。
Tests that a block of the specified type is present at the specified location. If it is not, an exception is thrown.
Throws
This function can throw errors.
assertBlockState()
assertBlockState(
blockLocation,callback):void
Beta
Parameters
blockLocation
Vector3
待检查的方块位置。
Location of the block to test at.
callback
(arg0) => boolean
回调函数,其中包含基于该位置方块的额外检查。
Callback function that contains additional tests based on the block at the specified location.
Returns
void
Remarks
断言在指定位置的方块具有特定的状态值。若不具有该状态值,则抛出异常。
Tests that a block has a particular state value at the specified location. If it does not have that state value, an exception is thrown.
Throws
This function can throw errors.
assertCanReachLocation()
assertCanReachLocation(
mob,blockLocation,canReach?):void
Beta
Parameters
mob
Entity
用于针对位置进行测试的实体。
Entity that you wish to test the location against.
blockLocation
Vector3
结构方块相对位置,用于测试指定 mob 是否能够抵达。
Structure-relative location to test whether the specified mob can reach.
canReach?
boolean
若为 true,检查 mob 是否能抵达该位置;若为 false,检查该 mob 是否无法抵达该位置。
If true, tests whether the mob can reach the location. If false, tests whether the mob is not able to reach the location. Defaults to: true
Returns
void
Remarks
断言实体能够抵达指定位置。根据 canReach 的取值,若条件未满足则抛出异常。
Tests that an entity can reach a particular location. Depending on the value of canReach, throws an exception if the condition is not met.
Throws
This function can throw errors.
assertContainerContains()
assertContainerContains(
itemStack,blockLocation):void
Beta
Parameters
itemStack
ItemStack
表示要检查的物品类型。指定容器必须至少包含 1 个与 itemStack 中定义的物品类型相匹配的物品。
Represents the type of item to check for. The specified container must contain at least 1 item matching the item type defined in itemStack.
blockLocation
Vector3
带容器的方块(例如箱子)的位置,将针对其内容进行测试。
Location of the block with a container (for example, a chest) to test the contents of.
Returns
void
Remarks
断言位于指定位置的容器(如箱子)内含有指定物品堆。否则抛出错误。
Tests that a container (e.g., a chest) at the specified location contains a specified of item stack. If not, an error is thrown.
Throws
This function can throw errors.
assertContainerEmpty()
assertContainerEmpty(
blockLocation):void
Beta
Parameters
blockLocation
Vector3
带容器的方块(例如箱子)的位置,将针对其是否为空进行测试。
Location of the block with a container (for example, a chest) to test is empty of contents.
Returns
void
Remarks
断言位于指定位置的容器(如箱子)为空。否则抛出错误。
Tests that a container (e.g., a chest) at the specified location is empty. If not, an error is thrown.
Throws
This function can throw errors.
assertEntityHasArmor()
assertEntityHasArmor(
entityTypeIdentifier,armorSlot,armorName,armorData,blockLocation,hasArmor?):void
Beta
Parameters
entityTypeIdentifier
string
要匹配的实体标识符(例如 'minecraft:skeleton')。
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.
hasArmor?
boolean
是否期望该实体装备了指定的护甲。
Whether or not the entity is expected to have the specified armor equipped. Defaults to: true
Returns
void
Remarks
断言实体已装备特定护甲。否则抛出错误。
Tests that an entity has a specific piece of armor equipped. If not, an error is thrown.
Throws
This function can throw errors.
assertEntityHasComponent()
assertEntityHasComponent(
entityTypeIdentifier,componentIdentifier,blockLocation,hasComponent?):void
Beta
Parameters
entityTypeIdentifier
string
指定实体的标识符(例如 'minecraft:skeleton')。若未指定命名空间,则默认为 'minecraft:'。
Identifier of the specified entity (e.g., 'minecraft:skeleton'). If the namespace is not specified, 'minecraft:' is assumed.
componentIdentifier
string
要检查的组件标识符。若未指定命名空间,则默认为 'minecraft:'。
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.)
hasComponent?
boolean
决定是测试该组件存在,还是测试其不存在。
Determines whether to test that the component exists, or does not. Defaults to: true
Returns
void
Remarks
断言实体具有特定组件。否则抛出异常。
Tests that an entity has a particular component. If not, an exception is thrown.
Throws
This function can throw errors.
assertEntityInstancePresent()
assertEntityInstancePresent(
entity,blockLocation,isPresent?):void
Beta
Parameters
entity
Entity
要测试的特定实体。
Specific entity to test for.
blockLocation
Vector3
实体待测试的位置。
Location of the entity to test for.
isPresent?
boolean
指明应测试在指定位置存在或不存在实体。
Whether to test that an entity is present or not present at the specified location. Defaults to: true
Returns
void
Remarks
根据 isPresent 的取值,断言指定位置上存在或不存在特定实体。根据 isPresent 的取值,若找到或未找到实体,则抛出错误。
Depending on the value for isPresent, tests that a particular entity is present or not present at the specified location. Depending on the value of isPresent, if the entity is found or not found, an error is thrown.
Throws
This function can throw errors.
assertEntityInstancePresentInArea()
assertEntityInstancePresentInArea(
entity,isPresent?):void
Beta
Parameters
entity
Entity
待测试的实体实例。
Entity instance to test for.
isPresent?
boolean
若为 true,则测试指定实体是否存在于 GameTest 区域内;若为 false,则测试指定实体不存在于该区域。
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. Defaults to: true
Returns
void
Remarks
断言在 GameTest 区域内存在一个实体实例。否则抛出异常。
Tests that an entity instance is present within the GameTest area. If not, an exception is thrown.
Throws
This function can throw errors.
Example
simpleMobTest.ts
assertEntityPresent()
assertEntityPresent(
entityTypeIdentifier,blockLocation,searchDistance?,isPresent?):void
Beta
Parameters
entityTypeIdentifier
string
待测试实体的类型(例如 'minecraft:skeleton')。若未指定实体命名空间,则默认为 'minecraft:'。
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.
searchDistance?
number
以 blockLocation 为起点搜索实体的距离。
The distance to search for the entity from the blockLocation. Defaults to: 0
isPresent?
boolean
若为 true,此函数测试指定类型实体是否存在;若为 false,则测试指定类型实体不存在。
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. Defaults to: true
Returns
void
Remarks
根据 isPresent 的取值,测试在某特定位置存在或不存在指定类型的实体。若条件未满足,则抛出异常。
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.
Throws
This function can throw errors.
assertEntityPresentInArea()
assertEntityPresentInArea(
entityTypeIdentifier,isPresent?):void
Beta
Parameters
entityTypeIdentifier
string
待测试实体的类型(例如 'minecraft:skeleton')。若未指定实体命名空间,则默认为 'minecraft:'。
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
isPresent?
boolean
若为 true,此函数测试指定类型实体是否存在于 GameTest 区域内;若为 false,则测试指定类型实体不存在于该区域。
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. Defaults to: true
Returns
void
Remarks
断言在 GameTest 区域内存在指定类型的实体。否则抛出异常。
Tests that an entity of a specified type is present within the GameTest area. If not, an exception is thrown.
Throws
This function can throw errors.
Examples
simpleMobTest.ts
simpleMobGameTest.ts
assertEntityState()
assertEntityState(
blockLocation,entityTypeIdentifier,callback):void
Beta
Parameters
blockLocation
Vector3
要查找的实体位置。
Location of the entity to look for.
entityTypeIdentifier
string
要查找的实体的标识符(例如 'minecraft:skeleton')。注意:若未指定命名空间,则默认为 'minecraft:'。
Identifier of the entity (e.g., 'minecraft:skeleton') to look for. Note if no namespace is specified, 'minecraft:' is assumed.
callback
(arg0) => boolean
用于对所选实体的各项属性进行测试的回调函数。若该回调函数返回 false 或未找到指定标识符的实体,则抛出异常。
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
Remarks
断言位于指定位置的实体(例如骷髅)具有特定数据。否则抛出错误。
Tests that an entity (e.g., a skeleton) at the specified location has a particular piece of data. If not, an error is thrown.
Throws
This function can throw errors.
assertEntityTouching()
assertEntityTouching(
entityTypeIdentifier,location,isTouching?):void
Beta
Parameters
entityTypeIdentifier
string
待测试实体的类型(例如 'minecraft:skeleton')。若未指定实体命名空间,则默认为 'minecraft:'。
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
location
Vector3
待测试实体的位置。
Location of the entity to test for.
isTouching?
boolean
若为 true,此函数测试实体是否接触指定位置;若为 false,则测试实体未接触指定位置。
If true, this function tests whether the entity is touching the specified location. If false, tests that an entity is not testing the specified location. Defaults to: true
Returns
void
Remarks
根据 isTouching 的取值,断言指定类型的实体正在接触或连接另一实体。若条件未满足,则抛出异常。
Depending on the value of isTouching, tests that an entity of a specified type is touching or connected to another entity. If the condition is not met, an exception is thrown.
Throws
This function can throw errors.
assertIsWaterlogged()
assertIsWaterlogged(
blockLocation,isWaterlogged?):void
Beta
Parameters
blockLocation
Vector3
待测试方块的位置。
Location of the block to test for.
isWaterlogged?
boolean
是否测试 position 处方块期望处于含水状态。
Whether to test that the block at position is expected to be waterlogged. Defaults to: true
Returns
void
Remarks
根据 isWaterlogged 的取值,断言某位置的方块含水。若条件未满足,则抛出错误。纯水方块不视为含水方块。
Depending on the value of isWaterlogged, tests that a block at a location contains water. If the condition is not met, an error is thrown. Pure water blocks are not considered to be waterlogged.
Throws
This function can throw errors.
assertItemEntityCountIs()
assertItemEntityCountIs(
itemType,blockLocation,searchDistance,count):void
Beta
Parameters
itemType
any
要查找的物品类型。
Type of item to look for.
blockLocation
Vector3
在该位置附近搜索指定物品集合。
Location to search around for the specified set of items.
searchDistance
number
搜索半径(以方块为单位),用于在范围内累计物品数量。若为 0,则仅搜索 position 处的特定方块。
Range, in blocks, to aggregate a count of items around. If 0, will only search the particular block at position.
count
number
至少要查找并用于测试的物品数量。
Number of items, at minimum, to look and test for.
Returns
void
Remarks
断言在某区域内存在指定类型和数量的物品。否则抛出错误。
Tests that items of a particular type and count are present within an area. If not, an error is thrown.
Throws
This function can throw errors.
assertItemEntityPresent()
assertItemEntityPresent(
itemType,blockLocation,searchDistance?,isPresent?):void
Beta
Parameters
itemType
any
待测试物品的类型。
Type of item to test for.
blockLocation
Vector3
待测试物品实体的位置。
Location of the item entity to test for.
searchDistance?
number
用于查找物品实体的半径(以方块为单位)。
Radius in blocks to look for the item entity. Defaults to: 0
isPresent?
boolean
若为 true,此函数测试指定类型的物品实体是否存在;若为 false,则测试指定类型的物品实体不存在。
If true, this function tests whether an item entity of the specified type is present. If false, tests that an item entity of the specified type is not present. Defaults to: true
Returns
void
Remarks
根据 isPresent 的取值,断言某特定位置存在或不存在特定物品实体。若条件未满足,则抛出异常。
Depending on the value of isPresent, tests whether a particular item entity is present or not at a particular location. If the condition is not met, an exception is thrown.
Throws
This function can throw errors.
assertRedstonePower()
assertRedstonePower(
blockLocation,power):void
Beta
Parameters
blockLocation
Vector3
待测试的位置。
Location to test.
power
number
期望的能量等级。
Expected power level.
Returns
void
Remarks
断言某位置上的红石信号强度等级与特定值匹配。否则抛出异常。
Tests that Redstone power at a particular location matches a particular value. If not, an exception is thrown.
Throws
This function can throw errors.
destroyBlock()
destroyBlock(
blockLocation,dropResources?):void
World Mutation Beta
Parameters
blockLocation
Vector3
要销毁的方块的位置。
Location of the block to destroy.
dropResources?
boolean
是否生成特定掉落所暴露的资源。
Whether to add resources exposed with a particular drop. Defaults to: false
Returns
void
Remarks
销毁特定位置上的方块。
Destroys a block at a particular location.
Throws
This function can throw errors.
fail()
fail(
errorMessage):void
Beta
Parameters
errorMessage
string
概括失败原因的错误消息。
Error message summarizing the failure condition.
Returns
void
Remarks
将当前测试标记为失败用例。
Marks the current test as a failure case.
Throws
This function can throw errors.
failIf()
failIf(
callback):void
Beta
Parameters
callback
() => void
要运行的回调函数。若该函数正常执行完毕,则测试将被标记为失败。通常该函数体内会调用 .assertXyz 系列方法。
Callback function that runs. If the function runs successfully, the test is marked as a failure. Typically, this function will have .assertXyz method calls within it.
Returns
void
Remarks
运行给定回调函数。若回调未抛出异常,则将该测试标记为失败。
Runs the given callback. If the callback does not throw an exception, the test is marked as a failure.
Throws
This function can throw errors.
getBlock()
getBlock(
blockLocation):Block
World Mutation Beta
Parameters
blockLocation
Vector3
要检索的方块的位置。
Location of the block to retrieve.
Returns
Block
Remarks
获取指定方块位置处的方块。
Gets a block at the specified block location.
Throws
This function can throw errors.
getDimension()
getDimension():
Dimension
Beta
Returns
Dimension
Remarks
获取此测试所处的维度。
Gets the dimension of this test.
Throws
This function can throw errors.
getFenceConnectivity()
getFenceConnectivity(
blockLocation):FenceConnectivity
World Mutation Beta
Parameters
blockLocation
Vector3
要检索的方块的位置。
Location of the block to retrieve.
Returns
Remarks
若指定方块位置处的方块是栅栏,则返回一个包含栅栏连接详情的辅助对象。
If the block at the specified block location is a fence, this returns a helper object with details on how a fence is connected.
Throws
This function can throw errors.
getSculkSpreader()
getSculkSpreader(
blockLocation):SculkSpreader|undefined
World Mutation Beta
Parameters
blockLocation
Vector3
要从中获取 sculk spreader 的方块的位置。
Location of the block to retrieve a sculk spreader from.
Returns
SculkSpreader | undefined
返回 SculkSpreader;若该方块上不存在 SculkSpreader 则返回 undefined。
Returns the SculkSpreader or undefined if no SculkSpreader is present on the block.
Remarks
获取一个 sculk spreader 对象,可用于控制和管理 sculk 从某个方块的扩散方式。
Retrieves a sculk spreader object that can be used to control and manage how sculk grows from a block.
Throws
This function can throw errors.
getTestDirection()
getTestDirection():
Direction
Beta
Returns
Direction
Remarks
返回当前测试的方向 —— 有关可能取值(北、东、南、西,数值 2-5),请参阅 minecraftserver.Direction 枚举。
Returns the direction of the current test - see the minecraftserver.Direction enum for more information on potential values (north, east, south, west - values 2-5).
Throws
This function can throw errors.
idle()
idle(
tickDelay):Promise<void>
World Mutation Beta
Parameters
tickDelay
number
等待时长(以 tick 为单位)。
Amount of time to wait, in ticks.
Returns
Promise<void>
Remarks
此异步函数将等待指定的 tick 数后再继续执行。
This asynchronous function will wait for the specified time in ticks before continuing execution.
Throws
This function can throw errors.
isCleaningUp()
isCleaningUp():
boolean
World Mutation Beta
Returns
boolean
Remarks
返回该测试当前是否处于运行后的 Clean Up(清理)阶段。
Returns whether or not the test is currently in the Clean Up step after running.
isCompleted()
isCompleted():
boolean
World Mutation Beta
Returns
boolean
Remarks
返回该测试是否已经完成。
Returns whether or not the test has already completed
killAllEntities()
killAllEntities():
void
World Mutation Beta
Returns
void
Remarks
杀死 GameTest 结构内的所有实体。
Kills all entities within the GameTest structure.
Throws
This function can throw errors.
onPlayerJump()
onPlayerJump(
mob,jumpAmount):void
World Mutation Beta
Parameters
mob
Entity
jumpAmount
number
Returns
void
Remarks
Throws
This function can throw errors.
pressButton()
pressButton(
blockLocation):void
World Mutation Beta
Parameters
blockLocation
Vector3
要按下按钮的位置。
Location to push the button at.
Returns
void
Remarks
在某个方块位置按下按钮。
Presses a button at a block location.
Throws
Will throw an error if a button is not present at the specified position.
print()
print(
text):void
World Mutation Beta
Parameters
text
string
要显示的消息。
Message to display.
Returns
void
Remarks
向所有玩家显示指定消息。
Displays the specified message to all players.
Throws
This function can throw errors.
pullLever()
pullLever(
blockLocation):void
World Mutation Beta
Parameters
blockLocation
Vector3
要扳动拉杆的位置。
Location to pull the lever at.
Returns
void
Remarks
在某个方块位置扳动拉杆。
Pulls a lever at a block location.
Throws
Will throw an error if a lever is not present at the specified position.
pulseRedstone()
pulseRedstone(
blockLocation,duration):void
World Mutation Beta
Parameters
blockLocation
Vector3
发射红石脉冲的位置。
Location to pulse Redstone at.
duration
number
脉冲持续的 tick 数。
Number of ticks to pulse Redstone.
Returns
void
Remarks
通过创建一个临时红石方块在某特定位置发出红石脉冲。
Sends a Redstone pulse at a particular location by creating a temporary Redstone block.
Throws
This function can throw errors.
relativeBlockLocation()
relativeBlockLocation(
worldBlockLocation):Vector3
Beta
Parameters
worldBlockLocation
Vector3
世界上要转换为相对位置的绝对位置。
Absolute location in the world to convert to a relative location.
Returns
Vector3
一个相对于 GameTest 命令方块的位置。
A location relative to the GameTest command block.
Remarks
从一个 BlockLocation 出发,返回一个坐标相对于当前 GameTest 结构方块的新 BlockLocation。例如,结构方块上方方块的相对坐标为 (0, 1, 0)。同时也会考虑 GameTest 结构的旋转。
From a BlockLocation, returns a new BlockLocation with coordinates relative to the current GameTest structure block. For example, the relative coordinates for the block above the structure block are (0, 1, 0). Rotation of the GameTest structure is also taken into account.
Throws
This function can throw errors.
relativeLocation()
relativeLocation(
worldLocation):Vector3
World Mutation Beta
Parameters
worldLocation
Vector3
世界上要转换为相对位置的绝对位置。
Absolute location in the world to convert to a relative location.
Returns
Vector3
一个相对于 GameTest 命令方块的位置。
A location relative to the GameTest command block.
Remarks
从一个位置出发,返回一个坐标相对于当前 GameTest 结构方块的新位置。例如,结构方块上方方块的相对坐标为 (0, 1, 0)。同时也会考虑 GameTest 结构的旋转。
From a location, returns a new location with coordinates relative to the current GameTest structure block. For example, the relative coordinates for the block above the structure block are (0, 1, 0). Rotation of the GameTest structure is also taken into account.
Throws
This function can throw errors.
removeSimulatedPlayer()
removeSimulatedPlayer(
simulatedPlayer):void
World Mutation Beta
Parameters
simulatedPlayer
要移除的模拟玩家。
Simulated player to remove.
Returns
void
Remarks
从世界中移除一个模拟玩家。
Removes a simulated player from the world.
Throws
This function can throw errors.
rotateDirection()
rotateDirection(
direction):Direction
World Mutation Beta
Parameters
direction
Direction
要转换为 GameTest 朝向相对方向的方向。传入 Direction.south 将返回测试方向;传入 Direction.north 则返回测试方向的反方向,以此类推。
Direction to translate into a direction relative to the GameTest facing. Passing in Direction.south will return the test direction; Passing in Direction.north will return the opposite of the test direction, and so on.
Returns
Direction
Remarks
根据当前测试的旋转方向返回某个方向的相对方向。传入 Direction.south 将返回测试方向;传入 Direction.north 则返回测试方向的反方向,以此类推。
Returns a relative direction given the current rotation of the current test. Passing in Direction.south will return the test direction; Passing in Direction.north will return the opposite of the test direction, and so on.
Throws
This function can throw errors.
rotateVector()
rotateVector(
vector):Vector3
World Mutation Beta
Parameters
vector
Vector3
Returns
Vector3
Remarks
Throws
This function can throw errors.
runAfterDelay()
runAfterDelay(
delayTicks,callback):void
World Mutation Beta
Parameters
delayTicks
number
运行指定回调之前的延迟 tick 数。
Number of ticks to delay before running the specified callback.
callback
() => void
要执行的回调函数。
Callback function to execute.
Returns
void
Remarks
在指定的 tick 延迟后运行某个特定的回调函数。
Runs a specific callback after a specified delay of ticks
Throws
This function can throw errors.
runAtTickTime()
runAtTickTime(
tick,callback):void
World Mutation Beta
Parameters
tick
number
从 GameTest 开始的 tick 计数,到达该 tick 时运行回调。
Tick (after the start of the GameTest) to run the callback at.
callback
() => void
要执行的回调函数。
Callback function to execute.
Returns
void
Remarks
在 GameTest 开始的 tick tick 之后运行给定的回调函数。
Runs the given callback after a delay of tick ticks from the start of the GameTest.
Throws
This function can throw errors.
runOnFinish()
runOnFinish(
callback):void
World Mutation Beta
Parameters
callback
() => void
要执行的回调。
Callback to execute.
Returns
void
Remarks
在 GameTest 完成后运行给定的回调函数,无论测试是通过、失败还是超时。
Runs the given callback after the GameTest has completed regardless if the test passed, failed, or timed out.
Throws
This function can throw errors.
setBlockPermutation()
setBlockPermutation(
blockData,blockLocation):void
World Mutation Beta
Parameters
blockData
BlockPermutation
包含方块配置数据的方块状态(Permutation)。
Permutation that contains the configuration data for a block.
blockLocation
Vector3
要设置的方块的位置。
Location of the block to set.
Returns
void
Remarks
在指定的方块位置将方块设为特定配置(即一个 BlockPermutation)。
Sets a block to a particular configuration (a BlockPermutation) at the specified block location.
Throws
This function can throw errors.
setBlockType()
setBlockType(
blockType,blockLocation):void
World Mutation Beta
Parameters
blockType
any
要设置的方块类型。
Type of block to set.
blockLocation
Vector3
要设置的方块的位置。
Location of the block to set.
Returns
void
Remarks
在指定的方块位置将方块设为特定类型。
Sets a block to a particular type at the specified block location.
Throws
This function can throw errors.
Example
minibiomes.ts
setFluidContainer()
setFluidContainer(
location,type):void
World Mutation Beta
Parameters
location
Vector3
盛液方块的位置。
Location of the fluid container block.
type
FluidType
要设置的液体类型。可取值请参阅 FluidType。
Type of fluid to set. See FluidType for a list of values.
Returns
void
Remarks
对于盛液体的方块(如炼药锅),可更改其中所盛液体的类型。
For blocks that are fluid containers - like a cauldron - changes the type of fluid within that container.
Throws
This function can throw errors.
setTntFuse()
setTntFuse(
entity,fuseLength):void
World Mutation Beta
Parameters
entity
Entity
可爆炸的实体。
Entity that is explodable.
fuseLength
number
实体爆炸之前的时长(以 tick 为单位)。
Length of time, in ticks, before the entity explodes.
Returns
void
Remarks
设置可爆炸实体的引信时长。
Sets the fuse of an explodable entity.
Throws
This function can throw errors.
spawn()
spawn(
entityTypeIdentifier,blockLocation):Entity
World Mutation Beta
Parameters
entityTypeIdentifier
string
要创建的实体类型。若未指定命名空间,则默认为 'minecraft:'。注意可在尖括号之间指定一个可选的初始生成事件(例如 namespace:entityType<spawnEvent>)。
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<spawnEvent>).
blockLocation
Vector3
Returns
Entity
已生成的实体。若无法生成该实体,则返回 undefined。
The spawned entity. If the entity cannot be spawned, returns undefined.
Remarks
在某位置生成一个实体。
Spawns an entity at a location.
Throws
This function can throw errors.
Examples
simpleMobTest.ts
simpleMobGameTest.ts
phantomsShouldFlyFromCats.ts
minibiomes.ts
spawnAtLocation()
spawnAtLocation(
entityTypeIdentifier,location):Entity
World Mutation Beta
Parameters
entityTypeIdentifier
string
要创建的实体类型。若未指定命名空间,则默认为 'minecraft:'。注意可在尖括号之间指定一个可选的初始生成事件(例如 namespace:entityType<spawnEvent>)。
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<spawnEvent>).
location
Vector3
Returns
Entity
已生成的实体。若无法生成该实体,则返回 undefined。
The spawned entity. If the entity cannot be spawned, returns undefined.
Remarks
在某位置生成一个实体。
Spawns an entity at a location.
Throws
This function can throw errors.
spawnItem()
spawnItem(
itemStack,location):Entity
World Mutation Beta
Parameters
itemStack
ItemStack
用于描述要创建的物品实体的 ItemStack。
ItemStack that describes the item entity to create.
location
Vector3
要在其上创建物品实体的位置。
Location to create the item entity at.
Returns
Entity
Remarks
在指定位置生成一个物品实体。
Spawns an item entity at a specified location.
Throws
This function can throw errors.
spawnSimulatedPlayer()
spawnSimulatedPlayer(
blockLocation,name?,gameMode?):SimulatedPlayer
World Mutation Beta
Parameters
blockLocation
Vector3
模拟玩家生成的位置。
Location where to spawn the simulated player.
name?
string
为新创建的模拟玩家指定的名称。
Name to give the new simulated player. Defaults to: "Simulated Player"
gameMode?
any
Defaults to: 0
Returns
Remarks
在世界中创建一个新的模拟玩家。
Creates a new simulated player within the world.
Throws
This function can throw errors.
spawnWithoutBehaviors()
spawnWithoutBehaviors(
entityTypeIdentifier,blockLocation):Entity
World Mutation Beta
Parameters
entityTypeIdentifier
string
blockLocation
Vector3
实体应被生成到的位置。
Location where the entity should be spawned.
Returns
Entity
Remarks
在某位置生成一个没有任何 AI 行为的实体。此方法经常与 .walkTo 等方法联用,以获得可预测的 mob 行为。
Spawns an entity at a location without any AI behaviors. This method is frequently used in conjunction with methods like .walkTo to create predictable mob actions.
Throws
This function can throw errors.
spawnWithoutBehaviorsAtLocation()
spawnWithoutBehaviorsAtLocation(
entityTypeIdentifier,location):Entity
World Mutation Beta
Parameters
entityTypeIdentifier
string
location
Vector3
实体应被生成到的位置。
Location where the entity should be spawned.
Returns
Entity
Remarks
在某位置生成一个没有任何 AI 行为的实体。此方法经常与 .walkTo 等方法联用,以获得可预测的 mob 行为。
Spawns an entity at a location without any AI behaviors. This method is frequently used in conjunction with methods like .walkTo to create predictable mob actions.
Throws
This function can throw errors.
spreadFromFaceTowardDirection()
spreadFromFaceTowardDirection(
blockLocation,fromFace,direction):void
World Mutation Beta
Parameters
blockLocation
Vector3
含有多面方块的 BlockLocation。
BlockLocation containing a multiface block.
fromFace
Direction
用于扩散的起始面。该面必须已被设置。
Face to spread from. This face must already be set.
direction
Direction
扩散方向。使用 Minecraft.Direction 枚举来指定方向。
Direction to spread. Use the Minecraft.Direction enum to specify a direction.
Returns
void
Remarks
断言在某一特定位置存在特定的物品实体。否则抛出异常。
Tests that a particular item entity is present at a particular location. If not, an exception is thrown.
Throws
This function can throw errors.
startSequence()
startSequence():
GameTestSequence
World Mutation Beta
Returns
一个新的 GameTestSequence,其链式方法便于创建一组步骤。
A new GameTestSequence with chaining methods that facilitate creating a set of steps.
Remarks
创建一个新的 GameTestSequence —— 一组在 GameTest 中按顺序执行的步骤。
Creates a new GameTestSequence - A set of steps that play out sequentially within a GameTest.
Throws
This function can throw errors.
succeed()
succeed():
void
World Mutation Beta
Returns
void
Remarks
将当前测试标记为成功用例。
Marks the current test as a success case.
Throws
This function can throw errors.
succeedIf()
succeedIf(
callback):void
World Mutation Beta
Parameters
callback
() => void
要运行的回调函数。若该函数正常执行完毕,则测试将被标记为成功。通常该函数体内会调用 .assertXyz 系列方法。
Callback function that runs. If the function runs successfully, the test is marked as a success. Typically, this function will have .assertXyz method calls within it.
Returns
void
Remarks
运行给定的回调函数。若回调未抛出异常,则将该测试标记为成功。
Runs the given callback. If the callback does not throw an exception, the test is marked as a success.
Throws
This function can throw errors.
succeedOnTick()
succeedOnTick(
tick):void
World Mutation Beta
Parameters
tick
number
自 GameTest 开始后到达该 tick 时将测试标记为成功。
Tick after the start of the GameTest to mark the test as successful.
Returns
void
Remarks
在指定的 tick 将测试标记为成功。
Marks the test as a success at the specified tick.
Throws
This function can throw errors.
succeedOnTickWhen()
succeedOnTickWhen(
tick,callback):void
World Mutation Beta
Parameters
tick
number
从 GameTest 开始后到达该 tick 时运行测试回调。
Tick after the start of the GameTest to run the testing callback at.
callback
() => void
要运行的回调函数。若该函数正常执行完毕,则测试将被标记为成功。
Callback function that runs. If the function runs successfully, the test is marked as a success.
Returns
void
Remarks
在测试开始 tick 个 tick 后运行给定的回调函数。若回调未抛出异常,则将该测试标记为失败。
Runs the given callback at tick ticks after the start of the test. If the callback does not throw an exception, the test is marked as a failure.
Throws
This function can throw errors.
succeedWhen()
succeedWhen(
callback):void
World Mutation Beta
Parameters
callback
() => void
要运行的测试回调函数。若该函数正常执行完毕,则测试将被标记为成功。
Testing callback function that runs. If the function runs successfully, the test is marked as a success.
Returns
void
Remarks
每个 tick 运行一次给定的回调函数。当回调成功执行(即不抛出异常)时,测试被标记为成功。
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.
Throws
This function can throw errors.
Example
simpleMobGameTest.ts
succeedWhenBlockPresent()
succeedWhenBlockPresent(
blockType,blockLocation,isPresent?):void
World Mutation Beta
Parameters
blockType
any
待测试的方块类型。
Type of block to test for.
blockLocation
Vector3
待测试的方块位置。
Location of the block to test at.
isPresent?
boolean
若为 true,此函数测试是否存在指定类型的方块;若为 false,则测试指定类型的方块不存在。
If true, this function tests whether a block of the specified type is present. If false, tests that a block of the specified type is not present. Defaults to: true
Returns
void
Remarks
根据 isPresent 的取值,每个 tick 测试是否存在某种类型的方块。当找到或未找到(取决于 isPresent)指定类型的方块时,测试即被标记为成功。
Depending on the condition of isPresent, tests for the presence of a block of a particular type on every tick. When the specified block of a type is found or not found (depending on isPresent), the test is marked as a success.
Throws
This function can throw errors.
succeedWhenEntityHasComponent()
succeedWhenEntityHasComponent(
entityTypeIdentifier,componentIdentifier,blockLocation,hasComponent):void
World Mutation Beta
Parameters
entityTypeIdentifier
string
要查找的实体类型。若未指定命名空间,则默认为 'minecraft:'。
Type of entity to look for. If no namespace is specified, 'minecraft:' is assumed.
componentIdentifier
string
用于测试其存在性的组件类型。若未指定命名空间,则默认为 'minecraft:'。
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
若为 true,此函数测试组件是否存在;若为 false,则测试组件不存在。
If true, this function tests for the presence of a component. If false, this function tests for the lack of a component.
Returns
void
Remarks
每个 tick 检查特定组件是否存在。根据 hasComponent 的取值,当找到指定组件时,测试即被标记为成功。
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.
Throws
This function can throw errors.
succeedWhenEntityPresent()
succeedWhenEntityPresent(
entityTypeIdentifier,blockLocation,isPresent?):void
World Mutation Beta
Parameters
entityTypeIdentifier
string
待测试的实体类型(例如 'minecraft:skeleton')。若未指定实体命名空间,则默认为 'minecraft:'。
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.
isPresent?
boolean
若为 true,此函数测试指定类型实体是否存在;若为 false,则测试指定类型实体不存在。
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. Defaults to: true
Returns
void
Remarks
根据 isPresent 的取值,每个 tick 测试实体的存在性。当找到或未找到(取决于 isPresent)指定类型的实体时,测试即被标记为成功。
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.
Throws
This function can throw errors.
Examples
phantomsShouldFlyFromCats.ts
minibiomes.ts
triggerInternalBlockEvent()
triggerInternalBlockEvent(
blockLocation,event,eventParameters?):void
World Mutation Beta
Parameters
blockLocation
Vector3
event
string
要触发的事件。有效值包括 minecraft:drip、minecraft:grow_stalagtite、minecraft:grow_stalagmite、minecraft:grow_up、minecraft:grow_down 以及 minecraft:grow_sideways。
Event to trigger. Valid values include minecraft:drip, minecraft:grow_stalagtite, minecraft:grow_stalagmite, minecraft:grow_up, minecraft:grow_down and minecraft:grow_sideways.
eventParameters?
number[]
Defaults to: []
Returns
void
Remarks
从固定列表中的方块事件触发一个方块事件。
Triggers a block event from a fixed list of available block events.
Throws
This function can throw errors.
until()
until(
callback):Promise<void>
World Mutation Beta
Parameters
callback
() => void
包含要执行的代码的函数。
Function with code to evaluate.
Returns
Promise<void>
Remarks
此异步函数将等待指定回调成功执行完毕。until 可以与 .assert 系列方法配合,用于评估某个条件是否为真。
This asynchronous function will wait until the code in the specified callback successfully completes. until can be used in conjunction with .assert functions to evaluate that a condition is true.
Throws
This function can throw errors.
walkTo()
walkTo(
mob,blockLocation,speedModifier?):void
World Mutation Beta
Parameters
mob
Entity
要下达指令的生物实体。
Mob entity to give orders to.
blockLocation
Vector3
实体应行走到的位置。
Location where the entity should be walk to.
speedModifier?
number
实体行走速度的可调修正系数。
Adjustable modifier to the mob's walking speed. Defaults to: 1
Returns
void
Remarks
强制一个生物走到特定位置。通常与 .spawnWithoutBehaviors 等方法配合使用,以获得更可预测的生物行为。一旦与目标位置相交,生物即会停止寻路。
Forces a mob to walk to a particular location. Usually used in conjunction with methods like .spawnWithoutBehaviors to have more predictable mob behaviors. Mobs will stop navigation as soon as they intersect the target location.
Throws
This function can throw errors.
walkToLocation()
walkToLocation(
mob,location,speedModifier?):void
World Mutation Beta
Parameters
mob
Entity
要下达指令的生物实体。
Mob entity to give orders to.
location
Vector3
实体应行走到的位置。
Location where the entity should be walk to.
speedModifier?
number
实体行走速度的可调修正系数。
Adjustable modifier to the mob's walking speed. Defaults to: 1
Returns
void
Remarks
强制一个生物走到特定位置。通常与 .spawnWithoutBehaviors 等方法配合使用,以获得更可预测的生物行为。一旦与目标位置相交,生物即会停止寻路。
Forces a mob to walk to a particular location. Usually used in conjunction with methods like .spawnWithoutBehaviors to have more predictable mob behaviors. Mobs will stop navigation as soon as they intersect the target location.
Throws
This function can throw errors.
worldBlockLocation()
worldBlockLocation(
relativeBlockLocation):Vector3
Beta
Parameters
relativeBlockLocation
Vector3
相对于 GameTest 命令方块的位置。
Location relative to the GameTest command block.
Returns
Vector3
一个相对于 GameTest 命令方块的绝对位置。
An absolute location relative to the GameTest command block.
Remarks
从一个相对于 GameTest 结构方块的 BlockLocation 出发,返回一个坐标相对于世界的新 BlockLocation。同时也会考虑 GameTest 结构的旋转。
From a BlockLocation with coordinates relative to the GameTest structure block, returns a new BlockLocation with coordinates relative to world. Rotation of the GameTest structure is also taken into account.
Throws
This function can throw errors.
worldLocation()
worldLocation(
relativeLocation):Vector3
Beta
Parameters
relativeLocation
Vector3
相对于 GameTest 命令方块的位置。
Location relative to the GameTest command block.
Returns
Vector3
一个相对于 GameTest 命令方块的绝对位置。
An absolute location relative to the GameTest command block.
Remarks
从一个相对于 GameTest 结构方块的位置出发,返回一个坐标相对于世界的新位置。同时也会考虑 GameTest 结构的旋转。
From a location with coordinates relative to the GameTest structure block, returns a new location with coordinates relative to world. Rotation of the GameTest structure is also taken into account.
Throws
This function can throw errors.
