A Minecraft datapack generator written in go.

feat: functions

+51
+14
function/emitter.go
··· 1 + package function 2 + 3 + import ( 4 + "strings" 5 + "tangled.org/cosmeak.tngl.sh/weave/internal/generator" 6 + ) 7 + 8 + func (f Function) Emit()(generator.File, error) { 9 + content := strings.Join(f.commands, "/n") 10 + return generator.File{ 11 + Path: "data/%namespace%/function/" + f.name + ".mcfunction", 12 + Content: []byte(content), 13 + }, nil 14 + }
+37
function/function.go
··· 1 + package function 2 + 3 + type Function struct { 4 + name string 5 + commands []string 6 + } 7 + 8 + func MkFunction(name string, commands ...string) Function { 9 + return Function{ 10 + name: name, 11 + commands: commands, 12 + } 13 + } 14 + 15 + func (f Function) Type() string { 16 + return "function" 17 + } 18 + 19 + func (f Function) Name() string { 20 + return f.name 21 + } 22 + 23 + func (f Function) Commands() []string { 24 + commands := make([]string, len(f.commands)) 25 + copy(commands, f.commands) 26 + return commands 27 + } 28 + 29 + func (f Function) AddCommand(command string) Function { 30 + f.commands = append(f.commands, command) 31 + return f 32 + } 33 + 34 + func (f Function) AddCommands(commands ...string) Function { 35 + f.commands = append(f.commands, commands...) 36 + return f 37 + }