tangled
alpha
login
or
join now
cosmeak.dev
/
weave
0
fork
atom
A Minecraft datapack generator written in go.
0
fork
atom
overview
issues
pulls
pipelines
feat: functions
cosmeak.dev
2 months ago
28d25730
f8a795f5
+51
2 changed files
expand all
collapse all
unified
split
function
emitter.go
function.go
+14
function/emitter.go
···
1
1
+
package function
2
2
+
3
3
+
import (
4
4
+
"strings"
5
5
+
"tangled.org/cosmeak.tngl.sh/weave/internal/generator"
6
6
+
)
7
7
+
8
8
+
func (f Function) Emit()(generator.File, error) {
9
9
+
content := strings.Join(f.commands, "/n")
10
10
+
return generator.File{
11
11
+
Path: "data/%namespace%/function/" + f.name + ".mcfunction",
12
12
+
Content: []byte(content),
13
13
+
}, nil
14
14
+
}
+37
function/function.go
···
1
1
+
package function
2
2
+
3
3
+
type Function struct {
4
4
+
name string
5
5
+
commands []string
6
6
+
}
7
7
+
8
8
+
func MkFunction(name string, commands ...string) Function {
9
9
+
return Function{
10
10
+
name: name,
11
11
+
commands: commands,
12
12
+
}
13
13
+
}
14
14
+
15
15
+
func (f Function) Type() string {
16
16
+
return "function"
17
17
+
}
18
18
+
19
19
+
func (f Function) Name() string {
20
20
+
return f.name
21
21
+
}
22
22
+
23
23
+
func (f Function) Commands() []string {
24
24
+
commands := make([]string, len(f.commands))
25
25
+
copy(commands, f.commands)
26
26
+
return commands
27
27
+
}
28
28
+
29
29
+
func (f Function) AddCommand(command string) Function {
30
30
+
f.commands = append(f.commands, command)
31
31
+
return f
32
32
+
}
33
33
+
34
34
+
func (f Function) AddCommands(commands ...string) Function {
35
35
+
f.commands = append(f.commands, commands...)
36
36
+
return f
37
37
+
}