Compare commits

...

5 Commits

Author SHA1 Message Date
Oversword fefcd5a316
Merge pull request #5 from oversword/account_for_cooking
Account for cooking recipes
2021-08-09 11:57:43 +01:00
Oversword 58e09ed48d Account for cooking recipes 2021-08-09 11:32:38 +01:00
Oversword 516b035345
Merge pull request #4 from oversword/stairs_conflicts
Remove stairs conflicting crafts before registering stairsplus crafts
2021-08-08 02:45:51 +01:00
Oversword d5a1b58a82 Lint 2021-08-08 02:44:28 +01:00
Oversword c6c62b1ddc Check registered stairs belong to the new node by matching mod or tile 2021-08-08 02:32:14 +01:00
1 changed files with 82 additions and 43 deletions

View File

@ -45,17 +45,66 @@ function stairsplus:prepare_groups(groups)
return result
end
local function get_tile(node_def, index)
if not index then index = 1 end
return
((node_def.tiles and node_def.tiles[index] and
(node_def.tiles[index].name or node_def.tiles[index]))
or (node_def.tile_images and node_def.tile_images[index]))
end
local function recipe_registered_to_register(existing_recipe)
local recipe_obj = {
output = existing_recipe.output,
}
if existing_recipe.type == "normal" and existing_recipe.width == 0 then
recipe_obj.type = "shapeless"
recipe_obj.recipe = existing_recipe.items
elseif existing_recipe.type == "cooking" then
recipe_obj.type = "cooking"
recipe_obj.recipe = existing_recipe.items[1]
elseif existing_recipe.type == "normal" then
recipe_obj.recipe = {{},{},{}}
for x=1,3 do
for y=1,existing_recipe.width do
local p = ((x-1)*existing_recipe.width)+y
recipe_obj.recipe[x][y] = existing_recipe.items[p] or ""
end
end
else
minetest.log("error", "Crafting type not accounted for, tell Oversword: "..dump(existing_recipe))
end
return recipe_obj
end
function stairsplus:register_all(modname, subname, recipeitem, fields, stairs_subname)
if not stairs_subname then stairs_subname = subname end
-- This could be distributed amongst the various sub-calls, but we almost always use register_all so this works
local stairs_items = {
-- This could be distributed amongst the various sub-calls, or put in register-single, but we almost always use register_all so this works
local possible_stairs_items = {
["stairs:stair_" .. stairs_subname] = modname .. ":stair_" .. subname,
["stairs:stair_outer_" .. stairs_subname] = modname .. ":stair_" .. subname .. "_outer",
["stairs:stair_inner_" .. stairs_subname] = modname .. ":stair_" .. subname .. "_inner",
["stairs:slab_" .. stairs_subname] = modname .. ":slab_" .. subname
}
local cleanup_stairs = false
local stairs_items = {}
local original_def = minetest.registered_nodes[recipeitem]
local original_tile = original_def and get_tile(original_def)
if original_tile then
for stair_item,alias in pairs(possible_stairs_items) do
local def = minetest.registered_nodes[stair_item]
if def and (
original_def.mod_origin == def.mod_origin or
original_tile == get_tile(def)
) then
stairs_items[stair_item] = alias
cleanup_stairs = true
end
end
end
if cleanup_stairs then
for stair_item, _ in pairs(stairs_items) do
minetest.clear_craft({ output=stair_item })
end
@ -74,23 +123,10 @@ function stairsplus:register_all(modname, subname, recipeitem, fields, stairs_su
end
end
if standard then
local recipe_obj = {
output = existing_recipe.output,
}
if existing_recipe.width == 0 then
recipe_obj.type = "shapeless"
recipe_obj.recipe = existing_recipe.items
table.insert(standard_recipes, recipe_registered_to_register(existing_recipe))
end
else
recipe_obj.recipe = {{},{},{}}
for x=1,3 do
for y=1,existing_recipe.width do
local p = ((x-1)*existing_recipe.width)+y
recipe_obj.recipe[x][y] = existing_recipe.items[p] or ""
end
end
end
table.insert(standard_recipes, recipe_obj)
end
table.insert(standard_recipes, recipe_registered_to_register(existing_recipe))
end
end
@ -99,6 +135,7 @@ function stairsplus:register_all(modname, subname, recipeitem, fields, stairs_su
minetest.register_craft(recipe)
end
end
end
self:register_stair(modname, subname, recipeitem, fields)
self:register_slab(modname, subname, recipeitem, fields)
@ -106,10 +143,12 @@ function stairsplus:register_all(modname, subname, recipeitem, fields, stairs_su
self:register_panel(modname, subname, recipeitem, fields)
self:register_micro(modname, subname, recipeitem, fields)
if cleanup_stairs then
for stair_item, alias in pairs(stairs_items) do
minetest.register_alias_force(stair_item, alias)
end
end
end
function stairsplus:register_alias_all(modname_old, subname_old, modname_new, subname_new)
self:register_stair_alias(modname_old, subname_old, modname_new, subname_new)