From c2681261e0e3c9e8c48b67db35455364bc4b3440 Mon Sep 17 00:00:00 2001 From: sys4 Date: Thu, 23 Jul 2020 22:10:33 +0200 Subject: [PATCH] [bushes_classic] Optimize math.random call function --- bushes_classic/nodes.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bushes_classic/nodes.lua b/bushes_classic/nodes.lua index cf94d99..95ea325 100644 --- a/bushes_classic/nodes.lua +++ b/bushes_classic/nodes.lua @@ -4,6 +4,8 @@ local S = minetest.get_translator("bushes_classic") plantlife_bushes = {} -- TODO: add support for nodebreakers? those dig like mese picks +local random = math.random + plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger) if not (digger and pos and oldnode) then return @@ -63,7 +65,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger) -- with a chance of 1/3, return 2 bushes local amount - if math.random(1,3) == 1 then + if random(1,3) == 1 then amount = "2" else amount = "1" @@ -75,7 +77,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger) elseif groupcaps.choppy then -- the amount of sticks may vary - local amount = math.random(4, 20) + local amount = random(4, 20) -- return some sticks harvested = "default:stick " .. amount @@ -136,7 +138,7 @@ minetest.register_abm({ local dirt = minetest.get_node(dirtpos) local is_soil = minetest.get_item_group(dirt.name, "soil") or minetest.get_item_group(dirt.name, "potting_soil") - if is_soil and (dirt.name == "farming:soil_wet" or math.random(1,3) == 1) then + if is_soil and (dirt.name == "farming:soil_wet" or random(1,3) == 1) then minetest.swap_node( pos, {name = "bushes:" .. bush_name .. "_bush"}) end end