From 78693c37be17aa0c64920ceb0aa0bebdb17896fa Mon Sep 17 00:00:00 2001 From: Jat15 Date: Sun, 19 Nov 2017 03:28:30 +0100 Subject: [PATCH] Convert node cut by Xdecor Registrations -Simplify and add alias for xdecor Micreoblocks, panels, slabs, stairs -Simplify for forcing alias or normal -Add function for convert block xdecor -Add alias in register. Init function uppercase calculate the number of capital letters for lbm name normal_alias_or_force .... Add function for alll alias Xdecor Add Settingtypes --- settingtypes.txt | 4 ++++ stairsplus/init.lua | 28 ++++++++++++++++++++++++ stairsplus/microblocks.lua | 41 +++++++++++++++++++++++++++++------ stairsplus/panels.lua | 42 ++++++++++++++++++++++++++++++------ stairsplus/registrations.lua | 2 ++ stairsplus/slabs.lua | 27 +++++++++++++++++------ stairsplus/stairs.lua | 31 ++++++++++++++++++++------ 7 files changed, 151 insertions(+), 24 deletions(-) create mode 100644 settingtypes.txt diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..91f8a4d --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,4 @@ +# + +moreblocks.circular_saw_crafting (If false desactive a craft the circular saw) bool true +moreblocks.conversion_xdecor>moreblocks (Convert all block cutting by xdecor) bool false diff --git a/stairsplus/init.lua b/stairsplus/init.lua index 5cd415c..79ac6d7 100644 --- a/stairsplus/init.lua +++ b/stairsplus/init.lua @@ -49,6 +49,28 @@ function stairsplus:prepare_groups(groups) return result end +function stairsplus:uppercase_index_string(words) + return string.gsub( + string.gsub( + minetest.serialize( + string.find( + words,"%u" + ) + ), + "return ", "_" + ), + ",", "_" + ) +end + +function stairsplus:normal_alias_or_force(force) + if force then + return minetest.register_alias_force + else + return minetest.register_alias + end +end + function stairsplus:register_all(modname, subname, recipeitem, fields) self:register_stair(modname, subname, recipeitem, fields) self:register_slab (modname, subname, recipeitem, fields) @@ -72,6 +94,12 @@ function stairsplus:register_alias_force_all(modname_old, subname_old, modname_n self:register_panel_alias_force(modname_old, subname_old, modname_new, subname_new) self:register_micro_alias_force(modname_old, subname_old, modname_new, subname_new) end +function stairsplus:register_xdecor_alias_all(modname_old, subname_old, modname_new, subname_new, force) + self:register_stairs_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + self:register_slabs_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + self:register_panels_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + self:register_micro_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) +end function register_stair_slab_panel_micro(modname, subname, recipeitem, groups, images, description, drop, light) stairsplus:register_all(modname, subname, recipeitem, { diff --git a/stairsplus/microblocks.lua b/stairsplus/microblocks.lua index 50d8487..1bf442e 100644 --- a/stairsplus/microblocks.lua +++ b/stairsplus/microblocks.lua @@ -69,18 +69,46 @@ for k,v in pairs(microblocks_defs) do table.insert(stairsplus.shapes_list, { "micro_", k }) end -function stairsplus:register_micro_alias(modname_old, subname_old, modname_new, subname_new) +function stairsplus:register_micro_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + if not(minetest.settings:get_bool("moreblocks.conversion_xdecor>moreblocks")) then + return + end + minetest.register_lbm({ + name = ":replace_xdecor_mano_cube_" .. modname_old .. "_" .. string.lower(subname_old) .. "_" .. stairsplus:uppercase_index_string(subname_old) .. "_" .. + modname_new .."_" .. string.lower(subname_new) .. stairsplus:uppercase_index_string(subname_new) .. string.gsub(minetest.serialize(force),"return ", "_"), + nodenames = {modname_old .. ":" .. subname_old .. "_nanoslab", modname_old .. ":" .. subname_old .."_cube"}, + run_at_every_load = false, + action = function(pos, node) + if modname_old .. ":" .. subname_old .. "_nanoslab" == node.name then + nodename = modname_new .. ":micro_" .. subname_new .. "_1" + else + nodename = modname_new .. ":micro_" .. subname_new + end + if node.param2 == 0 or node.param2%4 == 0 then + minetest.set_node(pos, {name = nodename, param2 = node.param2+3}) + else + minetest.set_node(pos, {name = nodename, param2 = node.param2-1}) + end + end, + }) +end + +function register_micro_alias_and_force(modname_old, subname_old, modname_new, subname_new, force) + local stairsplus_alias = stairsplus:normal_alias_or_force(force) local defs = stairsplus.copytable(microblocks_defs) for alternate, def in pairs(defs) do - minetest.register_alias(modname_old .. ":micro_" .. subname_old .. alternate, modname_new .. ":micro_" .. subname_new .. alternate) + stairsplus_alias(modname_old .. ":micro_" .. subname_old .. alternate, modname_new .. ":micro_" .. subname_new .. alternate) end + stairsplus:register_micro_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + +end + +function stairsplus:register_micro_alias(modname_old, subname_old, modname_new, subname_new) + register_micro_alias_and_force(modname_old, subname_old, modname_new, subname_new, false) end function stairsplus:register_micro_alias_force(modname_old, subname_old, modname_new, subname_new) - local defs = stairsplus.copytable(microblocks_defs) - for alternate, def in pairs(defs) do - minetest.register_alias_force(modname_old .. ":micro_" .. subname_old .. alternate, modname_new .. ":micro_" .. subname_new .. alternate) - end + register_micro_alias_and_force(modname_old, subname_old, modname_new, subname_new, true) end function stairsplus:register_micro(modname, subname, recipeitem, fields) @@ -102,6 +130,7 @@ function stairsplus:register_micro(modname, subname, recipeitem, fields) minetest.register_node(":" ..modname.. ":micro_" ..subname..alternate, def) end minetest.register_alias(modname.. ":micro_" ..subname.. "_bottom", modname.. ":micro_" ..subname) + stairsplus:register_micro_xdecor_alias(modname, subname, modname, subname, false) circular_saw.known_nodes[recipeitem] = {modname, subname} diff --git a/stairsplus/panels.lua b/stairsplus/panels.lua index 98e77fd..62409f1 100644 --- a/stairsplus/panels.lua +++ b/stairsplus/panels.lua @@ -69,18 +69,47 @@ for k,v in pairs(panels_defs) do table.insert(stairsplus.shapes_list, { "panel_", k }) end -function stairsplus:register_panel_alias(modname_old, subname_old, modname_new, subname_new) +function stairsplus:register_panels_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + if not(minetest.settings:get_bool("moreblocks.conversion_xdecor>moreblocks")) then + return + end + minetest.register_lbm({ + name = ":replace_xdecor_panel_micropanel_" .. modname_old .. "_" .. string.lower(subname_old) .. "_" .. stairsplus:uppercase_index_string(subname_old) .. "_" .. + modname_new .. "_" .. string.lower(subname_new) .. stairsplus:uppercase_index_string(subname_new) .. string.gsub(minetest.serialize(force),"return ", "_"), + nodenames = {modname_old .. ":" .. subname_old .. "_micropanel", modname_old .. ":" .. subname_old .. "_panel"}, + run_at_every_load = false, + action = function(pos, node) + if modname_old .. ":" .. subname_old .. "_micropanel" == node.name then + nodename = modname_new .. ":panel_" .. subname_new .. "_1" + else + nodename = modname_new .. ":panel_" .. subname_new + end + if node.param2 == 0 or node.param2%4 == 0 then + minetest.set_node(pos, {name = nodename, param2 = node.param2+2}) + elseif node.param2%4 == 3 or node.param2%2 == 0 then + minetest.set_node(pos, {name = nodename, param2 = node.param2-2}) + else + minetest.set_node(pos, {name = nodename, param2 = node.param2+2}) + end + end, + }) +end + +function register_panel_alias_and_force(modname_old, subname_old, modname_new, subname_new, force) + local stairsplus_alias = stairsplus:normal_alias_or_force(force) local defs = stairsplus.copytable(panels_defs) for alternate, def in pairs(defs) do - minetest.register_alias(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate) + stairsplus_alias(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate) end + stairsplus:register_panels_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) +end + +function stairsplus:register_panel_alias(modname_old, subname_old, modname_new, subname_new) + register_panel_alias_and_force(modname_old, subname_old, modname_new, subname_new, false) end function stairsplus:register_panel_alias_force(modname_old, subname_old, modname_new, subname_new) - local defs = stairsplus.copytable(panels_defs) - for alternate, def in pairs(defs) do - minetest.register_alias_force(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate) - end + register_panel_alias_and_force(modname_old, subname_old, modname_new, subname_new, true) end function stairsplus:register_panel(modname, subname, recipeitem, fields) @@ -102,6 +131,7 @@ function stairsplus:register_panel(modname, subname, recipeitem, fields) minetest.register_node(":" ..modname.. ":panel_" ..subname..alternate, def) end minetest.register_alias(modname.. ":panel_" ..subname.. "_bottom", modname.. ":panel_" ..subname) + stairsplus:register_panels_xdecor_alias(modname, subname, modname, subname, false) circular_saw.known_nodes[recipeitem] = {modname, subname} diff --git a/stairsplus/registrations.lua b/stairsplus/registrations.lua index 1e86954..b26dcd7 100644 --- a/stairsplus/registrations.lua +++ b/stairsplus/registrations.lua @@ -72,6 +72,7 @@ for _, name in pairs(default_nodes) do stairsplus:register_all(mod, name, nodename, ndef) minetest.register_alias_force("stairs:stair_" .. name, mod .. ":stair_" .. name) minetest.register_alias_force("stairs:slab_" .. name, mod .. ":slab_" .. name) + stairsplus:register_xdecor_alias_all("default", name, mod, name, false) end -- farming registrations @@ -87,6 +88,7 @@ if minetest.get_modpath("farming") then stairsplus:register_all(mod, name, nodename, ndef) minetest.register_alias_force("stairs:stair_" .. name, mod .. ":stair_" .. name) minetest.register_alias_force("stairs:slab_" .. name, mod .. ":slab_" .. name) + stairsplus:register_xdecor_alias_all("farming", name, mod, name, false) end end diff --git a/stairsplus/slabs.lua b/stairsplus/slabs.lua index de7f031..a696107 100644 --- a/stairsplus/slabs.lua +++ b/stairsplus/slabs.lua @@ -48,18 +48,31 @@ for k,v in pairs(slabs_defs) do table.insert(stairsplus.shapes_list, { "slab_", k }) end -function stairsplus:register_slab_alias(modname_old, subname_old, modname_new, subname_new) +function stairsplus:register_slabs_xdecor_alias(modname_old, subname_old, modname_new, subname_new) + if not(minetest.settings:get_bool("moreblocks.conversion_xdecor>moreblocks")) then + return + end + local stairsplus_alias = stairsplus:normal_alias_or_force(force) + stairsplus_alias(modname_old .. ":" .. subname_old .."_microslab", modname_new .. ":slab_" .. subname_new .. "_1") + stairsplus_alias("stairs:slab_" .. subname_old, modname_new .. ":slab_" .. subname_new) +end + +function register_slab_alias_and_force(modname_old, subname_old, modname_new, subname_new, force) + local stairsplus_alias = stairsplus:normal_alias_or_force(force) local defs = stairsplus.copytable(slabs_defs) for alternate, def in pairs(defs) do - minetest.register_alias(modname_old .. ":slab_" .. subname_old .. alternate, modname_new .. ":slab_" .. subname_new .. alternate) + stairsplus_alias(modname_old .. ":slab_" .. subname_old .. alternate, modname_new .. ":slab_" .. subname_new .. alternate) end + stairsplus:register_slabs_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) +end + +function stairsplus:register_slab_alias(modname_old, subname_old, modname_new, subname_new) + register_slab_alias_and_force(modname_old, subname_old, modname_new, subname_new, false) + minetest.register_alias("stairs:slab_" .. subname_old, modname_new .. ":slab_" .. subname_new) end function stairsplus:register_slab_alias_force(modname_old, subname_old, modname_new, subname_new) - local defs = stairsplus.copytable(slabs_defs) - for alternate, def in pairs(defs) do - minetest.register_alias_force(modname_old .. ":slab_" .. subname_old .. alternate, modname_new .. ":slab_" .. subname_new .. alternate) - end + register_slab_alias_and_force(modname_old, subname_old, modname_new, subname_new, true) end function stairsplus:register_slab(modname, subname, recipeitem, fields) @@ -100,6 +113,8 @@ function stairsplus:register_slab(modname, subname, recipeitem, fields) minetest.register_node(":" .. modname .. ":slab_" .. subname .. alternate, def) end + stairsplus:register_slabs_xdecor_alias(modname, subname, modname, subname, false) + circular_saw.known_nodes[recipeitem] = {modname, subname} -- Some saw-less recipes: diff --git a/stairsplus/stairs.lua b/stairsplus/stairs.lua index 815f7ac..904cb92 100644 --- a/stairsplus/stairs.lua +++ b/stairsplus/stairs.lua @@ -109,18 +109,35 @@ for k,v in pairs(stairs_defs) do table.insert(stairsplus.shapes_list, { "stair_", k }) end -function stairsplus:register_stair_alias(modname_old, subname_old, modname_new, subname_new) - local defs = stairsplus.copytable(stairs_defs) - for alternate, def in pairs(defs) do - minetest.register_alias(modname_old .. ":stair_" .. subname_old .. alternate, modname_new .. ":stair_" .. subname_new .. alternate) +function stairsplus:register_stairs_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) + if not(minetest.settings:get_bool("moreblocks.conversion_xdecor>moreblocks")) then + return end + local stairsplus_alias = stairsplus:normal_alias_or_force(force) + stairsplus_alias(modname_old .. ":" .. subname_old .."_thinstair", modname_new .. ":stair_" ..subname_new .. "_alt_1") + stairsplus_alias(modname_old .. ":" .. subname_old .."_doublepanel", modname_new .. ":stair_" ..subname_new .. "_alt") + stairsplus_alias(modname_old .. ":" .. subname_old .."_halfstair", modname_new .. ":stair_" ..subname_new .. "_half") + stairsplus_alias(modname_old .. ":" .. subname_old .."_outerstair", modname_new .. ":stair_" ..subname_new .. "_outer") + stairsplus_alias(modname_old .. ":" .. subname_old .."_innerstair", modname_new .. ":stair_" ..subname_new .. "_inner") + stairsplus_alias("stairs:stair_" .. subname_old, modname_new .. ":stair_" .. subname_new) end -function stairsplus:register_stair_alias_force(modname_old, subname_old, modname_new, subname_new) +function register_stair_alias_and_force(modname_old, subname_old, modname_new, subname_new, force) + local stairsplus_alias = stairsplus:normal_alias_or_force(force) local defs = stairsplus.copytable(stairs_defs) for alternate, def in pairs(defs) do - minetest.register_alias_force(modname_old .. ":stair_" .. subname_old .. alternate, modname_new .. ":stair_" .. subname_new .. alternate) + stairsplus_alias(modname_old .. ":stair_" .. subname_old .. alternate, modname_new .. ":stair_" .. subname_new .. alternate) end + stairsplus:register_stairs_xdecor_alias(modname_old, subname_old, modname_new, subname_new, force) +end + +function stairsplus:register_stair_alias(modname_old, subname_old, modname_new, subname_new) + register_stair_alias_and_force(modname_old, subname_old, modname_new, subname_new, false) +end + + +function stairsplus:register_stair_alias_force(modname_old, subname_old, modname_new, subname_new) + register_stair_alias_and_force(modname_old, subname_old, modname_new, subname_new, true) end function stairsplus:register_stair(modname, subname, recipeitem, fields) @@ -145,6 +162,8 @@ function stairsplus:register_stair(modname, subname, recipeitem, fields) minetest.register_node(":" .. modname .. ":stair_" .. subname .. alternate, def) end + stairsplus:register_stairs_xdecor_alias(modname, subname, modname, subname, false) + circular_saw.known_nodes[recipeitem] = {modname, subname} -- Some saw-less recipes: