• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Martomate / Hexacraft / 4212765122

pending completion
4212765122

push

github

Martin Jakobsson
Moved block specs from json files to code

51 of 51 new or added lines in 9 files covered. (100.0%)

1609 of 4743 relevant lines covered (33.92%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/scala/com/martomate/hexacraft/game/inventory/GUIBlocksRenderer.scala
1
package com.martomate.hexacraft.game.inventory
2

3
import com.martomate.hexacraft.gui.comp.GUITransformation
4
import com.martomate.hexacraft.renderer.{Shader, Shaders, TextureArray}
5
import com.martomate.hexacraft.world.block.{Block, Blocks}
6
import com.martomate.hexacraft.world.camera.CameraProjection
7
import com.martomate.hexacraft.world.render.{BlockRendererCollection, FlatBlockRenderer}
8

9
import org.joml.{Matrix4f, Vector3f}
10

11
object GUIBlocksRenderer:
×
12
  def withSingleSlot(
13
      blockProvider: () => Block,
×
14
      rendererLocation: () => (Float, Float) = () => (0, 0),
×
15
      brightnessFunc: () => Float = () => 1.0f
16
  )(using Blocks: Blocks): GUIBlocksRenderer =
×
17
    new GUIBlocksRenderer(1, 1)(_ => blockProvider(), rendererLocation, (_, _) => brightnessFunc())
18

×
19
class GUIBlocksRenderer(w: Int, h: Int = 1, separation: Float = 0.2f)(
20
    blockProvider: Int => Block,
21
    rendererLocation: () => (Float, Float) = () => (0, 0),
22
    brightnessFunc: (Int, Int) => Float = (_, _) => 1.0f
23
)(using Blocks: Blocks):
×
24
  private val guiBlockRenderer = new BlockRendererCollection(s => FlatBlockRenderer.forSide(s))
×
25
  private val guiBlockShader: Shader = Shader.get(Shaders.ShaderNames.GuiBlock).get
×
26
  private val guiBlockSideShader: Shader = Shader.get(Shaders.ShaderNames.GuiBlockSide).get
×
27
  private val blockTexture: TextureArray = TextureArray.getTextureArray("blocks")
28

×
29
  private var viewMatrix = new Matrix4f
×
30
  def setViewMatrix(matrix: Matrix4f): Unit = viewMatrix = matrix
31

×
32
  private var cameraProjection = new CameraProjection(70f, 16f / 9f, 0.02f, 1000)
×
33
  def onWindowAspectRatioChanged(aspectRatio: Float): Unit =
34
    cameraProjection.aspect = aspectRatio
×
35
    cameraProjection.updateProjMatrix()
36

×
37
  updateContent()
38

×
39
  def render(transformation: GUITransformation): Unit =
×
40
    guiBlockShader.setUniformMat4("viewMatrix", viewMatrix)
×
41
    guiBlockSideShader.setUniformMat4("viewMatrix", viewMatrix)
42

×
43
    guiBlockShader.setUniformMat4("projMatrix", cameraProjection.matrix)
×
44
    guiBlockSideShader.setUniformMat4("projMatrix", cameraProjection.matrix)
45

×
46
    blockTexture.bind()
47

×
48
    for (side <- 0 until 8)
×
49
      val sh = if side < 2 then guiBlockShader else guiBlockSideShader
×
50
      sh.enable()
×
51
      sh.setUniform1i("side", side)
×
52
      guiBlockRenderer.renderBlockSide(side)
53

×
54
  def updateContent(): Unit =
×
55
    val (xOff, yOff) = rendererLocation()
56

×
57
    for (side <- 0 until 8)
×
58
      guiBlockRenderer.updateContent(side, 9 * 9) { buf =>
×
59
        for (y <- 0 until h)
×
60
          for (x <- 0 until w)
×
61
            val blockToDraw = blockProvider(x + y * w)
×
62
            if blockToDraw.canBeRendered
63
            then
×
64
              buf.putFloat(x * separation + xOff)
×
65
              buf.putFloat(y * separation + yOff)
×
66
              buf.putInt(Blocks.textures(blockToDraw.name)(side))
×
67
              buf.putFloat(
68
                1.0f
69
              ) // blockInHand.blockHeight(new BlockState(BlockRelWorld(0, 0, 0, world), blockInHand)))
×
70
              buf.putFloat(1) // brightnessFunc(x, y))
71
      }
72

×
73
  def unload(): Unit =
×
74
    guiBlockRenderer.unload()
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc