Updated 1.21.6

This commit is contained in:
2025-06-16 12:46:46 +08:00
parent 539b4a3a7f
commit f67c9e3052
290 changed files with 22178 additions and 18088 deletions

View File

@ -0,0 +1,33 @@
// Code generated by {{Generator}}; DO NOT EDIT.
package item
import (
"github.com/Tnze/go-mc/level/block"
)
type (
{{- range .}}
{{.Name | ToGoTypeName}} struct {}
{{- end}}
)
{{- range .}}
func ({{.Name | ToGoTypeName}}) ID() string { return {{.Name | printf "%q"}} }
{{- end}}
{{- range .}}
{{- if .Block}}
func ({{.Name | ToGoTypeName}}) Block() block.Block {
return block.FromID[{{.Block | printf "%q"}}]
}
{{- end}}
{{- end}}
var FromID = map[string]Item { {{- range .}}
{{.Name | printf "%q"}}: {{.Name | ToGoTypeName}}{},{{end}}
}
var ToID = map[ID]Item { {{- range .}}
{{.Id | printf "%d"}}: {{.Name | ToGoTypeName}}{},{{end}}
}

View File

@ -0,0 +1,78 @@
package main
import (
"bytes"
"compress/gzip"
_ "embed"
"go/format"
"log"
"os"
"text/template"
"github.com/Tnze/go-mc/internal/generateutils"
"github.com/Tnze/go-mc/nbt"
)
//go:embed items.go.tmpl
var tempSource string
var temp = template.Must(template.
New("item_template").
Funcs(template.FuncMap{
"UpperTheFirst": generateutils.UpperTheFirst,
"ToGoTypeName": generateutils.ToGoTypeName,
"Generator": func() string { return "generator/main.go" },
}).
Parse(tempSource),
)
type Item struct {
Name string
Id int
Block string `nbt:"Block,omitempty"`
}
func main() {
var states []Item
readItems(&states)
// generate go source file
genSourceFile(states)
}
func readItems(states *[]Item) {
// open block_states data file
f, err := os.Open("items.nbt")
if err != nil {
log.Panic(err)
}
defer f.Close()
r, err := gzip.NewReader(f)
if err != nil {
log.Panic(err)
}
// parse the nbt format
if _, err := nbt.NewDecoder(r).Decode(states); err != nil {
log.Panic(err)
}
}
func genSourceFile(states []Item) {
var source bytes.Buffer
if err := temp.Execute(&source, states); err != nil {
log.Panic(err)
}
formattedSource, err := format.Source(source.Bytes())
if err != nil {
panic(err)
}
err = os.WriteFile("items.go", formattedSource, 0o666)
if err != nil {
panic(err)
}
log.Print("Generated items.go")
}

20
level/item/item.go Normal file
View File

@ -0,0 +1,20 @@
package item
import (
_ "embed"
"github.com/Tnze/go-mc/level/block"
)
type Item interface {
ID() string
}
type BlockItem interface {
Block() block.Block
}
// This file stores all possible block states into a TAG_List with gzip compressed.
//
//go:generate go run ./generator/main.go
type ID int

8610
level/item/items.go Normal file

File diff suppressed because it is too large Load Diff

BIN
level/item/items.nbt Normal file

Binary file not shown.