Refactor stairsplus registrations (#93)

* Refactor stairsplus registrations

 - Reorganize and remove redundant code.
 - Remove sunlight_propagates=true and default to paramtype="light".
    This causes cut blocks to have a shadow but not completely block light.
 - Fix several bugs (#90, #91, #92).

* Readd sunlight_propagates=true for compatibility.
This commit is contained in:
John Cole 2017-12-19 17:42:45 -05:00 committed by Hugo Locurcio
parent 80d35c8215
commit 6a996eb86a
1 changed files with 36 additions and 55 deletions

View File

@ -5,6 +5,7 @@ Copyright (c) 2011-2017 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information. Licensed under the zlib license. See LICENSE.md for more information.
--]] --]]
-- default registrations
local default_nodes = { -- Default stairs/slabs/panels/microblocks: local default_nodes = { -- Default stairs/slabs/panels/microblocks:
"stone", "stone",
"stone_block", "stone_block",
@ -48,73 +49,53 @@ local default_nodes = { -- Default stairs/slabs/panels/microblocks:
"desert_sandstone_block", "desert_sandstone_block",
"sandstone_block", "sandstone_block",
"coral_skeleton", "coral_skeleton",
"farming:straw"
} }
for _, name in pairs(default_nodes) do for _, name in pairs(default_nodes) do
local nodename = "default:"..name local mod = "default"
local a,b = string.find(name, ":") local nodename = mod .. ":" .. name
if b then local ndef = table.copy(minetest.registered_nodes[nodename])
nodename = name ndef.sunlight_propagates = true
name = string.sub(name, b+1)
-- Stone and desert_stone drop cobble and desert_cobble respectively.
if type(ndef.drop) == "string" then
ndef.drop = ndef.drop:gsub(".+:", "")
end end
local ndef = minetest.registered_nodes[nodename]
if ndef then
local drop
if type(ndef.drop) == "string" then
drop = ndef.drop:sub((b or 8)+1)
end
local tiles = ndef.tiles -- Use the primary tile for all sides of cut glasslike nodes.
if #ndef.tiles > 1 and ndef.drawtype:find("glass") then if #ndef.tiles > 1 and ndef.drawtype and ndef.drawtype:find("glass") then
tiles = { ndef.tiles[1] } ndef.tiles = {ndef.tiles[1]}
end end
stairsplus:register_all("moreblocks", name, nodename, { stairsplus:register_all("moreblocks", name, nodename, ndef)
description = ndef.description, end
drop = drop,
groups = ndef.groups, -- farming registrations
sounds = ndef.sounds, if minetest.get_modpath("farming") then
tiles = tiles, local farming_nodes = {"straw"}
sunlight_propagates = true, for _, name in pairs(farming_nodes) do
light_source = ndef.light_source local mod = "farming"
}) local nodename = mod .. ":" .. name
local ndef = table.copy(minetest.registered_nodes[nodename])
ndef.sunlight_propagates = true
stairsplus:register_all("moreblocks", name, nodename, ndef)
end end
end end
-- wool registrations -- wool registrations
if minetest.get_modpath("wool") then if minetest.get_modpath("wool") then
local dyes = {"white", "grey", "black", "red", "yellow", "green", "cyan",
"blue", "magenta", "orange", "violet", "brown", "pink",
"dark_grey", "dark_green"}
for _, name in pairs(dyes) do
local mod = "wool"
local nodename = mod .. ":" .. name
local ndef = table.copy(minetest.registered_nodes[nodename])
ndef.sunlight_propagates = true
local colorlist = { -- Prevent dye+cut wool recipy from creating a full wool block.
{"white", "White Wool"}, ndef.groups.wool = nil
{"grey", "Grey Wool"},
{"black", "Black Wool"},
{"red", "Red Wool"},
{"yellow", "Yellow Wool"},
{"green", "Green Wool"},
{"cyan", "Cyan Wool"},
{"blue", "Blue Wool"},
{"magenta", "Magenta Wool"},
{"orange", "Orange Wool"},
{"violet", "Violet Wool"},
{"brown", "Brown Wool"},
{"pink", "Pink Wool"},
{"dark_grey", "Dark Grey Wool"},
{"dark_green", "Dark Green Wool"},
}
for i in ipairs(colorlist) do stairsplus:register_all(mod, name, nodename, ndef)
local color = colorlist[i][1]
local colordesc = colorlist[i][2]
stairsplus:register_all("wool", color, "wool:"..color, {
description = colordesc,
tiles = {"wool_"..color..".png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,
flammable=3,wool=1,not_in_creative_inventory=1},
sounds = default.node_sound_defaults(),
sunlight_propagates = true,
})
end end
end end