[Mod] Framework to create new nodes [customnode]

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

[Mod] Framework to create new nodes [customnode]

by bell07 » Thu Apr 13, 2017 21:00

This mod is a result of my laziness, I found the MC-ressource pack https://minecraft.curseforge.com/projects/new-super-minio-bros/images and started to write a mod keeping in mind I cannot publish it ready to use because of license issues.

Because I was lazy to write > 60 nodes definitions I did written a framework that do it for me. The result is a mod that contains basically a method "customnode.add_nodes_from_textures()" that can be used from other mods. So the init.lua can be in best case:
Code: Select all
customnode.add_nodes_from_textures({ descr_prefix = "New Super Mario" })

I think this mod/way is welcome by modders which are good in creating textures but less good in writing lua code.

In further development the shapes handler was added. Beside node variants (wood, stone..) the support for tasks was added. The stairs/slabs is enabled by default for certain variants, the carpets support is provided only.
To be able to run tasks on already defined nodes the method customnode.apply_variants_to_depnodes() was introduced. This method reads the depends.txt from custom-mod and then check for usable nodes and apply the variant tasks on them.

Not implemented (and not planned currently): mobs, items.

More details in github readme.

github: https://github.com/bell07/minetest-customnode/
License: L-GPL2.1
Dependencies:
default (The sounds are used from this mod)
stairs (optional) - generates stairs and slabs for some variants

Screenshots: (not included, my usage in mods "smb", "sonic", kirby", "newsupermario")
Image
Image


customnode.apply_variants_to_depnodes() for abriglass, pbj_pup and
myroofs
Code: Select all
customnode.register_variant("glass", {
   tasks = {"stairs:stairs_slabs"},
})
customnode.register_variant("default", {
   tasks = {"carpets:carpet"},
})
customnode.apply_variants_to_depnodes()


Image
Attachments
Bildschirmfoto_2018-01-18_18-18-13.png
(144.14 KiB) Not downloaded yet
screenshot_20170413_220221.png
(864.74 KiB) Not downloaded yet
Bildschirmfoto_2017-04-13_21-53-27.png
(187.75 KiB) Not downloaded yet
Last edited by bell07 on Thu Jan 18, 2018 17:39, edited 4 times in total.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Fri Apr 14, 2017 15:03

azekill_DIABLO wrote:but a bit too simple!
That's is the basic idea. Nodes should be creatable by adding texture files to texture folder, without worry about the lua code.

azekill_DIABLO wrote:you could add a fast parameter like
nodetype = stone

nodetype is handled by "variant" in filename:
API wrote:modname_[addprefix_][variant_][name_][tiletype].ext

[] means optional
  • modname - to avoid overlapping all textures without modname in filename will be ignored
  • addprefix - additional prefix for mods that contains other textures that should not be processed
  • variant - determinate some nodes parameter:
    Supported: brick, cobblestone, dirt, grass, ice, iron, sandstone, stone, item (=will be skipped)
  • tiletype - defines the tile position
    Supported: top, bottom, down, right, left, back, inner, front, side, normal
  • name - additional string makes the nodename unique. Note: if tieltype or variant is not valid, you find it as a part of the name
  • ext - File extendion as supported by minetest
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [mod] Framework to create new nodes [customnode]

by azekill_DIABLO » Fri Apr 14, 2017 17:50

ok sir, i'm sorry, i didn't read it fully. it's useful by the way! but to make it extremely useful, you could add a function to define a group of node in one time (defining block, bricks, variants, stairs and slabs)
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Fri Apr 14, 2017 19:09

In short: stairs+slabs support added and enabled by default for variants "brick,cobblestone,ice,sandstone,stone"

Longer answer: I deliberately kept the API docu simple. For more complex things the modder should ask himself whether it is worth to use a framework or if it better to write the node definitions from scratch.
... And for the reason in order not to have to write docu....

The framework does have some features more. The function customnode.add_nodes_from_textures(conf) is basically defined as
Code: Select all
   local customnode_list = customnode.get_nodelist_by_textures(conf.check_prefix)
   for name, generator in pairs(customnode_list) do
      local nodedef = generator:get_nodedef(conf)
      if nodedef then
         minetest.register_node(nodedef.name, nodedef)
      end
   end

Of course you can use customnode.get_nodelist_by_textures(conf.check_prefix) directly in your mod to get the list and take with them what ever you need. And of course the "generator" API is not documented at the time :-(resp. the code is the docu ;)

I think stairs and slabs are most desired addition so I added the optional support for stairs mod. But this mod should not cover the full moreblocks or lib_node_shapes functionality at the time.
Maybe I'll add an API to register "shapes" in feature, but I do not have an idea currently about the abstract concept for for this.

EDIT: after second reading I see I did not understand the
define a group of node in one time
Can you pls. explain more? Maybe a pseudo-code-snippet how it should looks like?

EDIT2: if you need carpets based on new nodes, just add your mod to the depends.txt in https://github.com/bell07/minetest-carpets. Yet other way to get dynamic additional shapes for nodes...
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Wed Apr 19, 2017 11:55

Just additional info: I found out the xdecor mod does auto-generate stairs, slabs and microblocks for his workbench so the shapes generation in customnode can be disabled if used with xdecor.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [mod] Framework to create new nodes [customnode]

by azekill_DIABLO » Wed Apr 19, 2017 14:12

just define a function which does
Code: Select all
define_group_of_node(def)
     texture = lol.png
end


which has an output like this
Code: Select all
lol_block
lol_brick
lol_stair
lol_slab
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Wed Apr 19, 2017 14:44

block and brick are (usually?) different textures. So you get the block and brick by mymod_lol_block.png + mymod_lol_brick.png.

stairs and slabs are shapes with texture re-usage. So you get the stairs:lol_brick_stair and stairs:lol_brick_slab trough the last enhancement automagically.

For lol_block no slabs and stairs will be generated because "block" is not a valid variant at the time. Maybe it is just wording but all variants are "blocks" for me. I see some variants are still missed. Let me know which variants are important to be added and which "special settings" should the variant cover.

Maybe it should be something like
Code: Select all
register_variant("block",{
  groups = ???,
  sounds = ???,
  generate_stairs = true,
  generate_slabs = true,
}

that adds "block" to the valid variants table and defines the special settings? {[:idea:]}
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Thu Apr 20, 2017 12:52

I did some rewrites and implemented register_task() and register_variant().
Variants needs to be defined as "modname:variant" to be able to use same variant names for different implementations.
Now extendend usage is possible like

Code: Select all
customnode.register_task("recipe", function(nodedef, generator)
   minetest.register_craft({
      output = nodedef.name,
      recipe = {
         {"default:wood", ingredients[nodedef.name], "default:wood"},
      }
   })
end)

customnode.register_variant("mymod:wood", {
   groups = {choppy = 2, wood = 1}
   tasks = {"stairs_slabs", "recipe"},
})

customnode.add_nodes_from_textures({
   descr_prefix = "My crazy blocks",
})

This sample appiles the new variant to all nodes based on *_wood_* files.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Framework to create new nodes [customnode]

by bell07 » Thu Apr 20, 2017 17:46

Now I did code cleanup and splitted the init.lua to multiple files. Pls. note the tasks should be prefixed too, if you define own tasks in your mods. I renamed the both default tasks:
default => customnode:node
stairs_slabs => stairs:stairs_slabs
There is no check for the prefix on tasks, but it will be nice if the tasks be clearly assigned to avoid overlappings.

Now you can directly look to the default implementations for tasks and variants:
https://github.com/bell07/minetest-customnode/blob/master/tasks.lua
https://github.com/bell07/minetest-customnode/blob/master/variants.lua

Pls. let me know if any defined variants needs more love and better settings? If any additional variants and tasks should be applied to the mod (and available for all)? And show me your usage with code and screenshots of course ;)
 

bell07
Member
 
Posts: 534
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [Mod] Framework to create new nodes [customnode]

by bell07 » Thu Jan 18, 2018 17:28

Next update

I ported the "woodo magic" from my carpets mod to customnode and added the carpets task. So the carpets mod will be shrink to the API only (and some wool carpets) at the next.

The "woodo magic" is to add new nodes just by adding mod name to the depends.txt. In customnode the new function customnode.apply_variants_to_depnodes() is responsible for this for now.

An example:

custom_shapes $ cat depends.txt
Code: Select all
customnode
abriglass
pbj_pup
myroofs

custom_shapes $ cat init.lua
Code: Select all
-- Introduce glass carpets
customnode.register_variant("glass", {
   tasks = {"stairs:stairs_slabs"},
})


-- Enable carpets for all not classified (default) nodes
customnode.register_variant("default", {
   tasks = {"carpets:carpet"},
})

customnode.apply_variants_to_depnodes()

The result is
Image
 

User avatar
Codesound
Member
 
Posts: 202
Joined: Thu Jun 09, 2016 14:56
 


Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 6 guests