minecraft - nbt/lists_end.go
1 package nbt
2
3 import "strconv"
4
5 // ListEnd satisfies the List interface for a list of Ends
6 type ListEnd uint32
7
8 // Equal satisfies the equaler.Equaler interface, allowing for types to be
9 // checked for equality
10 func (l ListEnd) Equal(e interface{}) bool {
11 m, ok := e.(List)
12 return ok && m.TagType() == TagEnd && ListEnd(m.Len()) == l
13 }
14
15 // Copy simply returns a deep-copy the the data
16 func (l ListEnd) Copy() Data {
17 return &l
18 }
19
20 func (l ListEnd) String() string {
21 return strconv.Itoa(int(l)) + " entries of type End"
22 }
23
24 // Type returns the TagID of the data
25 func (ListEnd) Type() TagID {
26 return TagList
27 }
28
29 // TagType returns the TagID of the type of tag this list contains
30 func (ListEnd) TagType() TagID {
31 return TagEnd
32 }
33
34 // Set does nothing as it's not applicable for ListEnd
35 func (l ListEnd) Set(_ int, d Data) error {
36 return nil
37 }
38
39 // Get returns an end{}
40 func (ListEnd) Get(_ int) Data {
41 return end{}
42 }
43
44 // Append adds to the list
45 func (l *ListEnd) Append(d ...Data) error {
46 *l += ListEnd(len(d))
47 return nil
48 }
49
50 // Insert adds to the list
51 func (l *ListEnd) Insert(_ int, d ...Data) error {
52 *l += ListEnd(len(d))
53 return nil
54 }
55
56 // Remove removes from the list
57 func (l *ListEnd) Remove(i int) {
58 if ListEnd(i) < *l {
59 *l--
60 }
61 }
62
63 // Len returns the length of the List
64 func (l ListEnd) Len() int {
65 return int(l)
66 }
67
68 // ListEnd returns the list as a specifically typed List
69 func (l ListData) ListEnd() ListEnd {
70 if l.tagType != TagEnd {
71 return 0
72 }
73 return ListEnd(len(l.data))
74 }
75