Interface TestServerConnection
- All Known Subinterfaces:
TestDedicatedServerConnection
Unless otherwise specified, methods in this class can only be called on the client gametest thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default timeout in ticks to wait for chunks to load/render (1 minute). -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.client.multiplayer.ClientLevelGets the client level.net.minecraft.client.player.LocalPlayerGets the client player.net.minecraft.server.level.ServerLevelGets the server level of the same dimension as the client level.net.minecraft.server.level.ServerPlayerGets the server player corresponding to the connected client.default intWaits for all chunks that will be downloaded from the server to be downloaded.intwaitForChunksDownload(int timeout) Waits for all chunks that will be downloaded from the server to be downloaded.default intWaits for all chunks to be downloaded and rendered.default intwaitForChunksRender(boolean waitForDownload) Waits for all chunks to be rendered, optionally waiting for chunks to be downloaded first.intwaitForChunksRender(boolean waitForDownload, int timeout) Waits for all chunks to be rendered, optionally waiting for chunks to be downloaded first.default intwaitForChunksRender(int timeout) Waits for all chunks to be downloaded and rendered.voidwaitForClientboundEntityUpdates(net.minecraft.world.entity.EntityType<?> entityType, net.minecraft.world.entity.EntityType<?>... moreEntityTypes) Waits for updates to entities of the specified types on the server to be sent, and received and processed by the client.voidWaits for all packets that have already been sent on the server to be received and processed by the client.voidWaits for all packets that have already been sent on the client to be received and processed by the server.
-
Field Details
-
DEFAULT_CHUNK_LOAD_TIMEOUT
static final int DEFAULT_CHUNK_LOAD_TIMEOUTThe default timeout in ticks to wait for chunks to load/render (1 minute).- See Also:
-
-
Method Details
-
waitForChunksDownload
default int waitForChunksDownload()Waits for all chunks that will be downloaded from the server to be downloaded. Fails if the chunks haven't been downloaded afterDEFAULT_CHUNK_LOAD_TIMEOUTticks. SeewaitForChunksDownload(int)for details.- Returns:
- The number of ticks waited
-
waitForChunksDownload
int waitForChunksDownload(int timeout) Waits for all chunks that will be downloaded from the server to be downloaded. After this, methods such asLevel.getChunk(int, int)andLevel.getBlockState(BlockPos)will return the expected value. However, the chunks may not yet be rendered and may not appear in screenshots, if you need this, usewaitForChunksRender(int)instead. Fails if the chunks haven't been downloaded aftertimeoutticks.- Parameters:
timeout- The number of ticks before timing out- Returns:
- The number of ticks waited
-
waitForChunksRender
default int waitForChunksRender()Waits for all chunks to be downloaded and rendered. After this, all chunks that will ever be visible are visible in screenshots. Fails if the chunks haven't been downloaded and rendered afterDEFAULT_CHUNK_LOAD_TIMEOUTticks.- Returns:
- The number of ticks waited
-
waitForChunksRender
default int waitForChunksRender(int timeout) Waits for all chunks to be downloaded and rendered. After this, all chunks that will ever be visible are visible in screenshots. Fails if the chunks haven't been downloaded and rendered aftertimeoutticks.- Parameters:
timeout- The number of ticks before timing out- Returns:
- The number of ticks waited
-
waitForChunksRender
default int waitForChunksRender(boolean waitForDownload) Waits for all chunks to be rendered, optionally waiting for chunks to be downloaded first. After this, all chunks that are present in the client level will be visible in screenshots. Fails if the chunks haven't been rendered (and optionally downloaded) afterDEFAULT_CHUNK_LOAD_TIMEOUTticks.- Parameters:
waitForDownload- Whether to wait for chunks to be downloaded- Returns:
- The number of ticks waited
-
waitForChunksRender
int waitForChunksRender(boolean waitForDownload, int timeout) Waits for all chunks to be rendered, optionally waiting for chunks to be downloaded first. After this, all chunks that are present in the client level will be visible in screenshots. Fails if the chunks haven't been rendered (and optionally downloaded) aftertimeoutticks.- Parameters:
waitForDownload- Whether to wait for chunks to be downloadedtimeout- The number of ticks before timing out- Returns:
- The number of ticks waited
-
waitForClientboundPackets
void waitForClientboundPackets()Waits for all packets that have already been sent on the server to be received and processed by the client.Note that the server batches some updates, sending them later in the tick, so in some cases a wait may need to be added before calling this method to ensure the packets are sent. Notable examples include:
- Block changes, which require a call to
ClientGameTestContext.waitTick()before calling this method. - Entity updates, which are batched less frequently. You can call
waitForClientboundEntityUpdates(EntityType, EntityType...)instead of this method to handle this case.
It may be tempting to call
ClientGameTestContext.waitTick()instead of this method. This often appears to work, especially in singleplayer, since packets can often take less than a tick to arrive. However it is not 100% reliable and will produce flaky tests. For a similar reason, forgetting to callClientGameTestContext.waitTick()before this method for a block change often works anyway, since the packets sent by the server batching block updates can still arrive before control is returned to the client gametest thread, however this is not guaranteed. - Block changes, which require a call to
-
waitForServerboundPackets
void waitForServerboundPackets()Waits for all packets that have already been sent on the client to be received and processed by the server. -
waitForClientboundEntityUpdates
void waitForClientboundEntityUpdates(net.minecraft.world.entity.EntityType<?> entityType, net.minecraft.world.entity.EntityType<?>... moreEntityTypes) Waits for updates to entities of the specified types on the server to be sent, and received and processed by the client. This waits the maximum of all the update intervals of the specified entity types, then waits for the packets to be received.Some entities interpolate on the client when they are moved, rather than snapping immediately to the right position. If you encounter issues with this, you may need to wait for the interpolation to finish after calling this method. Living entities interpolate for
LinearInterpolationHandler.DEFAULT_INTERPOLATION_STEPSticks.- Parameters:
entityType- The entity type to wait formoreEntityTypes- Additional entity types to wait for
-
getClientPlayer
net.minecraft.client.player.LocalPlayer getClientPlayer()Gets the client player.This method can only be called from the render (client) thread.
- Returns:
- The client player
-
getServerPlayer
net.minecraft.server.level.ServerPlayer getServerPlayer()Gets the server player corresponding to the connected client.This method can only be called from the server thread.
- Returns:
- The server player
-
getClientLevel
net.minecraft.client.multiplayer.ClientLevel getClientLevel()Gets the client level.This method can only be called from the render (client) thread.
- Returns:
- The client level
-
getServerLevel
net.minecraft.server.level.ServerLevel getServerLevel()Gets the server level of the same dimension as the client level.This method can only be called from the server thread.
- Returns:
- The server level
-