forked from stefanha/chunkymonkey
-
Notifications
You must be signed in to change notification settings - Fork 16
/
playerdata.go
62 lines (52 loc) · 1.6 KB
/
playerdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package shardserver
import (
"io"
"github.com/huin/chunkymonkey/gamerules"
"github.com/huin/chunkymonkey/proto"
. "github.com/huin/chunkymonkey/types"
)
const (
// Assumed values for size of player axis-aligned bounding box (AAB).
playerAabH = AbsCoord(0.75) // Each side of player.
playerAabY = AbsCoord(2.00) // From player's feet position upwards.
)
// playerData represents a Chunk's knowledge about a player. Only one Chunk has
// this data at a time. This data is occasionally updated from the frontend
// server.
type playerData struct {
entityId EntityId
name string
position AbsXyz
look LookBytes
heldItemId ItemTypeId
// TODO Armor data.
}
func (player *playerData) sendSpawn(writer io.Writer) error {
return proto.WriteNamedEntitySpawn(
writer,
player.entityId, player.name,
player.position.ToAbsIntXyz(),
&player.look,
player.heldItemId,
)
// TODO Armor packet(s).
}
func (player *playerData) sendPositionLook(writer io.Writer) error {
return proto.WriteEntityTeleport(
writer,
player.entityId,
player.position.ToAbsIntXyz(),
&player.look)
}
func (player *playerData) OverlapsItem(item *gamerules.Item) bool {
// TODO note that calling this function repeatedly is not as efficient as it
// could be.
minX := player.position.X - playerAabH
maxX := player.position.X + playerAabH
minZ := player.position.Z - playerAabH
maxZ := player.position.Z + playerAabH
minY := player.position.Y
maxY := player.position.Y + playerAabY
pos := item.Position()
return pos.X >= minX && pos.X <= maxX && pos.Y >= minY && pos.Y <= maxY && pos.Z >= minZ && pos.Z <= maxZ
}