A Minecraft datapack generator written in go.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(function): possibilty to specify the namespace

Used to overwrite some of the vanilla one or from others datapack.

cosmeak 97db2624 88f7ea26

+39 -14
+15 -9
examples/basic/main.go
··· 9 9 10 10 func main() { 11 11 pack := weave.MkDatapack("demo", "My first basic datapack", 88, 88, []string{}). 12 - AddFeature(function.MkFunction( 13 - "set_day", 14 - "time set day", 15 - "say Daytime!", 16 - )). 17 - AddFeature(function.MkFunction( 18 - "spawn_stand", 19 - "summon armor_stand ~ ~ ~", 20 - )) 12 + AddFeature(function.MkFunction( 13 + "set_day", 14 + "time set day", 15 + "say Daytime!", 16 + )). 17 + AddFeature(function.MkFunction( 18 + "spawn_stand", 19 + "summon armor_stand ~ ~ ~", 20 + )). 21 + AddFeature(function.MkFunctionWithNamespace( 22 + "minecraft", 23 + "set_day", 24 + "time set day", 25 + "say Daytime!", 26 + )) 21 27 22 28 if err := pack.Generate("./out"); err != nil { 23 29 log.Fatal(err)
+12 -2
function/emitter.go
··· 1 1 package function 2 2 3 3 import ( 4 + "path" 4 5 "strings" 6 + 5 7 "tangled.org/cosmeak.tngl.sh/weave/internal/generator" 6 8 ) 7 9 8 - func (f Function) Emit()(generator.File, error) { 10 + func (f Function) Emit() (generator.File, error) { 9 11 content := strings.Join(f.commands, "\n") 12 + 13 + namespace := "" 14 + if f.namespace != "" { 15 + namespace = f.namespace 16 + } else { 17 + namespace = "%namespace%" 18 + } 19 + 10 20 return generator.File{ 11 - Path: "data/%namespace%/function/" + f.name + ".mcfunction", 21 + Path: path.Join("data", namespace, "function", f.name+".mcfunction"), 12 22 Content: []byte(content), 13 23 }, nil 14 24 }
+12 -3
function/function.go
··· 1 1 package function 2 2 3 3 type Function struct { 4 - name string 5 - commands []string 4 + namespace string 5 + name string 6 + commands []string 6 7 } 7 8 8 9 func MkFunction(name string, commands ...string) Function { 9 10 return Function{ 10 - name: name, 11 + name: name, 11 12 commands: commands, 13 + } 14 + } 15 + 16 + func MkFunctionWithNamespace(namespace, name string, commands ...string) Function { 17 + return Function{ 18 + namespace: namespace, 19 + name: name, 20 + commands: commands, 12 21 } 13 22 } 14 23