[nature_classic] Optimize math.random call function

This commit is contained in:
Sys Quatre 2020-07-23 23:10:37 +02:00
parent ec8132b06c
commit 8d65559828

View File

@ -2,6 +2,8 @@
local S = minetest.get_translator("nature_classic") local S = minetest.get_translator("nature_classic")
-- Blossoms and such -- Blossoms and such
local random = math.random
local function spawn_apple_under(pos) local function spawn_apple_under(pos)
local below = { local below = {
x = pos.x, x = pos.x,
@ -46,7 +48,7 @@ minetest.register_abm({
chance = nature.leaves_blossom_chance, chance = nature.leaves_blossom_chance,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if math.random(nature.leaves_blossom_chance) == 1 then if random(nature.leaves_blossom_chance) == 1 then
nature.enqueue_node(pos, node, nature.blossom_node) nature.enqueue_node(pos, node, nature.blossom_node)
end end
end end
@ -61,7 +63,7 @@ minetest.register_abm({
chance = nature.blossom_leaves_chance, chance = nature.blossom_leaves_chance,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if math.random(nature.blossom_leaves_chance) == 1 then if random(nature.blossom_leaves_chance) == 1 then
nature.enqueue_node(pos, node, nature.blossom_leaves) nature.enqueue_node(pos, node, nature.blossom_leaves)
end end
end end
@ -76,7 +78,7 @@ minetest.register_abm({
chance = nature.apple_chance, chance = nature.apple_chance,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if math.random(4) == 1 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then if random(4) == 1 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
spawn_apple_under(pos) spawn_apple_under(pos)
end end
end end