Merge pull request #2 from CasimirKaPazi/generic_ores

Lava cooling: Choose ore from the list of registered ores
master
Casimir 2017-05-06 16:39:25 +02:00 committed by GitHub
commit e93928fb57
1 changed files with 39 additions and 18 deletions

View File

@ -1,3 +1,5 @@
additional_stuff = {}
minetest.register_craft({
type = "cooking",
output = "default:lava_source",
@ -100,32 +102,51 @@ minetest.register_abm({
end
-- Lava cooling
-- Exclude coal and diamond from being generated
additional_stuff.not_an_ore = {"default:stone_with_coal", "default:stone_with_diamond"}
local function is_not_an_ore(ore_name)
for _,no_ore in ipairs(additional_stuff.not_an_ore) do
if ore_name == no_ore then
return true
end
end
return false
end
-- Place ore just as often as they occur in mapgen.
local function choose_ore()
local cool_flowing = "default:stone"
for _, ore in pairs(minetest.registered_ores) do
if is_not_an_ore(ore.ore) then
-- Do noting, keep cycling.
elseif ore.wherein == cool_flowing and ore.ore_type == "scatter" then
local rarity = math.floor(ore.clust_scarcity / ore.clust_size)
if math.random(rarity) == 1 then
cool_flowing = ore.ore
break
end
end
end
return cool_flowing
end
default.cool_lava = function(pos, node)
if node.name == "default:lava_source" then
-- different or subgame used
local cool_source = "default:stone"
-- different for subgame used
if minetest.registered_items["default:molten_rock"] then
-- Voxelgarden
minetest.set_node(pos, {name = "default:molten_rock"})
cool_source = "default:molten_rock"
elseif minetest.registered_items["default:obsidian"] then
-- Minetest Game
minetest.set_node(pos, {name = "default:obsidian"})
else
-- Unsupported
minetest.set_node(pos, {name = "default:stone"})
cool_source = "default:obsidian"
end
minetest.set_node(pos, {name = cool_source})
else -- Lava flowing
-- find one ore per max stack
local oneinastack = minetest.nodedef_default.stack_max
if math.random(1, oneinastack) == 1 then
local ore_choice = math.random(1, 2)
if ore_choice == 1 then
minetest.set_node(pos, {name = "default:stone_with_copper"})
elseif ore_choice == 2 then
minetest.set_node(pos, {name = "default:stone_with_iron"})
end
else
minetest.set_node(pos, {name = "default:stone"})
end
local cool_flowing = choose_ore()
minetest.set_node(pos, {name = cool_flowing})
end
minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.25})