-
Notifications
You must be signed in to change notification settings - Fork 143
/
conversion.go
45 lines (40 loc) · 1.16 KB
/
conversion.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
package chunk
import (
"bytes"
_ "embed"
"github.com/sandertv/gophertunnel/minecraft/nbt"
)
// legacyBlockEntry represents a block entry used in versions prior to 1.13.
type legacyBlockEntry struct {
Name string `nbt:"name"`
Meta int16 `nbt:"meta"`
}
var (
//go:embed legacy_states.nbt
legacyMappingsData []byte
// legacyMappings allows simple conversion from a legacy block entry to a new one.
legacyMappings = make(map[legacyBlockEntry]blockEntry)
)
// upgradeLegacyEntry upgrades a legacy block entry to a new one.
func upgradeLegacyEntry(name string, meta int16) (blockEntry, bool) {
entry, ok := legacyMappings[legacyBlockEntry{Name: name, Meta: meta}]
if !ok {
// Also try cases where the meta should be disregarded.
entry, ok = legacyMappings[legacyBlockEntry{Name: name}]
}
return entry, ok
}
// init creates conversions for each legacy and alias entry.
func init() {
var entry struct {
Legacy legacyBlockEntry `nbt:"legacy"`
Updated blockEntry `nbt:"updated"`
}
dec := nbt.NewDecoder(bytes.NewBuffer(legacyMappingsData))
for {
if err := dec.Decode(&entry); err != nil {
break
}
legacyMappings[entry.Legacy] = entry.Updated
}
}