github.com/df-mc/dragonfly@v0.9.13/server/internal/packbuilder/manifest.go (about) 1 package packbuilder 2 3 import ( 4 "encoding/json" 5 "github.com/google/uuid" 6 "github.com/sandertv/gophertunnel/minecraft/protocol" 7 "github.com/sandertv/gophertunnel/minecraft/resource" 8 "os" 9 "path/filepath" 10 "strconv" 11 "strings" 12 ) 13 14 // buildManifest creates a JSON manifest file for the client to be able to read the resource pack. It creates 15 // basic information and writes it to the pack. 16 func buildManifest(dir string, headerUUID, moduleUUID uuid.UUID) { 17 m, err := json.Marshal(resource.Manifest{ 18 FormatVersion: 2, 19 Header: resource.Header{ 20 Name: "dragonfly auto-generated resource pack", 21 Description: "This resource pack contains auto-generated content from dragonfly", 22 UUID: headerUUID.String(), 23 Version: [3]int{0, 0, 1}, 24 MinimumGameVersion: parseVersion(protocol.CurrentVersion), 25 }, 26 Modules: []resource.Module{ 27 { 28 UUID: moduleUUID.String(), 29 Description: "This resource pack contains auto-generated content from dragonfly", 30 Type: "resources", 31 Version: [3]int{0, 0, 1}, 32 }, 33 }, 34 }) 35 if err != nil { 36 panic(err) 37 } 38 if err := os.WriteFile(filepath.Join(dir, "manifest.json"), m, 0666); err != nil { 39 panic(err) 40 } 41 } 42 43 // parseVersion parses the version passed in the format of a.b.c as a [3]int. 44 func parseVersion(ver string) [3]int { 45 frag := strings.Split(ver, ".") 46 if len(frag) != 3 { 47 panic("invalid version number " + ver) 48 } 49 a, _ := strconv.ParseInt(frag[0], 10, 64) 50 b, _ := strconv.ParseInt(frag[1], 10, 64) 51 c, _ := strconv.ParseInt(frag[2], 10, 64) 52 return [3]int{int(a), int(b), int(c)} 53 }