7
data/README.md
Normal file
7
data/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## Updating `data`
|
||||
|
||||
1. Go to [https://github.com/PrismarineJS/minecraft-data/tree/master/data/pc/{version}](https://github.com/PrismarineJS/minecraft-data/tree/master/data/pc)
|
||||
2. Update the URL (if appropriate) in [gen_block.go](block/gen_block.go), [gen_entity.go](entity/gen_entity.go),
|
||||
[gen_item.go](item/gen_item.go), and [gen_packetid.go](packetid/gen_packetid.go)
|
||||
3. Update the `URL` in [gen_soundid.go](soundid/gen_soundid.go)
|
||||
4. Run `go generate ./...`
|
@ -130,7 +130,8 @@ func makeBlockDeclaration(blocks []Block) *ast.DeclStmt {
|
||||
return out
|
||||
}
|
||||
|
||||
//go:generate go run $GOFILE > ./packetid.go
|
||||
//go:generate go run $GOFILE
|
||||
//go:generate go fmt block.go
|
||||
func main() {
|
||||
blocks, err := downloadInfo()
|
||||
if err != nil {
|
||||
@ -138,7 +139,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(`// Code generated by gen_blocks.go; DO NOT EDIT.
|
||||
f, err := os.Create("entity.go")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fmt.Fprintln(f, `// Code generated by gen_blocks.go; DO NOT EDIT.
|
||||
|
||||
// Package block stores information about blocks in Minecraft.
|
||||
package block
|
||||
@ -176,26 +184,26 @@ type Block struct {
|
||||
`)
|
||||
format.Node(os.Stdout, token.NewFileSet(), makeBlockDeclaration(blocks))
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println()
|
||||
fmt.Println("// ByID is an index of minecraft blocks by their ID.")
|
||||
fmt.Println("var ByID = map[ID]*Block{")
|
||||
fmt.Fprintln()
|
||||
fmt.Fprintln()
|
||||
fmt.Fprintln(f, "// ByID is an index of minecraft blocks by their ID.")
|
||||
fmt.Fprintln(f, "var ByID = map[ID]*Block{")
|
||||
for _, b := range blocks {
|
||||
fmt.Printf(" %d: &%s,\n", b.ID, strcase.ToCamel(b.Name))
|
||||
fmt.Fprintf(f," %d: &%s,\n", b.ID, strcase.ToCamel(b.Name))
|
||||
}
|
||||
fmt.Println("}")
|
||||
fmt.Fprintln(f, "}")
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("// StateID maps all possible state IDs to a corresponding block ID.")
|
||||
fmt.Println("var StateID = map[uint32]ID{")
|
||||
fmt.Fprintln()
|
||||
fmt.Fprintln(f, "// StateID maps all possible state IDs to a corresponding block ID.")
|
||||
fmt.Fprintln(f, "var StateID = map[uint32]ID{")
|
||||
for _, b := range blocks {
|
||||
if b.MinStateID == b.MaxStateID {
|
||||
fmt.Printf(" %d: %d,\n", b.MinStateID, b.ID)
|
||||
fmt.Fprintf(f, " %d: %d,\n", b.MinStateID, b.ID)
|
||||
} else {
|
||||
for i := b.MinStateID; i <= b.MaxStateID; i++ {
|
||||
fmt.Printf(" %d: %d,\n", i, b.ID)
|
||||
fmt.Fprintf(f, " %d: %d,\n", i, b.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("}")
|
||||
fmt.Fprintln("}")
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// gen_entity.go generates entity information.
|
||||
//+build ignore
|
||||
|
||||
// gen_entity.go generates entity information.
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -106,7 +107,7 @@ func makeEntityDeclaration(entities []Entity) *ast.DeclStmt {
|
||||
}
|
||||
|
||||
//go:generate go run $GOFILE
|
||||
//go:generate go fmt ../entity.go
|
||||
//go:generate go fmt entity.go
|
||||
func main() {
|
||||
entities, err := downloadInfo()
|
||||
if err != nil {
|
||||
@ -114,7 +115,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
f, err := os.Create("../entity.go")
|
||||
f, err := os.Create("entity.go")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
@ -1,7 +1,6 @@
|
||||
// gen_blocks.go generates block information.
|
||||
|
||||
//+build ignore
|
||||
|
||||
// gen_item.go generates item information.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,8 +1,11 @@
|
||||
// This program can automatic download language.json file and convert into .go
|
||||
//+build ignore
|
||||
|
||||
// This program can automatically download language.json file and convert into .go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@ -27,12 +30,11 @@ func main() {
|
||||
readLang("en_us", f)
|
||||
return
|
||||
}
|
||||
// Pseudo code for get versionURL:
|
||||
// $manifest = {https://launchermeta.mojang.com/mc/game/version_manifest.json}
|
||||
// $latest = $manifest.latest.release
|
||||
// $version = {$manifest.versions[where .id == $latest ].url}
|
||||
// $versionURL = $version.assetIndex.url
|
||||
versionURL := "https://launchermeta.mojang.com/v1/packages/e5af543d9b3ce1c063a97842c38e50e29f961f00/1.17.json"
|
||||
|
||||
versionURL, err := assetIndexURL()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Print("start generating lang packages")
|
||||
|
||||
resp, err := http.Get(versionURL)
|
||||
@ -155,3 +157,59 @@ func trans(m map[string]string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assetIndexURL() (string, error) {
|
||||
// Pseudo code for get versionURL:
|
||||
// $manifest = {https://launchermeta.mojang.com/mc/game/version_manifest.json}
|
||||
// $latest = $manifest.latest.release
|
||||
// $versionURL = {$manifest.versions[where .id == $latest ].url}
|
||||
// $assetIndexURL = $version.assetIndex.url
|
||||
var manifest struct {
|
||||
Latest struct {
|
||||
Release string `json:"release"`
|
||||
} `json:"latest"`
|
||||
Versions []struct{
|
||||
ID string `json:"id"`
|
||||
URL string `json:"url"`
|
||||
} `json:"versions"`
|
||||
}
|
||||
|
||||
manifestRes, err := http.Get("https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not reach version manifest: %w", err)
|
||||
}
|
||||
defer manifestRes.Body.Close()
|
||||
|
||||
if err := json.NewDecoder(manifestRes.Body).Decode(&manifest); err != nil {
|
||||
return "", fmt.Errorf("could not decode manifest JSON: %w", err)
|
||||
}
|
||||
|
||||
var versionURL string
|
||||
for _, v := range manifest.Versions {
|
||||
if strings.EqualFold(manifest.Latest.Release, v.ID) {
|
||||
versionURL = v.URL
|
||||
break
|
||||
}
|
||||
}
|
||||
if versionURL == "" {
|
||||
return "", errors.New("could not determine versionURL")
|
||||
}
|
||||
|
||||
var version struct{
|
||||
AssetIndex struct{
|
||||
URL string `json:"url"`
|
||||
} `json:"assetIndex"`
|
||||
}
|
||||
|
||||
versionRes, err := http.Get(versionURL)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not reach versionURL: %w", err)
|
||||
}
|
||||
defer versionRes.Body.Close()
|
||||
|
||||
if err := json.NewDecoder(versionRes.Body).Decode(&version); err != nil {
|
||||
return "", fmt.Errorf("could not decode version JSON: %w", err)
|
||||
}
|
||||
|
||||
return version.AssetIndex.URL, nil
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
// gen_packetIDs.go generates the enumeration of packet IDs used on the wire.
|
||||
//+build ignore
|
||||
|
||||
//gen_packetid.go generates the enumeration of packet IDs used on the wire.
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -161,7 +163,7 @@ func downloadInfo() (*protocolIDs, error) {
|
||||
}
|
||||
|
||||
//go:generate go run $GOFILE
|
||||
//go:generate go fmt ../packetid.go
|
||||
//go:generate go fmt packetid.go
|
||||
func main() {
|
||||
pIDs, err := downloadInfo()
|
||||
if err != nil {
|
||||
@ -169,7 +171,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
f, err := os.Create("../packetid.go")
|
||||
f, err := os.Create("packetid.go")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
@ -1,6 +1,6 @@
|
||||
//+build ignore
|
||||
|
||||
// gen_soundIDs.go generates the enumeration of sound IDs.
|
||||
// gen_soundid.go generates the enumeration of sound IDs.
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
protocolURL = "https://pokechu22.github.io/Burger/1.17.1.json"
|
||||
URL = "https://pokechu22.github.io/Burger/1.17.1.json"
|
||||
)
|
||||
|
||||
type sound struct {
|
||||
@ -61,7 +61,7 @@ func main() {
|
||||
}
|
||||
|
||||
func downloadSoundInfo() ([]sound, error) {
|
||||
resp, err := http.Get(protocolURL)
|
||||
resp, err := http.Get(URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
Reference in New Issue
Block a user