/
registryProvider.go
82 lines (65 loc) · 2.11 KB
/
registryProvider.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
80
81
82
package main
import (
"encoding/json"
"io/ioutil"
"sort"
"strconv"
)
type Registry struct {
blockStates map[string]int
blockStateFields map[string]map[string]bool
reverseBlockStates map[int]string
}
var registry map[int]*Registry
func makeBlockStateIdentifier(name string, properties []string) string {
output := name + ";"
sort.Strings(properties)
for _, i := range properties {
output = output + i + ";"
}
return output
}
func loadRegistry() {
log("Loading registry...")
registry = make(map[int]*Registry)
type jsonRegistryState struct {
Properties map[string]string `json:"properties"`
Id int `json:"id"`
Default bool `json:"default"`
}
type jsonRegistryEntry struct {
Properties map[string][]string `json:"properties"`
States []jsonRegistryState `json:"states"`
}
type jsonRegistryBase map[string]jsonRegistryEntry
handledVersions, _ := ioutil.ReadDir("registries")
for _, val := range handledVersions {
log("Protocol: ", val.Name())
var bruh jsonRegistryBase = make(map[string]jsonRegistryEntry)
registriesInfo, _ := ioutil.ReadFile("registries/" + val.Name() + "/blocks.json")
json.Unmarshal(registriesInfo, &bruh)
protId, _ := strconv.Atoi(val.Name())
registry[protId] = new(Registry)
registry[protId].blockStateFields = make(map[string]map[string]bool)
registry[protId].blockStates = make(map[string]int)
registry[protId].reverseBlockStates = make(map[int]string)
for key, value := range bruh {
registry[protId].blockStateFields[key] = make(map[string]bool)
//fmt.Println(key)
for property := range value.Properties {
registry[protId].blockStateFields[key][property] = true
}
// Assemble block state string
for _, data := range value.States {
states := []string{}
for stateName, stateValue := range data.Properties {
states = append(states, stateName+"="+stateValue)
}
fullStateName := makeBlockStateIdentifier(key, states)
registry[protId].blockStates[fullStateName] = data.Id
registry[protId].reverseBlockStates[data.Id] = fullStateName
}
}
}
log("Registry finished loading")
}