From 9e1cace0da990bfd815aaf53cdf91c2a64357aa0 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Tue, 20 Nov 2018 22:49:44 -0700 Subject: [PATCH] generalizing the heating/cooling ABM --- README.md | 20 ++++++++++-- cook_soil.lua | 11 ------- hot_rock.lua | 89 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 77 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 2987578..6a66e2a 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,25 @@ This mod makes magma more sparsely distributed across the map, but where it is f ## Lava interaction with adjacent nodes -This mod provides a number of ABMs that cause nodes adjacent to lava to slowly convert into glowing "hot" forms, and then back to cool forms again if the lava goes away. Stone is converted into hot cobble and obsidian converts to a glowing red form. +This mod provides an ABM that causes some types of nodes adjacent to lava to slowly convert into glowing "hot" forms, and then back to cool forms again if the lava goes away. Stone is converted into hot cobble and obsidian converts to a glowing red form. -Also included are ABMs that cause soil adjacent to lava to be cooked into barren sand, and coal and diamond ore to be cooked into cobble. +Other mods can hook into this ABM by adding the following to node definitions: + +``` +group:lava_heatable +_magma_conduits_heats_to = hot node name +``` + +and + +``` +group:lava_heated +_magma_conduits_cools_to = cool node name +``` + +so for example default:stone is added to the lava_heatable group and given _magma_conduits_heats_to = "magma_conduits:hot_cobble" and magma_conduits:hot_cobble is in the lava_heated group and is given _magma_conduits_cools_to = "default:cobble". + +Also included is an ABM that causes soil adjacent to lava to be cooked into barren sand. ## Magma veins diff --git a/cook_soil.lua b/cook_soil.lua index c8a109f..97d4521 100644 --- a/cook_soil.lua +++ b/cook_soil.lua @@ -9,14 +9,3 @@ minetest.register_abm{ minetest.check_for_falling(pos) end, } - -minetest.register_abm{ - label = "ore burning", - nodenames = {"default:stone_with_coal", "default:stone_with_diamond"}, - neighbors = {"default:lava_source", "default:lava_flowing"}, - interval = 10, - chance = 5, - action = function(pos) - minetest.set_node(pos, {name = "default:cobble"}) - end, -} \ No newline at end of file diff --git a/hot_rock.lua b/hot_rock.lua index cc24b4b..eff62e7 100644 --- a/hot_rock.lua +++ b/hot_rock.lua @@ -9,7 +9,8 @@ minetest.register_node("magma_conduits:hot_cobble", { _doc_items_usagehelp = S("When normal stone is heated by lava it is converted into this. Beware when digging here!"), tiles = {"magma_conduits_hot_cobble.png"}, is_ground_content = false, - groups = {cracky = 3, stone = 2, hot=1}, + groups = {cracky = 3, stone = 2, lava_heated=1}, + _magma_conduits_cools_to = "default:cobble", sounds = default.node_sound_stone_defaults(), light_source = 6, drop = "default:cobble", @@ -22,53 +23,81 @@ minetest.register_node("magma_conduits:glow_obsidian", { tiles = {"magma_conduits_glow_obsidian.png"}, is_ground_content = true, sounds = default.node_sound_stone_defaults(), - groups = {cracky=1, hot=1, level=2}, + groups = {cracky=1, lava_heated=1, level=2}, + _magma_conduits_cools_to = "default:obsidian", light_source = 6, drop = "default:obsidian", }) +local simple_copy +simple_copy = function(t) + local r = {} + for k, v in pairs(t) do + if type(v) == "table" then + r[k] = simple_copy(v) + else + r[k] = v + end + end + return r +end + +-- can't use minetest.override_item to change group memberships here due to issue https://github.com/minetest/minetest/issues/5518 + +local make_heatable = function(nodename, heats_to) + local original_def = minetest.registered_nodes[nodename] + if original_def ~= nil then + local def = simple_copy(original_def) + def.groups.lava_heatable = 1 + def._magma_conduits_heats_to = heats_to + minetest.register_node(":"..nodename, def) + end +end + +make_heatable("default:obsidian", "magma_conduits:glow_obsidian") +make_heatable("default:stone", "magma_conduits:hot_cobble") +make_heatable("default:cobble", "magma_conduits:hot_cobble") +make_heatable("default:mossycobble", "magma_conduits:hot_cobble") +make_heatable("default:stone_with_coal", "magma_conduits:hot_cobble") +make_heatable("default:stone_with_diamond", "magma_conduits:hot_cobble") + +make_heatable("default:permafrost", "default:dirt") +make_heatable("default:permafrost_with_stones", "default:dirt") +make_heatable("default:permafrost_with_moss", "default:dirt") + minetest.register_abm{ - label = "stone heating", - nodenames = {"default:stone", "default:cobble", "default:mossycobble"}, + label = "magma_conduits lava heating neighbors", + nodenames = {"group:lava_heatable"}, neighbors = {"default:lava_source", "default:lava_flowing"}, interval = 10, chance = 5, action = function(pos) - minetest.set_node(pos, {name = "magma_conduits:hot_cobble"}) - end, -} - -minetest.register_abm{ - label = "obsidian heating", - nodenames = {"default:obsidian"}, - neighbors = {"default:lava_source", "default:lava_flowing"}, - interval = 10, - chance = 5, - action = function(pos) - minetest.set_node(pos, {name = "magma_conduits:glow_obsidian"}) - end, -} - -minetest.register_abm{ - label = "stone cooling", - nodenames = {"magma_conduits:hot_cobble"}, - interval = 100, - chance = 10, - action = function(pos) - if not minetest.find_node_near(pos, 2, {"default:lava_source", "default:lava_flowing"}, false) then - minetest.set_node(pos, {name = "default:cobble"}) + local name = minetest.get_node(pos).name + local def = minetest.registered_nodes[name] + local target = def._magma_conduits_heats_to + if target then + minetest.set_node(pos, {name = target}) + else + minetest.log("error", name .. " is in group lava_heatable but doesn't have a _magma_conduits_heats_to property defined in its definition") end end, } minetest.register_abm{ - label = "obsidian cooling", - nodenames = {"magma_conduits:glow_obsidian"}, + label = "magma_conduits cooling stuff heated by lava", + nodenames = {"group:lava_heated"}, interval = 100, chance = 10, action = function(pos) if not minetest.find_node_near(pos, 2, {"default:lava_source", "default:lava_flowing"}, false) then - minetest.set_node(pos, {name = "default:obsidian"}) + local name = minetest.get_node(pos).name + local def = minetest.registered_nodes[name] + local target = def._magma_conduits_cools_to + if target then + minetest.set_node(pos, {name = "default:cobble"}) + else + minetest.log("error", name .. " is in group lava_heated but doesn't have a _magma_conduits_cools_to property defined in its definition") + end end end, }