summaryrefslogtreecommitdiff
path: root/nbt/helpers.go
blob: 3f2413312271fa62989a272eeb22b04050131700 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package nbt

import (
	"errors"
)

// Errors for TagCompound.Get* functions
var (
	NotFound  = errors.New("Key not found in TagCompound")
	WrongType = errors.New("Tag has wrong type.")
)

func (tc TagCompound) GetByte(key string) (byte, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Byte {
		return 0, WrongType
	}
	return t.Payload.(byte), nil
}
func (tc TagCompound) GetShort(key string) (int16, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Short {
		return 0, WrongType
	}
	return t.Payload.(int16), nil
}
func (tc TagCompound) GetInt(key string) (int32, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Int {
		return 0, WrongType
	}
	return t.Payload.(int32), nil
}
func (tc TagCompound) GetLong(key string) (int64, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Long {
		return 0, WrongType
	}
	return t.Payload.(int64), nil
}
func (tc TagCompound) GetFloat(key string) (float32, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Float {
		return 0, WrongType
	}
	return t.Payload.(float32), nil
}
func (tc TagCompound) GetDouble(key string) (float64, error) {
	t, ok := tc[key]
	if !ok {
		return 0, NotFound
	}
	if t.Type != TAG_Double {
		return 0, WrongType
	}
	return t.Payload.(float64), nil
}
func (tc TagCompound) GetByteArray(key string) ([]byte, error) {
	t, ok := tc[key]
	if !ok {
		return nil, NotFound
	}
	if t.Type != TAG_Byte_Array {
		return nil, WrongType
	}
	return t.Payload.([]byte), nil
}
func (tc TagCompound) GetString(key string) (string, error) {
	t, ok := tc[key]
	if !ok {
		return "", NotFound
	}
	if t.Type != TAG_String {
		return "", WrongType
	}
	return t.Payload.(string), nil
}
func (tc TagCompound) GetList(key string) (TagList, error) {
	t, ok := tc[key]
	if !ok {
		return TagList{}, NotFound
	}
	if t.Type != TAG_List {
		return TagList{}, WrongType
	}
	return t.Payload.(TagList), nil
}
func (tc TagCompound) GetCompound(key string) (TagCompound, error) {
	t, ok := tc[key]
	if !ok {
		return nil, NotFound
	}
	if t.Type != TAG_Compound {
		return nil, WrongType
	}
	return t.Payload.(TagCompound), nil
}
func (tc TagCompound) GetIntArray(key string) ([]int32, error) {
	t, ok := tc[key]
	if !ok {
		return nil, NotFound
	}
	if t.Type != TAG_Int_Array {
		return nil, WrongType
	}
	return t.Payload.([]int32), nil
}