From 923574461251481fcc5a4b5589a14ef9cfec6d82 Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sat, 27 Nov 2021 19:26:31 -0500 Subject: [PATCH] Items can cool in storeboxes, but not cook Cooking recipes run in all visinv nodes, not just item stacks, BUT non-stack-only nodes (i.e. all storeboxes) block flame touchgroups so things in boxes cannot be heated/melted. This allows items dropped into boxes from ore melting to cool, but prevents sand from being melted in a box which would naively replace the box with the molten glass entirely. This also fixes an old rumored bug where forcing glowing lode items into a shelf with a door would cause them to stay hot indefinitely. N.B. lode cooking/cooling used to assume it could replace the entire node, and deleted the thing as a fail-safe when an item of the given temper was not found (e.g. tools w/ handles). This is now gone, and invalid tempers will throw errors if they can ever be achieved in practice. --- mods/nc_api_craft/craft_check.lua | 3 +++ mods/nc_items/hooks.lua | 9 +++++++-- mods/nc_lode/metallurgy.lua | 9 ++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mods/nc_api_craft/craft_check.lua b/mods/nc_api_craft/craft_check.lua index 2263bc64..14219cb0 100644 --- a/mods/nc_api_craft/craft_check.lua +++ b/mods/nc_api_craft/craft_check.lua @@ -47,6 +47,9 @@ local function craftcheck(recipe, pos, node, data, xx, xz, zx, zz) addgroups(sum, rel(0, -1, 0)) addgroups(sum, rel(0, 0, 1)) addgroups(sum, rel(0, 0, -1)) + if data.touchgroupmodify then + data.touchgroupmodify(sum) + end for k, v in pairs(recipe.touchgroups) do local w = sum[k] or 0 if v > 0 and w < v then return end diff --git a/mods/nc_items/hooks.lua b/mods/nc_items/hooks.lua index eafe715e..8b42e3c2 100644 --- a/mods/nc_items/hooks.lua +++ b/mods/nc_items/hooks.lua @@ -26,12 +26,17 @@ minetest.after(0, function() end end) +local function flameblock(sum) sum.flame = nil end nodecore.register_dnt({ name = dntname, time = 1, - nodenames = {modname .. ":stack"}, + nodenames = {"group:visinv"}, action = function(pos, node) + node.stack = nodecore.stack_get(pos) local data = nodecore.craft_cooking_data() + if minetest.get_item_group(node.name, "is_stack_only") == 0 then + data.touchgroupmodify = flameblock + end nodecore.craft_check(pos, node, data) if not data.progressing then return minetest.get_meta(pos):set_string(modname, "") @@ -43,7 +48,7 @@ nodecore.register_dnt({ minetest.register_abm({ label = "item stack cook", - nodenames = {modname .. ":stack"}, + nodenames = {"group:visinv"}, interval = 1, chance = 1, action = function(pos) diff --git a/mods/nc_lode/metallurgy.lua b/mods/nc_lode/metallurgy.lua index 56e72616..1b7560e2 100644 --- a/mods/nc_lode/metallurgy.lua +++ b/mods/nc_lode/metallurgy.lua @@ -1,6 +1,6 @@ -- LUALOCALS < --------------------------------------------------------- -local ItemStack, minetest, nodecore, pairs, type - = ItemStack, minetest, nodecore, pairs, type +local ItemStack, error, minetest, nodecore, pairs, type + = ItemStack, error, minetest, nodecore, pairs, type -- LUALOCALS > --------------------------------------------------------- local modname = minetest.get_current_modname() @@ -104,14 +104,13 @@ local function replacestack(pos, alt) local name = stack and stack:get_name() or node.name local def = minetest.registered_items[name] or {} alt = def["metal_alt_" .. alt] - if not alt then return nodecore.remove_node(pos) end + if not alt then return error("no " .. alt .. " alt for " .. name) end if stack then local repl = ItemStack(alt) local qty = stack:get_count() if qty == 0 then qty = 1 end repl:set_count(qty * repl:get_count()) - nodecore.remove_node(pos) - return nodecore.item_eject(pos, repl) + nodecore.stack_set(pos, repl) else nodecore.set_node(pos, {name = alt}) nodecore.fallcheck(pos)