Huge changes on functions.lua

This commit is contained in:
JoseDouglas26 2024-05-21 17:12:57 -03:00
parent d7ab3f74eb
commit 6552c4ba6b
1 changed files with 128 additions and 123 deletions

View File

@ -1,3 +1,13 @@
mcl_copper.subnodes = {
["bars_copper"] = {"", "flat"},
["button_copper"] = {"off"},
["door"] = {"b_1", "b_2", "b_3", "b_4", "t_1", "t_2", "t_3", "t_4"},
["pressure_plate_copper"] = {"off"},
["slab_copper"] = {"", "double", "top"},
["stair_copper"] = {"", "inner", "outer"},
["trapdoor"] = {"", "open"}
}
-- Functions used to strip wax from the other half of the door
local function strip(pos, node, node_def)
local node = node or minetest.get_node(pos)
@ -9,10 +19,10 @@ local function strip(pos, node, node_def)
minetest.swap_node(pos, node)
end
local function strip_door_top(pos, node, node_def)
strip(vector.offset(pos,0,-1,0))
strip(vector.offset(pos, 0, 1, 0))
end
local function strip_door_bottom(pos, node, node_def)
strip(vector.offset(pos,0,1,0))
strip(vector.offset(pos, 0, -1, 0))
end
-- Functions used to wax the other half of the door
@ -26,18 +36,18 @@ local function wax(pos, node, node_def)
minetest.swap_node(pos, node)
end
local function wax_door_top(pos, node, node_def)
wax(vector.offset(pos,0,-1,0))
wax(vector.offset(pos, 0, 1, 0))
end
local function wax_door_bottom(pos, node, node_def)
wax(vector.offset(pos,0,1,0))
wax(vector.offset(pos, 0, -1, 0))
end
-- Functions used to oxidize the other half of the door.
local function oxidize_door_top(pos, node, node_def)
mcl_oxidize.oxidize(vector.offset(pos,0,-1,0))
mcl_oxidize.oxidize(vector.offset(pos, 0, 1, 0))
end
local function oxidize_door_bottom(pos, node, node_def)
mcl_oxidize.oxidize(vector.offset(pos,0,1,0))
mcl_oxidize.oxidize(vector.offset(pos, 0, 1, 0))
end
--- Function used to define the oxidized and stripped variants of copper-related blocks that
@ -50,55 +60,59 @@ end
---@param decay_chain table
local function register_oxidation_and_scraping(mod_name, subname, decay_chain)
local item, oxidized_item
-- Handling special decay chain names.
if mod_name == "mcl_stairs" then
for i = 1, 4 do
decay_chain[i] = decay_chain[i].."_cut"
end
end
for i = 1, #decay_chain - 1 do
item = mod_name..":"..subname..decay_chain[i]
oxidized_item = mod_name..":"..subname..decay_chain[i + 1]
-- Copper buttons have a special treatment due to the format of your name.
if subname:find("button") or subname:find("pressure_plate") then
item = item.."_off"
oxidized_item = oxidized_item.."_off"
end
minetest.override_item(item, {_mcl_oxidized_variant = oxidized_item})
minetest.override_item(oxidized_item, {_mcl_stripped_variant = item})
if subname:find("stair") then
minetest.override_item(item.."_inner", {_mcl_oxidized_variant = oxidized_item.."_inner"})
minetest.override_item(item.."_outer", {_mcl_oxidized_variant = oxidized_item.."_outer"})
minetest.override_item(oxidized_item.."_inner", {_mcl_stripped_variant = item.."_inner"})
minetest.override_item(oxidized_item.."_outer", {_mcl_stripped_variant = item.."_outer"})
elseif subname:find("slab") then
minetest.override_item(item.."_double", {_mcl_oxidized_variant = oxidized_item.."_double"})
minetest.override_item(item.."_top", {_mcl_oxidized_variant = oxidized_item.."_top"})
minetest.override_item(oxidized_item.."_double", {_mcl_stripped_variant = item.."_double"})
minetest.override_item(oxidized_item.."_top", {_mcl_stripped_variant = item.."_top"})
elseif subname:find("trapdoor") then
minetest.override_item(item.."_open", {_mcl_oxidized_variant = oxidized_item.."_open"})
minetest.override_item(oxidized_item.."_open", {_mcl_stripped_variant = item.."_open"})
elseif subname == "door" then
for i = 1,4 do
local is = tostring(i)
minetest.override_item(item.."_b_"..is, {
_mcl_oxidized_variant = oxidized_item.."_b_"..is,
_mcl_on_oxidize = oxidize_door_bottom
})
minetest.override_item(oxidized_item.."_b_"..is, {
_mcl_stripped_variant = item.."_b_"..is,
_mcl_on_strip = strip_door_bottom,
})
minetest.override_item(item.."_t_"..is, {
_mcl_oxidized_variant = oxidized_item.."_t_"..is,
_mcl_on_oxidize = oxidize_door_top,
})
minetest.override_item(oxidized_item.."_t_"..is, {
_mcl_stripped_variant = item.."_t_"..is,
_mcl_on_strip = strip_door_top,
})
for _, subnode in pairs(mcl_copper.subnodes[subname]) do
if subnode == "" then
minetest.override_item(item, {_mcl_oxidized_variant = oxidized_item})
minetest.override_item(oxidized_item, {_mcl_stripped_variant = item})
else
if subname == "door" then
if subnode:find("b_") then
minetest.override_item(item.."_"..subnode,
{
_mcl_oxidized_variant = oxidized_item.."_"..subnode,
_mcl_on_oxidize = oxidize_door_top,
}
)
minetest.override_item(oxidized_item.."_"..subnode,
{
_mcl_stripped_variant = item.."_"..subnode,
_mcl_on_strip = strip_door_top,
}
)
else
minetest.override_item(item.."_"..subnode,
{
_mcl_oxidized_variant = oxidized_item.."_"..subnode,
_mcl_on_oxidize = oxidize_door_bottom,
}
)
minetest.override_item(oxidized_item.."_"..subnode,
{
_mcl_stripped_variant = item.."_"..subnode,
_mcl_on_strip = strip_door_bottom,
}
)
end
else
minetest.override_item(item.."_"..subnode,
{_mcl_oxidized_variant = oxidized_item.."_"..subnode}
)
minetest.override_item(oxidized_item.."_"..subnode,
{_mcl_stripped_variant = item.."_"..subnode}
)
end
end
elseif subname:find("bars") then
minetest.override_item(item.."_flat", {_mcl_oxidized_variant = oxidized_item.."_flat"})
minetest.override_item(oxidized_item.."_flat", {_mcl_stripped_variant = item.."_flat"})
end
end
end
@ -110,94 +124,85 @@ end
--- containing the list of subnames of the block oxidation chain (without the waxed variants subnames).
local function register_waxing_and_scraping(mod_name, subname, decay_chain)
local waxed_item, unwaxed_item
-- Handling special decay chain names.
if mod_name == "mcl_stairs" then
for i = 1, 4 do
decay_chain[i] = decay_chain[i].."_cut"
end
end
for i = 1, #decay_chain do
waxed_item = mod_name..":"..subname..decay_chain[i]
unwaxed_item = mod_name..":"..subname:gsub("waxed_", "")..decay_chain[i]
-- Copper buttons have a special treatment due to the format of your name.
if subname:find("button") or subname:find("pressure_plate") then
waxed_item = waxed_item.."_off"
unwaxed_item = unwaxed_item.."_off"
end
minetest.override_item(waxed_item, {_mcl_stripped_variant = unwaxed_item})
minetest.override_item(unwaxed_item, {_mcl_waxed_variant = waxed_item})
if subname:find("stair") then
minetest.override_item(waxed_item.."_inner", {_mcl_stripped_variant = unwaxed_item.."_inner"})
minetest.override_item(waxed_item.."_outer", {_mcl_stripped_variant = unwaxed_item.."_outer"})
minetest.override_item(unwaxed_item.."_inner", {_mcl_waxed_variant = waxed_item.."_inner"})
minetest.override_item(unwaxed_item.."_outer", {_mcl_waxed_variant = waxed_item.."_outer"})
elseif subname:find("slab") then
minetest.override_item(waxed_item.."_double", {_mcl_stripped_variant = unwaxed_item.."_double"})
minetest.override_item(waxed_item.."_top", {_mcl_stripped_variant = unwaxed_item.."_top"})
minetest.override_item(unwaxed_item.."_double", {_mcl_waxed_variant = waxed_item.."_double"})
minetest.override_item(unwaxed_item.."_top", {_mcl_waxed_variant = waxed_item.."_top"})
elseif subname:find("trapdoor") then
minetest.override_item(waxed_item.."_open", {_mcl_stripped_variant = unwaxed_item.."_open"})
minetest.override_item(unwaxed_item.."_open", {_mcl_waxed_variant = waxed_item.."_open"})
elseif subname == "waxed_door" then
for i = 1,4 do
local is = tostring(i)
minetest.override_item(waxed_item.."_b_"..is, {
_mcl_stripped_variant = unwaxed_item.."_b_"..is,
_mcl_on_strip = strip_door_bottom,
})
minetest.override_item(unwaxed_item.."_b_"..is, {
_mcl_waxed_variant = waxed_item.."_b_"..is,
_mcl_on_wax = wax_door_bottom,
})
minetest.override_item(waxed_item.."_t_"..is, {
_mcl_stripped_variant = unwaxed_item.."_t_"..is,
_mcl_on_strip = strip_door_top,
})
minetest.override_item(unwaxed_item.."_t_"..is, {
_mcl_waxed_variant = waxed_item.."_t_"..is,
_mcl_on_wax = wax_door_top,
})
for _, subnode in pairs(mcl_copper.subnodes[subname]) do
if subnode == "" then
minetest.override_item(waxed_item, {_mcl_stripped_variant = unwaxed_item})
minetest.override_item(unwaxed_item, {_mcl_waxed_variant = waxed_item})
else
if subname == "door" then
if subnode:find("b_") then
minetest.override_item(waxed_item.."_"..subnode,
{
_mcl_stripped_variant = unwaxed_item.."_"..subnode,
_mcl_on_strip = strip_door_top,
}
)
minetest.override_item(unwaxed_item.."_"..subnode,
{
_mcl_waxed_variant = waxed_item.."_"..subnode,
_mcl_on_wax = wax_door_top,
}
)
else
minetest.override_item(waxed_item.."_"..subnode,
{
_mcl_stripped_variant = unwaxed_item.."_"..subnode,
_mcl_on_strip = strip_door_bottom,
}
)
minetest.override_item(unwaxed_item.."_"..subnode,
{
_mcl_waxed_variant = waxed_item.."_"..subnode,
_mcl_on_wax = wax_door_bottom,
}
)
end
else
minetest.override_item(waxed_item.."_"..subnode,
{_mcl_stripped_variant = unwaxed_item.."_"..subnode}
)
minetest.override_item(unwaxed_item.."_"..subnode,
{_mcl_waxed_variant = waxed_item.."_"..subnode}
)
end
end
elseif subname:find("bars") then
minetest.override_item(waxed_item.."_flat", {_mcl_stripped_variant = unwaxed_item.."_flat"})
minetest.override_item(unwaxed_item.."_flat", {_mcl_waxed_variant = waxed_item.."_flat"})
end
end
end
-- Decay chain for doors and trapdoors
-- Decay chain for almost all blocks.
local decay_chain = {
"",
"_exposed",
"_weathered",
"_oxidized"
}
-- Defining variants for doors, trapdoors, button, pressure plates and bars.
register_oxidation_and_scraping("mcl_copper", "trapdoor", decay_chain)
-- Blocks per mod. {mod_name, unwaxed (first on decay chain), waxed (first waxed on decay chain)}
local mods_and_blocks = {
{"xpanes", "bars_copper", "bars_waxed_copper"},
{"mesecons_button", "button_copper", "button_waxed_copper"},
{"mcl_copper", "door", "waxed_door"},
{"mcl_copper", "pressure_plate_copper", "pressure_plate_waxed_copper"},
{"mcl_stairs", "slab_copper", "slab_waxed_copper"},
{"mcl_stairs", "stair_copper", "stair_waxed_copper"},
{"mcl_copper", "trapdoor", "waxed_trapdoor"}
}
-- Defining variants for all blocks registered by other API's.
for _, mod_and_blocks in pairs(mods_and_blocks) do
local mod = mod_and_blocks[1]
local oxidize_and_scrap = mod_and_blocks[2]
local wax_and_scrap = mod_and_blocks[3]
register_oxidation_and_scraping("mcl_copper", "door", decay_chain)
register_oxidation_and_scraping("mesecons_button", "button_copper", decay_chain)
register_oxidation_and_scraping("mcl_copper", "pressure_plate_copper", decay_chain)
register_oxidation_and_scraping("xpanes", "bars_copper", decay_chain)
register_waxing_and_scraping("mcl_copper", "waxed_trapdoor", decay_chain)
register_waxing_and_scraping("mcl_copper", "waxed_door", decay_chain)
register_waxing_and_scraping("mesecons_button", "button_waxed_copper", decay_chain)
register_waxing_and_scraping("mcl_copper", "pressure_plate_copper", decay_chain)
register_waxing_and_scraping("xpanes", "bars_waxed_copper", decay_chain)
-- Redefining values and using decay chains for stairs and slabs.
for i = 1, 4 do
decay_chain[i] = decay_chain[i].."_cut"
register_oxidation_and_scraping(mod, oxidize_and_scrap, decay_chain)
register_waxing_and_scraping(mod, wax_and_scrap, decay_chain)
end
-- Defining variants for stairs and slabs.
register_oxidation_and_scraping("mcl_stairs", "stair_copper", decay_chain)
register_oxidation_and_scraping("mcl_stairs", "slab_copper", decay_chain)
register_waxing_and_scraping("mcl_stairs", "stair_waxed_copper", decay_chain)
register_waxing_and_scraping("mcl_stairs", "slab_waxed_copper", decay_chain)