forked from mtcontrib/plantlife_modpack
[cavestuff] Optimize math.* call functions
This commit is contained in:
parent
c2681261e0
commit
f661500cb3
@ -1,5 +1,8 @@
|
|||||||
--Map Generation Stuff
|
--Map Generation Stuff
|
||||||
|
|
||||||
|
local random = math.random
|
||||||
|
local floor = math.floor
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
if maxp.y >= 2 and minp.y <= 0 then
|
if maxp.y >= 2 and minp.y <= 0 then
|
||||||
-- Generate pebbles
|
-- Generate pebbles
|
||||||
@ -9,12 +12,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local divs = (maxp.x-minp.x)/divlen+1;
|
local divs = (maxp.x-minp.x)/divlen+1;
|
||||||
for divx=0,divs-1 do
|
for divx=0,divs-1 do
|
||||||
for divz=0,divs-1 do
|
for divz=0,divs-1 do
|
||||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
local x0 = minp.x + floor((divx+0)*divlen)
|
||||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
local z0 = minp.z + floor((divz+0)*divlen)
|
||||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
local x1 = minp.x + floor((divx+1)*divlen)
|
||||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
local z1 = minp.z + floor((divz+1)*divlen)
|
||||||
-- Determine pebble amount from perlin noise
|
-- 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
|
-- Find random positions for pebbles based on this random
|
||||||
local pr = PseudoRandom(seed+1)
|
local pr = PseudoRandom(seed+1)
|
||||||
for i=0,pebble_amount do
|
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
|
nn = minetest.get_node({x=x,y=ground_y,z=z}).name
|
||||||
-- If desert sand, add dry shrub
|
-- If desert sand, add dry shrub
|
||||||
if nn == "default:dirt_with_grass" then
|
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
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
-- support for i18n
|
-- support for i18n
|
||||||
local S = minetest.get_translator("cavestuff")
|
local S = minetest.get_translator("cavestuff")
|
||||||
|
|
||||||
|
local random = math.random
|
||||||
|
|
||||||
--Rocks
|
--Rocks
|
||||||
|
|
||||||
local cbox = {
|
local cbox = {
|
||||||
@ -20,7 +22,7 @@ minetest.register_node("cavestuff:pebble_1",{
|
|||||||
collision_box = cbox,
|
collision_box = cbox,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
-- place a random pebble node
|
-- place a random pebble node
|
||||||
local stack = ItemStack("cavestuff:pebble_"..math.random(1,2))
|
local stack = ItemStack("cavestuff:pebble_"..random(1,2))
|
||||||
local ret = minetest.item_place(stack, placer, pointed_thing)
|
local ret = minetest.item_place(stack, placer, pointed_thing)
|
||||||
return ItemStack("cavestuff:pebble_1 "..itemstack:get_count()-(1-ret:get_count()))
|
return ItemStack("cavestuff:pebble_1 "..itemstack:get_count()-(1-ret:get_count()))
|
||||||
end,
|
end,
|
||||||
@ -53,7 +55,7 @@ minetest.register_node("cavestuff:desert_pebble_1",{
|
|||||||
collision_box = cbox,
|
collision_box = cbox,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
-- place a random pebble node
|
-- place a random pebble node
|
||||||
local stack = ItemStack("cavestuff:desert_pebble_"..math.random(1,2))
|
local stack = ItemStack("cavestuff:desert_pebble_"..random(1,2))
|
||||||
local ret = minetest.item_place(stack, placer, pointed_thing)
|
local ret = minetest.item_place(stack, placer, pointed_thing)
|
||||||
return ItemStack("cavestuff:desert_pebble_1 "..itemstack:get_count()-(1-ret:get_count()))
|
return ItemStack("cavestuff:desert_pebble_1 "..itemstack:get_count()-(1-ret:get_count()))
|
||||||
end,
|
end,
|
||||||
@ -97,7 +99,7 @@ minetest.register_node("cavestuff:stalactite_1",{
|
|||||||
if minetest.get_node(pt.under).name=="default:stone"
|
if minetest.get_node(pt.under).name=="default:stone"
|
||||||
and minetest.get_node({x=pt.under.x, y=pt.under.y-1, z=pt.under.z}).name=="air"
|
and minetest.get_node({x=pt.under.x, y=pt.under.y-1, z=pt.under.z}).name=="air"
|
||||||
and minetest.get_node({x=pt.under.x, y=pt.under.y-2, z=pt.under.z}).name=="air" then
|
and minetest.get_node({x=pt.under.x, y=pt.under.y-2, z=pt.under.z}).name=="air" then
|
||||||
minetest.swap_node({x=pt.under.x, y=pt.under.y-1, z=pt.under.z}, {name="cavestuff:stalactite_"..math.random(1,3)})
|
minetest.swap_node({x=pt.under.x, y=pt.under.y-1, z=pt.under.z}, {name="cavestuff:stalactite_"..random(1,3)})
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user