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

Stairs: Add helper function for textures #3060

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions mods/stairs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ local function get_node_vars(nodename)
local def = minetest.registered_nodes[nodename]
Copy link
Contributor

@appgurueu appgurueu Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm seeing this correctly, the only thing this function is ever used for is to "transplant" a few definition fields? Why not refactor it to be a local function transplant_def_fields(nodename, to_def)?

The code would then become something like

local def = minetest.registered_nodes[nodename]
if not def then return end
for _, field in ipairs({"light_source", "use_texture_alpha", "sunlight_propagates", "sounds"}) do
    if to_def[field] == nil then
        to_def[field] = def[field]
    end
end

Or alternatively, something like register_node_based_on(nodename, base_nodename, def)?

Another alternative to get rid of get_node_vars: Replace its usage with local def = minetest.registered_nodes[nodename] or {}, then you can directly access def fields as def.light_source etc.


if def then
return def.light_source, def.use_texture_alpha, def.sunlight_propagates
return def.light_source, def.use_texture_alpha, def.sunlight_propagates, def.sounds
end

return nil, nil, nil
return nil, nil, nil, nil
end

-- Set backface culling and world-aligned textures
Expand All @@ -95,7 +95,7 @@ end

function stairs.register_stair(subname, recipeitem, groups, images, description,
sounds, worldaligntex)
local light_source, texture_alpha, sunlight = get_node_vars(recipeitem)
local light, alpha, sunlight, node_sounds = get_node_vars(recipeitem)
local stair_images = set_textures(images, worldaligntex)
local new_groups = table.copy(groups)
new_groups.stair = 1
Expand All @@ -104,14 +104,14 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
description = description,
drawtype = "nodebox",
tiles = stair_images,
use_texture_alpha = texture_alpha,
use_texture_alpha = alpha,
sunlight_propagates = sunlight,
light_source = light_source,
light_source = light,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = new_groups,
sounds = sounds,
sounds = sounds or node_sounds,
node_box = {
type = "fixed",
fixed = {
Expand Down Expand Up @@ -178,7 +178,7 @@ end

function stairs.register_slab(subname, recipeitem, groups, images, description,
sounds, worldaligntex)
local light_source, texture_alpha, sunlight = get_node_vars(recipeitem)
local light, alpha, sunlight, mode_sounds = get_node_vars(recipeitem)
local slab_images = set_textures(images, worldaligntex)
local new_groups = table.copy(groups)
new_groups.slab = 1
Expand All @@ -187,14 +187,14 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
description = description,
drawtype = "nodebox",
tiles = slab_images,
use_texture_alpha = texture_alpha,
use_texture_alpha = alpha,
sunlight_propagates = sunlight,
light_source = light_source,
light_source = light,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = new_groups,
sounds = sounds,
sounds = sounds or node_sounds,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
Expand Down Expand Up @@ -301,7 +301,7 @@ end

function stairs.register_stair_inner(subname, recipeitem, groups, images,
description, sounds, worldaligntex, full_description)
local light_source, texture_alpha, sunlight = get_node_vars(recipeitem)
local light, alpha, sunlight, node_sounds = get_node_vars(recipeitem)
local stair_images = set_textures(images, worldaligntex)
local new_groups = table.copy(groups)
new_groups.stair = 1
Expand All @@ -315,14 +315,14 @@ function stairs.register_stair_inner(subname, recipeitem, groups, images,
description = description,
drawtype = "nodebox",
tiles = stair_images,
use_texture_alpha = texture_alpha,
use_texture_alpha = alpha,
sunlight_propagates = sunlight,
light_source = light_source,
light_source = light,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = new_groups,
sounds = sounds,
sounds = sounds or node_sounds,
node_box = {
type = "fixed",
fixed = {
Expand Down Expand Up @@ -372,7 +372,7 @@ end

function stairs.register_stair_outer(subname, recipeitem, groups, images,
description, sounds, worldaligntex, full_description)
local light_source, texture_alpha, sunlight = get_node_vars(recipeitem)
local light, alpha, sunlight, node_sounds = get_node_vars(recipeitem)
local stair_images = set_textures(images, worldaligntex)
local new_groups = table.copy(groups)
new_groups.stair = 1
Expand All @@ -386,14 +386,14 @@ function stairs.register_stair_outer(subname, recipeitem, groups, images,
description = description,
drawtype = "nodebox",
tiles = stair_images,
use_texture_alpha = texture_alpha,
use_texture_alpha = alpha,
sunlight_propagates = sunlight,
light_source = light_source,
light_source = light,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = new_groups,
sounds = sounds,
sounds = sounds or node_sounds,
node_box = {
type = "fixed",
fixed = {
Expand Down
Loading