Class TCompletableScreen<R>

Type Parameters:
R - The type of the result that will be returned when the screen is closed.
All Implemented Interfaces:
INode<TElement>, INodeBounded<TElement,Bounds2i>, INodeRenderable<TElement, TGuiGraphics>, ILastScreenProvider, Iterable<TElement>, Collection<TElement>
Direct Known Subclasses:
TFileChooserScreen

@Environment(CLIENT) public abstract class TCompletableScreen<R> extends TScreen implements ILastScreenProvider
A TScreen that provides a CompletableFuture that yields a result when the screen is closed. This can be used for screens that require user input or choices, allowing the caller to await the result asynchronously.

If the screen is closed prematurely without a result, the future is canceled.

See Also:
  • Constructor Details

    • TCompletableScreen

      protected TCompletableScreen()
    • TCompletableScreen

      protected TCompletableScreen(@Nullable @Nullable net.minecraft.client.gui.screens.Screen lastScreen)
  • Method Details

    • getResult

      @NotNull public final @NotNull CompletableFuture<R> getResult()
      Returns a future that will be completed when this TScreen is closed. The future will contain the result of the screen, which can be used to perform actions based on the user's input or choices made within the screen.
    • canCompleteAsync

      protected final BooleanProperty canCompleteAsync()
      BooleanProperty that indicates whether the result of this screen can be completed asynchronously. If this property is set to true, the result can be completed from any thread without scheduling on the main thread. If set to false, completion actions will be scheduled on the client's main thread to ensure thread safety.
    • getLastScreen

      @Nullable public final @Nullable net.minecraft.client.gui.screens.Screen getLastScreen()
      Description copied from interface: ILastScreenProvider
      Returns the last Screen instance that was open before this one.
      Specified by:
      getLastScreen in interface ILastScreenProvider
    • renderCallback

      @Virtual public void renderCallback(@NotNull @NotNull TGuiGraphics pencil)
      Description copied from interface: INodeRenderable
      Callback method that is invoked when this Node is being rendered.
      Specified by:
      renderCallback in interface INodeRenderable<TElement, TGuiGraphics>
      Overrides:
      renderCallback in class TElement
      Parameters:
      pencil - The rendering context.
    • closeCallback

      @Virtual protected void closeCallback()
      Callback method that is invoked whenever this TScreen is closed via Gui.setScreen(Screen).
      This takes place after TScreen.close() is invoked.

      This method automatically cancels getResult() if not already completed. Overrides of this method should call super to preserve this behavior.

      Overrides:
      closeCallback in class TScreen
      See Also:
      • Screen.removed()