• 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

76.92
/src/main/scala/com/martomate/hexacraft/world/gen/planner/EntityGroupPlanner.scala
1
package com.martomate.hexacraft.world.gen.planner
2

3
import com.martomate.hexacraft.util.CylinderSize
4
import com.martomate.hexacraft.world.BlocksInWorld
5
import com.martomate.hexacraft.world.block.Blocks
6
import com.martomate.hexacraft.world.chunk.Chunk
7
import com.martomate.hexacraft.world.coord.fp.BlockCoords
8
import com.martomate.hexacraft.world.coord.integer.{BlockRelWorld, ChunkRelWorld}
9
import com.martomate.hexacraft.world.entity.{Entity, EntityFactory}
10
import com.martomate.hexacraft.world.entity.sheep.SheepEntity
11

12
import scala.collection.mutable
13
import scala.util.Random
14

15
class EntityGroupPlanner(world: BlocksInWorld, entityFactory: EntityFactory, mainSeed: Long)(using
16
    CylinderSize,
17
    Blocks
18
) extends WorldFeaturePlanner:
1✔
19
  private val plannedEntities: mutable.Map[ChunkRelWorld, Seq[Entity]] = mutable.Map.empty
1✔
20
  private val chunksPlanned: mutable.Set[ChunkRelWorld] = mutable.Set.empty
21

22
  private val maxEntitiesPerGroup = 7
23

1✔
24
  override def decorate(chunk: Chunk): Unit =
1✔
25
    for
1✔
26
      entities <- plannedEntities.get(chunk.coords)
1✔
27
      entity <- entities
×
28
    do chunk.addEntity(entity)
29

1✔
30
  override def plan(coords: ChunkRelWorld): Unit =
1✔
31
    if !chunksPlanned(coords) then
1✔
32
      val rand = new Random(mainSeed ^ coords.value + 364453868)
1✔
33
      if rand.nextDouble() < 0.01 then plannedEntities(coords) = makePlan(rand, coords)
1✔
34
      chunksPlanned += coords
35

1✔
36
  private def makePlan(rand: Random, coords: ChunkRelWorld): Seq[Entity] =
1✔
37
    val thePlan = mutable.Buffer.empty[Entity]
1✔
38
    val count = rand.nextInt(maxEntitiesPerGroup) + 1
1✔
39
    for _ <- 0 until count do
1✔
40
      val column = world.provideColumn(coords.getColumnRelWorld)
1✔
41
      val cx = rand.nextInt(16)
1✔
42
      val cz = rand.nextInt(16)
1✔
43
      val y = column.terrainHeight(cx, cz)
×
44
      if y >= coords.Y * 16 && y < (coords.Y + 1) * 16 then
×
45
        val groundCoords = BlockCoords(BlockRelWorld(cx, y & 15, cz, coords)).toCylCoords
×
46
        val entityStartPos = groundCoords.offset(0, 0.001f, 0)
×
47
        val entity = entityFactory.atStartPos(entityStartPos)
×
48
        thePlan += entity
1✔
49
    thePlan.toSeq
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