Skip to main content
Version: Minecraft 26.2

dev.polymodloader.api.devtools.gametest

Generated

This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.

TypeKindDescription
GameTestfunctional interfaceOne in-game test.
GameTestContextinterfaceA running game test.
GameTestRegistrarinterfaceRegisters in-game tests that run on Mojang's game test server (net.minecraft.gametest.Main, for example through the polyScenarios Gradle tasks).
TestArearecordThe empty space a game test gets, in blocks; (0, 0, 0) is its lowest corner.

GameTest​

functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public interface GameTest

One in-game test.

run(GameTestContext)​

void run(GameTestContext context)

Since 0.1.0-alpha.4 or earlier

Starts the test on the server thread. The test passes when it calls GameTestContext.succeed() (now or from a later tick) and fails when an assertion or the code throws.

ParameterTypeDescription
contextGameTestContext—

GameTestContext​

interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public interface GameTestContext

A running game test. Positions are relative to the test area; (0, 0, 0) is its lowest corner and the area is at least 1×1×1 blocks plus room above.

Assertions throw an exception the game reports as a test failure with the position and message.

world()​

WorldView world()

Since 0.1.0-alpha.4 or earlier

The world the test runs in.

Returns WorldView

absolute(BlockPos)​

BlockPos absolute(BlockPos relative)

Since 0.1.0-alpha.4 or earlier

Converts a test-relative position into a world position.

ParameterTypeDescription
relativeBlockPos—

Returns BlockPos

setBlock(BlockPos, ResourceId)​

void setBlock(BlockPos relative, ResourceId block)

Since 0.1.0-alpha.4 or earlier

Places the default state of block at a test-relative position.

ParameterTypeDescription
relativeBlockPos—
blockResourceId—

assertBlock(BlockPos, ResourceId)​

void assertBlock(BlockPos relative, ResourceId expected)

Since 0.1.0-alpha.4 or earlier

Fails unless the block at a test-relative position is expected.

ParameterTypeDescription
relativeBlockPos—
expectedResourceId—

assertTrue(boolean, String)​

void assertTrue(boolean condition, String message)

Since 0.1.0-alpha.4 or earlier

Fails with message unless condition holds.

ParameterTypeDescription
conditionboolean—
messageString—

createMockPlayer()​

PlayerView createMockPlayer()

Since 0.1.0-alpha.4 or earlier

Creates a survival-mode player in the test world that is not connected to any client.

Returns PlayerView

createMockServerPlayer()​

PlayerView createMockServerPlayer()

Since 0.1.0-alpha.4 or earlier

Creates a survival-mode server player that is not connected and not in the world, for what needs one, such as advancements.

Returns PlayerView

createConnectedMockPlayer()​

PlayerView createConnectedMockPlayer()

Since 0.1.0-alpha.4 or earlier

Creates a survival-mode player that joins the server like a client over an in-memory connection (PlayerEvents.JOINED fires) and reports that it finished loading, so it can take damage. It stands where the game puts new players. Interactions work as for createMockServerPlayer().

While connected it affects the whole test world like a real player: mobs far from every player despawn and mobs spawn near it, which disturbs other tests running at the same time. Call disconnect before the test function returns; players still connected when the test ends are disconnected then.

Returns PlayerView

respawn(PlayerView, boolean)​

PlayerView respawn(PlayerView player, boolean returnedFromEnd)

Since 0.1.0-alpha.4 or earlier

Respawns a player from createConnectedMockPlayer() as its client asks from the death screen (or after the End credits): the game builds a new player object, PlayerEvents.COPY and RESPAWNED fire, and the new player reports that it loaded.

ParameterTypeDescription
playerPlayerView—
returnedFromEndbooleantrue to respawn as when leaving the End (everything is kept); false to respawn after death

Returns PlayerView — the new player

Throws IllegalArgumentException — when player is not a connected mock player of this test

Throws IllegalStateException — when respawning after death and the player is alive

disconnect(PlayerView)​

void disconnect(PlayerView player)

Since 0.1.0-alpha.4 or earlier

Disconnects a player from createConnectedMockPlayer() (PlayerEvents.LEAVING fires); does nothing for a player that already left.

ParameterTypeDescription
playerPlayerView—

Throws IllegalArgumentException — when player is not a connected mock player of this test

useBlock(BlockPos, PlayerView)​

void useBlock(BlockPos relative, PlayerView player)

Since 0.1.0-alpha.4 or earlier

Makes player use (right-click) the block at a test-relative position with an empty hand.

ParameterTypeDescription
relativeBlockPos—
playerPlayerView—

interactBlock(PlayerView, BlockPos, Direction)​

InteractionResult interactBlock(PlayerView player, BlockPos relative, Direction face)

Since 0.1.0-alpha.4 or earlier

Makes a server player (from createMockServerPlayer()) right-click a face of the block at a test-relative position with its main hand, the way the server handles the click from a connected client: interaction events first, then the held item and the block. Unlike useBlock, a held block item is placed.

ParameterTypeDescription
playerPlayerView—
relativeBlockPos—
faceDirection—

Returns InteractionResult — the result the game reached, mapped onto the Native API's result

Throws IllegalArgumentException — when player is not a server player

interactItem(PlayerView)​

InteractionResult interactItem(PlayerView player)

Since 0.1.0-alpha.4 or earlier

Makes a server player use the item in its main hand in the air, the way the server handles the click from a connected client (interaction events, then the item).

ParameterTypeDescription
playerPlayerView—

Returns InteractionResult

Throws IllegalArgumentException — when player is not a server player

interactEntity(PlayerView, EntityView)​

InteractionResult interactEntity(PlayerView player, EntityView target)

Since 0.1.0-alpha.4 or earlier

Makes a server player right-click target with its main hand, the way the server handles the click from a connected client (interaction events, then the entity and the item).

ParameterTypeDescription
playerPlayerView—
targetEntityView—

Returns InteractionResult

Throws IllegalArgumentException — when player is not a server player

attackEntity(PlayerView, EntityView)​

void attackEntity(PlayerView player, EntityView target)

Since 0.1.0-alpha.4 or earlier

Makes a server player attack target with its main hand, as a left-click does (interaction events, then damage and knockback).

ParameterTypeDescription
playerPlayerView—
targetEntityView—

Throws IllegalArgumentException — when player is not a server player

breakBlock(PlayerView, BlockPos)​

boolean breakBlock(PlayerView player, BlockPos relative)

Since 0.1.0-alpha.4 or earlier

Makes a server player break the block at a test-relative position at once, the way the server finishes a player's digging: block events, the game's checks, drops in survival mode.

ParameterTypeDescription
playerPlayerView—
relativeBlockPos—

Returns boolean — whether the block was broken

Throws IllegalArgumentException — when player is not a server player

runCommand(String)​

int runCommand(String command)

Since 0.1.0-alpha.4 or earlier

Runs a command as the server at the test area's origin.

ParameterTypeDescription
commandString—

Returns int — the command's result value; 0 when it failed

runAfter(int, Runnable)​

void runAfter(int ticks, Runnable action)

Since 0.1.0-alpha.4 or earlier

Runs action after ticks more ticks, on the server thread.

ParameterTypeDescription
ticksint—
actionRunnable—

succeed()​

void succeed()

Since 0.1.0-alpha.4 or earlier

Marks the test passed.

fail(String)​

void fail(String message)

Since 0.1.0-alpha.4 or earlier

Marks the test failed.

ParameterTypeDescription
messageString—

GameTestRegistrar​

interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public interface GameTestRegistrar

Registers in-game tests that run on Mojang's game test server (net.minecraft.gametest.Main, for example through the polyScenarios Gradle tasks). Each test gets a fresh empty area; its ID is <mod id>:<name>, so --tests <mod id>:* runs all of a mod's tests. In a normal world they also run with /test run <mod id>:<name>.

When: inside common entrypoints.

register(String, GameTest)​

default void register(String name, GameTest test)

Since 0.1.0-alpha.4 or earlier

Registers a required test that must finish within 100 ticks.

ParameterTypeDescription
nameString—
testGameTest—

register(String, int, GameTest)​

default void register(String name, int maxTicks, GameTest test)

Since 0.1.0-alpha.4 or earlier

Registers a required test.

ParameterTypeDescription
nameString—
maxTicksintticks before the test fails with a timeout
testGameTest—

Throws IllegalArgumentException — for an invalid or already used name (POLY-GAMETEST-001)

Throws IllegalStateException — after registration closed (POLY-GAMETEST-002)

register(String, int, TestArea, GameTest)​

void register(String name, int maxTicks, TestArea area, GameTest test)

Since 0.1.0-alpha.4 or earlier

Registers a required test that gets area to itself.

ParameterTypeDescription
nameString—
maxTicksint—
areaTestArea—
testGameTest—

Throws IllegalArgumentException — for an invalid or already used name (POLY-GAMETEST-001)

Throws IllegalStateException — after registration closed (POLY-GAMETEST-002)

TestArea​

record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public record TestArea(int width, int height, int depth)

The empty space a game test gets, in blocks; (0, 0, 0) is its lowest corner. The game keeps a few blocks between neighbouring test areas, so a test that builds or moves things beyond one block needs an area that covers them, or it may disturb its neighbours.

ComponentTypeDescription
widthintsize along x, 1–48
heightintsize along y, 1–48
depthintsize along z, 1–48
Constant or fieldTypeDescription
SINGLE_BLOCKTestAreaOne block, the default.

cube(int)​

public static TestArea cube(int size)

Since 0.1.0-alpha.4 or earlier

A size × size × size cube.

ParameterTypeDescription
sizeint—

Returns TestArea

Buy me a coffee