forked from mtcontrib/plantlife_modpack
[bushes_classic] Optimize math.random call function
This commit is contained in:
parent
2c433e0b57
commit
c2681261e0
@ -4,6 +4,8 @@ local S = minetest.get_translator("bushes_classic")
|
|||||||
plantlife_bushes = {}
|
plantlife_bushes = {}
|
||||||
|
|
||||||
-- TODO: add support for nodebreakers? those dig like mese picks
|
-- TODO: add support for nodebreakers? those dig like mese picks
|
||||||
|
local random = math.random
|
||||||
|
|
||||||
plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
if not (digger and pos and oldnode) then
|
if not (digger and pos and oldnode) then
|
||||||
return
|
return
|
||||||
@ -63,7 +65,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|||||||
|
|
||||||
-- with a chance of 1/3, return 2 bushes
|
-- with a chance of 1/3, return 2 bushes
|
||||||
local amount
|
local amount
|
||||||
if math.random(1,3) == 1 then
|
if random(1,3) == 1 then
|
||||||
amount = "2"
|
amount = "2"
|
||||||
else
|
else
|
||||||
amount = "1"
|
amount = "1"
|
||||||
@ -75,7 +77,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|||||||
elseif groupcaps.choppy then
|
elseif groupcaps.choppy then
|
||||||
|
|
||||||
-- the amount of sticks may vary
|
-- the amount of sticks may vary
|
||||||
local amount = math.random(4, 20)
|
local amount = random(4, 20)
|
||||||
-- return some sticks
|
-- return some sticks
|
||||||
harvested = "default:stick " .. amount
|
harvested = "default:stick " .. amount
|
||||||
|
|
||||||
@ -136,7 +138,7 @@ minetest.register_abm({
|
|||||||
local dirt = minetest.get_node(dirtpos)
|
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")
|
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"})
|
minetest.swap_node( pos, {name = "bushes:" .. bush_name .. "_bush"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user