Adjust blockentities.go.tmpl
This commit is contained in:
@ -21,10 +21,3 @@ func ToGoTypeName(name string) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(words, "")
|
return strings.Join(words, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToFuncReceiverName(name string) string {
|
|
||||||
if len(name) > 0 {
|
|
||||||
name = string(unicode.ToLower([]rune(name)[0]))
|
|
||||||
}
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
@ -19,7 +19,8 @@ func ({{.Name | ToGoTypeName}}Entity) ID() string { return {{.Name | printf "%q"
|
|||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
{{range .}}
|
{{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() {
|
{{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}},
|
case {{index .ValidBlocks 0 | printf "%q"}}{{range slice .ValidBlocks 1}},
|
||||||
{{. | printf "%q"}}{{end}}:
|
{{. | printf "%q"}}{{end}}:
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"go/format"
|
"go/format"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/internal/generateutils"
|
"github.com/Tnze/go-mc/internal/generateutils"
|
||||||
@ -21,7 +22,7 @@ var temp = template.Must(template.
|
|||||||
Funcs(template.FuncMap{
|
Funcs(template.FuncMap{
|
||||||
"UpperTheFirst": generateutils.UpperTheFirst,
|
"UpperTheFirst": generateutils.UpperTheFirst,
|
||||||
"ToGoTypeName": generateutils.ToGoTypeName,
|
"ToGoTypeName": generateutils.ToGoTypeName,
|
||||||
"ToFuncReceiverName": generateutils.ToFuncReceiverName,
|
"ToLower": strings.ToLower,
|
||||||
"Generator": func() string { return "generator/blockentities/main.go" },
|
"Generator": func() string { return "generator/blockentities/main.go" },
|
||||||
}).
|
}).
|
||||||
Parse(tempSource),
|
Parse(tempSource),
|
||||||
|
Reference in New Issue
Block a user