[flowers_plus] Optimize math.random call function

This commit is contained in:
Sys Quatre 2020-07-23 23:02:17 +02:00
parent 4dcf14ce1f
commit ec8132b06c
1 changed files with 9 additions and 7 deletions

View File

@ -4,6 +4,8 @@ local S = minetest.get_translator("flowers_plus")
-- This file supplies a few additional plants and some related crafts
-- for the plantlife modpack. Last revision: 2013-04-24
local random = math.random
flowers_plus = {}
local SPAWN_DELAY = 1000
@ -97,7 +99,7 @@ for i in ipairs(lilies_list) do
if not keys["sneak"] then
local node = minetest.get_node(pt.under)
local waterlily = math.random(1,8)
local waterlily = random(1,8)
if waterlily == 1 then
nodename = "flowers:waterlily"
elseif waterlily == 2 then
@ -115,7 +117,7 @@ for i in ipairs(lilies_list) do
elseif waterlily == 8 then
nodename = "flowers:waterlily_s4"
end
minetest.swap_node(place_pos, {name = nodename, param2 = math.random(0,3) })
minetest.swap_node(place_pos, {name = nodename, param2 = random(0,3) })
else
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.swap_node(place_pos, {name = "flowers:waterlily", param2 = fdir})
@ -197,7 +199,7 @@ for i in ipairs(algae_list) do
if not keys["sneak"] then
--local node = minetest.get_node(pt.under)
local seaweed = math.random(1,4)
local seaweed = random(1,4)
if seaweed == 1 then
nodename = "flowers:seaweed"
elseif seaweed == 2 then
@ -207,7 +209,7 @@ for i in ipairs(algae_list) do
elseif seaweed == 4 then
nodename = "flowers:seaweed_4"
end
minetest.swap_node(place_pos, {name = nodename, param2 = math.random(0,3) })
minetest.swap_node(place_pos, {name = nodename, param2 = random(0,3) })
else
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.swap_node(place_pos, {name = "flowers:seaweed", param2 = fdir})
@ -285,7 +287,7 @@ minetest.register_alias( "along_shore:seaweed_4" , "flowers:seaweed_4" )
flowers_plus.grow_waterlily = function(pos)
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
for i in ipairs(lilies_list) do
local chance = math.random(1,8)
local chance = random(1,8)
local ext = ""
local num = lilies_list[i][3]
@ -294,7 +296,7 @@ flowers_plus.grow_waterlily = function(pos)
end
if chance == num then
minetest.swap_node(right_here, {name="flowers:waterlily"..ext, param2=math.random(0,3)})
minetest.swap_node(right_here, {name="flowers:waterlily"..ext, param2=random(0,3)})
end
end
end
@ -318,7 +320,7 @@ biome_lib:register_generate_plant({
flowers_plus.grow_seaweed = function(pos)
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.swap_node(right_here, {name="along_shore:seaweed_"..math.random(1,4), param2=math.random(1,3)})
minetest.swap_node(right_here, {name="along_shore:seaweed_"..random(1,4), param2=random(1,3)})
end
biome_lib:register_generate_plant({