github.com/df-mc/dragonfly@v0.9.13/server/world/chunk/conversion.go (about) 1 package chunk 2 3 import ( 4 "bytes" 5 _ "embed" 6 "github.com/sandertv/gophertunnel/minecraft/nbt" 7 ) 8 9 // legacyBlockEntry represents a block entry used in versions prior to 1.13. 10 type legacyBlockEntry struct { 11 Name string `nbt:"name"` 12 Meta int16 `nbt:"meta"` 13 } 14 15 var ( 16 //go:embed legacy_states.nbt 17 legacyMappingsData []byte 18 // legacyMappings allows simple conversion from a legacy block entry to a new one. 19 legacyMappings = make(map[legacyBlockEntry]blockEntry) 20 ) 21 22 // upgradeLegacyEntry upgrades a legacy block entry to a new one. 23 func upgradeLegacyEntry(name string, meta int16) (blockEntry, bool) { 24 entry, ok := legacyMappings[legacyBlockEntry{Name: name, Meta: meta}] 25 if !ok { 26 // Also try cases where the meta should be disregarded. 27 entry, ok = legacyMappings[legacyBlockEntry{Name: name}] 28 } 29 return entry, ok 30 } 31 32 // init creates conversions for each legacy and alias entry. 33 func init() { 34 var entry struct { 35 Legacy legacyBlockEntry `nbt:"legacy"` 36 Updated blockEntry `nbt:"updated"` 37 } 38 dec := nbt.NewDecoder(bytes.NewBuffer(legacyMappingsData)) 39 for { 40 if err := dec.Decode(&entry); err != nil { 41 break 42 } 43 legacyMappings[entry.Legacy] = entry.Updated 44 } 45 }