forked from mtcontrib/plantlife_modpack
[flowers_plus] Optimize math.random call function
This commit is contained in:
parent
4dcf14ce1f
commit
ec8132b06c
@ -4,6 +4,8 @@ local S = minetest.get_translator("flowers_plus")
|
|||||||
-- This file supplies a few additional plants and some related crafts
|
-- This file supplies a few additional plants and some related crafts
|
||||||
-- for the plantlife modpack. Last revision: 2013-04-24
|
-- for the plantlife modpack. Last revision: 2013-04-24
|
||||||
|
|
||||||
|
local random = math.random
|
||||||
|
|
||||||
flowers_plus = {}
|
flowers_plus = {}
|
||||||
|
|
||||||
local SPAWN_DELAY = 1000
|
local SPAWN_DELAY = 1000
|
||||||
@ -97,7 +99,7 @@ for i in ipairs(lilies_list) do
|
|||||||
|
|
||||||
if not keys["sneak"] then
|
if not keys["sneak"] then
|
||||||
local node = minetest.get_node(pt.under)
|
local node = minetest.get_node(pt.under)
|
||||||
local waterlily = math.random(1,8)
|
local waterlily = random(1,8)
|
||||||
if waterlily == 1 then
|
if waterlily == 1 then
|
||||||
nodename = "flowers:waterlily"
|
nodename = "flowers:waterlily"
|
||||||
elseif waterlily == 2 then
|
elseif waterlily == 2 then
|
||||||
@ -115,7 +117,7 @@ for i in ipairs(lilies_list) do
|
|||||||
elseif waterlily == 8 then
|
elseif waterlily == 8 then
|
||||||
nodename = "flowers:waterlily_s4"
|
nodename = "flowers:waterlily_s4"
|
||||||
end
|
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
|
else
|
||||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
minetest.swap_node(place_pos, {name = "flowers:waterlily", param2 = fdir})
|
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
|
if not keys["sneak"] then
|
||||||
--local node = minetest.get_node(pt.under)
|
--local node = minetest.get_node(pt.under)
|
||||||
local seaweed = math.random(1,4)
|
local seaweed = random(1,4)
|
||||||
if seaweed == 1 then
|
if seaweed == 1 then
|
||||||
nodename = "flowers:seaweed"
|
nodename = "flowers:seaweed"
|
||||||
elseif seaweed == 2 then
|
elseif seaweed == 2 then
|
||||||
@ -207,7 +209,7 @@ for i in ipairs(algae_list) do
|
|||||||
elseif seaweed == 4 then
|
elseif seaweed == 4 then
|
||||||
nodename = "flowers:seaweed_4"
|
nodename = "flowers:seaweed_4"
|
||||||
end
|
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
|
else
|
||||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
minetest.swap_node(place_pos, {name = "flowers:seaweed", param2 = fdir})
|
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)
|
flowers_plus.grow_waterlily = function(pos)
|
||||||
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
|
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
for i in ipairs(lilies_list) do
|
for i in ipairs(lilies_list) do
|
||||||
local chance = math.random(1,8)
|
local chance = random(1,8)
|
||||||
local ext = ""
|
local ext = ""
|
||||||
local num = lilies_list[i][3]
|
local num = lilies_list[i][3]
|
||||||
|
|
||||||
@ -294,7 +296,7 @@ flowers_plus.grow_waterlily = function(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if chance == num then
|
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
|
end
|
||||||
end
|
end
|
||||||
@ -318,7 +320,7 @@ biome_lib:register_generate_plant({
|
|||||||
|
|
||||||
flowers_plus.grow_seaweed = function(pos)
|
flowers_plus.grow_seaweed = function(pos)
|
||||||
local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
|
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
|
end
|
||||||
|
|
||||||
biome_lib:register_generate_plant({
|
biome_lib:register_generate_plant({
|
||||||
|
Loading…
Reference in New Issue
Block a user