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:
parent
a546617feb
commit
58f49c7275
33
init.lua
33
init.lua
@ -26,7 +26,7 @@
|
|||||||
2017-06-20 v0.05 * Hammer sound bugfix
|
2017-06-20 v0.05 * Hammer sound bugfix
|
||||||
2017-06-24 v1.00 * Released version w/o any changes
|
2017-06-24 v1.00 * Released version w/o any changes
|
||||||
2017-07-08 V1.01 * extended for moreores
|
2017-07-08 V1.01 * extended for moreores
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
gravelsieve = {
|
gravelsieve = {
|
||||||
@ -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
|
||||||
end
|
gravelsieve.ore_probability[ore] = nil
|
||||||
|
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,16 +111,14 @@ 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
|
inv:add_item("dst", item)
|
||||||
inv:add_item("dst", item)
|
return true -- ore placed
|
||||||
return true -- ore placed
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user