From f8cadd77258279a0141657d52ea031f079c6f7ba Mon Sep 17 00:00:00 2001 From: JoseDouglas26 Date: Sun, 5 May 2024 10:53:41 -0300 Subject: [PATCH] Comments on crafting.lua --- mods/ITEMS/mcl_copper/crafting.lua | 83 ++++++++++++++++++------------ 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/mods/ITEMS/mcl_copper/crafting.lua b/mods/ITEMS/mcl_copper/crafting.lua index 628173e3f..0b0217d0d 100644 --- a/mods/ITEMS/mcl_copper/crafting.lua +++ b/mods/ITEMS/mcl_copper/crafting.lua @@ -1,39 +1,28 @@ -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" }, - }, -}) - +--- 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) +---@param name string +---@param material string +---@return table local function get_shape(name, material) - if name == "cut" then + if name == "cut" then -- Shape of cut copper blocks return { {material, material}, {material, material} } - elseif name == "grate" then + elseif name == "grate" then -- Shape of copper grates return { {"", material, ""}, {material, "", material}, {"", material, ""} } - elseif name == "chiseled" then + elseif name == "chiseled" then -- Shape of chiseled copper blocks return { {material}, {material}, } - elseif name == "bulb_off" then + elseif name == "bulb_off" then -- Shape of copper bulbs (with fixed materials) return { {"", material, ""}, {material, "mcl_mobitems:blaze_rod", material}, @@ -44,10 +33,19 @@ local function get_shape(name, material) 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, @@ -63,7 +61,7 @@ local function register_variants_recipes(name, material, amount) "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, @@ -74,7 +72,10 @@ local function register_variants_recipes(name, material, amount) 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), @@ -82,11 +83,11 @@ local function register_variants_recipes(name, material, amount) }) 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) - +-- Chiseled copper uses slabs as the main material. local chiseled_materials = { "mcl_stairs:slab_copper_cut", "mcl_stairs:slab_waxed_copper_cut", @@ -97,9 +98,9 @@ local chiseled_materials = { "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", @@ -122,7 +123,7 @@ local waxable_blocks = { "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, @@ -131,7 +132,7 @@ for _, w in ipairs(waxable_blocks) do }, }) end - +-- List of blocks that can be cutted on stonecutter local cuttable_blocks = { "block", "waxed_block", @@ -142,13 +143,31 @@ local cuttable_blocks = { "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",