From 8d6555982869932dc8807db269b9e20788525f35 Mon Sep 17 00:00:00 2001 From: sys4 Date: Thu, 23 Jul 2020 23:10:37 +0200 Subject: [PATCH] [nature_classic] Optimize math.random call function --- nature_classic/blossom.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nature_classic/blossom.lua b/nature_classic/blossom.lua index 6cbb729..a5ab214 100644 --- a/nature_classic/blossom.lua +++ b/nature_classic/blossom.lua @@ -2,6 +2,8 @@ local S = minetest.get_translator("nature_classic") -- Blossoms and such +local random = math.random + local function spawn_apple_under(pos) local below = { x = pos.x, @@ -46,7 +48,7 @@ minetest.register_abm({ chance = nature.leaves_blossom_chance, 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) end end @@ -61,7 +63,7 @@ minetest.register_abm({ chance = nature.blossom_leaves_chance, 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) end end @@ -76,7 +78,7 @@ minetest.register_abm({ chance = nature.apple_chance, 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) end end