Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for changing a node's appearance #2887

Closed
bluebear94 opened this issue Jul 5, 2015 · 5 comments
Closed

API for changing a node's appearance #2887

bluebear94 opened this issue Jul 5, 2015 · 5 comments
Labels
Duplicate Feature request Issues that request the addition or enhancement of a feature

Comments

@bluebear94
Copy link
Contributor

Currently, there are only a few preset ways to change a node's appearance based on its node data. I propose moving this functionality to the API.

Perhaps having minetest.change_tile(pos, node, tiles) and minetest.change_nodebox(pos, node, nodebox), or making the tile and nodebox fields of the node definitions take functions as well as fixed values?

@est31
Copy link
Contributor

est31 commented Jul 5, 2015

I guess you will like #1118.
Another way to do this would be to specify client side functions which modify the nodebox depending on the node metadata.

@bluebear94
Copy link
Contributor Author

Well, let's hope that a "snapshot" (if that kind of thing is done here) comes out with such a change so I can work on something that plans to use this functionality.

@ShadowNinja
Copy link
Member

Meta_set_nodedef is very powerfull, but it has some limitations:

  • Storage space; Currently it stores the whole itemdef in the meta. This could be changed to just store the changed fields, but that's still quite a bit of space (eg, {nodebox = {{0.5, 0.5, 0.5, 0, 0, 0}}} or so when top-front-right or even 8 would do).
  • Updates: Say you change the mesecons nodebox. Now you have to somehow update every mesecon on the map to give it the new nodebox.

I think the best approach would be two pronged:

  • Meta_set_nodedef for when you have to make changes to a node at one specific position. (examples: ?)
  • A "variant" option for nodes that have a limited number of variations. (eg, colored nodes, connecting nodes (mesecons, fences, technic wires...))

The variant would be stored as a node field (like param1) or in the nodedef. It would be either a string (more flexible?) or a 16-bit number (more compact).

Here's a example of what an API might look like (string option):

minetest.register_node("mymod:colored_wood", {
    ...
    variants = {
        blue = {tiles = {"mymod_wood_blue"}},
        red = {tiles = {"mymod_wood_red"}},
    }
})

@est31
Copy link
Contributor

est31 commented Nov 12, 2015

Agreed, I, too, favour a variant like approach over one where the full nodedef gets specified in the nodedef.

With client side scripting we could perhaps even have something even more flexible than what you described above, where the nodedef is returned by a function that gets the variant specifier/name/data as input. So e.g. you'd have client side code like (with the number option):

local color_name_table = ["mymod_wood_blue", "mymod_wood_red", "mymod_wood_pink"]
minetest.set_node_variant_function("mymod:colored_wood", 
    -- returns the table overriding the nodedef, nil if variant_id is invalid
    function(variant_id)
        local color_name = color_name_table[variant_id]
        if not color_name then
            return nil
        end
        return {
            tiles = {color_name}
        }
    end)

@paramat
Copy link
Contributor

paramat commented Mar 21, 2017

Duplicate of #2107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Feature request Issues that request the addition or enhancement of a feature
Projects
None yet
Development

No branches or pull requests

4 participants