From 7a5022472b1de0c9db53fdc70f53cd68f3fe86a8 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Mon, 27 Jun 2022 14:58:00 -0700 Subject: [PATCH] fix crafts for shapes --- stairsplus/api/recipe.lua | 83 +++++++++++++++++++++--------- stairsplus_legacy/default.lua | 97 +++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 24 deletions(-) diff --git a/stairsplus/api/recipe.lua b/stairsplus/api/recipe.lua index c5afb2c..8119448 100644 --- a/stairsplus/api/recipe.lua +++ b/stairsplus/api/recipe.lua @@ -171,34 +171,69 @@ local function shapes_match(a, b) return true end +local function register_cooking_for_shapes(recipe) + local mod, name = recipe.recipe:match("^([^:]+):(.*)$") + + if mod ~= "group" and not shapes_match(recipe.output, recipe.recipe) then + error(("error: shapes of %s and %s do not match"):format(recipe.output, recipe.recipe)) + end + + local shapes = api.get_shapes(recipe.output) + + for _, shape in ipairs(shapes) do + local shape_def = api.registered_shapes[shape] + local input + if mod == "group" then + input = "group:" .. shape_def.name_format:format(name) + else + input = api.get_schema_recipe_item(recipe.recipe, shape) + end + + minetest.register_craft({ + type = "cooking", + output = api.get_schema_recipe_item(recipe.output, shape), + recipe = input, + cooktime = math.max(1.0, (recipe.cooktime or 3) * (shape_def.eighths / 8)), + }) + end +end + +local function register_fuel_for_shapes(recipe) + local mod, name = recipe.recipe:match("^([^:]+):(.*)$") + local shapes + if mod == "group" then + shapes = api.registered_shapes + else + shapes = api.get_shapes_hash(recipe.recipe) + end + + if not shapes then + error(("don't know how to handle fuel %s"):format(recipe.recipe)) + end + + for shape in pairs(shapes) do + local shape_def = api.registered_shapes[shape] + local input + if mod == "group" then + input = "group:" .. shape_def.name_format:format(name) + else + input = api.get_schema_recipe_item(recipe.recipe, shape) + end + + minetest.register_craft({ + type = "fuel", + recipe = input, + burntime = math.max(1.0, (recipe.burntime or 1) * (shape_def.eighths / 8)), + }) + end +end + function api.register_crafts_for_shapes(recipe) if recipe.type == "cooking" then - assert( - shapes_match(recipe.output, recipe.recipe), - ("error: shapes of %s and %s do not match"):format(recipe.output, recipe.recipe) - ) - - local shapes = api.get_shapes(recipe.recipe) - - for _, shape in ipairs(shapes) do - minetest.register_craft({ - type = "cooking", - output = api.get_schema_recipe_item(recipe.output, shape), - recipe = api.get_schema_recipe_item(recipe.recipe, shape), - cooktime = recipe.cooktime * (api.registered_shapes[shape].eighths / 8), - }) - end + register_cooking_for_shapes(recipe) elseif recipe.type == "fuel" then - local shapes = api.get_shapes(recipe.recipe) - - for _, shape in ipairs(shapes) do - minetest.register_craft({ - type = "fuel", - recipe = api.get_schema_recipe_item(recipe.recipe, shape), - burntime = recipe.burntime * (api.registered_shapes[shape].eighths / 8), - }) - end + register_fuel_for_shapes(recipe) else error(("unsupported recipe type %s"):format(recipe.type)) diff --git a/stairsplus_legacy/default.lua b/stairsplus_legacy/default.lua index 5df7b50..0cb5e67 100644 --- a/stairsplus_legacy/default.lua +++ b/stairsplus_legacy/default.lua @@ -79,6 +79,7 @@ local default_nodes = { -- Default stairs/slabs/panels/microblocks: "sandstone_block", "coral_skeleton", "ice", + "sand", -- TODO tmp remove } for _, name in ipairs(default_nodes) do @@ -98,3 +99,99 @@ for _, name in ipairs(glass) do stairsplus_legacy.register_legacy(node, nil, {ignore_paramtype2 = true}) stairsplus.api.register_alias_all(("moreblocks:%s"):format(name), node) end + +stairsplus.api.register_crafts_for_shapes({ + type = "cooking", + output = "default:glass", + recipe = "group:sand", +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "cooking", + output = "default:stone", + recipe = "default:cobble", +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "cooking", + output = "default:stone", + recipe = "default:mossycobble", +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "cooking", + output = "default:desert_stone", + recipe = "default:desert_cobble", +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "group:tree", + burntime = 30, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:tree", + burntime = 30, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:aspen_tree", + burntime = 22, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:pine_tree", + burntime = 26, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:acacia_tree", + burntime = 34, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:jungletree", + burntime = 38, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "group:wood", + burntime = 7, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:wood", + burntime = 7, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:aspen_wood", + burntime = 5, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:pine_wood", + burntime = 6, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:acacia_wood", + burntime = 8, +}) + +stairsplus.api.register_crafts_for_shapes({ + type = "fuel", + recipe = "default:junglewood", + burntime = 9, +})