Take ore_rarity global accessable trough gravelsieve.ore_rarity

Unify check for optional maybe not existing ores
Removed not needed check against probability ~= nil (nil means does not exists, so "pairs" does not return them)
This commit is contained in:
Joachim Stolberg 2017-07-08 14:08:57 +02:00 committed by Alexander Weber
parent a546617feb
commit 58f49c7275

View File

@ -38,23 +38,22 @@ gravelsieve.ore_rarity = tonumber(minetest.setting_get("gravelsieve_ore_rarity")
-- Ore probability table (1/n) -- Ore probability table (1/n)
local ore_probability = { gravelsieve.ore_probability = {
["default:iron_lump"] = 35, ["default:iron_lump"] = 35,
["default:copper_lump"] = 60, ["default:copper_lump"] = 60,
["default:tin_lump"] = 80, ["default:tin_lump"] = 80,
["default:gold_lump"] = 175, ["default:gold_lump"] = 175,
["default:mese_crystal"] = 275, ["default:mese_crystal"] = 275,
["default:diamond"] = 340, ["default:diamond"] = 340,
["moreores:silver_lump"] = 100,
["moreores:mithril_lump"] = 250,
} }
if minetest.get_modpath("moreores") then -- remove not registered ores from list
ore_probability["moreores:silver_lump"] = 100 for ore, probability in pairs(gravelsieve.ore_probability) do
ore_probability["moreores:mithril_lump"] = 250 if not minetest.registered_items[ore] then
gravelsieve.ore_probability[ore] = nil
end end
-- check if tin is available
if ItemStack("default:tin_lump") == nil then
ore_probability["tin_lump"] = nil -- not available
end end
local sieve_formspec = local sieve_formspec =
@ -112,10 +111,9 @@ end
-- place ores to dst according to the calculated probability -- place ores to dst according to the calculated probability
local function random_ore(inv, src) local function random_ore(inv, src)
local num local num
for ore, probability in pairs(ore_probability) do for ore, probability in pairs(gravelsieve.ore_probability) do
-- calculate the probability based on user configuration -- calculate the probability based on user configuration
probability = probability * gravelsieve.ore_rarity probability = probability * gravelsieve.ore_rarity
if probability ~= nil then
if math.random(probability) == 1 then if math.random(probability) == 1 then
local item = ItemStack(ore) local item = ItemStack(ore)
if inv:room_for_item("dst", item) then if inv:room_for_item("dst", item) then
@ -124,7 +122,6 @@ local function random_ore(inv, src)
end end
end end
end end
end
return false -- gravel has to be moved return false -- gravel has to be moved
end end