-- Squaresville desolate.lua -- Copyright Duane Robertson (duane@duanerobertson.com), 2017 -- Distributed under the LGPLv2.1 (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) local cobble = squaresville.cobble local desolation = squaresville.desolation local ground_nodes = squaresville.ground_nodes local math_random = math.random local node = squaresville.node local node_air = node['air'] local node_cobble = node['default:cobble'] local node_dirt = node['default:dirt'] local node_glowing_fungal_stone = node['squaresville:glowing_fungal_stone'] local node_gravel = node['default:gravel'] local node_light_panel = node['squaresville:light_panel'] local node_mossycobble = node['default:mossycobble'] local node_plate_glass = node['squaresville:plate_glass'] local node_snowblock = node['default:snowblock'] local node_stone_with_copper = node['default:stone_with_copper'] local node_stone_with_iron = node['default:stone_with_iron'] -- This table looks up the names of broken nodes. local broken_node = setmetatable({}, { __index = function(t, k) if not (t and k and type(t) == 'table' and type(k) == 'number') then return end local s = minetest.get_name_from_content_id(k) s = string.gsub(s, '.*:', 'squaresville:')..'_broken' t[k] = k if minetest.registered_nodes[s] then t[k] = node[s] end return t[k] end }) -- This table looks up the properties of nodes. local groups = setmetatable({}, { __index = function(t, k) if not (t and k and type(t) == 'table' and type(k) == 'string') then return end local s = minetest.get_name_from_content_id(k) t[k] = minetest.registered_items[s].groups return t[k] end }) function squaresville.breaker(node_n, dy, humidity, desolation) if desolation == 0 then return node_n end local dry = 100 - humidity + dy local sr = math_random(50) local goff = 1 dry = dry + 1 if node_n == node_light_panel then sr = 1 elseif node_n == node_plate_glass then goff = 3 end if not ground_nodes[node_n] and node_n ~= node_snowblock and sr <= desolation * goff then return node_air elseif not ground_nodes[node_n] and cobble and sr <= desolation * 3 and groups[node_n].cracky then sr = math_random(700) if sr == 1 then sr = math_random(4) if sr == 1 then return node_stone_with_copper else return node_stone_with_iron end elseif sr <= 15 then return node_glowing_fungal_stone elseif sr <= 40 then return node_gravel elseif sr <= 140 then return node_dirt else if sr <= dry * 10 then return node_cobble else return node_mossycobble end end elseif sr <= desolation * 5 then return broken_node[node_n] end return node_n end