• 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

41.51
/game/src/main/scala/hexacraft/world/entity/sheep.scala
1
package hexacraft.world.entity
2

3
import hexacraft.renderer.TextureSingle
4
import hexacraft.world.{BlocksInWorld, CollisionDetector, CylinderSize, HexBox}
5

6
import com.martomate.nbt.Nbt
7
import hexacraft.world.coord.{BlockCoords, CylCoords}
8
import org.joml.Vector3f
9

10
class SheepEntity(
11
    model: EntityModel,
12
    initData: EntityBaseData,
13
    private val ai: EntityAI
14
)(using CylinderSize)
15
    extends Entity(initData, model) {
×
16
  override val boundingBox: HexBox = new HexBox(0.4f, 0, 0.75f)
17

×
18
  override def tick(world: BlocksInWorld, collisionDetector: CollisionDetector): Unit = {
×
19
    ai.tick(world, data, boundingBox)
×
20
    data.velocity.add(ai.acceleration())
21

22
    data.velocity.x *= 0.9
23
    data.velocity.z *= 0.9
24

×
25
    EntityPhysicsSystem(world, collisionDetector).update(data, boundingBox)
×
26
    model.tick()
27
  }
28

×
29
  override def toNBT: Nbt.MapTag =
×
30
    super.toNBT
×
31
      .withField("type", Nbt.StringTag("sheep"))
×
32
      .withField("ai", ai.toNBT)
33
}
34

35
class SheepFactory(makeModel: () => EntityModel) extends EntityFactory:
×
36
  override def atStartPos(pos: CylCoords)(using CylinderSize): SheepEntity =
×
37
    val model = makeModel()
×
38
    new SheepEntity(model, new EntityBaseData(position = pos), SimpleWalkAI.create)
39

×
40
  override def fromNBT(tag: Nbt.MapTag)(using CylinderSize): SheepEntity =
×
41
    val model = makeModel()
×
42
    val baseData = EntityBaseData.fromNBT(tag)
43
    val ai: EntityAI =
×
44
      tag.getMap("ai") match
×
45
        case Some(t) => SimpleWalkAI.fromNBT(t)
×
46
        case None    => SimpleWalkAI.create
×
47
    new SheepEntity(model, baseData, ai)
48

49
class SheepEntityModel(
50
    val head: BasicEntityPart,
51
    val body: BasicEntityPart,
52
    val frontRightLeg: BasicEntityPart,
53
    val frontLeftLeg: BasicEntityPart,
54
    val backRightLeg: BasicEntityPart,
55
    val backLeftLeg: BasicEntityPart,
56
    val textureName: String
UNCOV
57
) extends EntityModel:
×
58
  override val parts: Seq[EntityPart] = Seq(head, body, frontRightLeg, frontLeftLeg, backRightLeg, backLeftLeg)
59

1✔
60
  private val animation = new SheepAnimation(this)
61

×
62
  override def tick(): Unit = animation.tick()
63

×
64
  override def texture: TextureSingle =
×
65
    TextureSingle.getTexture(
×
66
      "textures/entities/" + textureName
67
    )
68

69
class SheepAnimation(model: SheepEntityModel):
70
  var time = 0f
71

×
72
  def tick(): Unit =
73
    time += 1f / 60
74

×
75
    val phase = time * 2 * math.Pi
76

×
77
    model.frontRightLeg.rotation.z = -0.5f * math.sin(phase).toFloat
×
78
    model.frontLeftLeg.rotation.z = 0.5f * math.sin(phase).toFloat
79

×
80
    model.backRightLeg.rotation.z = 0.5f * math.sin(phase).toFloat
×
81
    model.backLeftLeg.rotation.z = -0.5f * math.sin(phase).toFloat
82

83
object SheepEntityModel:
1✔
84
  private def makeHexBox(r: Int, b: Float, h: Int): HexBox =
1✔
85
    HexBox(r / 32f * 0.5f, b / 32f * 0.5f, (h + b) / 32f * 0.5f)
86

1✔
87
  private def makePartPosition(xp: Double, yp: Double, zp: Double): BlockCoords.Offset =
88
    BlockCoords.Offset(xp / 32.0, yp / 32.0, zp / 32.0)
89

1✔
90
  def create(textureName: String): SheepEntityModel =
91
    val legLength = 32
92
    val legRadius = 6
93
    val bodyLength = 48
94
    val bodyRadius = 16
95
    val headDepth = 16
96
    val headRadius = 12
97

98
    val headOffset = 2
99
    val headYOffset = 2
100
    val legOffset = bodyRadius * 0.25f / CylinderSize.y60
101
    val legYOffset = 3
102

103
    val px = 2.0 / 3
104
    val pz = 1.0 / 3
105

1✔
106
    val headBounds = makeHexBox(headRadius, -headDepth / 2f, headDepth)
1✔
107
    val bodyBounds = makeHexBox(bodyRadius, 0, bodyLength)
1✔
108
    val legBounds = makeHexBox(legRadius, 0, legLength)
109

110
    val headDistXZ = 0.5 * bodyLength + headOffset
111
    val bodyDist = 0.5 * bodyLength
112
    val legDist = 0.5 * bodyLength - legRadius
113

114
    val headY = legLength + legYOffset + (headRadius + headYOffset) * CylinderSize.y60
115
    val bodyY = legLength + legYOffset
116
    val legY = legLength
117

1✔
118
    val headPos = makePartPosition(headDistXZ * px, headY, -headDistXZ * pz).toCylCoordsOffset
1✔
119
    val bodyPos = makePartPosition(-bodyDist * px, bodyY, bodyDist * pz).toCylCoordsOffset
1✔
120
    val frontRightLegPos = makePartPosition(legDist * px, legY, legOffset - legDist * pz).toCylCoordsOffset
1✔
121
    val frontLeftLegPos = makePartPosition(legDist * px, legY, -legOffset - legDist * pz).toCylCoordsOffset
1✔
122
    val backRightLegPos = makePartPosition(-legDist * px, legY, legOffset + legDist * pz).toCylCoordsOffset
1✔
123
    val backLeftLegPos = makePartPosition(-legDist * px, legY, -legOffset + legDist * pz).toCylCoordsOffset
124

1✔
125
    val pi = math.Pi.toFloat
126

1✔
127
    new SheepEntityModel(
1✔
128
      head = BasicEntityPart(headBounds, headPos, Vector3f(0, pi / 2, pi / 2), (0, 168)),
1✔
129
      body = BasicEntityPart(bodyBounds, bodyPos, Vector3f(0, pi / 2, -pi / 2), (0, 88)),
1✔
130
      frontRightLeg = BasicEntityPart(legBounds, frontRightLegPos, Vector3f(pi, 0, 0), (36, 44)),
1✔
131
      frontLeftLeg = BasicEntityPart(legBounds, frontLeftLegPos, Vector3f(pi, 0, 0), (0, 44)),
1✔
132
      backRightLeg = BasicEntityPart(legBounds, backRightLegPos, Vector3f(pi, 0, 0), (36, 0)),
1✔
133
      backLeftLeg = BasicEntityPart(legBounds, backLeftLegPos, Vector3f(pi, 0, 0), (0, 0)),
134
      textureName
135
    )
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