From 1a03b041dd49cf52e8d5d84e72206718055b1455 Mon Sep 17 00:00:00 2001 From: Oblomov Date: Fri, 26 Feb 2021 12:04:45 +0100 Subject: [PATCH 1/2] Handle shapeless recipes in redefinitions (#171) They can be recognized from having width == 0, and don't need the items list to be massaged to be transformed into the recipe field for the Lua API. --- redefinitions.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/redefinitions.lua b/redefinitions.lua index e9c5ff7..4d59c3c 100644 --- a/redefinitions.lua +++ b/redefinitions.lua @@ -17,9 +17,10 @@ local reconstruct_internal_craft = function(recipe) { "", "", "" }, { "", "", "" }, } + local width = recipe.width for idx, item in pairs(recipe.items) do - local row = math.ceil(idx / recipe.width) - local col = idx - (row-1)*recipe.width + local row = math.ceil(idx / width) + local col = idx - (row-1)*width recp[row][col] = item end return recp @@ -27,7 +28,11 @@ end -- Change the amount produced by recipe by apply func to the old amount local change_recipe_amount = function(product, recipe, func) - local recp = reconstruct_internal_craft(recipe) + -- if width == 0, this is a shapeless recipe, for which the + -- internal and Lua API recipe table is the same. + -- Otherwise we need to reconstruct the table for the shaped recipe. + local shapeless = (recipe.width == 0) + local recp = shapeless and recipe.items or reconstruct_internal_craft(recipe) local oldamount = tonumber(recipe.output:match(" [0-9]+$") or "1") @@ -35,6 +40,10 @@ local change_recipe_amount = function(product, recipe, func) -- remove old crafting recipe local redo = { recipe = recp } + -- preserve shapelessness + if shapeless then + redo.type = "shapeless" + end minetest.clear_craft(redo) -- new output From bcd1a5688b4ff8d5a03b1db09374c6c2633cf5c1 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 26 Feb 2021 12:06:27 +0100 Subject: [PATCH 2/2] Update the changelog with recent fixes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e050101..1fe879c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- [Shapeless crafting recipes are now handled in redefinitions.](https://github.com/minetest-mods/moreblocks/pull/171) +- [Aliases are now resolved in Stairs+ circular saw cost calculation.](https://github.com/minetest-mods/moreblocks/pull/175) - [Fixed strange placement behavior for non-default Stairs+ nodes.](https://github.com/minetest-mods/moreblocks/pull/168) - [Fixed stairs placement over oddly-shaped nodes.](https://github.com/minetest-mods/moreblocks/pull/166)