mirror of
https://github.com/mt-mods/plantlife_modpack.git
synced 2025-07-18 07:40:39 +02:00
[cavestuff] Optimize math.* call functions
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
--Map Generation Stuff
|
||||
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if maxp.y >= 2 and minp.y <= 0 then
|
||||
-- Generate pebbles
|
||||
@ -9,12 +12,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local divs = (maxp.x-minp.x)/divlen+1;
|
||||
for divx=0,divs-1 do
|
||||
for divz=0,divs-1 do
|
||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
||||
local x0 = minp.x + floor((divx+0)*divlen)
|
||||
local z0 = minp.z + floor((divz+0)*divlen)
|
||||
local x1 = minp.x + floor((divx+1)*divlen)
|
||||
local z1 = minp.z + floor((divz+1)*divlen)
|
||||
-- Determine pebble amount from perlin noise
|
||||
local pebble_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 2 * 2)
|
||||
local pebble_amount = floor(perlin1:get2d({x=x0, y=z0}) ^ 2 * 2)
|
||||
-- Find random positions for pebbles based on this random
|
||||
local pr = PseudoRandom(seed+1)
|
||||
for i=0,pebble_amount do
|
||||
@ -38,9 +41,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
nn = minetest.get_node({x=x,y=ground_y,z=z}).name
|
||||
-- If desert sand, add dry shrub
|
||||
if nn == "default:dirt_with_grass" then
|
||||
minetest.swap_node(p,{name="cavestuff:pebble_"..pr:next(1,2), param2=math.random(0,3)})
|
||||
minetest.swap_node(p,{name="cavestuff:pebble_"..pr:next(1,2), param2=random(0,3)})
|
||||
elseif nn == "default:desert_sand" then
|
||||
minetest.swap_node(p,{name="cavestuff:desert_pebble_"..pr:next(1,2), param2=math.random(0,3)})
|
||||
minetest.swap_node(p,{name="cavestuff:desert_pebble_"..pr:next(1,2), param2=random(0,3)})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user