2020-06-04 08:09:30 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local math, minetest, nodecore, pairs
|
|
|
|
= math, minetest, nodecore, pairs
|
|
|
|
local math_random
|
|
|
|
= math.random
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local harden_to = {}
|
|
|
|
local harden_idx = {}
|
2020-08-30 21:07:13 -04:00
|
|
|
local soften_to = {}
|
2020-06-04 08:09:30 -04:00
|
|
|
minetest.after(0, function()
|
|
|
|
for _, v in pairs(minetest.registered_nodes) do
|
|
|
|
if v.strata then
|
|
|
|
for i, n in pairs(v.strata) do
|
|
|
|
harden_to[n] = v.strata[i + 1]
|
2020-08-30 21:07:13 -04:00
|
|
|
soften_to[n] = v.strata[i - 1]
|
2020-06-04 08:09:30 -04:00
|
|
|
harden_idx[n] = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
local queue = {}
|
|
|
|
|
|
|
|
local function process(pos)
|
2020-08-30 21:07:13 -04:00
|
|
|
local water = #nodecore.find_nodes_around(pos, "group:water")
|
|
|
|
local lux = #nodecore.find_nodes_around(pos, "group:lux_fluid")
|
|
|
|
if water == lux then return end
|
|
|
|
|
2020-06-04 08:09:30 -04:00
|
|
|
local node = minetest.get_node(pos)
|
2020-08-30 21:07:13 -04:00
|
|
|
node.name = (water > lux and harden_to or soften_to)[node.name]
|
2020-06-04 08:09:30 -04:00
|
|
|
if not node.name then return end
|
|
|
|
|
|
|
|
local lava = #nodecore.find_nodes_around(pos, "group:lava")
|
2020-08-30 21:07:13 -04:00
|
|
|
if lava < 1 then return end
|
2020-06-04 08:09:30 -04:00
|
|
|
|
2020-08-30 21:07:13 -04:00
|
|
|
local fluid = water > lux and (water - lux) or (lux - water)
|
|
|
|
local chance = harden_idx[node.name] - (fluid > lava and fluid or lava) / 8
|
|
|
|
if (chance > 0) and (math_random() > (1/3) ^ chance) then return end
|
|
|
|
nodecore.log("action", (water > lux and "hardened" or "softened")
|
|
|
|
.. " to " .. node.name .. " at " .. minetest.pos_to_string(pos))
|
2020-09-11 17:20:21 -04:00
|
|
|
nodecore.witness(pos, "stone " .. (water > lux and "hardened" or "softened"))
|
2020-06-04 08:09:30 -04:00
|
|
|
return nodecore.set_loud(pos, node)
|
|
|
|
end
|
|
|
|
|
2020-06-15 07:21:39 -04:00
|
|
|
nodecore.register_globalstep("stone hardening", function()
|
2020-06-04 08:09:30 -04:00
|
|
|
for _, p in pairs(queue) do process(p) end
|
|
|
|
queue = {}
|
|
|
|
end)
|
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
2020-06-17 07:09:20 -04:00
|
|
|
label = "stone hardening",
|
2020-06-04 08:09:30 -04:00
|
|
|
nodenames = {"group:lava"},
|
|
|
|
neighbors = {"group:stone"},
|
|
|
|
interval = 10,
|
2020-06-18 06:40:19 -04:00
|
|
|
chance = 50,
|
2020-06-04 08:09:30 -04:00
|
|
|
action = function(pos)
|
2020-08-30 21:07:13 -04:00
|
|
|
if not minetest.find_node_near(pos, 2,
|
|
|
|
{"group:water", "group:lux_fluid"}) then return end
|
2020-06-04 08:09:30 -04:00
|
|
|
for _, p in pairs(nodecore.find_nodes_around(pos, "group:stone")) do
|
|
|
|
queue[minetest.hash_node_position(p)] = p
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|