Interface IRenderer

All Superinterfaces:
IDisposable

public interface IRenderer extends IDisposable
The graphics context to interact with OpenGL as well as a multitude of game-provided rendering methods. To access these methods, use the IRenderer object given to you in render methods or access IGameInstance.getRenderer()
  • Method Details

    • setDefaultProgram

      @ApiInternal void setDefaultProgram(IShaderProgram program)
      Sets the IShaderProgram that the game should fall back to when setProgram(IShaderProgram) is called with a null parameter. This should only be used internally to set the world and gui shaders.
      Parameters:
      program - The new default shader program
    • addTexturedRegion

      void addTexturedRegion(ITexture texture, float x, float y, float x2, float y2, float x3, float y3, float x4, float y4, float srcX, float srcY, float srcX2, float srcY2, int[] light, int filter)
      Adds a certain region of a texture to this renderer. This method gets called by all ITexture.draw(float, float) methods, so using those will be more convenient in most cases.
      Parameters:
      texture - The texture to set
      x - The top left x coordinate
      y - The top left y coordinate
      x2 - The top right x coordinate
      y2 - The top right y coordinate
      x3 - The bottom right x coordinate
      y3 - The bottom right y coordinate
      x4 - The bottom left x coordinate
      y4 - The bottom left y coordinate
      srcX - The top left x coordinate of the texture
      srcY - The top left y coordinate of the texture
      srcX2 - The bottom right x coordinate of the texture
      srcY2 - The bottom right y coordinate of the texture
      light - The light that the four corners of the drawn region should interpolate between, or null if there should be no light influence
      filter - A filter color to modify this texture by
      See Also:
    • addTriangle

      void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3, int color1, int color2, int color3, float u1, float v1, float u2, float v2, float u3, float v3)
      Adds a triangle to this renderer. This method gets called by addTexturedRegion(ITexture, float, float, float, float, float, float, float, float, float, float, float, float, int[], int) twice to draw the two triangles of the square (or square-ish) region.
      Parameters:
      x1 - The first x coordinate
      y1 - The first y coordinate
      x2 - The second x coordinate
      y2 - The second y coordinate
      x3 - The third x coordinate
      y3 - The third y coordinate
      color1 - The color at the first corner
      color2 - The color at the second corner
      color3 - The color at the third corner
      u1 - The first texture x
      v1 - The first texture y
      u2 - The second texture x
      v2 - The second texture y
      u3 - The third texture x
      v3 - The third texture y
      See Also:
    • put

      IRenderer put(float f)
      Puts a single vertex component into this renderer and returns it for convenience
      Parameters:
      f - The component to add
      Returns:
      This renderer
    • addVertex

      void addVertex(float x, float y, int color, float u, float v)
      Puts a single vertex into this renderer. This method gets called three times by addTriangle(float, float, float, float, float, float, int, int, int, float, float, float, float, float, float) to add the three vertices for the three corners.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      color - The color
      u - The texture x
      v - The texture y
      See Also:
    • begin

      @ApiInternal void begin()
      Begins rendering with this renderer. This method is internal and there should not be any reasons for a mod to call it.
    • end

      @ApiInternal void end()
      Finishes rendering with this renderer and flushes the current rendering context. This method is internal and there should not be any reasons for a mod to call it.
    • flush

      @ApiInternal void flush()
      Flushes the current rendering context, rendering everything that has been added to the renderer since the last call to this method. This method is internal and there should not be any reasons for a mod to call it.
    • pushMatrix

      void pushMatrix()
    • popMatrix

      void popMatrix()
    • rotate

      void rotate(float angle)
      Rotates this renderer's rendering context by the given angle. This will only affect any vertices that are added to this renderer after calling this method.
      Parameters:
      angle - The angle
    • translate

      void translate(float x, float y)
      Translates this renderer's origin by the given amount. This will only affect any vertices that are added to this renderer after calling this method.
      Parameters:
      x - The origin x
      y - The origin y
    • scale

      void scale(float scale)
      Scales the renderer in both axes by the given amount. This will only affect any vertices that are added to this renderer after calling this method.
      Parameters:
      scale - The scale
    • scale

      void scale(float x, float y)
      Scales the renderer by the given amount. This will only affect any vertices that are added to this renderer after calling this method.
      Parameters:
      x - The x scale
      y - The y scale
    • resetMatrix

      void resetMatrix()
      Resets this renderer's translation, rotation, scale, mirrored states and texture origin back to their default values.
    • getProgram

      IShaderProgram getProgram()
      Returns:
      The renderer's current shader program, set using setProgram(IShaderProgram)
    • setProgram

      void setProgram(IShaderProgram program)
      Sets the IShaderProgram that the renderer should use to draw. Calling this method while the renderer is active will cause the current vertices to be flushed and rendered with the last set shader program.
      Parameters:
      program - The new shader program
    • getTexture

      ITexture getTexture()
      Returns:
      The renderer's current texture, set using setTexture(ITexture)
    • setTexture

      void setTexture(ITexture texture)
      Sets the ITexture that the renderer should render any vertices with. Calling this method while the renderer is active will cause the current vertices to be flushed and rendererd with the last set texture.
      Parameters:
      texture - The new texture
    • renderSlotInGui

      void renderSlotInGui(IGameInstance game, IAssetManager manager, ItemInstance slot, float x, float y, float scale, boolean hovered, boolean canPlaceInto)
      Renders a slot. This displays the (by default) green box based on the gui color as well as the item inside and the amount. To make a slot that has functionality, use ItemContainer to create functioning slots.
      Parameters:
      game - The game instance
      manager - The asset manager
      slot - The content of the slot to draw
      x - The x coordinate
      y - The y coordinate
      scale - The scale
      hovered - If the slot is currently being hovered or not. If this value is true, then the slot will be rendered with a slightly brighter color
      canPlaceInto - If the slot can contain the item that is currently on the cursor. If this value is true, then the slot will be rendered in grayscale
    • renderSlotInGui

      void renderSlotInGui(IGameInstance game, IAssetManager manager, ItemInstance slot, float x, float y, float scale, boolean hovered, boolean canPlaceInto, boolean renderBackground, int colorOverride)
      Renders a slot with additional arguments
      Parameters:
      game - the game instance
      manager - the asset manager
      slot - the item instance to put into the slot
      x - the x coordinate
      y - the y coordinate
      scale - scale
      hovered - can it be hovered
      canPlaceInto - can it placed into it
      renderBackground - Should the slot overlay be rendered? Usually true.
      colorOverride - What color should the slot be? Usually Settings.guiColor
    • renderItemInGui

      void renderItemInGui(IGameInstance game, IAssetManager manager, ItemInstance slot, float x, float y, float scale, int color)
      Renders an item and its amount. This is similar to renderSlotInGui(IGameInstance, IAssetManager, ItemInstance, float, float, float, boolean, boolean), only that it doesn't render the box below the item.
      Parameters:
      game - The game instance
      manager - The asset manager
      slot - The item to draw
      x - The x coordinate
      y - The y coordinate
      scale - The scale
      color - The color to filter the item's renderer with
    • renderItemInGui

      void renderItemInGui(IGameInstance game, IAssetManager manager, ItemInstance slot, float x, float y, float scale, int color, boolean displayAmount, boolean displayDurability)
      Renders an item and its amount. This is similar to renderSlotInGui(IGameInstance, IAssetManager, ItemInstance, float, float, float, boolean, boolean), only that it doesn't render the box below the item.
      Parameters:
      game - The game instance
      manager - The asset manager
      slot - The item to draw
      x - The x coordinate
      y - The y coordinate
      scale - The scale
      color - The color to filter the item's renderer with
      displayAmount - If the amount of items in this instance should be displayed as a little number below the item
      displayDurability - If the durability of the item should be displayed
    • describeItem

      void describeItem(IGameInstance game, IAssetManager manager, ItemInstance instance, boolean isRealItem)
      Renders an item's hover over information on the mouse cursor position. Additionally, it draws the isItemInfoDebug() text and also fires the TooltipEvent.
      Parameters:
      game - The game instance
      manager - The asset manager
      instance - The item whose information to draw
      isRealItem - Does the player own the item or is it just a preview in a GUI?
    • drawHoverInfoAtMouse

      void drawHoverInfoAtMouse(IGameInstance game, IAssetManager manager, boolean firstLineOffset, int maxLength, String... text)
      Draws a hovering information at the mouse's position using the specified text
      Parameters:
      game - The game instance
      manager - The asset manager
      firstLineOffset - If the first line should have a bit of a gap below it making it act as a "headline"
      maxLength - The maximum length before the tooltip wraps into the next line
      text - The array of lines of text to draw
    • drawHoverInfoAtMouse

      void drawHoverInfoAtMouse(IGameInstance game, IAssetManager manager, boolean firstLineOffset, int maxLength, List<String> text)
      Draws a hovering information at the mouse's position using the specified text
      Parameters:
      game - The game instance
      manager - The asset manager
      firstLineOffset - If the first line should have a bit of a gap below it making it act as a "headline"
      maxLength - The maximum length before the tooltip wraps into the next line
      text - The list of lines of text to draw
    • drawHoverInfo

      void drawHoverInfo(IGameInstance game, IAssetManager manager, float x, float y, float scale, boolean firstLineOffset, boolean canLeaveScreen, int maxLength, List<String> text)
      Draws a hovering information at the specified position using the specified text
      Parameters:
      game - The game instance
      manager - The asset manager
      x - The x position
      y - The y position
      scale - The scale of the tooltip
      firstLineOffset - If the first line should have a bit of a gap below it making it act as a "headline"
      canLeaveScreen - If the tooltip can leave the screen or should stop at the borders
      maxLength - The maximum length before the tooltip wraps into the next line
      text - The list of lines of text to draw
    • addEmptyRect

      void addEmptyRect(float x, float y, float width, float height, int color)
      Draws a colored, unfilled rectangle at the specified x and y coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      width - The width
      height - The height
      color - The color
    • addEmptyRect

      void addEmptyRect(float x, float y, float width, float height, float lineWidth, int color)
      Draws a colored, unfilled rectangle at the specified x and y coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      width - The width
      height - The height
      lineWidth - The width of the outlines
      color - The color
    • addFilledRect

      void addFilledRect(float x, float y, float width, float height, int color)
      Draws a colored, filled rectangle at the spcified x and y coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
      width - The width
      height - The height
      color - The color
    • activateTextureBank

      void activateTextureBank(TextureBank bank)
      Activates a certain texture bank. This can be used to draw from multiple textures at the same time, however it requires a custom shader to do so.
      Parameters:
      bank - The texture bank to read/write to and from
    • unbindTexture

      void unbindTexture()
      Unbinds the currently bound texture
    • unbindAllTextures

      void unbindAllTextures()
      Unbinds all currently bound textures in all banks
    • unbindVAO

      void unbindVAO()
      Unbinds the currently bound vao
    • unbindVBO

      void unbindVBO()
      Unbinds the currently bound vbo
    • unbindShaderProgram

      void unbindShaderProgram()
      Unbinds the currently bound shader program
    • createVAO

      IVAO createVAO()
      Creates a new vao for any modder to use
      Returns:
      A new vao
    • createVBO

      IVBO createVBO(boolean isStatic)
      Creates a new vbo for any modder to use
      Parameters:
      isStatic - Wether or not this vbo should use GL15.GL_STATIC_DRAW or GL15.GL_DYNAMIC_DRAW
      Returns:
      A new vbo
    • calcScales

      @ApiInternal void calcScales()
      Calculates the gui and world scale. This is an internal method that should not be called by modders.
    • getDisplayRatio

      float getDisplayRatio()
      Gets the display's ratio as a float. For example, if the window's current display ratio was 16/9, that is the value that this method would return.
      Returns:
      The display ratio
    • getGuiScale

      float getGuiScale()
      Returns:
      The scale with which the gui is currently being rendered. This factors in both the gui scale option and the getDisplayRatio().
    • getWorldScale

      float getWorldScale()
      Returns:
      The scale with which the world is currently being rendered. This factors in both the world scale option and the getDisplayRatio().
    • getWidthInWorld

      float getWidthInWorld()
      Returns:
      The width of the currently visible area of the world, in pixels.
      See Also:
    • getHeightInWorld

      float getHeightInWorld()
      Returns:
      The height of the currently visible area of the world, in pixels.
      See Also:
    • getWidthInGui

      float getWidthInGui()
      Returns:
      The width of the currently visible area of a gui, in pixels. This is IGameInstance.getWidth() multiplied by getGuiScale().
      See Also:
    • getHeightInGui

      float getHeightInGui()
      Returns:
      The height of the currently visible area of a gui, in pixels. This is IGameInstance.getHeight() multiplied by getGuiScale().
      See Also:
    • getMouseInGuiX

      float getMouseInGuiX()
      Returns:
      The y position of the mouse on gui scale level
      See Also:
    • getMouseInGuiY

      float getMouseInGuiY()
      Returns:
      The y position of the mouse on gui scale level
      See Also:
    • isDebug

      boolean isDebug()
      Returns:
      If the renderer is currently in debug mode, meaning the debug menu with a lot of additional information is open. This is activated by pressing F1.
    • isItemInfoDebug

      boolean isItemInfoDebug()
      Returns:
      If the renderer is currently in item info debug mode, meaning hovering over an item in an inventory will reveal additional information about its status. This is activated by pressing F5.
    • isChunkBorderDebug

      boolean isChunkBorderDebug()
      Returns:
      If the renderer is currently in chunk border debug mode, meaning that the borders of chunks will be shown in the world as green lines. This is activated by pressing F6.
    • isGuiDebug

      boolean isGuiDebug()
      Returns:
      If the renderer is currently in gui debug mode, meaning that opening and looking at a gui will show the bounding boxes of all of their components, along with their names and positions. This is activated by pressing F4.
    • isLineDebug

      boolean isLineDebug()
      Returns:
      If the renderer is currently in line debug mode, meaning that it will render a direct line between the drawn vertices rather than actually filling them with color or a texture. This is activated by pressing F2.
    • isBiomeDebug

      boolean isBiomeDebug()
      Returns:
      If the renderer is currently in biome debug mode, meaning that semi-transparent colored squares will be shown over every tile indicating its biome.
    • isHeightDebug

      boolean isHeightDebug()
      Returns:
      If the renderer is currently in height debug mode, meaning that a line will be shown on every tile to indicate the height of that position in the chunk.
    • isBoundBoxDebug

      boolean isBoundBoxDebug()
    • isCullingDebug

      boolean isCullingDebug()
    • getMousedTileX

      double getMousedTileX()
      Returns the x position of the tile that the mouse is currently over. Rounding this value down using something like Util.floor(double) will reveal the tile's grid position in the world, whereas the decimal will reveal the percentage of how far into the tile the mouse cursor is.
      Returns:
      The x position of the moused tile
    • getMousedTileY

      double getMousedTileY()
      Returns the y position of the tile that the mouse is currently over. Rounding this value down using something like Util.floor(double) will reveal the tile's grid position in the world, whereas the decimal will reveal the percentage of how far into the tile the mouse cursor is.
      Returns:
      The y position of the moused tile
    • getFlushes

      int getFlushes()
      Returns:
      The amount of flushes that this renderer has done since the last render frame.
      See Also:
    • backgroundColor

      void backgroundColor(int color)
      Sets the background color for this renderer to clear the screen with. This is used for the sky and the main menu background's color.
      Parameters:
      color - The color
    • getVertices

      FloatBuffer getVertices()
      Gets the current vertices that this renderer is about to render. These should only be modified using put(float).
      Returns:
      The vertices
    • getVertexAmount

      int getVertexAmount()
      Returns:
      The amount of vertices that are currently in the buffer
    • getCameraX

      double getCameraX()
    • getCameraY

      double getCameraY()
    • getMatrixStack

      MatrixStack getMatrixStack()