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

@ -26,7 +26,7 @@
2017-06-20 v0.05 * Hammer sound bugfix
2017-06-24 v1.00 * Released version w/o any changes
2017-07-08 V1.01 * extended for moreores
]]--
gravelsieve = {
@ -38,23 +38,22 @@ gravelsieve.ore_rarity = tonumber(minetest.setting_get("gravelsieve_ore_rarity")
-- Ore probability table (1/n)
local ore_probability = {
gravelsieve.ore_probability = {
["default:iron_lump"] = 35,
["default:copper_lump"] = 60,
["default:tin_lump"] = 80,
["default:gold_lump"] = 175,
["default:mese_crystal"] = 275,
["default:diamond"] = 340,
["moreores:silver_lump"] = 100,
["moreores:mithril_lump"] = 250,
}
if minetest.get_modpath("moreores") then
ore_probability["moreores:silver_lump"] = 100
ore_probability["moreores:mithril_lump"] = 250
end
-- check if tin is available
if ItemStack("default:tin_lump") == nil then
ore_probability["tin_lump"] = nil -- not available
-- remove not registered ores from list
for ore, probability in pairs(gravelsieve.ore_probability) do
if not minetest.registered_items[ore] then
gravelsieve.ore_probability[ore] = nil
end
end
local sieve_formspec =
@ -112,16 +111,14 @@ end
-- place ores to dst according to the calculated probability
local function random_ore(inv, src)
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
probability = probability * gravelsieve.ore_rarity
if probability ~= nil then
if math.random(probability) == 1 then
local item = ItemStack(ore)
if inv:room_for_item("dst", item) then
inv:add_item("dst", item)
return true -- ore placed
end
if math.random(probability) == 1 then
local item = ItemStack(ore)
if inv:room_for_item("dst", item) then
inv:add_item("dst", item)
return true -- ore placed
end
end
end