Interface ClientGameTestContext


@NonExtendable public interface ClientGameTestContext
Context for a client gametest containing various helpful functions and functions to access the game.

Functions in this class can only be called on the client gametest thread.

  • Field Details

    • NO_TIMEOUT

      static final int NO_TIMEOUT
      Used to specify that a wait task should have no timeout.
      See Also:
    • DEFAULT_TIMEOUT

      static final int DEFAULT_TIMEOUT
      The default timeout in ticks for wait tasks (10 seconds).
      See Also:
  • Method Details

    • waitTick

      void waitTick()
      Runs a single tick and waits for it to complete.
    • waitTicks

      void waitTicks(int ticks)
      Runs ticks ticks and waits for them to complete.
      Parameters:
      ticks - The amount of ticks to run
    • waitFor

      int waitFor(Predicate<MinecraftClient> predicate)
      Waits for a predicate to be true. Fails if the predicate is not satisfied after DEFAULT_TIMEOUT ticks.
      Parameters:
      predicate - The predicate to check
      Returns:
      The number of ticks waited
    • waitFor

      int waitFor(Predicate<MinecraftClient> predicate, int timeout)
      Waits for a predicate to be true. Fails if the predicate is not satisfied after timeout ticks. If timeout is NO_TIMEOUT, there is no timeout.
      Parameters:
      predicate - The predicate to check
      timeout - The number of ticks before timing out
      Returns:
      The number of ticks waited
    • waitForScreen

      int waitForScreen(@Nullable @Nullable Class<? extends Screen> screenClass)
      Waits for the given screen class to be shown. If screenClass is null, waits for the current screen to be null. Fails if the screen does not open after DEFAULT_TIMEOUT ticks.
      Parameters:
      screenClass - The screen class to wait to open
      Returns:
      The number of ticks waited
    • setScreen

      void setScreen(Supplier<@Nullable Screen> screen)
      Opens a Screen on the client.
      Parameters:
      screen - The screen to open
      See Also:
    • clickScreenButton

      void clickScreenButton(String translationKey)
      Presses the button in the current screen whose label is the given translation key. Fails if the button couldn't be found.
      Parameters:
      translationKey - The translation key of the label of the button to press
    • tryClickScreenButton

      boolean tryClickScreenButton(String translationKey)
      Presses the button in the current screen whose label is the given translation key, if the button exists. Returns whether the button was found.
      Parameters:
      translationKey - The translation key of the label of the button to press
      Returns:
      Whether the button was found
    • takeScreenshot

      Path takeScreenshot(String name)
      Takes a screenshot and saves it in the screenshots directory.
      Parameters:
      name - The name of the screenshot
      Returns:
      The Path to the screenshot
    • takeScreenshot

      Path takeScreenshot(TestScreenshotOptions options)
      Takes a screenshot with the given options.
      Parameters:
      options - The TestScreenshotOptions to take the screenshot with
      Returns:
      The Path to the screenshot
    • getInput

      TestInput getInput()
      Gets the input handler used to simulate inputs to the client.
      Returns:
      The client gametest input handler
    • worldBuilder

      TestWorldBuilder worldBuilder()
      Creates a world builder for creating singleplayer worlds and dedicated servers.
      Returns:
      A new world builder
    • restoreDefaultGameOptions

      void restoreDefaultGameOptions()
      Restores all game options in MinecraftClient.options to their default values for client gametests. This is called automatically before each gametest is run, so you only need to call this explicitly if you want to do it in the middle of the test.
    • runOnClient

      <E extends Throwable> void runOnClient(org.apache.commons.lang3.function.FailableConsumer<MinecraftClient,E> action) throws E
      Runs the given action on the render thread (client thread), and waits for it to complete.
      Type Parameters:
      E - The type of checked exception that the action throws
      Parameters:
      action - The action to run on the render thread
      Throws:
      E - When the action throws an exception
    • computeOnClient

      <T, E extends Throwable> T computeOnClient(org.apache.commons.lang3.function.FailableFunction<MinecraftClient,T,E> function) throws E
      Runs the given function on the render thread (client thread), and returns the result.
      Type Parameters:
      T - The type of the value to return
      E - The type of the checked exception that the function throws
      Parameters:
      function - The function to run on the render thread
      Returns:
      The result of the function
      Throws:
      E - When the function throws an exception