stairs use original nodes transparency and light levels

This commit is contained in:
tenplus1 2020-05-28 16:17:22 +01:00
parent 17dad254d9
commit ee67461896
2 changed files with 127 additions and 78 deletions

View File

@ -25,4 +25,5 @@ Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
Note: This mod has been changed by TenPlus1 to include other blocks from different mods as well as corner stairs and slopes... Holding sneak when placing will copy the rotation of the block pointed at to the newly placed stair. Note: This mod has been changed by TenPlus1 to include other blocks from different mods as well as corner stairs and slopes... Holding sneak when placing will copy the rotation of the block pointed at to the newly placed stair.
Nodes with a light source will also have stairs using same light levels. Nodes with a light source will also have stairs using same light levels, also
nodes using alpha textures for transparency will copy over to stairs as well.

202
init.lua
View File

@ -1,46 +1,54 @@
stairs = {}
stairs.mod = "redo"
-- wool sounds
function default.node_sound_wool_defaults(table) function default.node_sound_wool_defaults(table)
table = table or {} table = table or {}
table.footstep = table.footstep or table.footstep = table.footstep or
{name = "wool_coat_movement", gain = 1.0} {name = "wool_coat_movement", gain = 1.0}
table.dug = table.dug or table.dug = table.dug or
{name = "wool_coat_movement", gain = 0.25} {name = "wool_coat_movement", gain = 0.25}
table.place = table.place or table.place = table.place or
{name = "default_place_node", gain = 1.0} {name = "default_place_node", gain = 1.0}
return table return table
end end
stairs.wood = default.node_sound_wood_defaults() stairs = {
stairs.dirt = default.node_sound_dirt_defaults() mod = "redo",
stairs.stone = default.node_sound_stone_defaults() wood = default.node_sound_wood_defaults(),
stairs.glass = default.node_sound_glass_defaults() dirt = default.node_sound_dirt_defaults(),
stairs.leaves = default.node_sound_leaves_defaults() stone = default.node_sound_stone_defaults(),
stairs.metal = default.node_sound_metal_defaults() glass = default.node_sound_glass_defaults(),
stairs.wool = stairs.leaves leaves = default.node_sound_leaves_defaults(),
if minetest.get_modpath("xanadu") then metal = default.node_sound_metal_defaults(),
stairs.wool = default.node_sound_wool_defaults() wool = default.node_sound_wool_defaults()
end }
-- cache creative -- cache creative
local creative = minetest.settings:get_bool("creative_mode") local creative = minetest.settings:get_bool("creative_mode")
function is_creative_enabled_for(name) function is_creative_enabled_for(name)
if creative or minetest.check_player_privs(name, {creative = true}) then if creative or minetest.check_player_privs(name, {creative = true}) then
return true return true
end end
return false return false
end end
-- process textures -- process textures
local set_textures = function(images) local set_textures = function(images)
local stair_images = {} local stair_images = {}
for i, image in ipairs(images) do for i, image in ipairs(images) do
if type(image) == "string" then if type(image) == "string" then
stair_images[i] = { stair_images[i] = {
name = image, name = image,
backface_culling = true, backface_culling = true,
@ -48,14 +56,17 @@ local set_textures = function(images)
} }
else else
stair_images[i] = table.copy(image) stair_images[i] = table.copy(image)
if stair_images[i].backface_culling == nil then if stair_images[i].backface_culling == nil then
stair_images[i].backface_culling = true stair_images[i].backface_culling = true
end end
if stair_images[i].align_style == nil then if stair_images[i].align_style == nil then
stair_images[i].align_style = "world" stair_images[i].align_style = "world"
end end
end end
end end
return stair_images return stair_images
end end
@ -82,7 +93,10 @@ local stair_place = function(itemstack, placer, pointed_thing, stair_node)
if minetest.get_item_group(node_u.name, "stair") > 0 if minetest.get_item_group(node_u.name, "stair") > 0
or minetest.get_item_group(node_u.name, "slab") > 0 then or minetest.get_item_group(node_u.name, "slab") > 0 then
minetest.set_node(pos_a, {name = stair_node, param2 = node_u.param2}) minetest.set_node(pos_a, {
name = stair_node,
param2 = node_u.param2
})
if not is_creative_enabled_for(name) then if not is_creative_enabled_for(name) then
itemstack:take_item() itemstack:take_item()
@ -99,7 +113,8 @@ local stair_place = function(itemstack, placer, pointed_thing, stair_node)
return itemstack return itemstack
end end
local function get_light_source(nodename)
local function get_light(nodename)
local def = minetest.registered_nodes[nodename] local def = minetest.registered_nodes[nodename]
@ -110,10 +125,26 @@ local function get_light_source(nodename)
return nil return nil
end end
local function get_alpha(nodename)
local def = minetest.registered_nodes[nodename]
if def and def.use_texture_alpha then
return def.use_texture_alpha
end
return nil
end
-- Node will be called stairs:stair_<subname> -- Node will be called stairs:stair_<subname>
function stairs.register_stair(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_stair(
subname, recipeitem, groups, images, description, snds)
local stair_images = set_textures(images) local stair_images = set_textures(images)
local new_groups = table.copy(groups) local new_groups = table.copy(groups)
new_groups.stair = 1 new_groups.stair = 1
minetest.register_node(":stairs:stair_" .. subname, { minetest.register_node(":stairs:stair_" .. subname, {
@ -123,8 +154,8 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
use_texture_alpha = alpha, use_texture_alpha = get_alpha(recipeitem),
light_source = get_light_source(recipeitem), light_source = get_light(recipeitem),
groups = new_groups, groups = new_groups,
sounds = snds, sounds = snds,
node_box = { node_box = {
@ -135,6 +166,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
}, },
}, },
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return stair_place(itemstack, placer, pointed_thing, return stair_place(itemstack, placer, pointed_thing,
"stairs:stair_" .. subname) "stairs:stair_" .. subname)
end, end,
@ -167,9 +199,12 @@ end
-- Node will be called stairs:slab_<subname> -- Node will be called stairs:slab_<subname>
function stairs.register_slab(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_slab(
subname, recipeitem, groups, images, description, snds)
local slab_images = set_textures(images) local slab_images = set_textures(images)
local new_groups = table.copy(groups) local new_groups = table.copy(groups)
new_groups.slab = 1 new_groups.slab = 1
minetest.register_node(":stairs:slab_" .. subname, { minetest.register_node(":stairs:slab_" .. subname, {
@ -179,8 +214,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
use_texture_alpha = alpha, use_texture_alpha = get_alpha(recipeitem),
light_source = get_light_source(recipeitem), light_source = get_light(recipeitem),
groups = new_groups, groups = new_groups,
sounds = snds, sounds = snds,
node_box = { node_box = {
@ -188,6 +223,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
}, },
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return stair_place(itemstack, placer, pointed_thing, return stair_place(itemstack, placer, pointed_thing,
"stairs:slab_" .. subname) "stairs:slab_" .. subname)
end, end,
@ -218,9 +254,12 @@ end
-- Node will be called stairs:stair_outer_<subname> -- Node will be called stairs:stair_outer_<subname>
function stairs.register_stair_outer(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_stair_outer(
subname, recipeitem, groups, images, description, snds)
local stair_images = set_textures(images) local stair_images = set_textures(images)
local new_groups = table.copy(groups) local new_groups = table.copy(groups)
new_groups.stair = 1 new_groups.stair = 1
minetest.register_node(":stairs:stair_outer_" .. subname, { minetest.register_node(":stairs:stair_outer_" .. subname, {
@ -230,8 +269,8 @@ function stairs.register_stair_outer(subname, recipeitem, groups, images, descri
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
use_texture_alpha = alpha, use_texture_alpha = get_alpha(recipeitem),
light_source = get_light_source(recipeitem), light_source = get_light(recipeitem),
groups = new_groups, groups = new_groups,
sounds = snds, sounds = snds,
node_box = { node_box = {
@ -242,13 +281,15 @@ function stairs.register_stair_outer(subname, recipeitem, groups, images, descri
}, },
}, },
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return stair_place(itemstack, placer, pointed_thing, return stair_place(itemstack, placer, pointed_thing,
"stairs:stair_outer_" .. subname) "stairs:stair_outer_" .. subname)
end, end,
}) })
-- add alias for old stairs redo name -- add alias for old stairs redo name
minetest.register_alias("stairs:corner_" .. subname, "stairs:stair_outer_" .. subname) minetest.register_alias("stairs:corner_" .. subname,
"stairs:stair_outer_" .. subname)
-- if no recipe item provided then skip craft recipes -- if no recipe item provided then skip craft recipes
if not recipeitem then if not recipeitem then
@ -269,23 +310,30 @@ function stairs.register_stair_outer(subname, recipeitem, groups, images, descri
minetest.register_craft({ minetest.register_craft({
output = recipeitem .. " 2", output = recipeitem .. " 2",
recipe = { recipe = {
{"stairs:stair_outer_" .. subname, "stairs:stair_outer_" .. subname}, {"stairs:stair_outer_" .. subname,
{"stairs:stair_outer_" .. subname, "stairs:stair_outer_" .. subname}, "stairs:stair_outer_" .. subname},
{"stairs:stair_outer_" .. subname,
"stairs:stair_outer_" .. subname},
}, },
}) })
end end
-- compatibility function for previous stairs:corner_<subname> -- compatibility function for previous stairs:corner_<subname>
function stairs.register_corner(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_corner(
stairs.register_stair_outer(subname, recipeitem, groups, images, description, snds, alpha) subname, recipeitem, groups, images, description, snds)
stairs.register_stair_outer(
subname, recipeitem, groups, images, description, snds)
end end
-- Node will be called stairs:stair_inner_<subname> -- Node will be called stairs:stair_inner_<subname>
function stairs.register_stair_inner(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_stair_inner(
subname, recipeitem, groups, images, description, snds)
local stair_images = set_textures(images) local stair_images = set_textures(images)
local new_groups = table.copy(groups) local new_groups = table.copy(groups)
new_groups.stair = 1 new_groups.stair = 1
minetest.register_node(":stairs:stair_inner_" .. subname, { minetest.register_node(":stairs:stair_inner_" .. subname, {
@ -295,8 +343,8 @@ function stairs.register_stair_inner(subname, recipeitem, groups, images, descri
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
use_texture_alpha = alpha, use_texture_alpha = get_alpha(recipeitem),
light_source = get_light_source(recipeitem), light_source = get_light(recipeitem),
groups = new_groups, groups = new_groups,
sounds = snds, sounds = snds,
node_box = { node_box = {
@ -308,13 +356,15 @@ function stairs.register_stair_inner(subname, recipeitem, groups, images, descri
}, },
}, },
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return stair_place(itemstack, placer, pointed_thing, return stair_place(itemstack, placer, pointed_thing,
"stairs:stair_inner_" .. subname) "stairs:stair_inner_" .. subname)
end, end,
}) })
-- add alias for old stairs redo name -- add alias for old stairs redo name
minetest.register_alias("stairs:invcorner_" .. subname, "stairs:stair_inner_" .. subname) minetest.register_alias("stairs:invcorner_" .. subname,
"stairs:stair_inner_" .. subname)
-- if no recipe item provided then skip craft recipes -- if no recipe item provided then skip craft recipes
if not recipeitem then if not recipeitem then
@ -335,22 +385,30 @@ function stairs.register_stair_inner(subname, recipeitem, groups, images, descri
minetest.register_craft({ minetest.register_craft({
output = recipeitem .. " 3", output = recipeitem .. " 3",
recipe = { recipe = {
{"stairs:stair_inner_" .. subname, "stairs:stair_inner_" .. subname}, {"stairs:stair_inner_" .. subname,
{"stairs:stair_inner_" .. subname, "stairs:stair_inner_" .. subname}, "stairs:stair_inner_" .. subname},
{"stairs:stair_inner_" .. subname,
"stairs:stair_inner_" .. subname},
}, },
}) })
end end
-- compatibility function for previous stairs:invcorner_<subname> -- compatibility function for previous stairs:invcorner_<subname>
function stairs.register_invcorner(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_invcorner(
stairs.register_stair_inner(subname, recipeitem, groups, images, description, snds, alpha) subname, recipeitem, groups, images, description, snds)
stairs.register_stair_inner(
subname, recipeitem, groups, images, description, snds)
end end
-- Node will be called stairs:slope_<subname> -- Node will be called stairs:slope_<subname>
function stairs.register_slope(subname, recipeitem, groups, images, description, snds, alpha) function stairs.register_slope(
subname, recipeitem, groups, images, description, snds)
local stair_images = set_textures(images) local stair_images = set_textures(images)
local new_groups = table.copy(groups) local new_groups = table.copy(groups)
new_groups.stair = 1 new_groups.stair = 1
minetest.register_node(":stairs:slope_" .. subname, { minetest.register_node(":stairs:slope_" .. subname, {
@ -361,8 +419,8 @@ function stairs.register_slope(subname, recipeitem, groups, images, description,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
use_texture_alpha = alpha, use_texture_alpha = get_alpha(recipeitem),
light_source = get_light_source(recipeitem), light_source = get_light(recipeitem),
groups = new_groups, groups = new_groups,
sounds = snds, sounds = snds,
selection_box = { selection_box = {
@ -405,19 +463,35 @@ end
-- Nodes will be called stairs:{stair,slab}_<subname> -- Nodes will be called stairs:{stair,slab}_<subname>
function stairs.register_stair_and_slab(subname, recipeitem, groups, images, function stairs.register_stair_and_slab(
desc_stair, desc_slab, sounds, alpha) subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds, alpha)
stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds, alpha) stairs.register_stair(
subname, recipeitem, groups, images, desc_stair, sounds)
stairs.register_slab(
subname, recipeitem, groups, images, desc_slab, sounds)
end end
-- Nodes will be called stairs:{stair,slab,corner,invcorner,slope}_<subname> -- Nodes will be called stairs:{stair,slab,corner,invcorner,slope}_<subname>
function stairs.register_all(subname, recipeitem, groups, images, desc, snds, alpha) function stairs.register_all(
stairs.register_stair(subname, recipeitem, groups, images, desc, snds, alpha) subname, recipeitem, groups, images, desc, snds)
stairs.register_slab(subname, recipeitem, groups, images, desc, snds, alpha)
stairs.register_corner(subname, recipeitem, groups, images, desc, snds, alpha) stairs.register_stair(
stairs.register_invcorner(subname, recipeitem, groups, images, desc, snds, alpha) subname, recipeitem, groups, images, desc, snds)
stairs.register_slope(subname, recipeitem, groups, images, desc, snds, alpha)
stairs.register_slab(
subname, recipeitem, groups, images, desc, snds)
stairs.register_corner(
subname, recipeitem, groups, images, desc, snds)
stairs.register_invcorner(
subname, recipeitem, groups, images, desc, snds)
stairs.register_slope(
subname, recipeitem, groups, images, desc, snds)
end end
@ -722,34 +796,8 @@ local colours = {
{"yellow", "Yellow", "#e3ff0070"}, {"yellow", "Yellow", "#e3ff0070"},
} }
--= Coloured Blocks Mod
if minetest.get_modpath("cblocks") then
local col
for i = 1, #colours, 1 do
col = colours[i][1]
stairs.register_all(colours[i][1] .. "_glass", "cblocks:glass_" .. colours[i][1],
{cracky = 3, oddly_breakable_by_hand = 3},
{"cblocks.png^[colorize:" .. colours[i][3]},
colours[i][2] .. " Glass",
stairs.glass, true)
if col == "yellow" then col = "yellow2" end -- fixes ethereal yellow wood and cblocks yellow wood mixup
stairs.register_all(col .. "_wood", "cblocks:wood_" .. colours[i][1],
{choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
{"default_wood.png^[colorize:" .. colours[i][3]},
colours[i][2] .. " Wooden",
stairs.wood)
end --for
end
--= More Ores Mod --= More Ores Mod
if minetest.get_modpath("moreores") then if minetest.get_modpath("moreores") then
grp = {cracky = 1, level = 2} grp = {cracky = 1, level = 2}