实验性
实验性
Location of the block with a container (for example, a chest) to test is empty of contents.
实验性
Identifier of the entity to match (e.g., 'minecraft:skeleton').
Container slot index to test.
Name of the armor to look for.
Data value integer to look for.
Location of the entity with armor to test for.
可选
hasArmor: booleanWhether or not the entity is expected to have the specified armor equipped.
实验性
Identifier of the specified entity (e.g., 'minecraft:skeleton'). If the namespace is not specified, 'minecraft:' is assumed.
Identifier of the component to check for. If the namespace is not specified, 'minecraft:' is assumed.
Location of the block with a container (for example, a chest.)
可选
hasComponent: booleanDetermines whether to test that the component exists, or does not.
实验性
Entity instance to test for.
可选
isPresent: booleanIf true, this function tests whether the specified entity is present in the GameTest area. If false, tests that the specified entity is not present.
Tests that an entity instance is present within the GameTest area. If not, an exception is thrown.
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');
实验性
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
Location of the entity to test for.
可选
searchDistance: numberThe distance to search for the entity from the blockLocation.
可选
isPresent: booleanIf 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.
实验性
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
可选
isPresent: booleanIf 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.
Tests that an entity of a specified type is present within the GameTest area. If not, an exception is thrown.
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");
实验性
Location of the entity to look for.
Identifier of the entity (e.g., 'minecraft:skeleton') to look for. Note if no namespace is specified, 'minecraft:' is assumed.
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.
实验性
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
Location of the entity to test for.
可选
isTouching: booleanIf true, this function tests whether the entity is touching the specified location. If false, tests that an entity is not testing the specified location.
实验性
Location of the block to test for.
可选
isWaterlogged: booleanWhether to test that the block at position is expected to be waterlogged.
实验性
Type of item to look for.
Location to search around for the specified set of items.
Range, in blocks, to aggregate a count of items around. If 0, will only search the particular block at position.
Number of items, at minimum, to look and test for.
实验性
Type of item to test for.
Location of the item entity to test for.
可选
searchDistance: numberRadius in blocks to look for the item entity.
可选
isPresent: booleanIf 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.
实验性
Location to test.
Expected power level.
实验性
Location of the block to destroy.
可选
dropResources: booleanWhether to add resources exposed with a particular drop.
实验性
Location of the block to retrieve.
If the block at the specified block location is a fence, this returns a helper object with details on how a fence is connected.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Location of the block to retrieve a sculk spreader from.
Returns the SculkSpreader or undefined if no SculkSpreader is present on the block.
Retrieves a sculk spreader object that can be used to control and manage how sculk grows from a block.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
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).
实验性
Amount of time to wait, in ticks.
This asynchronous function will wait for the specified time in ticks before continuing execution.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Location to push the button at.
实验性
Location to pull the lever at.
实验性
Location to pulse Redstone at.
Number of ticks to pulse Redstone.
Sends a Redstone pulse at a particular location by creating a temporary Redstone block.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Absolute location in the world to convert to a relative location.
A location relative to the GameTest command block.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Simulated player to remove.
实验性
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 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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Tick (after the start of the GameTest) to run the callback at.
Callback function to execute.
Runs the given callback after a delay of tick ticks from the start of the GameTest.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Permutation that contains the configuration data for a block.
Location of the block to set.
Sets a block to a particular configuration (a BlockPermutation) at the specified block location.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Sets a block to a particular type at the specified block location.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
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);
实验性
Location of the fluid container block.
Type of fluid to set. See minecraftserver.FluidType for a list of values.
For blocks that are fluid containers - like a cauldron - changes the type of fluid within that container.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Entity that is explodable.
Length of time, in ticks, before the entity explodes.
实验性
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
The spawned entity. If the entity cannot be spawned, returns undefined.
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);
实验性
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
The spawned entity. If the entity cannot be spawned, returns undefined.
实验性
实验性
Location where the entity should be spawned.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Location where the entity should be spawned.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Tests that a particular item entity is present at a particular location. If not, an exception is thrown.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
A new GameTestSequence with chaining methods that facilitate creating a set of steps.
Creates a new GameTestSequence - A set of steps that play out sequentially within a GameTest.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
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.
Runs the given callback. If the callback does not throw an exception, the test is marked as a success.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Tick after the start of the GameTest to run the testing callback at.
Callback function that runs. If the function runs successfully, the test is marked as a success.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Testing callback function that runs. If the function runs successfully, the test is marked as a success.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
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");
实验性
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Type of entity to look for. If no namespace is specified, 'minecraft:' is assumed.
Type of component to test for the presence of. If no namespace is specified, 'minecraft:' is assumed.
Block location of the entity to test.
If true, this function tests for the presence of a component. If false, this function tests for the lack of a component.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Type of entity to test for (e.g., 'minecraft:skeleton'). If an entity namespace is not specified, 'minecraft:' is assumed.
Location of the entity to test for.
可选
isPresent: booleanIf 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.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
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);
实验性
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[]Triggers a block event from a fixed list of available block events.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
Function with code to evaluate.
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性
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.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
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.