Fix no light above 288. Spawnplayer function: optimise noise and move to init.lua. Make slabs not buildable-to. Add 'is ground content' lines. Add missing spaces. Shorten lines. Add info to readme

master
paramat 2015-08-25 22:59:33 +01:00
parent c536b9c2c9
commit b06e40a5ed
5 changed files with 153 additions and 162 deletions

View File

@ -1,16 +1,18 @@
noisegrid 0.3.10 by paramat
noisegrid 0.4.0 by paramat
For Minetest 0.4.12 and later
Depends default
Licenses: Code LGPL 2.1, textures CC BY-SA
For use with 'singlenode' mapgen.
City street grid areas, coastal intercity roads, tunnel roads, 2 dirt paths, wooden bridges over fissures.
Underground fissure system.
All default ores.
White lines, raised half-slab pavements.
Mountains up to y = 256.
Tree, grass and flower areas with varying density.
Mod's own appletree drops saplings that are grown by voxelmanip.
Overgeneration is used in x and z axes for continuous roads and paths over chunk borders.
Version changes:
flags="nolight" instead of set_lighting()
paramtype="light" to spread light source light
add vm:update_liquids
remove light spread ABMs and dummy light source nodes
2D perlinmap Z-size = 1
create noise objects only once
new LGPL/CC BY-SA licences
Spawnplayer function randomly searches a large area for land to spawn players on.
Players are spawned scattered up to 1280 nodes from world centre.
The player scatter from world centre can be set by parameter 'PSCA' in the functions.lua file, since oceans can be up to 2kn across searches will fail when PSCA is set too small.

View File

@ -88,10 +88,10 @@ minetest.register_abm({
local y = pos.y
local z = pos.z
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-2, y=y-2, z=z-2}
local pos2 = {x=x+2, y=y+5, z=z+2}
local pos1 = {x = x - 2, y = y - 2, z = z - 2}
local pos2 = {x = x + 2, y = y + 5, z = z + 2}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
noisegrid_appletree(x, y, z, area, data)
@ -101,87 +101,3 @@ minetest.register_abm({
vm:update_map()
end,
})
-- Spawn player
function spawnplayer(player)
-- Parameters
local PSCA = 16 -- Player scatter. Maximum distance in chunks (80 nodes) of player spawn from (0, 0, 0)
local YFLAT = 7 -- Flat area elevation
local TERSCA = 192 -- Vertical terrain scale
local TFLAT = 0.2 -- Flat area width
local xsp
local ysp
local zsp
local np_base = {
offset = 0,
scale = 1,
spread = {x=2048, y=2048, z=2048},
seed = -9111,
octaves = 6,
persist = 0.6
}
for chunk = 1, 128 do
print ("[noisegrid] searching for spawn "..chunk)
local x0 = 80 * math.random(-PSCA, PSCA) - 32
local z0 = 80 * math.random(-PSCA, PSCA) - 32
local y0 = -32
local x1 = x0 + 79
local z1 = z0 + 79
local y1 = 47
local sidelen = 80
local chulens = {x=sidelen, y=sidelen, z=sidelen}
local minposxz = {x=x0, y=z0}
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
local nixz = 1
for z = z0, z1 do
for x = x0, x1 do
local ysurf
local n_base = nvals_base[nixz]
local n_absbase = math.abs(n_base)
if n_base > TFLAT then
ysurf = YFLAT + math.floor((n_base - TFLAT) * TERSCA)
elseif n_base < -TFLAT then
ysurf = YFLAT - math.floor((-TFLAT - n_base) * TERSCA)
else
ysurf = YFLAT
end
if ysurf >= 1 then
ysp = ysurf + 1
xsp = x
zsp = z
break
end
nixz = nixz + 1
end
if ysp then
break
end
end
if ysp then
break
end
end
if ysp then
print ("[noisegrid] spawn player ("..xsp.." "..ysp.." "..zsp..")")
player:setpos({x=xsp, y=ysp, z=zsp})
else
print ("[noisegrid] no suitable spawn found")
player:setpos({x=0, y=2, z=0})
end
end
minetest.register_on_newplayer(function(player)
spawnplayer(player)
end)
minetest.register_on_respawnplayer(function(player)
spawnplayer(player)
return true
end)

167
init.lua
View File

@ -6,22 +6,26 @@ local TERSCA = 192 -- Vertical terrain scale in nodes
local STODEP = 5 -- Stone depth below surface in nodes at sea level
local TGRID = 0.18 -- City grid area width
local TFLAT = 0.2 -- Flat coastal area width
local TCITY = 0 -- City size. 0.3 = 1/3 of coastal land area, 0 = 1/2 of coastal land area
local TCITY = 0 -- City size.
-- 0.3 = 1/3 of coastal land area, 0 = 1/2 of coastal land area.
local TFIS = 0.01 -- Fissure width
local TTUN = 0.02 -- Tunnel width
local LUXCHA = 1 / 9 ^ 3 -- Luxore chance per stone node.
local ORECHA = 1 / 5 ^ 3 -- Ore chance per stone node. 1 / n ^ 3 where n = average distance between ores
local APPCHA = 1 / 4 ^ 2 -- Appletree maximum chance per grass node. 1 / n ^ 2 where n = minimum average distance between flora
local ORECHA = 1 / 5 ^ 3 -- Ore chance per stone node.
-- 1 / n ^ 3 where n = average distance between ores.
local APPCHA = 1 / 4 ^ 2 -- Appletree maximum chance per grass node.
-- 1 / n ^ 2 where n = minimum average distance between flora.
local FLOCHA = 1 / 13 ^ 2 -- Flowers maximum chance per grass node
local GRACHA = 1 / 5 ^ 2 -- Grasses maximum chance per grass node
local PSCA = 16 -- Player scatter. Maximum distance in chunks (80 nodes)
-- of player spawn points from (0, 0, 0).
-- 2D noise for base terrain
local np_base = {
offset = 0,
scale = 1,
spread = {x=2048, y=2048, z=2048},
spread = {x = 2048, y = 2048, z = 2048},
seed = -9111,
octaves = 6,
persist = 0.6
@ -32,7 +36,7 @@ local np_base = {
local np_road = {
offset = 0,
scale = 1,
spread = {x=2048, y=2048, z=2048},
spread = {x = 2048, y = 2048, z = 2048},
seed = -9111, -- same seed as above for similar structre but smoother
octaves = 5,
persist = 0.5
@ -43,7 +47,7 @@ local np_road = {
local np_alt = {
offset = 0,
scale = 1,
spread = {x=1024, y=1024, z=1024},
spread = {x = 1024, y = 1024, z = 1024},
seed = 11,
octaves = 3,
persist = 0.4
@ -54,7 +58,7 @@ local np_alt = {
local np_city = {
offset = 0,
scale = 1,
spread = {x=1024, y=1024, z=1024},
spread = {x = 1024, y = 1024, z = 1024},
seed = 3166616,
octaves = 2,
persist = 0.5
@ -65,7 +69,7 @@ local np_city = {
local np_path = {
offset = 0,
scale = 1,
spread = {x=512, y=512, z=512},
spread = {x = 512, y = 512, z = 512},
seed = 7000023,
octaves = 4,
persist = 0.4
@ -74,7 +78,7 @@ local np_path = {
local np_path2 = {
offset = 0,
scale = 1,
spread = {x=512, y=512, z=512},
spread = {x = 512, y = 512, z = 512},
seed = -2315551,
octaves = 4,
persist = 0.4
@ -85,7 +89,7 @@ local np_path2 = {
local np_tree = {
offset = 0,
scale = 1,
spread = {x=256, y=256, z=256},
spread = {x = 256, y = 256, z = 256},
seed = 133338,
octaves = 3,
persist = 0.5
@ -96,7 +100,7 @@ local np_tree = {
local np_grass = {
offset = 0,
scale = 1,
spread = {x=256, y=256, z=256},
spread = {x = 256, y = 256, z = 256},
seed = 133,
octaves = 2,
persist = 0.5
@ -107,7 +111,7 @@ local np_grass = {
local np_flower = {
offset = 0,
scale = 1,
spread = {x=256, y=256, z=256},
spread = {x = 256, y = 256, z = 256},
seed = -70008,
octaves = 1,
persist = 0.5
@ -119,7 +123,7 @@ local np_flower = {
local np_fissure = {
offset = 0,
scale = 1,
spread = {x=384, y=384, z=384},
spread = {x = 384, y = 384, z = 384},
seed = 2001,
octaves = 4,
persist = 0.5
@ -130,7 +134,7 @@ local np_fissure = {
local np_weba = {
offset = 0,
scale = 1,
spread = {x=192, y=192, z=192},
spread = {x = 192, y = 192, z = 192},
seed = 5900033,
octaves = 3,
persist = 0.5
@ -141,7 +145,7 @@ local np_weba = {
local np_webb = {
offset = 0,
scale = 1,
spread = {x=191, y=191, z=191},
spread = {x = 191, y = 191, z = 191},
seed = 33,
octaves = 3,
persist = 0.5
@ -152,7 +156,7 @@ local np_webb = {
local np_webc = {
offset = 0,
scale = 1,
spread = {x=190, y=190, z=190},
spread = {x = 190, y = 190, z = 190},
seed = -18000001,
octaves = 3,
persist = 0.5
@ -161,14 +165,14 @@ local np_webc = {
-- Do files
dofile(minetest.get_modpath("noisegrid").."/functions.lua")
dofile(minetest.get_modpath("noisegrid").."/nodes.lua")
dofile(minetest.get_modpath("noisegrid") .. "/functions.lua")
dofile(minetest.get_modpath("noisegrid") .. "/nodes.lua")
-- Set mapgen parameters
minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({mgname="singlenode", flags="nolight"})
minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
end)
@ -192,10 +196,6 @@ local nobj_webc = nil
-- On generated function
minetest.register_on_generated(function(minp, maxp, seed)
if minp.y > 208 then
return
end
local t1 = os.clock()
local x1 = maxp.x
local y1 = maxp.y
@ -205,7 +205,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local z0 = minp.z
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
@ -232,10 +232,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
local sidelen = x1 - x0 + 1
local overlen = sidelen + 1
local chulensxyz = {x=overlen, y=sidelen, z=overlen}
local minposxyz = {x=x0-1, y=y0, z=z0-1}
local chulensxz = {x=overlen, y=overlen, z=1} -- different because here x=x, y=z
local minposxz = {x=x0-1, y=z0-1}
local chulensxyz = {x = overlen, y = sidelen, z = overlen}
local minposxyz = {x = x0 - 1, y = y0, z = z0 - 1}
local chulensxz = {x = overlen, y = overlen, z = 1} -- different because here x=x, y=z
local minposxz = {x = x0 - 1, y = z0 - 1}
nobj_base = nobj_base or minetest.get_perlin_map(np_base, chulensxz)
nobj_road = nobj_road or minetest.get_perlin_map(np_road, chulensxz)
@ -276,19 +276,19 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nixz = 1
local nixyz = 1
local stable = {}
for z = z0-1, z1 do
for x = x0-1, x1 do
for z = z0 - 1, z1 do
for x = x0 - 1, x1 do
local si = x - x0 + 2 -- +2 because overgeneration
stable[si] = 2
end
for y = y0, y1 do
local vi = area:index(x0-1, y, z)
local via = area:index(x0-1, y+1, z)
local vi = area:index(x0 - 1, y, z)
local via = area:index(x0 - 1, y + 1, z)
local n_xprepath = false
local n_xprepath2 = false
local n_xpreroad = false
local n_xprealt = false
for x = x0-1, x1 do
for x = x0 - 1, x1 do
local nodid = data[vi]
local xr = x - x0
local zr = z - z0
@ -316,7 +316,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local n_fissure = nvals_fissure[nixyz]
local n_absfissure = math.abs(n_fissure)
local nofis = n_absfissure > TFIS and not (weba and webb) and not (weba and webc)
local nofis = n_absfissure > TFIS and
not (weba and webb) and not (weba and webc)
local wood = n_absfissure < TFIS * 2 and not flat
local n_city = nvals_city[nixz]
@ -355,8 +356,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
for i = -3, 3 do
for k = -3, 3 do
if (math.abs(i)) ^ 2 + (math.abs(k)) ^ 2 <= 13 then
local vi = area:index(x+i, y, z+k)
local via = area:index(x+i, y+1, z+k)
local vi = area:index(x + i, y, z + k)
local via = area:index(x + i, y + 1, z + k)
local nodid = data[vi]
if nodid ~= c_roadwhite then
data[vi] = c_roadblack
@ -416,8 +417,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
for i = -3, 3 do
for k = -3, 3 do
if (math.abs(i)) ^ 2 + (math.abs(k)) ^ 2 <= 13 then
local vi = area:index(x+i, y, z+k)
local via = area:index(x+i, y+1, z+k)
local vi = area:index(x + i, y, z + k)
local via = area:index(x + i, y + 1, z + k)
local nodid = data[vi]
if nodid ~= c_roadwhite then
data[vi] = c_roadblack
@ -492,14 +493,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
((n_path >= 0 and n_zprepath < 0) or
(n_path < 0 and n_zprepath >= 0)) then
if wood then
local viu = area:index(x, y-1, z)
local viuu = area:index(x, y-2, z)
local viu = area:index(x, y - 1, z)
local viuu = area:index(x, y - 2, z)
data[viu] = c_wood
data[viuu] = c_wood
end
for i = -1, 1 do
for k = -1, 1 do
local vi = area:index(x+i, y, z+k)
local vi = area:index(x + i, y, z + k)
local nodid = data[vi]
if nodid ~= c_roadwhite and
nodid ~= c_roadblack then
@ -517,14 +518,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
((n_path2 >= 0 and n_zprepath2 < 0) or
(n_path2 < 0 and n_zprepath2 >= 0)) then
if wood then
local viu = area:index(x, y-1, z)
local viuu = area:index(x, y-2, z)
local viu = area:index(x, y - 1, z)
local viuu = area:index(x, y - 2, z)
data[viu] = c_wood
data[viuu] = c_wood
end
for i = -1, 1 do
for k = -1, 1 do
local vi = area:index(x+i, y, z+k)
local vi = area:index(x + i, y, z + k)
local nodid = data[vi]
if nodid ~= c_roadwhite and
nodid ~= c_roadblack then
@ -545,7 +546,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
n_abspath2 > 0.015 and
n_absroad > 0.02 and
(n_absalt > 0.04 or y > YFLAT) then
noisegrid_appletree(x, y+1, z, area, data)
noisegrid_appletree(x, y + 1, z, area, data)
else
data[vi] = c_grass
-- flowers
@ -598,6 +599,78 @@ minetest.register_on_generated(function(minp, maxp, seed)
vm:update_liquids()
local chugent = math.ceil((os.clock() - t1) * 1000)
print ("[noisegrid] chunk ("..x0.." "..y0.." "..z0..") "..chugent.." ms")
print ("[noisegrid] " .. chugent .. " ms")
end)
-- Spawn player function
local function noisegrid_spawnplayer(player)
local xsp
local ysp
local zsp
local nobj_base = nil
for chunk = 1, 128 do
print ("[noisegrid] searching for spawn " .. chunk)
local x0 = 80 * math.random(-PSCA, PSCA) - 32
local z0 = 80 * math.random(-PSCA, PSCA) - 32
local y0 = -32
local x1 = x0 + 79
local z1 = z0 + 79
local y1 = 47
local sidelen = 80
local chulens = {x = sidelen, y = sidelen, z = 1}
local minposxz = {x = x0, y = z0}
nobj_base = nobj_base or minetest.get_perlin_map(np_base, chulens)
local nvals_base = nobj_base:get2dMap_flat(minposxz)
local nixz = 1
for z = z0, z1 do
for x = x0, x1 do
local ysurf
local n_base = nvals_base[nixz]
local n_absbase = math.abs(n_base)
if n_base > TFLAT then
ysurf = YFLAT + math.floor((n_base - TFLAT) * TERSCA)
elseif n_base < -TFLAT then
ysurf = YFLAT - math.floor((-TFLAT - n_base) * TERSCA)
else
ysurf = YFLAT
end
if ysurf >= 1 then
ysp = ysurf + 1
xsp = x
zsp = z
break
end
nixz = nixz + 1
end
if ysp then
break
end
end
if ysp then
break
end
end
if ysp then
print ("[noisegrid] spawn player (" .. xsp .. " " .. ysp .. " " .. zsp .. ")")
player:setpos({x = xsp, y = ysp, z = zsp})
else
print ("[noisegrid] no suitable spawn found")
player:setpos({x = 0, y = 2, z = 0})
end
end
minetest.register_on_newplayer(function(player)
noisegrid_spawnplayer(player)
end)
minetest.register_on_respawnplayer(function(player)
noisegrid_spawnplayer(player)
return true
end)

View File

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
License of media (textures)
--------------------------------------
---------------------------
Copyright (C) 2014-2015 paramat
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

View File

@ -2,10 +2,10 @@ minetest.register_node("noisegrid:grass", {
description = "Grass",
tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"},
is_ground_content = false,
groups = {crumbly=3,soil=1},
groups = {crumbly = 3, soil = 1},
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.25},
footstep = {name = "default_grass_footstep", gain = 0.25},
}),
})
@ -13,7 +13,7 @@ minetest.register_node("noisegrid:dirt", {
description = "Dirt",
tiles = {"default_dirt.png"},
is_ground_content = false,
groups = {crumbly=3,soil=1},
groups = {crumbly = 3, soil = 1},
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults(),
})
@ -22,7 +22,7 @@ minetest.register_node("noisegrid:path", {
description = "Dirt Path",
tiles = {"noisegrid_path.png"},
is_ground_content = false,
groups = {crumbly=3},
groups = {crumbly = 3},
sounds = default.node_sound_dirt_defaults(),
})
@ -30,7 +30,7 @@ minetest.register_node("noisegrid:stone", {
description = "Stone",
tiles = {"default_stone.png"},
is_ground_content = false,
groups = {cracky=3},
groups = {cracky = 3},
drop = "default:cobble",
sounds = default.node_sound_stone_defaults(),
})
@ -39,7 +39,7 @@ minetest.register_node("noisegrid:roadblack", {
description = "Road Black",
tiles = {"noisegrid_roadblack.png"},
is_ground_content = false,
groups = {cracky=2},
groups = {cracky = 2},
sounds = default.node_sound_stone_defaults(),
})
@ -47,7 +47,7 @@ minetest.register_node("noisegrid:roadwhite", {
description = "Road White",
tiles = {"noisegrid_roadwhite.png"},
is_ground_content = false,
groups = {cracky=2},
groups = {cracky = 2},
sounds = default.node_sound_stone_defaults(),
})
@ -58,7 +58,6 @@ minetest.register_node("noisegrid:slab", {
paramtype = "light",
is_ground_content = false,
sunlight_propagates = true,
buildable_to = true,
node_box = {
type = "fixed",
fixed = {
@ -71,7 +70,7 @@ minetest.register_node("noisegrid:slab", {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5}
},
},
groups = {cracky=2},
groups = {cracky = 2},
sounds = default.node_sound_stone_defaults(),
})
@ -82,11 +81,11 @@ minetest.register_node("noisegrid:appleleaf", {
tiles = {"default_leaves.png"},
paramtype = "light",
is_ground_content = false,
groups = {snappy=3, flammable=2},
groups = {snappy = 3, flammable = 2},
drop = {
max_items = 1,
items = {
{items = {"noisegrid:appling"},rarity = 20},
{items = {"noisegrid:appling"}, rarity = 20},
{items = {"noisegrid:appleleaf"}}
}
},
@ -107,7 +106,7 @@ minetest.register_node("noisegrid:appling", {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
},
groups = {snappy=2,dig_immediate=3,flammable=2,attached_node=1},
groups = {snappy = 2, dig_immediate = 3, flammable = 2, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
})
@ -116,7 +115,8 @@ minetest.register_node("noisegrid:light", {
tiles = {"noisegrid_light.png"},
paramtype = "light",
light_source = 14,
groups = {cracky=3,oddly_breakable_by_hand=3},
is_ground_content = false,
groups = {cracky = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
})
@ -124,7 +124,7 @@ minetest.register_node("noisegrid:concrete", {
description = "Sandy Concrete",
tiles = {"noisegrid_concrete.png"},
is_ground_content = false,
groups = {cracky=3},
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults(),
})
@ -132,8 +132,9 @@ minetest.register_node("noisegrid:luxore", {
description = "Lux Ore",
tiles = {"noisegrid_luxore.png"},
paramtype = "light",
is_ground_content = false,
light_source = 14,
groups = {cracky=3},
groups = {cracky = 3},
sounds = default.node_sound_glass_defaults(),
})
@ -147,4 +148,3 @@ minetest.register_craft({
{"default:glass", "default:glass", "default:glass"},
},
})