diff --git a/internal/generateutils/utils.go b/internal/generateutils/utils.go index f27ce0b..226bc6d 100644 --- a/internal/generateutils/utils.go +++ b/internal/generateutils/utils.go @@ -21,10 +21,3 @@ func ToGoTypeName(name string) string { } return strings.Join(words, "") } - -func ToFuncReceiverName(name string) string { - if len(name) > 0 { - name = string(unicode.ToLower([]rune(name)[0])) - } - return name -} diff --git a/level/block/generator/blockentities/blockentities.go.tmpl b/level/block/generator/blockentities/blockentities.go.tmpl index c4dd202..d5e9ae1 100644 --- a/level/block/generator/blockentities/blockentities.go.tmpl +++ b/level/block/generator/blockentities/blockentities.go.tmpl @@ -19,7 +19,8 @@ func ({{.Name | ToGoTypeName}}Entity) ID() string { return {{.Name | printf "%q" {{- end}} {{range .}} -func ({{.Name | ToFuncReceiverName}} {{.Name | ToGoTypeName}}Entity) IsValidBlock(block Block) bool { +{{- $v := slice (.Name | ToLower) 0 1 }} +func ({{$v}} {{.Name | ToGoTypeName}}Entity) IsValidBlock(block Block) bool { {{if eq 1 (len .ValidBlocks)}}return block.ID() == {{index .ValidBlocks 0 | printf "%q"}}{{else}}switch block.ID() { case {{index .ValidBlocks 0 | printf "%q"}}{{range slice .ValidBlocks 1}}, {{. | printf "%q"}}{{end}}: diff --git a/level/block/generator/blockentities/main.go b/level/block/generator/blockentities/main.go index 413d090..d4e51b8 100644 --- a/level/block/generator/blockentities/main.go +++ b/level/block/generator/blockentities/main.go @@ -7,6 +7,7 @@ import ( "go/format" "log" "os" + "strings" "text/template" "github.com/Tnze/go-mc/internal/generateutils" @@ -19,10 +20,10 @@ var tempSource string var temp = template.Must(template. New("block_template"). Funcs(template.FuncMap{ - "UpperTheFirst": generateutils.UpperTheFirst, - "ToGoTypeName": generateutils.ToGoTypeName, - "ToFuncReceiverName": generateutils.ToFuncReceiverName, - "Generator": func() string { return "generator/blockentities/main.go" }, + "UpperTheFirst": generateutils.UpperTheFirst, + "ToGoTypeName": generateutils.ToGoTypeName, + "ToLower": strings.ToLower, + "Generator": func() string { return "generator/blockentities/main.go" }, }). Parse(tempSource), )