Interface VRClientAPI


public interface VRClientAPI
The main interface for interacting with the local player using Vivecraft from client code. For rendering, one should use VRRenderingAPI.
Since:
1.3.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Registers a handler, which consumes a VivecraftClientRegistrationEvent.
    boolean
    closeKeyboard(CloseKeyboardContext closeKeyboardContext)
    Closes Vivecraft's keyboard, doing nothing if the keyboard is already opened or the provided closeKeyboardContext doesn't result in the keyboard closing.
    Gets the mode used for full-body tracking for the local player.
    Returns the history of VR poses for the local player.
    Gets the VR pose representing the player in the room after the most recent poll of VR hardware.
    Gets the VR pose representing the player in the room after the game tick.
    Gets the VR pose representing the player in Minecraft world coordinates after the game tick.
    Gets the VR pose representing the player in Minecraft world coordinates before the game tick.
    Gets the VR pose representing the player in Minecraft world coordinates interpolated for rendering.
    float
    Get the currently active world scale.
    Gets the API instance for interacting with Vivecraft from the client-side, for interactions not related to rendering.
    boolean
    Get whether the local player is currently configured to use left-handed mode when in VR.
    boolean
    Get whether the local player is currently configured to be in seated mode when in VR.
    boolean
    Get whether the client is actively in VR.
    boolean
    Get whether VR support is currently initialized.
    boolean
    openKeyboard(OpenKeyboardContext openKeyboardContext)
    Opens Vivecraft's keyboard, doing nothing if the keyboard is already opened or the provided openKeyboardContext doesn't result in the keyboard opening.
    default void
    triggerHapticPulse(VRBodyPart bodyPart, float duration)
    Causes a haptic pulse (vibration/rumble) at full strength with 160 Hz for the specified VRBodyPart, if possible.
    void
    triggerHapticPulse(VRBodyPart bodyPart, float duration, float frequency, float amplitude, float delay)
    Causes a haptic pulse (vibration/rumble) for the specified VRBodyPart, if possible.
  • Method Details

    • instance

      static VRClientAPI instance()
      Gets the API instance for interacting with Vivecraft from the client-side, for interactions not related to rendering.
      Returns:
      The Vivecraft API instance for interacting with Vivecraft's client API.
      Since:
      1.3.0
    • addClientRegistrationHandler

      void addClientRegistrationHandler(Consumer<VivecraftClientRegistrationEvent> handler) throws IllegalStateException
      Registers a handler, which consumes a VivecraftClientRegistrationEvent. With this one can register custom Tracker and InteractModule for the local player.
      Needs to be called before the game loop starts.
      Parameters:
      handler - handler to add.
      Throws:
      IllegalStateException - When called after the handlers were already processed.
      Since:
      1.3.0
    • isVRInitialized

      boolean isVRInitialized()
      Get whether VR support is currently initialized. This is NOT the same as whether the local player is actively in VR, which can instead be checked with isVRActive().
      Returns:
      Whether VR support is initialized.
      Since:
      1.3.0
    • isVRActive

      boolean isVRActive()
      Get whether the client is actively in VR.
      Returns:
      Whether the client is actively in VR.
      Since:
      1.3.0
    • getLatestRoomPose

      @Nullable VRPose getLatestRoomPose()
      Gets the VR pose representing the player in the room after the most recent poll of VR hardware.
      Returns:
      The most up-to-date VR pose representing the player in the room, or null if the local player isn't in VR.
      Since:
      1.3.0
    • getPostTickRoomPose

      @Nullable VRPose getPostTickRoomPose()
      Gets the VR pose representing the player in the room after the game tick. Note that this pose is gathered AFTER mod loaders' post-tick events.
      Returns:
      The VR pose representing the player in the room post-tick, or null if the local player isn't in VR.
      Since:
      1.3.0
    • getPreTickWorldPose

      @Nullable VRPose getPreTickWorldPose()
      Gets the VR pose representing the player in Minecraft world coordinates before the game tick. If you're unsure which VRPose method to use, you very likely want to use this one. Note that this pose is gathered BEFORE mod loaders' pre-tick events.
      Returns:
      The VR pose representing the player in world space pre-tick, or null if the local player isn't in VR.
      Since:
      1.3.0
    • getPostTickWorldPose

      @Nullable VRPose getPostTickWorldPose()
      Gets the VR pose representing the player in Minecraft world coordinates after the game tick. This is the pose sent to the server, and also used to calculate the pose in getWorldRenderPose(). Note that this pose is gathered AFTER mod loaders' post-tick events.
      Returns:
      The VR pose representing the player in Minecraft space post-tick, or null if the local player isn't in VR.
      Since:
      1.3.0
    • getWorldRenderPose

      @Nullable VRPose getWorldRenderPose()
      Gets the VR pose representing the player in Minecraft world coordinates interpolated for rendering.
      Returns:
      The VR pose representing the player in Minecraft space post-tick interpolated for rendering, or null if the local player isn't in VR.
      Since:
      1.3.0
    • getHistoricalVRPoses

      @Nullable VRPoseHistory getHistoricalVRPoses()
      Returns the history of VR poses for the local player. If one wants historical VR poses for other players and/or on the server, use VRAPI.getHistoricalVRPoses(net.minecraft.world.entity.player.Player) instead.
      Returns:
      The history of VR poses for the player. Will be null if the player isn't in VR.
      Since:
      1.3.0
    • triggerHapticPulse

      void triggerHapticPulse(VRBodyPart bodyPart, float duration, float frequency, float amplitude, float delay)
      Causes a haptic pulse (vibration/rumble) for the specified VRBodyPart, if possible. This function silently fails if called for players not in VR or players who are in seated mode.
      Parameters:
      bodyPart - The VRBodyPart to trigger a haptic pulse on.
      duration - The duration of the haptic pulse in seconds. Note that this number is passed to the underlying VR API used by Vivecraft, and may act with a shorter length than expected beyond very short pulses.
      frequency - The frequency of the haptic pulse in Hz. (might be ignored if the targeted device doesn't support it)
      160 Hz is a safe bet for this number, with Vivecraft's codebase using anywhere from 160 Hz for actions such as a bite on a fishing line, to 1000 Hz for things such as a chat notification.
      amplitude - The amplitude of the haptic pulse. This should be kept between 0 and 1.
      delay - An amount of time to delay until creating the haptic pulse. The majority of the time, one should use 0 here.
      Since:
      1.3.0
    • triggerHapticPulse

      default void triggerHapticPulse(VRBodyPart bodyPart, float duration)
      Causes a haptic pulse (vibration/rumble) at full strength with 160 Hz for the specified VRBodyPart, if possible.
      If one wants more control over the used parameters one should use triggerHapticPulse(VRBodyPart, float, float, float, float) instead.
      This function silently fails if called for players not in VR or players who are in seated mode.
      Parameters:
      bodyPart - The VRBodyPart to trigger a haptic pulse on.
      duration - The duration of the haptic pulse in seconds. Note that this number is passed to the underlying VR API used by Vivecraft, and may act with a shorter length than expected beyond very short pulses.
      Since:
      1.3.0
    • isSeated

      boolean isSeated()
      Get whether the local player is currently configured to be in seated mode when in VR. This doesn't check if VR is active/enabled, it just checks the user setting.
      Returns:
      Whether the local player is currently in seated mode when in VR.
      Since:
      1.3.0
    • isLeftHanded

      boolean isLeftHanded()
      Get whether the local player is currently configured to use left-handed mode when in VR. This doesn't check if VR is active/enabled, it just checks the user setting.
      Returns:
      Whether the local player is playing with left-handed controls when in VR.
      Since:
      1.3.0
    • getFBTMode

      FBTMode getFBTMode()
      Gets the mode used for full-body tracking for the local player. Will return a sane default value if the local player isn't in VR.
      Returns:
      The full-body tracking mode currently in-use or some default value if the local player is not in VR.
      Since:
      1.3.0
    • getWorldScale

      float getWorldScale()
      Get the currently active world scale.
      Returns:
      The currently active world scale.
      Since:
      1.3.0
    • openKeyboard

      boolean openKeyboard(OpenKeyboardContext openKeyboardContext)
      Opens Vivecraft's keyboard, doing nothing if the keyboard is already opened or the provided openKeyboardContext doesn't result in the keyboard opening. Will silently fail if the player isn't in VR.
      Parameters:
      openKeyboardContext - The context to use for opening the keyboard.
      Returns:
      Whether the keyboard is showing after this method was called.
      Since:
      1.3.0
    • closeKeyboard

      boolean closeKeyboard(CloseKeyboardContext closeKeyboardContext)
      Closes Vivecraft's keyboard, doing nothing if the keyboard is already opened or the provided closeKeyboardContext doesn't result in the keyboard closing. Will silently fail if the player isn't in VR.
      Parameters:
      closeKeyboardContext - The context to use for closing the keyboard.
      Returns:
      Whether the keyboard is showing after this method was called.
      Since:
      1.3.0