Multiple planets. Spawn above planet 1. Add sand and grass. Squashed terrain starts at beach top
This commit is contained in:
parent
1656687dc5
commit
4a6c284e8f
@ -1,4 +1,4 @@
|
|||||||
planets 0.1.3 by paramat
|
planets 0.1.4 by paramat
|
||||||
For Minetest 0.4.13 and later
|
For Minetest 0.4.13 and later
|
||||||
Depends default
|
Depends default
|
||||||
Licenses: code WTFPL
|
Licenses: Code LGPL 2.1. Media CC BY-SA 3.0
|
||||||
|
67
init.lua
67
init.lua
@ -1,14 +1,14 @@
|
|||||||
-- Parameters
|
-- Parameters
|
||||||
|
|
||||||
local pnum = 1 -- number of planets desired
|
local pnum = 64 -- number of planets desired
|
||||||
local maxatt = 128 -- maximum number of attempts to add a planet
|
local maxatt = 4096 -- maximum number of attempts to add a planet
|
||||||
|
|
||||||
local np_terrain = {
|
local np_terrain = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1.0,
|
scale = 1.0,
|
||||||
spread = {x = 96, y = 96, z = 96},
|
spread = {x = 192, y = 192, z = 192},
|
||||||
seed = 921181,
|
seed = 921181,
|
||||||
octaves = 3,
|
octaves = 4,
|
||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ minetest.set_mapgen_params({mgname = "singlenode",
|
|||||||
chunksize = 5, water_level = -31000, flags = "nolight"})
|
chunksize = 5, water_level = -31000, flags = "nolight"})
|
||||||
|
|
||||||
|
|
||||||
-- Create pseudorandom galaxy
|
-- Create planetary system
|
||||||
|
|
||||||
-- space is 64 ^ 3 chunks, centred on world centre
|
-- space is 64 ^ 3 chunks, centred on world centre
|
||||||
-- space table is flat array of planet ids or nil (vacuum chunk)
|
-- space table is flat array of planet ids or nil (vacuum chunk)
|
||||||
@ -44,16 +44,17 @@ local spzstr = 64 * 64 -- space array z stride
|
|||||||
local spystr = 64 -- space array y stride
|
local spystr = 64 -- space array y stride
|
||||||
local plid = 0 -- planet id of last planet added, 0 = none
|
local plid = 0 -- planet id of last planet added, 0 = none
|
||||||
local addatt = 0 -- number of attempts to add a planet
|
local addatt = 0 -- number of attempts to add a planet
|
||||||
|
math.randomseed(42) -- set pseudorandom seed
|
||||||
|
|
||||||
while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
||||||
-- create initial planet data to check for obstruction
|
-- create initial planet data to check for obstruction
|
||||||
-- cenx/y/z is planet centre
|
-- cenx/y/z is planet centre
|
||||||
-- radter = terrain radius / water level
|
-- radter = terrain radius / beach top / water level + 4
|
||||||
-- radmax = atmosphere radius or max mountain radius
|
-- radmax = atmosphere radius or max mountain radius
|
||||||
local cenx = 0
|
local cenx = math.random(-2000, 2000)
|
||||||
local ceny = 0
|
local ceny = math.random(-2000, 2000)
|
||||||
local cenz = 0
|
local cenz = math.random(-2000, 2000)
|
||||||
local radter = 256
|
local radter = 256 -- TODO randomise these
|
||||||
local radmax = 384
|
local radmax = 384
|
||||||
|
|
||||||
-- chunk co-ords of chunk containing planet centre
|
-- chunk co-ords of chunk containing planet centre
|
||||||
@ -65,7 +66,6 @@ while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
|||||||
|
|
||||||
-- check space is clear for planet
|
-- check space is clear for planet
|
||||||
local clear = true -- is space clear
|
local clear = true -- is space clear
|
||||||
print ("[planets] Checking for obstruction")
|
|
||||||
|
|
||||||
for cz = cenzcc - radmaxc, cenzcc + radmaxc do
|
for cz = cenzcc - radmaxc, cenzcc + radmaxc do
|
||||||
for cy = cenycc - radmaxc, cenycc + radmaxc do
|
for cy = cenycc - radmaxc, cenycc + radmaxc do
|
||||||
@ -73,7 +73,7 @@ while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
|||||||
for cx = cenxcc - radmaxc, cenxcc + radmaxc do
|
for cx = cenxcc - radmaxc, cenxcc + radmaxc do
|
||||||
if space[spi] ~= nil then
|
if space[spi] ~= nil then
|
||||||
clear = false
|
clear = false
|
||||||
print ("[planets] Planet obstructed")
|
--print ("[planets] Planet obstructed")
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
spi = spi + 1
|
spi = spi + 1
|
||||||
@ -88,7 +88,7 @@ while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
|||||||
end
|
end
|
||||||
|
|
||||||
if clear then -- add planet
|
if clear then -- add planet
|
||||||
-- TODO generate extra planet data
|
-- TODO generate extra planet data here
|
||||||
plid = #def + 1 -- planet id
|
plid = #def + 1 -- planet id
|
||||||
-- add planet data to def table
|
-- add planet data to def table
|
||||||
def[plid] = {i = cenx, j = ceny, k = cenz, t = radter, m = radmax}
|
def[plid] = {i = cenx, j = ceny, k = cenz, t = radter, m = radmax}
|
||||||
@ -109,6 +109,21 @@ while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Spawn above planet 1
|
||||||
|
|
||||||
|
local pdef = def[1]
|
||||||
|
local spawn_pos = {x = pdef.i, y = pdef.j + pdef.m, z = pdef.k}
|
||||||
|
|
||||||
|
minetest.register_on_newplayer(function(player)
|
||||||
|
player:setpos(spawn_pos)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_respawnplayer(function(player)
|
||||||
|
player:setpos(spawn_pos)
|
||||||
|
return true
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- Globalstep function
|
-- Globalstep function
|
||||||
|
|
||||||
local skybox_space = {
|
local skybox_space = {
|
||||||
@ -176,11 +191,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
-- planet def
|
-- planet def
|
||||||
local pdef = def[defi]
|
local pdef = def[defi]
|
||||||
|
|
||||||
local c_air = minetest.get_content_id("air")
|
|
||||||
local c_lava = minetest.get_content_id("planets:lava")
|
|
||||||
local c_stone = minetest.get_content_id("planets:stone")
|
|
||||||
local c_water = minetest.get_content_id("planets:water")
|
|
||||||
local c_cloud = minetest.get_content_id("planets:cloud")
|
|
||||||
local c_vacuum = minetest.get_content_id("planets:vacuum")
|
local c_vacuum = minetest.get_content_id("planets:vacuum")
|
||||||
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
@ -188,6 +198,14 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
|
||||||
if pdef then -- planet chunk
|
if pdef then -- planet chunk
|
||||||
|
local c_air = minetest.get_content_id("air")
|
||||||
|
local c_lava = minetest.get_content_id("planets:lava")
|
||||||
|
local c_stone = minetest.get_content_id("planets:stone")
|
||||||
|
local c_sand = minetest.get_content_id("planets:sand")
|
||||||
|
local c_grass = minetest.get_content_id("planets:grass")
|
||||||
|
local c_water = minetest.get_content_id("planets:water")
|
||||||
|
local c_cloud = minetest.get_content_id("planets:cloud")
|
||||||
|
|
||||||
local pmapdims = {x = 80, y = 80, z = 80} -- perlinmap dimensions
|
local pmapdims = {x = 80, y = 80, z = 80} -- perlinmap dimensions
|
||||||
local pmapminp = {x = x0, y = y0, z = z0} -- perlinmap minp
|
local pmapminp = {x = x0, y = y0, z = z0} -- perlinmap minp
|
||||||
local pmapdimsclo = {x = 5, y = 5, z = 5} -- cloud perlinmap dimensions
|
local pmapdimsclo = {x = 5, y = 5, z = 5} -- cloud perlinmap dimensions
|
||||||
@ -200,6 +218,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local nvals_cloud = nobj_cloud:get3dMap_flat(pmapminpclo, nbuf_cloud)
|
local nvals_cloud = nobj_cloud:get3dMap_flat(pmapminpclo, nbuf_cloud)
|
||||||
|
|
||||||
local tersca = (pdef.m - pdef.t) / 2 -- terrain scale
|
local tersca = (pdef.m - pdef.t) / 2 -- terrain scale
|
||||||
|
local stot = 3 / tersca -- stone noise threshold
|
||||||
|
|
||||||
local ni = 1 -- noise index
|
local ni = 1 -- noise index
|
||||||
for z = z0, z1 do
|
for z = z0, z1 do
|
||||||
@ -217,9 +236,15 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
|
|
||||||
if nodrad <= pdef.t / 2 then -- lava
|
if nodrad <= pdef.t / 2 then -- lava
|
||||||
data[vi] = c_lava
|
data[vi] = c_lava
|
||||||
elseif density >= 0 then -- stone
|
elseif density >= stot then -- stone
|
||||||
data[vi] = c_stone
|
data[vi] = c_stone
|
||||||
elseif nodrad <= pdef.t then -- water
|
elseif density >= 0 then -- fine materials
|
||||||
|
if nodrad <= pdef.t then
|
||||||
|
data[vi] = c_sand
|
||||||
|
else
|
||||||
|
data[vi] = c_grass
|
||||||
|
end
|
||||||
|
elseif nodrad <= pdef.t - 4 then -- water
|
||||||
data[vi] = c_water
|
data[vi] = c_water
|
||||||
elseif dengrad >= -1.0 and dengrad <= -0.95 then -- clouds
|
elseif dengrad >= -1.0 and dengrad <= -0.95 then -- clouds
|
||||||
local xq = math.floor((x - x0) / 16) -- quantise position
|
local xq = math.floor((x - x0) / 16) -- quantise position
|
||||||
@ -255,7 +280,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
vm:set_data(data)
|
vm:set_data(data)
|
||||||
if pdef then
|
if pdef then
|
||||||
vm:calc_lighting()
|
vm:calc_lighting()
|
||||||
else -- vacuum chunk, don't propagate shadow
|
else -- vacuum chunk, don't propagate shadow from above
|
||||||
vm:calc_lighting(nil, nil, false)
|
vm:calc_lighting(nil, nil, false)
|
||||||
end
|
end
|
||||||
vm:write_to_map(data)
|
vm:write_to_map(data)
|
||||||
|
29
license.txt
29
license.txt
@ -1,14 +1,25 @@
|
|||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
License of source code
|
||||||
Version 2, December 2004
|
----------------------
|
||||||
|
Copyright (C) 2016 paramat
|
||||||
|
|
||||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim or modified
|
This program is distributed in the hope that it will be useful,
|
||||||
copies of this license document, and changing it is allowed as long
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
as the name is changed.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
License of media (textures)
|
||||||
|
---------------------------
|
||||||
|
Copyright (C) 2016 paramat
|
||||||
|
|
||||||
|
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||||
|
http://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
|
||||||
|
16
nodes.lua
16
nodes.lua
@ -5,6 +5,22 @@ minetest.register_node("planets:stone", {
|
|||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_node("planets:grass", {
|
||||||
|
description = "Grass",
|
||||||
|
tiles = {"default_grass.png"},
|
||||||
|
groups = {crumbly = 3, soil = 1},
|
||||||
|
sounds = default.node_sound_dirt_defaults({
|
||||||
|
footstep = {name = "default_grass_footstep", gain = 0.4},
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("planets:sand", {
|
||||||
|
description = "Sand",
|
||||||
|
tiles = {"default_sand.png"},
|
||||||
|
groups = {crumbly = 3, sand = 1},
|
||||||
|
sounds = default.node_sound_sand_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node("planets:cloud", {
|
minetest.register_node("planets:cloud", {
|
||||||
description = "Cloud",
|
description = "Cloud",
|
||||||
drawtype = "glasslike",
|
drawtype = "glasslike",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user