Browse Source

[nature_classic] Optimize math.random call function

master
sys4 2 weeks ago
parent
commit
8d65559828
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      nature_classic/blossom.lua

+ 5
- 3
nature_classic/blossom.lua View File

@@ -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


Loading…
Cancel
Save