mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2024-11-15 23:10:18 +01:00
fix crafts for shapes
This commit is contained in:
parent
b2217af50e
commit
7a5022472b
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user