crafting again

This commit is contained in:
JoseDouglas26 2024-06-02 10:58:03 -03:00
parent 068212d8c9
commit e6de710911
1 changed files with 258 additions and 198 deletions

View File

@ -1,202 +1,262 @@
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)")
}
--- 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}
}
-- All longdescs for copper-related blocks. Waxed variants share the same description with its unwaxed
-- variant. Like the descriptions, they are indexed by the block name.
mcl_copper.copper_longdescs = {
["block"] = {
S("A block of copper is mostly a decorative block."),
S("Exposed copper is a decorative block."),
S("Weathered copper is a decorative block."),
S("Oxidized copper is a decorative block.")
},
["cut"] = {
S("Cut copper is a decorative block."),
S("Exposed cut copper is a decorative block."),
S("Weathered cut copper is a decorative block."),
S("Oxidized cut copper is a decorative block.")
},
["grate"] = {
S("Copper grate is a decorative block."),
S("Exposed copper grate is a decorative block."),
S("Weathered copper grate is a decorative block."),
S("Oxidized copper grate is a decorative block.")
},
["chiseled"] = {
S("Chiseled copper is a decorative block."),
S("Exposed chiseled copper is a decorative block."),
S("Weathered chiseled copper is a decorative block."),
S("Oxidized chiseled copper is a decorative block.")
},
["bulb_off"] = {
S("Copper bulb is a decorative block and a light source when lited."),
S("Exposed copper bulb is a decorative block and a light source when lited."),
S("Weathered copper bulb is a decorative block and a light source when lited."),
S("Oxidized copper bulb is a decorative block and a light source when lited.")
},
["bulb_on"] = {
S("Copper bulb is a decorative block and a light source."),
S("Exposed copper bulb is a decorative block and a light source."),
S("Weathered copper bulb is a decorative block and a light source."),
S("Oxidized copper bulb is a decorative block and a light source.")
},
["bulb_powered_off"] = {
S("Copper bulb is a decorative block and a light source when lited."),
S("Exposed copper bulb is a decorative block and a light source when lited."),
S("Weathered copper bulb is a decorative block and a light source when lited."),
S("Oxidized copper bulb is a decorative block and a light source when lited.")
},
["bulb_powered_on"] = {
S("Copper bulb is a decorative block and a light source."),
S("Exposed copper bulb is a decorative block and a light source."),
S("Weathered copper bulb is a decorative block and a light source."),
S("Oxidized copper bulb is a decorative block and a light source.")
}
-- 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"
}
-- 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"
}
-- 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"
}
-- 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")
-- 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,
})