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

Martomate / Hexacraft / 7351367576

28 Dec 2023 06:50PM UTC coverage: 51.185% (-0.1%) from 51.312%
7351367576

push

github

Martomate
Refactor: Made Chunk not know if it has been saved to file

9 of 12 new or added lines in 2 files covered. (75.0%)

110 existing lines in 32 files now uncovered.

2829 of 5527 relevant lines covered (51.19%)

0.51 hits per line

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

96.15
/game/src/main/scala/hexacraft/world/Player.scala
1
package hexacraft.world
2

3
import hexacraft.world.block.Block
4
import hexacraft.world.coord.CylCoords
5

6
import com.martomate.nbt.Nbt
7
import org.joml.Vector3d
8

9
class Player(var inventory: Inventory) {
1✔
10
  val bounds = new HexBox(0.2f, -1.65f, 0.1f)
1✔
11
  val velocity = new Vector3d
1✔
12
  val position = new Vector3d
1✔
13
  val rotation = new Vector3d
14
  var flying = false
15
  var selectedItemSlot: Int = 0
16

1✔
17
  def blockInHand: Block = inventory(selectedItemSlot) // TODO: temporary, make inventory system
18

1✔
19
  def toNBT: Nbt.MapTag = {
20
    Nbt
1✔
21
      .makeMap(
1✔
22
        "position" -> Nbt.makeVectorTag(position),
1✔
23
        "rotation" -> Nbt.makeVectorTag(rotation),
1✔
24
        "velocity" -> Nbt.makeVectorTag(velocity),
1✔
25
        "flying" -> Nbt.ByteTag(flying),
1✔
26
        "selectedItemSlot" -> Nbt.ShortTag(selectedItemSlot.toShort),
1✔
27
        "inventory" -> inventory.toNBT
28
      )
29
  }
30
}
31

32
object Player {
1✔
33
  def atStartPos(initialFootCoords: CylCoords): Player = {
1✔
34
    val player = new Player(Inventory.default)
1✔
35
    player.position.set(
36
      initialFootCoords.x,
37
      initialFootCoords.y - player.bounds.bottom,
38
      initialFootCoords.z
39
    )
40
    player
41
  }
42

1✔
43
  def fromNBT(tag: Nbt.MapTag): Player = {
44
    val inventory =
1✔
45
      tag.getMap("inventory") match
1✔
46
        case Some(tag) => Inventory.fromNBT(tag)
1✔
47
        case None      => Inventory.default
48

1✔
49
    val player = new Player(inventory)
UNCOV
50

×
51
    tag.getMap("position").foreach(p => p.setVector(player.position))
1✔
52
    tag.getMap("rotation").foreach(p => p.setVector(player.rotation))
1✔
53
    tag.getMap("velocity").foreach(p => p.setVector(player.velocity))
54

1✔
55
    player.flying = tag.getByte("flying", 0) != 0
1✔
56
    player.selectedItemSlot = tag.getShort("selectedItemSlot", 0)
57

58
    player
59
  }
60
}
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