dev.polymodloader.api.devtools.gametest
This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.
| Type | Kind | Description |
|---|---|---|
GameTest | functional interface | One in-game test. |
GameTestContext | interface | A running game test. |
GameTestRegistrar | interface | Registers in-game tests that run on Mojang's game test server (net.minecraft.gametest.Main, for example through the polyScenarios Gradle tasks). |
TestArea | record | The 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.
| Parameter | Type | Description |
|---|---|---|
context | GameTestContext | — |
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.
| Parameter | Type | Description |
|---|---|---|
relative | BlockPos | — |
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.
| Parameter | Type | Description |
|---|---|---|
relative | BlockPos | — |
block | ResourceId | — |
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.
| Parameter | Type | Description |
|---|---|---|
relative | BlockPos | — |
expected | ResourceId | — |
assertTrue(boolean, String)
void assertTrue(boolean condition, String message)
Since 0.1.0-alpha.4 or earlier
Fails with message unless condition holds.
| Parameter | Type | Description |
|---|---|---|
condition | boolean | — |
message | String | — |
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.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
returnedFromEnd | boolean | true 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.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
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.
| Parameter | Type | Description |
|---|---|---|
relative | BlockPos | — |
player | PlayerView | — |
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.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
relative | BlockPos | — |
face | Direction | — |
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).
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
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).
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
target | EntityView | — |
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).
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
target | EntityView | — |
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.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | — |
relative | BlockPos | — |
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.
| Parameter | Type | Description |
|---|---|---|
command | String | — |
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.
| Parameter | Type | Description |
|---|---|---|
ticks | int | — |
action | Runnable | — |
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.
| Parameter | Type | Description |
|---|---|---|
message | String | — |
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.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
test | GameTest | — |
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.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
maxTicks | int | ticks before the test fails with a timeout |
test | GameTest | — |
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.
| Parameter | Type | Description |
|---|---|---|
name | String | — |
maxTicks | int | — |
area | TestArea | — |
test | GameTest | — |
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.
| Component | Type | Description |
|---|---|---|
width | int | size along x, 1–48 |
height | int | size along y, 1–48 |
depth | int | size along z, 1–48 |
| Constant or field | Type | Description |
|---|---|---|
SINGLE_BLOCK | TestArea | One block, the default. |
cube(int)
public static TestArea cube(int size)
Since 0.1.0-alpha.4 or earlier
A size × size × size cube.
| Parameter | Type | Description |
|---|---|---|
size | int | — |
Returns TestArea