[SOLVED] Not quite understanding the stairs module?

Post Reply
Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

[SOLVED] Not quite understanding the stairs module?

by Icalasari » Post

Wanting to add the woods I made for my mod (since well, the base mod alone is going to add 20 trees. Not all make wood as some trees are made thinner to match the real trees but yeah) to the stairs and slabs, but when I took a look at the stairs mod in Minetest Game, I don't quite grasp how to register them to it? I get the base register part, but I'm not sure how exactly to implement it? Checking the moretrees mod didn't clarify things any, either (beyond that my code is REALLY inefficient overall, wish I knew how it did it like that so I didn't have to have 100+ lines of code per tree SMALL EDIT: All those lines is probably why the mod loads in slower than I feel it should compared to other mods XD Really need to figure out how to just define the nodes by name instead of filling out all the information every time for nodes that are basically identical in all but name, appearance, drops, and in the case of saplings growth rate/light level)

It's... Somewhat confusing

Snippet of one of the wood nodes in my mod for reference:

Code: Select all

minetest.register_node("mindeca:wood_tree_cherry", {
	description = "Cherry Tree Wood\n\nMindeca",
	tiles = {"mindeca_wood_tree_cherry.png"},
	is_ground_content = false,
	light_source = 3,
	groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
	flags = "force_placement",
	sounds = default.node_sound_wood_defaults(),
})
EDIT 2: Ok I think part of the problem is information overload - trying to grasp too much at once so I'm getting very confused

EDIT 3: Slowly grasping things but yeah, still slow going
Last edited by Icalasari on Sun Aug 07, 2022 03:40, edited 1 time in total.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: Not quite understanding the stairs module?

by loosewheel » Post

From what I've done in the past, registration for stairs and slabs isn't done through the node registration. Its done through the api in the stairs mod.

For example:

Node registration

Code: Select all

minetest.register_node("interiors:wall_white", {
	description = S("White Wall"),
	tiles = { "wall_white.png" },
	drawtype = "normal",
	groups = { choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1 },
	sounds = default.node_sound_wood_defaults(),
})

Stairs and slabs

Code: Select all

stairs.register_stair_and_slab(
   "wall_white",
   "interiors:wall_white",
   { choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1 },
   { "wall_white.png" },
   S("White Wall Stair"),
   S("White Wall Slab"),
   default.node_sound_wood_defaults()
)
This example registers both a stair and slab. From memory the api has methods to only register one. Just look in the stairs mod for the api and which parts you want to use.

Also, this I don't know for sure, if the stairs/slabs don't handle the lighting properly you may need to add paramtype = "light" to your definition. Just try it out and see what happens.

As far as registering many nodes that are virtually identical there are many considerations in how to do that. For simple nodes you can make a local function to do the registering with parameters for the small differences (make sure each registration creates a unique definition table or you will just be updating the same one).

You could even make a table with each entry the parameters for that function, and have a loop further down which calls the registration function for each entry. That way you can easily add a node just by making an entry in that table.

So far this shouldn't really make any difference than just placing each registration call per node. If your nodes are complex and have extensive callback code which are all the same, coding the callback functions as local functions and just giving the function name in the registration the function will only be compiled once and be used by every node. If the callback function is coded in the definition a unique function will be compiled for each one. This method may reduce load times and memory usage but how much difference it would make (or if it would even be noticeable) is ambiguous.

There is no set way to do this. You just do whatever works best for your mod. Keeping in mind that you may need to go back and make modifications months or years from now, and understand what you did.

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [SOLVED] Not quite understanding the stairs module?

by Icalasari » Post

Thanks Loosewheel. Found a system that does work, although hitting snags so needing another thread for that as it's different enough to need a new thread

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests