Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Singlenode option with spawn egg
Browse files Browse the repository at this point in the history
  • Loading branch information
paramat committed May 26, 2014
1 parent e76469c commit 19e2d52
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.txt
@@ -1,4 +1,4 @@
moonrealm 0.6.5 by paramat
moonrealm 0.6.6 by paramat
For latest stable Minetest and back to 0.4.8
Depends default
Licenses: code WTFPL, textures CC BY-SA
Expand Down
180 changes: 179 additions & 1 deletion functions.lua
Expand Up @@ -169,4 +169,182 @@ minetest.register_abm({
action = function(pos, node, active_object_count, active_object_count_wider)
moonrealm_appletree(pos)
end,
})
})

-- Singlenode option

local SINGLENODE = true

if SINGLENODE then
minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({mgname="singlenode", water_level=-33000})
end)

-- Spawn player

function spawnplayer(player)
local GRADCEN = 1 -- -- Gradient centre / terrain centre average level
local CENAMP = 64 -- -- Grad centre amplitude, terrain centre is varied by this
local HIGRAD = 128 -- -- Surface generating noise gradient above gradcen, controls depth of upper terrain
local LOGRAD = 128 -- -- Surface generating noise gradient below gradcen, controls depth of lower terrain
local HEXP = 0.5 -- -- Noise offset exponent above gradcen, 1 = normal 3D perlin terrain
local LEXP = 2 -- -- Noise offset exponent below gradcen
local STOT = 0.04 -- -- Stone density threshold, depth of dust
local PSCA = 4 -- Player scatter from world centre in chunks (80 nodes).
local xsp
local ysp
local zsp
local np_terrain = {
offset = 0,
scale = 1,
spread = {x=512, y=512, z=512},
seed = 58588900033,
octaves = 6,
persist = 0.67
}
local np_terralt = {
offset = 0,
scale = 1,
spread = {x=414, y=414, z=414},
seed = 13331930910,
octaves = 6,
persist = 0.67
}
local np_smooth = {
offset = 0,
scale = 1,
spread = {x=828, y=828, z=828},
seed = 113,
octaves = 4,
persist = 0.4
}
local np_fault = {
offset = 0,
scale = 1,
spread = {x=414, y=828, z=414},
seed = 14440002,
octaves = 4,
persist = 0.5
}
local np_gradcen = {
offset = 0,
scale = 1,
spread = {x=1024, y=1024, z=1024},
seed = 9344,
octaves = 4,
persist = 0.4
}
local np_terblen = {
offset = 0,
scale = 1,
spread = {x=2048, y=2048, z=2048},
seed = -13002,
octaves = 3,
persist = 0.4
}
for chunk = 1, 64 do
print ("[moonrealm] 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 minpos = {x=x0, y=y0, z=z0}
local minposd = {x=x0, y=z0}

local nvals_terrain = minetest.get_perlin_map(np_terrain, chulens):get3dMap_flat(minpos)
local nvals_terralt = minetest.get_perlin_map(np_terralt, chulens):get3dMap_flat(minpos)
local nvals_smooth = minetest.get_perlin_map(np_smooth, chulens):get3dMap_flat(minpos)
local nvals_fault = minetest.get_perlin_map(np_fault, chulens):get3dMap_flat(minpos)

local nvals_terblen = minetest.get_perlin_map(np_terblen, chulens):get2dMap_flat(minposd)
local nvals_gradcen = minetest.get_perlin_map(np_gradcen, chulens):get2dMap_flat(minposd)

local nixz = 1
local nixyz = 1
local stable = {}
for z = z0, z1 do
for y = y0, y1 do
for x = x0, x1 do
local si = x - x0 + 1
local grad
local density
local terblen = math.max(math.min(math.abs(nvals_terblen[nixz]) * 4, 1.5), 0.5) - 0.5
local gradcen = GRADCEN + nvals_gradcen[nixz] * CENAMP
if y > gradcen then
grad = -((y - gradcen) / HIGRAD) ^ HEXP
else
grad = ((gradcen - y) / LOGRAD) ^ LEXP
end
if nvals_fault[nixyz] >= 0 then
density = (nvals_terrain[nixyz] + nvals_terralt[nixyz]) / 2 * (1 - terblen)
+ nvals_smooth[nixyz] * terblen + grad
else
density = (nvals_terrain[nixyz] - nvals_terralt[nixyz]) / 2 * (1 - terblen)
- nvals_smooth[nixyz] * terblen + grad
end
if density >= STOT then
stable[si] = true
elseif stable[si] and density < 0 then
ysp = y + 8
xsp = x
zsp = z
break
end
nixz = nixz + 1
nixyz = nixyz + 1
end
if ysp then
break
end
nixz = nixz - 80
end
if ysp then
break
end
nixz = nixz + 80
end
if ysp then
break
end
end
print ("[moonrealm] spawn player ("..xsp.." "..ysp.." "..zsp..")")
player:setpos({x=xsp, y=ysp, z=zsp})
local vm = minetest.get_voxel_manip()
local pos1 = {x=xsp-2, y=ysp-2, z=zsp-2}
local pos2 = {x=xsp+2, y=ysp+2, z=zsp+2}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
local c_glass = minetest.get_content_id("default:glass")
local c_lsair = minetest.get_content_id("moonrealm:air")
for i = -2, 2 do
for j = -2, 2 do
for k = -2, 2 do
local vi = area:index(xsp + i, ysp + j, zsp + k)
if i ^ 2 + j ^ 2 + k ^ 2 >= 4 then
data[vi] = c_glass
else
data[vi] = c_lsair
end
end
end
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
end

minetest.register_on_newplayer(function(player)
spawnplayer(player)
end)

minetest.register_on_respawnplayer(function(player)
spawnplayer(player)
return true
end)
end
35 changes: 21 additions & 14 deletions init.lua
@@ -1,22 +1,20 @@
-- moonrealm 0.6.5 by paramat
-- moonrealm 0.6.6 by paramat
-- For latest stable Minetest and back to 0.4.8
-- Depends default
-- Licenses: code WTFPL, textures CC BY-SA

-- TODO
-- Craters
-- Exclusive ores
-- singlenode mode with spawn chamber

-- Parameters

local XMIN = -33000 -- -- Approx horizontal limits
local XMAX = 33000
local ZMIN = -33000
local ZMAX = 33000
local XMIN = -8000 -- -- Approx horizontal limits. 1/4 of normal realm size.
local XMAX = 8000
local ZMIN = -8000
local ZMAX = 8000

local YMIN = 14000 -- -- Approx lower limit
local GRADCEN = 15000 -- -- Gradient centre / terrain centre average level
local YMAX = 16000 -- -- Approx upper limit
local YMIN = -8000 -- -- Approx lower limit
local GRADCEN = 1 -- -- Gradient centre / terrain centre average level
local YMAX = 8000 -- -- Approx upper limit

local FOOT = true -- -- Footprints in dust
local CENAMP = 64 -- -- Grad centre amplitude, terrain centre is varied by this
Expand Down Expand Up @@ -196,6 +194,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()

local c_air = minetest.get_content_id("air")
local c_mese = minetest.get_content_id("default:mese")
local c_mrironore = minetest.get_content_id("moonrealm:ironore")
local c_mrcopperore = minetest.get_content_id("moonrealm:copperore")
Expand Down Expand Up @@ -237,6 +236,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local vi = area:index(x0, y, z) -- LVM index for first node in x row
local icecha = ICECHA * (1 + (GRADCEN - y) / ICEGRAD)
for x = x0, x1 do -- for each node
local nodid = data[vi]
local air = nodid == c_air
local grad
local density
local si = x - x0 + 1 -- indexes start from 1
Expand Down Expand Up @@ -283,15 +284,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[vi] = c_dust
end
else -- fissure
data[vi] = c_vacuum
if air then
data[vi] = c_vacuum
end
stable[si] = false
end
else -- fissure or unstable missing node
data[vi] = c_vacuum
if air then
data[vi] = c_vacuum
end
stable[si] = false
end
else -- vacuum
data[vi] = c_vacuum
if air then
data[vi] = c_vacuum
end
stable[si] = false
end
ni = ni + 1
Expand Down

0 comments on commit 19e2d52

Please sign in to comment.