Recipe enhancements (#311)

This commit is contained in:
OgelGames 2023-06-27 18:29:50 +10:00 committed by GitHub
parent 395aba802a
commit 6c09f739c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 69 deletions

View File

@ -3,6 +3,7 @@ local S = technic.getter
technic.register_recipe_type("alloy", {
description = S("Alloying"),
icon = "technic_mv_alloy_furnace_front.png",
input_size = 2,
})
@ -12,15 +13,13 @@ function technic.register_alloy_recipe(data)
end
local recipes = {
{"technic:copper_dust 7", "technic:tin_dust", "technic:bronze_dust 8", 12},
{"technic:copper_dust 7", "technic:tin_dust", "default:bronze_ingot 8", 12},
{"default:copper_ingot 7", "default:tin_ingot", "default:bronze_ingot 8", 12},
{"technic:wrought_iron_dust 2", "technic:coal_dust", "technic:carbon_steel_dust 2", 6},
{"technic:wrought_iron_dust 2", "technic:coal_dust", "technic:carbon_steel_ingot 2", 6},
{"technic:wrought_iron_ingot 2", "technic:coal_dust", "technic:carbon_steel_ingot 2", 6},
{"technic:carbon_steel_dust 2", "technic:coal_dust", "technic:cast_iron_dust 2", 6},
{"technic:carbon_steel_ingot 2", "technic:coal_dust", "technic:cast_iron_ingot 2", 6},
{"technic:carbon_steel_dust 4", "technic:chromium_dust", "technic:stainless_steel_dust 5", 7.5},
{"technic:carbon_steel_dust 4", "technic:chromium_dust", "technic:stainless_steel_ingot 5", 7.5},
{"technic:carbon_steel_ingot 4", "technic:chromium_ingot", "technic:stainless_steel_ingot 5", 7.5},
{"technic:copper_dust 2", "technic:zinc_dust", "technic:brass_dust 3"},
{"technic:copper_dust 2", "technic:zinc_dust", "basic_materials:brass_ingot 3"},
{"default:copper_ingot 2", "technic:zinc_ingot", "basic_materials:brass_ingot 3"},
{"default:sand 2", "technic:coal_dust 2", "technic:silicon_wafer"},
{"technic:silicon_wafer", "technic:gold_dust", "technic:doped_silicon_wafer"},

View File

@ -2,7 +2,8 @@ local S = technic.getter
technic.register_recipe_type("separating", {
description = S("Separating"),
output_size = 2,
icon = "technic_mv_centrifuge_front.png",
output_size = 4,
})
function technic.register_separating_recipe(data)

View File

@ -1,7 +1,10 @@
local S = technic.getter
technic.register_recipe_type("compressing", { description = S("Compressing") })
technic.register_recipe_type("compressing", {
description = S("Compressing"),
icon = "technic_hv_compressor_front.png",
})
function technic.register_compressor_recipe(data)
data.time = data.time or 4

View File

@ -1,7 +1,10 @@
local S = technic.getter
technic.register_recipe_type("extracting", { description = S("Extracting") })
technic.register_recipe_type("extracting", {
description = S("Extracting"),
icon = "technic_mv_extractor_front.png",
})
function technic.register_extractor_recipe(data)
data.time = data.time or 4

View File

@ -1,7 +1,10 @@
local S = technic.getter
technic.register_recipe_type("freezing", { description = S("Freezing") })
technic.register_recipe_type("freezing", {
description = S("Freezing"),
icon = "technic_mv_freezer_front.png",
})
function technic.register_freezer_recipe(data)
data.time = data.time or 5

View File

@ -1,7 +1,10 @@
local S = technic.getter
technic.register_recipe_type("grinding", { description = S("Grinding") })
technic.register_recipe_type("grinding", {
description = S("Grinding"),
icon = "technic_hv_grinder_front.png",
})
function technic.register_grinder_recipe(data)
data.time = data.time or 3

View File

@ -1,31 +1,31 @@
local have_ui = minetest.get_modpath("unified_inventory")
local have_cg = minetest.get_modpath("craftguide")
local have_i3 = minetest.get_modpath("i3")
technic.recipes = { cooking = { input_size = 1, output_size = 1 } }
function technic.register_recipe_type(typename, origdata)
local data = {}
for k, v in pairs(origdata) do data[k] = v end
local data = table.copy(origdata)
data.input_size = data.input_size or 1
data.output_size = data.output_size or 1
if data.output_size == 1 then
if have_ui and unified_inventory.register_craft_type then
unified_inventory.register_craft_type(typename, {
description = data.description,
width = data.input_size,
height = 1,
})
end
if have_cg and craftguide.register_craft_type then
craftguide.register_craft_type(typename, {
description = data.description,
})
end
if have_i3 then
i3.register_craft_type(typename, {
description = data.description,
})
end
if have_ui and unified_inventory.register_craft_type then
unified_inventory.register_craft_type(typename, {
description = data.description,
icon = data.icon,
width = data.input_size,
height = 1,
})
end
if have_cg and craftguide.register_craft_type then
craftguide.register_craft_type(typename, {
description = data.description,
})
end
if have_i3 then
i3.register_craft_type(typename, {
description = data.description,
})
end
data.recipes = {}
technic.recipes[typename] = data
@ -57,7 +57,7 @@ local function register_recipe(typename, data)
local recipe = {time = data.time, input = {}, output = data.output}
local index = get_recipe_index(data.input)
if not index then
print("[Technic] ignored registration of garbage recipe!")
minetest.log("warning", "[Technic] ignored registration of garbage recipe!")
return
end
for _, stack in ipairs(data.input) do
@ -65,32 +65,30 @@ local function register_recipe(typename, data)
end
technic.recipes[typename].recipes[index] = recipe
if have_ui and technic.recipes[typename].output_size == 1 then
unified_inventory.register_craft({
type = typename,
output = data.output,
items = data.input,
width = 0,
})
end
if (have_cg or have_i3) and technic.recipes[typename].output_size == 1 then
local result = data.output
if (type(result)=="table") then
result = result[1]
if data.hidden then return end
local outputs = type(data.output) == "table" and data.output or {data.output}
for _,output in ipairs(outputs) do
if have_ui then
unified_inventory.register_craft({
type = typename,
output = output,
items = data.input,
width = 0,
})
end
local items = table.concat(data.input, ", ")
if have_cg and craftguide.register_craft then
craftguide.register_craft({
type = typename,
result = result,
items = {items},
result = output,
items = {table.concat(data.input, ", ")},
})
end
if have_i3 then
i3.register_craft({
type = typename,
result = result,
items = {items},
result = output,
items = {table.concat(data.input, ", ")},
})
end
end
@ -101,48 +99,51 @@ function technic.register_recipe(typename, data)
end
function technic.get_recipe(typename, items)
if typename == "cooking" then -- Already builtin in Minetest, so use that
if typename == "cooking" then -- Already built into Minetest, so use that
local result, new_input = minetest.get_craft_result({
method = "cooking",
width = 1,
items = items})
items = items,
})
-- Compatibility layer
if not result or result.time == 0 then
return nil
return
-- Workaround for recipes with replacements
elseif not new_input.items[1]:is_empty() and new_input.items[1]:get_name() ~= items[1]:get_name() then
items[1]:take_item(1)
return {time = result.time,
new_input = {items[1]},
output = {new_input.items[1], result.item}}
return {
time = result.time,
new_input = {items[1]},
output = {new_input.items[1], result.item}
}
else
return {time = result.time,
new_input = new_input.items,
output = result.item}
return {
time = result.time,
new_input = new_input.items,
output = result.item
}
end
end
local index = get_recipe_index(items)
if not index then
print("[Technic] ignored registration of garbage recipe!")
return
end
if not index then return end
local recipe = technic.recipes[typename].recipes[index]
if recipe then
local new_input = {}
for i, stack in ipairs(items) do
if stack:get_count() < recipe.input[stack:get_name()] then
return nil
return
else
new_input[i] = ItemStack(stack)
new_input[i]:take_item(recipe.input[stack:get_name()])
end
end
return {time = recipe.time,
new_input = new_input,
output = recipe.output}
return {
time = recipe.time,
new_input = new_input,
output = recipe.output
}
else
return nil
return
end
end