-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayer.go
79 lines (73 loc) · 1.68 KB
/
player.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package mcpiapi
import (
"fmt"
"strconv"
"strings"
)
// Player provides methods to manipulate the player you typed.
type Player struct{
obj object
name string
}
// GetTile returns the world coordinates of the player's location.
func (obj Player) GetTile() (x, y, z int, err error) {
s := "player.getTile(" + obj.name + ")"
x = 0
y = 0
z = 0
var r string
var i int64
r, err = object(obj.obj).sendReceive(s)
if err != nil {
return
}
arr := strings.Split(r, ",")
arr2 := make([]*int, 3)
arr2[0] = &x
arr2[1] = &y
arr2[2] = &z
for index, rs := range arr {
i, err = strconv.ParseInt(rs, 10, 32)
if err != nil {
return
}
*(arr2[index]) = int(i)
}
return
}
// SetTile moves the player the given world coordinates.
func (obj Player) SetTile(x, y, z int) error {
s := fmt.Sprintf("player.setTile(%s,%d,%d,%d)",obj.name, x, y, z)
return object(obj.obj).send(s)
}
// GetPos returns the player's position. Note the the player position
// is more granular than a world position.
func (obj Player) GetPos() (xf, yf, zf float64, err error) {
s := "player.getPos(" + obj.name + ")"
xf = 0.0
yf = 0.0
zf = 0.0
var r string
r, err = object(obj.obj).sendReceive(s)
if err != nil {
return
}
arr := strings.Split(r, ",")
arr2 := make([]*float64, 3)
arr2[0] = &xf
arr2[1] = &yf
arr2[2] = &zf
for index, rs := range arr {
*(arr2[index]), err = strconv.ParseFloat(rs, 64)
if err != nil {
return
}
}
return
}
// SetPos sets the player's position. Note that the player position
// is more granular than a world position.
func (obj Player) SetPos(xf, yf, zf float64) error {
s := fmt.Sprintf("player.setPos(%s,%f,%f,%f)",obj.name, xf, yf, zf)
return object(obj.obj).send(s)
}