[bushes_classic] Optimize math.random call function

This commit is contained in:
Sys Quatre 2020-07-23 22:10:33 +02:00
parent 2c433e0b57
commit c2681261e0

View File

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