Interface IGameInstance

All Superinterfaces:
IMod

public interface IGameInstance extends IMod
The game instance that can be used to interact with various game-related values and acces things like IRenderer and IAssetManager. Notice that this instance represents both the server and the client, however some methods that are not implemented on the dedicated server (like graphics and rendering methods) will throw an UnsupportedOperationException. To access any methods from this class, use RockBottomAPI.getGame().
  • Method Details

    • startWorld

      @ApiInternal void startWorld(File worldFile, WorldInfo info, boolean isNewlyCreated)
    • joinWorld

      @ApiInternal void joinWorld(DataSet playerSet, WorldInfo info, ResourceName subName, DataSet worldData, DynamicRegistryInfo regInfo)
    • changeWorld

      @ApiInternal void changeWorld(ResourceName subName, DataSet worldData)
    • quitWorld

      @ApiInternal void quitWorld()
    • openIngameMenu

      @ApiInternal void openIngameMenu()
    • enqueueAction

      <T> void enqueueAction(BiConsumer<IGameInstance,T> action, T object)
      Enqueues an action to be executed next tick. This is done synchronously, meaning that you can call this function from a different thread without causing concurrent modification issues.
      Type Parameters:
      T - A user-chosen generic typ for the passed additional object
      Parameters:
      action - The action to be executed
      object - An object you can pass for later use in the action consumer
      See Also:
    • getDataManager

      IDataManager getDataManager()
      Gets the IDataManager of the current game instance. This can be used for accessing locations on disk like the save folder or the game folder itself. Additionally, it can save IJsonSettings.
      Returns:
      The data manager
    • restart

      @ApiInternal void restart()
    • getSettings

      Settings getSettings()
      Gets the Settings of the current game instance. These store all of the values that can be edited in the settings gui.
      Returns:
      The settings
    • getPlayer

      Gets the AbstractPlayerEntity of the current game instance. Note that this is not implemented on the dedicated server.
      Returns:
      The player
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getGuiManager

      IGuiManager getGuiManager()
      Gets the IGuiManager of the current game instance. This can be used to open Guis and fade the screen in and out. Note that this is not implemented on the dedicated server.
      Returns:
      The gui manager
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getInteractionManager

      IInteractionManager getInteractionManager()
      Gets the IInteractionManager of the current game instance. This can be used to access the positions in the world that the player is currently breaking. Note that this is not implemented on the dedicated server.
      Returns:
      The interaction manager
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getChatLog

      IChatLog getChatLog()
      Gets the IChatLog of the current game instance. This can be used to write messages and commands into the in-game chat.
      Returns:
      The chat log
    • getWorld

      IWorld getWorld()
      Gets the IWorld of the current game instance. In the title screen, this value is unassigned.
      Returns:
      The world
    • getPlayerWorld

      IWorld getPlayerWorld()
      Gets the IWorld that the player is currently in. If the player is in the normal world, then this call will be equal to getWorld(). If the player is in a sub world, then this call will return the sub world. Notice that, on the client side, this call will always return the same as getWorld().
      Returns:
      The player's world
    • getAssetManager

      IAssetManager getAssetManager()
      Gets the IAssetManager of the current game instance. This can be used to get graphics, sounds and various other assets. Note that this is not implemented on the dedicated server.
      Returns:
      The asset manager
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getRenderer

      IRenderer getRenderer()
      Gets the IRenderer context of the current game instance. This can be used to draw various shapes and interact with the OpenGL context.
      Returns:
      The graphics context
    • getParticleManager

      IParticleManager getParticleManager()
      Gets the IParticleManager of the current game instance. This can be used to spawn and render particles. Note that this is not implemented on the dedicated server.
      Returns:
      The particle manager
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getUniqueId

      UUID getUniqueId()
      Gets the UUID of the current game instance. This will be applied to the player as soon as a world starts. Note that the dedicated server does not have a unique id. In case the current unique id does not exist for one reason or another, the getDefaultUniqueId() will be returned.
      Returns:
      The game's unique id
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getDefaultUniqueId

      UUID getDefaultUniqueId()
      Gets the default UUID that will be applied to the game while there is no logged in account. This is also the UUID that the default player will be saved to disk with.
      Returns:
      The default unique id
    • getTpsAverage

      @ApiInternal int getTpsAverage()
    • getFpsAverage

      @ApiInternal int getFpsAverage()
    • getClassLoader

      URLClassLoader getClassLoader()
      Gets the URLClassLoader that the game is using to load its own classes and classes from jars out of the mods folder.
      Returns:
      The class loader
    • getResourceStream

      InputStream getResourceStream(String s)
      Gets an input stream based on a resource available to the game using the getClassLoader(). This is equivalent to Class.getResourceAsStream(String), however it will include all resources loaded by the class loader, even content pack and mod resources.
      Parameters:
      s - The location
      Returns:
      An input stream or null if there is nothing at the specified location
    • getResourceURL

      URL getResourceURL(String s)
      Gets a url based on a resource available to the game using the getClassLoader(). This is equivalent to Class.getResource(String), however it will include all resources loaded by the class loader, even content pack and mod resources.
      Parameters:
      s - The location
      Returns:
      A url or null if there is nothing at the specified location
    • setFullscreen

      @ApiInternal void setFullscreen(boolean fullscreen)
    • getTotalTicks

      int getTotalTicks()
      Gets the total amount of ticks the game has been running for. Note that, when closing down the game and opening it back up, this value will be reset.
      Returns:
      The total ticks
    • getPlayerDesign

      IPlayerDesign getPlayerDesign()
      Gets the IPlayerDesign that defines what the player looks like. Note that this is not implemented on the dedicated server.
      Returns:
      The player design
      Throws:
      UnsupportedOperationException - on the dedicated server
    • setPlayerDesign

      @ApiInternal void setPlayerDesign(String jsonString)
    • isDedicatedServer

      boolean isDedicatedServer()
      Gets if the game is currently in dedicated server mode. This will be true when "--server" is appended to the launch arguments.
      Returns:
      If the instance is a dedicated server.
    • getInput

      IInputHandler getInput()
      Gets the IInputHandler of the current game instance. This is a class that allows for the polling of inputs. Note that, when using Keybind, Keybind.isDown() and Keybind.isPressed() should be used instead. Note that this is not implemented on the dedicated server.
      Returns:
      The input manager
      Throws:
      UnsupportedOperationException - on the dedicated server
    • exit

      @ApiInternal void exit()
    • getToaster

      IToaster getToaster()
      Gets the IToaster of the current game instance. This is the system that displays BasicToast objects, which are the little pop-up messages in the top left. Note that this is not implemented on the dedicated server.
      Returns:
      The toaster
      Throws:
      UnsupportedOperationException - on the dedicated server
    • getWidth

      int getWidth()
      Gets the current width of the window in pixels
      Returns:
      The width
      Throws:
      UnsupportedOperationException - on the dedicated server
      See Also:
    • getHeight

      int getHeight()
      Gets the current height of the window in pixels
      Returns:
      The height
      Throws:
      UnsupportedOperationException - on the dedicated server
      See Also:
    • getWindow

      long getWindow()
      Gets the GLFW pointer to the window that is open.
      Returns:
      The window pointer
      Throws:
      UnsupportedOperationException - on the dedicated server
    • isRunning

      boolean isRunning()
      Returns:
      True if the game's update loop should continue. This can be useful when working with different Thread instances that loop.
    • getPlayerCap

      @ApiInternal int getPlayerCap()
    • getTickDelta

      float getTickDelta()
      Returns:
      The amount of ticks that have passed since the last tick. This will always return 0 when called from an update loop, but can return values between 0 and 1 when called from a rendering loop, as there are more FPS than TPS.