forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_tag.go
60 lines (50 loc) · 1.08 KB
/
item_tag.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
package recipe
import (
_ "embed"
"encoding/json"
)
var (
//go:embed item_tags.json
itemTagData []byte
itemTags = make(map[string][]string)
)
func init() {
if err := json.Unmarshal(itemTagData, &itemTags); err != nil {
panic(err)
}
}
// ItemTag represents a recipe item that is identified by a tag, such as "minecraft:planks" or
// "minecraft:digger" and so on.
type ItemTag struct {
tag string
count int
items []string
}
// NewItemTag creates a new item tag with the tag and count passed.
func NewItemTag(tag string, count int) ItemTag {
if count < 0 {
count = 0
}
return ItemTag{tag: tag, count: count, items: itemTags[tag]}
}
// Count ...
func (i ItemTag) Count() int {
return i.count
}
// Empty ...
func (i ItemTag) Empty() bool {
return i.count == 0 || i.tag == ""
}
// Tag returns the tag of the item.
func (i ItemTag) Tag() string {
return i.tag
}
// Contains returns true if the item tag contains the item with the name passed.
func (i ItemTag) Contains(name string) bool {
for _, item := range i.items {
if item == name {
return true
}
}
return false
}