Copper blocks migration

This commit is contained in:
JoseDouglas26 2024-06-11 07:16:02 -03:00
parent 34961f4e23
commit ea44d5cb3c
9 changed files with 75 additions and 938 deletions

View File

@ -0,0 +1,2 @@
voxelibre.events = {}
voxelibre.load_mod_files()

View File

@ -0,0 +1,2 @@
name = events
depends = voxelibre

View File

@ -0,0 +1,39 @@
voxelibre.events.oxidation_chain = {"exposed", "weathered", "oxidized"}
local function set_oxidize(definitions)
local var = definitions._mcl_oxidized_variant
if var then
for count, level in pairs(voxelibre.events.oxidation_chain) do
if var:find(level) then
return var:gsub(level, voxelibre.events.oxidation_chain[count + 1])
end
end
end
end
local function set_identifier(identifier, definitions)
for count, level in pairs(voxelibre.events.oxidation_chain) do
if identifier:find(level) then
return identifier:gsub(level, voxelibre.events.oxidation_chain[count + 1])
end
end
return definitions._mcl_oxidized_variant:gsub("blocks:", "")
end
function voxelibre.events.register_decay_chain(identifier, definitions)
if definitions.groups.oxidizable then
local copy_defs = table.copy(definitions)
local new_id = set_identifier(identifier, definitions)
if copy_defs.description then
copy_defs.description = nil
end
set_oxidize(copy_defs)
copy_defs._mcl_stripped_variant = "blocks:"..identifier
voxelibre.register_block(new_id, copy_defs)
end
end

View File

@ -1,262 +0,0 @@
--- This function determines the format of the crafting recipe in the crafting grid based on the
--- block name. Each block must have its own crafting format for the given material(s).
--- Some materials in the recipe can be pre-defined (e.g. copper bulbs have fixed materials
--- (blaze stick and redstone) and materials that vary according to the material parameter).
--- material can be nil if the recipe uses copper ingots.
---@param name string
---@param material string|nil
---@return table
local function get_shape(name, material)
if not material then
material = "mcl_copper:copper_ingot"
end
if name == "cut" then -- Shape of cut copper blocks.
return {
{material, material},
{material, material}
}
--[[elseif name == "grate" then -- Shape of copper grates.
return {
{"", material, ""},
{material, "", material},
{"", material, ""}
}]]
elseif name == "chiseled" then -- Shape of chiseled copper blocks.
return {
{material},
{material},
}
elseif name == "bulb_off" then -- Shape of copper bulbs (with fixed materials).
return {
{"", material, ""},
{material, "mcl_mobitems:blaze_rod", material},
{"", "mesecons:redstone", ""}
}
elseif name == "mcl_copper:door" then
return {
{material, material},
{material, material},
{material, material}
}
elseif name:find("trapdoor") then
return {
{material, material},
{material, material}
}
elseif name:find("button_copper_off") then
return {material}
elseif name:find("pressure_plate_copper_off") then
return {
{material, material}
}
elseif name:find("bars_copper_flat") then
return {
{material, material, material},
{material, material, material}
}
else
return {}
end
end
--- This function is responsible for recording the recipes for each block (including oxidized variants).
--- If the recipe's main material is the Block of Copper, the material parameter must be passed as "block".
--- If the main material is another block (as in the case of the chiseled copper block), the material
--- parameter must be a table containing 8 itemstrings of the blocks used in the recipes.
--- Special fixed materials (such as copper bulbs) must be registered to the crafting grid format in the
--- get_shape function.
---@param name string
---@param material string|table
---@param amount integer
local function register_variants_recipes(name, material, amount)
local names
local materials = {}
-- Handling the inconsistency of the original itemstrings.
if name ~= "cut" then
names = {
name, "waxed_"..name,
name.."_exposed", "waxed_"..name.."_exposed",
name.."_weathered", "waxed_"..name.."_weathered",
name.."_oxidized", "waxed_"..name.."_oxidized"
}
else
names = {
"block_"..name, "waxed_block_"..name,
"block_exposed_"..name, "waxed_block_exposed_"..name,
"block_weathered_"..name, "waxed_block_weathered_"..name,
"block_oxidized_"..name, "waxed_block_oxidized_"..name
}
end
-- Checking the type of material.
if type(material) == "string" then
materials = {
"mcl_copper:"..material, "mcl_copper:waxed_"..material,
"mcl_copper:"..material.."_exposed", "mcl_copper:waxed_"..material.."_exposed",
"mcl_copper:"..material.."_weathered", "mcl_copper:waxed_"..material.."_weathered",
"mcl_copper:"..material.."_oxidized", "mcl_copper:waxed_"..material.."_oxidized"
}
else
materials = material
end
-- Registering each recipe according to the materials blocks made from copper and its oxidized and
-- waxed variations.
for i = 1, 8 do
minetest.register_craft({
output = "mcl_copper:"..names[i].." "..tostring(amount),
recipe = get_shape(name, materials[i])
})
end
end
-- Using the function above to record the recipes for cut copper blocks, copper grates and copper bulbs.
register_variants_recipes("cut", "block", 4)
--register_variants_recipes("grate", "block", 4)
register_variants_recipes("bulb_off", "block", 4)
--- Function used to register recipes that uses copper ingots as material.
---@param name string
---@param amount integer
local function register_ingot_recipes(name, amount)
local type = "shaped"
if name:find("button") then
type = "shapeless"
end
minetest.register_craft({
output = name.." "..tostring(amount),
recipe = get_shape(name, nil),
type = type
})
end
-- Blocks made with copper ingots.
local made_of_ingots = {
{"xpanes:bars_copper_flat", 16},
{"mesecons_button:button_copper_off", 1},
{"mcl_copper:door", 3},
{"mcl_copper:pressure_plate_copper_off", 1},
{"mcl_copper:trapdoor", 2}
}
-- Registering crafting recipes for blocks made with copper ingot.
for i = 1, #made_of_ingots do
register_ingot_recipes(made_of_ingots[i][1], made_of_ingots[i][2])
end
-- Chiseled copper uses slabs as the main material.
local chiseled_materials = {
"mcl_stairs:slab_copper_cut",
"mcl_stairs:slab_waxed_copper_cut",
"mcl_stairs:slab_copper_exposed_cut",
"mcl_stairs:slab_waxed_copper_exposed_cut",
"mcl_stairs:slab_copper_weathered_cut",
"mcl_stairs:slab_waxed_copper_weathered_cut",
"mcl_stairs:slab_copper_oxidized_cut",
"mcl_stairs:slab_waxed_copper_oxidized_cut"
}
-- Registering recipes for chiseled copper blocks using the slabs.
register_variants_recipes("chiseled", chiseled_materials, 1)
-- List of blocks that can be waxed.
local waxable_blocks = {
"block",
"block_cut",
--"grate",
"chiseled",
"bulb_off",
"block_exposed",
"block_exposed_cut",
--"grate_exposed",
"chiseled_exposed",
"bulb_off_exposed",
"block_weathered",
"block_weathered_cut",
--"grate_weathered",
"chiseled_weathered",
"bulb_off_weathered",
"block_oxidized",
"block_oxidized_cut",
--"grate_oxidized",
"chiseled_oxidized",
"bulb_off_oxidized"
}
-- Registering the waxing recipes for each block listed above.
for _, w in ipairs(waxable_blocks) do
minetest.register_craft({
output = "mcl_copper:waxed_"..w,
recipe = {
{ "mcl_copper:"..w, "mcl_honey:honeycomb" },
},
})
end
-- List of blocks that can be cutted on stonecutter.
local cuttable_blocks = {
"block",
"waxed_block",
"block_exposed",
"waxed_block_exposed",
"block_weathered",
"waxed_block_weathered",
"block_oxidized",
"waxed_block_oxidized"
}
-- Registering stonecutter recipes using the blocks listed above.
for _, c in ipairs(cuttable_blocks) do
mcl_stonecutter.register_recipe("mcl_copper:"..c, "mcl_copper:"..c.."_cut", 4)
--mcl_stonecutter.register_recipe("mcl_copper:"..c, "mcl_copper:"..c:gsub("block", "grate"), 4)
--mcl_stonecutter.register_recipe("mcl_copper:"..c, "mcl_copper:"..c:gsub("block", "chiseled"), 4)
--mcl_stonecutter.register_recipe("mcl_copper:"..c.."_cut", "mcl_copper:"..c:gsub("block", "chiseled"))
end
-- Registering blocks and items specific recipes.
minetest.register_craft({
output = "mcl_copper:block_raw",
recipe = {
{ "mcl_copper:raw_copper", "mcl_copper:raw_copper", "mcl_copper:raw_copper" },
{ "mcl_copper:raw_copper", "mcl_copper:raw_copper", "mcl_copper:raw_copper" },
{ "mcl_copper:raw_copper", "mcl_copper:raw_copper", "mcl_copper:raw_copper" },
},
})
minetest.register_craft({
output = "mcl_copper:block",
recipe = {
{ "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" },
{ "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" },
{ "mcl_copper:copper_ingot", "mcl_copper:copper_ingot", "mcl_copper:copper_ingot" },
},
})
minetest.register_craft({
output = "mcl_copper:copper_ingot 9",
recipe = {
{ "mcl_copper:block" },
},
})
minetest.register_craft({
output = "mcl_copper:raw_copper 9",
recipe = {
{ "mcl_copper:block_raw" },
},
})
minetest.register_craft({
type = "cooking",
output = "mcl_copper:copper_ingot",
recipe = "mcl_copper:raw_copper",
cooktime = 10,
})
minetest.register_craft({
type = "cooking",
output = "mcl_copper:copper_ingot",
recipe = "mcl_copper:stone_with_copper",
cooktime = 10,
})
minetest.register_craft({
type = "cooking",
output = "mcl_copper:block",
recipe = "mcl_copper:block_raw",
cooktime = 90,
})

View File

@ -1,151 +0,0 @@
local S = minetest.get_translator("mcl_copper")
-- Copper-related blocks descriptions, indexed by its names and selected by its position on the
-- oxidation chain.
mcl_copper.copper_descs = {
["block"] = {
S("Block of Copper"), S("Waxed Block of Copper"),
S("Exposed Copper"), S("Waxed Exposed Copper"),
S("Weathered Copper"), S("Waxed Weathered Copper"),
S("Oxidized Copper"), S("Waxed Oxidized Copper")
},
["cut"] = {
S("Cut Copper"), S("Waxed Cut Copper"),
S("Exposed Cut Copper"), S("Waxed Exposed Cut Copper"),
S("Weathered Cut Copper"), S("Waxed Weathered Cut Copper"),
S("Oxidized Cut Copper"), S("Waxed Oxidized Cut Copper")
},
["grate"] = {
S("Copper Grate"), S("Waxed Copper Grate"),
S("Exposed Copper Grate"), S("Waxed Exposed Copper Grate"),
S("Weathered Copper Grate"), S("Waxed Weathered Copper Grate"),
S("Oxidized Copper Grate"), S("Waxed Oxidized Copper Grate")
},
["chiseled"] = {
S("Chiseled Copper"), S("Waxed Chiseled Copper"),
S("Exposed Chiseled Copper"), S("Waxed Exposed Chiseled Copper"),
S("Weathered Chiseled Copper"), S("Waxed Weathered Chiseled Copper"),
S("Oxidized Chiseled Copper"), S("Waxed Oxidized Chiseled Copper")
},
["bulb_off"] = {
S("Copper Bulb"), S("Waxed Copper Bulb"),
S("Exposed Copper Bulb"), S("Waxed Exposed Copper Bulb"),
S("Weathered Copper Bulb"), S("Waxed Weathered Copper Bulb"),
S("Oxidized Copper Bulb"), S("Waxed Oxidized Copper Bulb")
},
["bulb_on"] = {
S("Copper Bulb").." "..S("(Lit)"),
S("Waxed Copper Bulb").." "..S("(Lit)"),
S("Exposed Copper Bulb").." "..S("(Lit)"),
S("Waxed Exposed Copper Bulb").." "..S("(Lit)"),
S("Weathered Copper Bulb").." "..S("(Lit)"),
S("Waxed Weathered Copper Bulb").." "..S("(Lit)"),
S("Oxidized Copper Bulb").." "..S("(Lit)"),
S("Waxed Oxidized Copper Bulb").." "..S("(Lit)")
},
["bulb_powered_off"] = {
S("Copper Bulb").." "..S("(Powered)"),
S("Waxed Copper Bulb").." "..S("(Powered)"),
S("Exposed Copper Bulb").." "..S("(Powered)"),
S("Waxed Exposed Copper Bulb").." "..S("(Powered)"),
S("Weathered Copper Bulb").." "..S("(Powered)"),
S("Waxed Weathered Copper Bulb").." "..S("(Powered)"),
S("Oxidized Copper Bulb").." "..S("(Powered)"),
S("Waxed Oxidized Copper Bulb").." "..S("(Powered)")
},
["bulb_powered_on"] = {
S("Copper Bulb").." "..S("(Lit and Powered)"),
S("Waxed Copper Bulb").." "..S("(Lit and Powered)"),
S("Exposed Copper Bulb").." "..S("(Lit and Powered)"),
S("Waxed Exposed Copper Bulb").." "..S("(Lit and Powered)"),
S("Weathered Copper Bulb").." "..S("(Lit and Powered)"),
S("Waxed Weathered Copper Bulb").." "..S("(Lit and Powered)"),
S("Oxidized Copper Bulb").." "..S("(Lit and Powered)"),
S("Waxed Oxidized Copper Bulb").." "..S("(Lit and Powered)")
}
}
-- Subnames for copper stairs and slabs. For now, just indexed for the cut copper blocks.
mcl_copper.stairs_subnames = {
["cut"] = {
"copper_cut", "waxed_copper_cut",
"copper_exposed_cut", "waxed_copper_exposed_cut",
"copper_weathered_cut", "waxed_copper_weathered_cut",
"copper_oxidized_cut", "waxed_copper_oxidized_cut"
}
}
-- Descriptions for the mcl_stairs blocks. Indexed by the name of oxidation stage of its material.
mcl_copper.stairs_descs = {
["copper_cut"] = {
S("Slab of Cut Copper"),
S("Double Slab of Cut Copper"),
S("Stairs of Cut Copper"),
},
["waxed_copper_cut"] = {
S("Waxed Slab of Cut Copper"),
S("Waxed Double Slab of Cut Copper"),
S("Waxed Stairs of Cut Copper"),
},
["copper_exposed_cut"] = {
S("Slab of Exposed Cut Copper"),
S("Double Slab of Exposed Cut Copper"),
S("Stairs of Exposed Cut Copper")
},
["waxed_copper_exposed_cut"] = {
S("Waxed Slab of Exposed Cut Copper"),
S("Waxed Double Slab of Exposed Cut Copper"),
S("Waxed Stairs of Exposed Cut Copper")
},
["copper_weathered_cut"] = {
S("Slab of Weathered Cut Copper"),
S("Double Slab of Weathered Cut Copper"),
S("Stairs of Weathered Cut Copper")
},
["waxed_copper_weathered_cut"] = {
S("Waxed Slab of Weathered Cut Copper"),
S("Waxed Double Slab of Weathered Cut Copper"),
S("Waxed Stairs of Weathered Cut Copper")
},
["copper_oxidized_cut"] = {
S("Slab of Oxidized Cut Copper"),
S("Double Slab of Oxidized Cut Copper"),
S("Stairs of Oxidized Cut Copper")
},
["waxed_copper_oxidized_cut"] = {
S("Waxed Slab of Oxidized Cut Copper"),
S("Waxed Double Slab of Oxidized Cut Copper"),
S("Waxed Stairs of Oxidized Cut Copper")
}
}
-- Description for the mcl_doors blocks. Selected by its position on the inner table.
-- {door_description, trapdoor_description}.
mcl_copper.doors_descs = {
{S("Copper Door"), S("Copper Trapdoor")},
{S("Waxed Copper Door"), S("Waxed Copper Trapdoor")},
{S("Exposed Copper Door"), S("Exposed Copper Trapdoor")},
{S("Waxed Exposed Copper Door"), S("Waxed Exposed Copper Trapdoor")},
{S("Weathered Copper Door"), S("Weathered Copper Trapdoor")},
{S("Waxed Weathered Copper Door"), S("Waxed Weathered Copper Trapdoor")},
{S("Oxidized Copper Door"), S("Oxidized Copper Trapdoor")},
{S("Waxed Oxidized Copper Door"), S("Waxed Oxidized Copper Trapdoor")}
}
-- Description for copper buttons, selected by its position on the table.
mcl_copper.button_descs = {
S("Copper Button"), S("Waxed Copper Button"),
S("Exposed Copper Button"), S("Waxed Exposed Copper Button"),
S("Weathered Copper Button"), S("Waxed Weathered Copper Button"),
S("Oxidized Copper Button"), S("Waxed Oxidized Copper Button")
}
-- Description for copper pressure plates, selected by its position on the table.
mcl_copper.pp_descs = {
S("Copper Pressure Plate"), S("Waxed Copper Pressure Plate"),
S("Exposed Copper Pressure Plate"), S("Waxed Exposed Copper Pressure Plate"),
S("Weathered Copper Pressure Plate"), S("Waxed Weathered Copper Pressure Plate"),
S("Oxidized Copper Pressure Plate"), S("Waxed Oxidized Copper Pressure Plate")
}
-- Description for copper bars, selected by its position on the table.
mcl_copper.bars_descs = {
S("Copper Bars"), S("Waxed Copper Bars"),
S("Exposed Copper Bars"), S("Waxed Exposed Copper Bars"),
S("Weathered Copper Bars"), S("Waxed Weathered Copper Bars"),
S("Oxidized Copper Bars"), S("Waxed Oxidized Copper Bars")
}

View File

@ -1,212 +0,0 @@
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)
local node_def = node_def or minetest.registered_nodes[node.name]
if not node_def then return end
if not node_def._mcl_stripped_variant then return end
node.name = node_def._mcl_stripped_variant
minetest.swap_node(pos, node)
end
local function strip_door_top(pos, node, node_def)
strip(vector.offset(pos, 0, 1, 0))
end
local function strip_door_bottom(pos, node, node_def)
strip(vector.offset(pos, 0, -1, 0))
end
-- Functions used to wax the other half of the door
local function wax(pos, node, node_def)
local node = node or minetest.get_node(pos)
local node_def = node_def or minetest.registered_nodes[node.name]
if not node_def then return end
if not node_def._mcl_waxed_variant then return end
node.name = node_def._mcl_waxed_variant
minetest.swap_node(pos, node)
end
local function wax_door_top(pos, node, node_def)
wax(vector.offset(pos, 0, 1, 0))
end
local function wax_door_bottom(pos, node, node_def)
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))
end
local function oxidize_door_bottom(pos, node, node_def)
mcl_oxidize.oxidize(vector.offset(pos, 0, 1, 0))
end
--- Function used to define the oxidized and stripped variants of copper-related blocks that
--- are registered by APIs external to mcl_copper (stairs, slabs, doors and trapdoors). "mod_name"
--- should be the name of the mod the blocks belong to. "subname" must be the subname of the block that
--- will receive the changes (see registered subnames below). "decay_chain" should be a table containing
--- the list of subnames of the block oxidation chain (without the waxed variants subnames).
---@param mod_name string
---@param subname string
---@param decay_chain table
local function register_oxidation_and_scraping(mod_name, subname, decay_chain)
local item, oxidized_item
for i = 1, #decay_chain - 1 do
item = mod_name..":"..subname..decay_chain[i]
oxidized_item = mod_name..":"..subname..decay_chain[i + 1]
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
end
end
end
--- Function used to define the waxed and stripped variants (for the waxed variants) of copper-related
--- blocks that are registered by APIs external to mcl_copper (stairs, slabs, doors and trapdoors).
--- "mod_name" should be the name of the mod the blocks belong to. "subname" must be the subname of the
--- block that will receive the changes (see registered subnames below). "decay_chain" should be a table
--- 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
for i = 1, #decay_chain do
waxed_item = mod_name..":"..subname..decay_chain[i]
unwaxed_item = mod_name..":"..subname:gsub("waxed_", "")..decay_chain[i]
for _, subnode in pairs(mcl_copper.subnodes[subname:gsub("waxed_", "")]) 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
end
end
end
-- Decay chain for almost all blocks.
local decay_chain = {
"",
"_exposed",
"_weathered",
"_oxidized"
}
-- 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_copper", "trapdoor", "waxed_trapdoor"}
}
-- Defining variants for almost 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(mod, oxidize_and_scrap, decay_chain)
register_waxing_and_scraping(mod, wax_and_scrap, decay_chain)
end
-- Redefining things to handle mcl_stairs copper nodes.
for i = 1, 4 do
decay_chain[i] = decay_chain[i].."_cut"
end
mods_and_blocks = {
{"mcl_stairs", "slab_copper", "slab_waxed_copper"},
{"mcl_stairs", "stair_copper", "stair_waxed_copper"}
}
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(mod, oxidize_and_scrap, decay_chain)
register_waxing_and_scraping(mod, wax_and_scrap, decay_chain)
end

View File

@ -1,15 +0,0 @@
local S = minetest.get_translator("mcl_copper")
minetest.register_craftitem("mcl_copper:copper_ingot", {
description = S("Copper Ingot"),
_doc_items_longdesc = S("Molten Raw Copper. It is used to craft blocks."),
inventory_image = "mcl_copper_ingot.png",
groups = { craftitem = 1 },
})
minetest.register_craftitem("mcl_copper:raw_copper", {
description = S("Raw Copper"),
_doc_items_longdesc = S("Raw Copper. Mine a Copper Ore to get it."),
inventory_image = "mcl_copper_raw.png",
groups = { craftitem = 1, blast_furnace_smeltable = 1 },
})

View File

@ -1,293 +1,5 @@
local S = minetest.get_translator("mcl_copper")
--- Function to set drop (only useful for copper bulbs that are not available in the creative inventory).
--- To have a special drop, the block definition must contain the "drop" parameter.
--- "old_name" must be a string containing the name of the node that will receive the special drop
--- (for example, the lit copper bulb that should drop the unlit copper bulb).
--- "index_name" contains the name of the dropped block (in the case of the previous example, name must
--- be bulb_off to define the drop as the unlit and unpowered bulb).
---@param drop string|nil
---@param old_name string
---@param index_name string
---@return string|nil
local function set_drop(drop, old_name, index_name)
if drop and old_name and index_name then
drop = "mcl_copper:"..old_name:gsub(index_name, drop)
end
return drop
end
--- Function used to set special groups for some blocks based on its names.
--- "oxidizable" is the group that indicates that the block can oxidize.
--- "waxed" is the group that indicates that the block can not oxidize.
--- Doors and trapdoors they will be part of groups related to mesecon, indicating that mesecon
--- (redstone) has an effect on them.
---@param name string
---@param groups table
---@return table|nil
local function set_groups(name, groups)
local groups = table.copy(groups)
if name and groups then
if name:find("waxed") then
groups.waxed = 1
elseif not name:find("oxidized") then
groups.oxidizable = 1
end
if name:find("door") then
groups.building_block = 0
groups.mesecon_effector_on = 1
end
else
return nil
end
return groups
end
--- Function to set the light level for copper bulbs. Calculated based on the index passed to the function.
--- "light_source" must be a integer which is the maximum desired light level. "index" must be a integer
--- as well. "index" is used to define the level of oxidation of the bulb, as the light level decreases
--- as the degree of oxidation advances.
---@param light_source integer
---@param index integer
---@return integer
local function set_light_level(light_source, index)
local ceil, floor_5, floor_7 = math.ceil(index / 2), math.floor(index / 5), math.floor(index / 7)
if light_source then
light_source = light_source - 3 * (ceil - 1) - floor_5 - floor_7
end
return light_source
end
--- Function used to set tiles for blocks. "tiles" must be a table with 4 values as waxed variants
--- use the same textures as the unwaxed versions. "index" must be an integer that must be, at most,
--- twice the number of textures in the table (8 as the maximum value).
---@param tiles table
---@param index integer
---@return string|nil
local function set_tiles(tiles, index)
if not tiles or not index then
return
end
return tiles[math.ceil(index / 2)]
end
--- Function used to register all blocks on the oxidation chain, including the waxed variants for each
--- block. It also registers some special blocks like doors, trapdoors, slabs and stairs. "name" should
--- be a string containing the subname of the block. "definitions" must be a table that contains only
--- particular definitions for each block, such as the light level for copper bulbs or the "allfaces"
--- drawtype for copper grates. Some nodes contain a special definition to define the registration of
--- some other blocks (copper slabs and ladders are based on cut copper blocks).
---@param name string
---@param definitions table
local function register_copper_variants(name, definitions)
local names, oxidized_variant, stripped_variant, waxed_variant, tiles
-- Handling the inconsistency of the original itemstrings.
if name ~= "cut" then
names = {
name, "waxed_"..name,
name.."_exposed", "waxed_"..name.."_exposed",
name.."_weathered", "waxed_"..name.."_weathered",
name.."_oxidized", "waxed_"..name.."_oxidized"
}
else
names = {
"block_"..name, "waxed_block_"..name,
"block_exposed_"..name, "waxed_block_exposed_"..name,
"block_weathered_"..name, "waxed_block_weathered_"..name,
"block_oxidized_"..name, "waxed_block_oxidized_"..name
}
end
-- Also handling the inconsistency of the original texture names.
if name == "block" then
tiles = {
"mcl_copper_block.png",
"mcl_copper_exposed.png",
"mcl_copper_weathered.png",
"mcl_copper_oxidized.png"
}
else
tiles = {
"mcl_copper_block_"..name..".png",
"mcl_copper_exposed_"..name..".png",
"mcl_copper_weathered_"..name..".png",
"mcl_copper_oxidized_"..name..".png"
}
end
-- Registering the 8 nodes in the oxidation chain.
for i = 1, #names do
-- Defining whether the block is waxed and defining its stripped variant (its non-oxidized
-- variant, which must precede the waxed variant in the name table).
if names[i]:find("waxed") then
stripped_variant = "mcl_copper:"..names[i-1]
else
-- While the "oxidized" variant is not found, this snippet defines the oxidized variant of
-- the block.
if not names[i]:find("oxidized") then
oxidized_variant = "mcl_copper:"..names[i+2]
end
-- Defining the stripped variant with the exception of the first block in the chain
-- (and the waxed ones that were defined before).
if i ~= 1 then
stripped_variant = "mcl_copper:"..names[i-2]
end
-- Defining the waxed variant for unwaxed variants.
waxed_variant = "mcl_copper:"..names[i+1]
end
-- Registering the blocks.
minetest.register_node("mcl_copper:"..names[i], {
description = mcl_copper.copper_descs[name][i],
drawtype = definitions.drawtype or "normal",
drop = set_drop(definitions.drop, names[i], name),
groups = set_groups(names[i], definitions.groups),
is_ground_content = false,
light_source = set_light_level(definitions.light_source, i),
mesecons = definitions.mesecons,
paramtype = definitions.paramtype or "none",
paramtype2 = definitions.paramtype2 or "none",
sounds = mcl_sounds.node_sound_metal_defaults(),
sunlight_propagates = definitions.sunlight_propagates or false,
tiles = {set_tiles(tiles, i)},
_mcl_blast_resistance = 6,
_mcl_hardness = 3,
_mcl_oxidized_variant = oxidized_variant,
_mcl_stripped_variant = stripped_variant,
_mcl_waxed_variant = waxed_variant,
})
-- Defining blocks that use mcl_stairs.
if definitions._mcl_stairs then
local subname = mcl_copper.stairs_subnames[name][i]
mcl_stairs.register_slab(subname, "mcl_copper:"..names[i], set_groups(subname, definitions.groups),
{set_tiles(tiles, i), set_tiles(tiles, i), set_tiles(tiles, i)},
mcl_copper.stairs_descs[subname][1], nil, nil, nil,
mcl_copper.stairs_descs[subname][2]
)
mcl_stairs.register_stair(subname, "mcl_copper:"..names[i], set_groups(subname, definitions.groups),
{set_tiles(tiles, i), set_tiles(tiles, i), set_tiles(tiles, i),
set_tiles(tiles, i), set_tiles(tiles, i), set_tiles(tiles, i)},
mcl_copper.stairs_descs[subname][3], nil, nil, nil, "woodlike"
)
end
-- Defining blocks that use mcl_doors.
if definitions._mcl_doors then
local itemimg, lowertext, uppertext, frontimg, sideimg
-- Defining the special groups for doors and trapdoors.
local door_groups = set_groups(names[i]:gsub(name, "door"), definitions.groups)
local trapdoor_groups = set_groups(names[i]:gsub(name, "trapdoor"), definitions.groups)
-- Managing the textures related to doors and trapdoors, as well as the texture of the item
-- for each door. As with the other blocks, the waxed variant uses the same textures as the
-- unwaxed variants.
-- itemimg -> item image for the doors on inventory;
-- lowertext / uppertext -> lower and bottom textures for the doors;
-- frontimg / sideimg -> front and side textures for the trapdoors;
if i % 2 == 1 then
itemimg = "mcl_copper_item_"..names[i]:gsub(name, "door")..".png"
lowertext = "mcl_copper_"..names[i]:gsub(name, "door").."_lower.png"
uppertext = "mcl_copper_"..names[i]:gsub(name, "door").."_upper.png"
frontimg = "mcl_copper_"..names[i]:gsub(name, "trapdoor")..".png"
sideimg = "mcl_copper_"..names[i]:gsub(name, "trapdoor").."_side.png"
else
itemimg = "mcl_copper_item_"..names[i-1]:gsub(name, "door")..".png"
lowertext = "mcl_copper_"..names[i-1]:gsub(name, "door").."_lower.png"
uppertext = "mcl_copper_"..names[i-1]:gsub(name, "door").."_upper.png"
frontimg = "mcl_copper_"..names[i-1]:gsub(name, "trapdoor")..".png"
sideimg = "mcl_copper_"..names[i-1]:gsub(name, "trapdoor").."_side.png"
end
-- Registering doors.
mcl_doors:register_door("mcl_copper:"..names[i]:gsub(name, "door"), {
description = mcl_copper.doors_descs[i][1],
groups = door_groups,
inventory_image = itemimg,
only_redstone_can_open = false,
sounds = mcl_sounds.node_sound_metal_defaults(),
sound_close = "doors_steel_door_close",
sound_open = "doors_steel_door_open",
tiles_bottom = lowertext,
tiles_top = uppertext,
_mcl_blast_resistance = 3,
_mcl_hardness = 3
})
-- Registering trapdoors.
mcl_doors:register_trapdoor("mcl_copper:"..names[i]:gsub(name, "trapdoor"), {
description = mcl_copper.doors_descs[i][2],
groups = trapdoor_groups,
only_redstone_can_open = false,
sounds = mcl_sounds.node_sound_metal_defaults(),
sound_close = "doors_steel_door_close",
sound_open = "doors_steel_door_open",
tile_front = frontimg,
tile_side = sideimg,
wield_image = frontimg,
_mcl_blast_resistance = 3,
_mcl_hardness = 3
})
end
-- Registering buttons.
if definitions._mesecons_buttons then
mesecon.register_button(
names[i]:gsub("block", "copper"),
mcl_copper.button_descs[i],
set_tiles(tiles, i),
nil,
mcl_sounds.node_sound_metal_defaults(),
set_groups(names[i], {handy = 1, pickaxey = 1}),
math.ceil(i / 2) * 0.5,
true,
nil,
"mesecons_button_push"
)
end
-- Registering pressure plates.
if definitions._mesecons_pp then
mesecon.register_pressure_plate(
"mcl_copper:pressure_plate_"..names[i]:gsub("block", "copper"),
mcl_copper.pp_descs[i],
{set_tiles(tiles, i)},
{set_tiles(tiles, i)},
set_tiles(tiles, i),
nil,
nil,
mcl_sounds.node_sound_metal_defaults(),
set_groups(names[i], {pickaxey = 1}),
{player = true, mob = true}
)
end
-- Registering copper bars.
if definitions._xpanes then
local top_img = set_tiles(tiles, i):gsub("mcl_", "xpanes_top_")
local side_img = set_tiles(tiles, i):gsub("mcl_", "xpanes_pane_")
xpanes.register_pane("bars_"..names[i]:gsub("block", "copper"), {
description = mcl_copper.bars_descs[i],
textures = {side_img, side_img, top_img},
inventory_image = side_img,
wield_image = side_img,
groups = set_groups(names[i], {pickaxey = 1}),
sounds = mcl_sounds.node_sound_metal_defaults(),
recipe = nil,
_mcl_blast_resistance = 6,
_mcl_hardness = 3
})
end
end
end
-- Using the function above to register the copper blocks.
register_copper_variants("block", {
groups = {pickaxey = 2, building_block = 1},
})
-- Using the function above to register the cut copper blocks.
register_copper_variants("cut", {
groups = {pickaxey = 2, building_block = 1},
_mcl_stairs = true,
})
-- Registering specific blocks.
minetest.register_node("mcl_copper:stone_with_copper", {
description = S("Copper Ore"),
@ -301,13 +13,3 @@ minetest.register_node("mcl_copper:stone_with_copper", {
_mcl_silk_touch_drop = true,
_mcl_fortune_drop = mcl_core.fortune_drop_ore,
})
minetest.register_node("mcl_copper:block_raw", {
description = S("Block of Raw Copper"),
tiles = {"mcl_copper_block_raw.png"},
is_ground_content = false,
groups = {pickaxey = 2, building_block = 1, blast_furnace_smeltable = 1},
sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 6,
_mcl_hardness = 5,
})

View File

@ -1,4 +1,10 @@
local common_defs = {
copper = {
_mcl_blast_resistance = 6,
_mcl_hardness = 3,
groups = {building_blocks = 1, oxidizable = 1, pickaxey = 3},
sounds = mcl_sounds.node_sound_metal_defaults()
},
quartz = {
_mcl_blast_resistance = 0.8,
_mcl_hardness = 0.8,
@ -7,6 +13,32 @@ local common_defs = {
}
}
local copper_blocks = {
["chiseled_copper"] = {
_mcl_oxidized_variant = "blocks:exposed_chiseled_copper"
},
["copper_block"] = {
_mcl_oxidized_variant = "blocks:exposed_copper",
description = "Block of Copper",
groups = {stonecuttable = 1}
},
["copper_grate"] = {
_mcl_oxidized_variant = "blocks:exposed_copper_grate",
drawtype = "allfaces",
paramtype = "light",
sunlight_propagates = true
},
["cut_copper"] = {
_mcl_oxidized_variant = "blocks:exposed_cut_copper",
groups = {stonecuttable = 1}
}
}
for identifier, definitions in pairs(copper_blocks) do
voxelibre.register_block(identifier, table.merge(common_defs.copper, definitions))
voxelibre.events.register_decay_chain(identifier, table.merge(common_defs.copper, definitions))
end
local quartz_blocks = {
["chiseled_quartz_block"] = {
groups = {stonecuttable = 1},