Fix skyboxes for mt5.2, tidy code

This commit is contained in:
TenPlus1 2020-05-22 16:30:26 +01:00
parent 0d9c464698
commit 78d5a22340
12 changed files with 383 additions and 238 deletions

View File

@ -1,12 +1,12 @@
Other Worlds
Other Worlds
===
Minetest mod which adds asteroid layers.
Minetest mod which adds asteroid layers.
Each layer contains:
1. Asteroids composed of unique materials.
2. Decoration (or lack of) for the asteroid surfaces, including plants and glowing crystals.
2. Decoration (or lack of) for the asteroid surfaces, including plants and glowing crystals.
3. A skybox for the layer.
Default layers are Space and Red Sky, but anyone familiar with editing mods should be able to easily adjust these or create different/ additional layers.
@ -15,19 +15,19 @@ Default layers are Space and Red Sky, but anyone familiar with editing mods shou
Settings
--------
Settings for this mod can be adjusted by editing the settings.lua file.
Settings for this mod can be adjusted by editing the settings.lua file.
See the comments in this file for how to adjust:
1. The minimum and maximum height of each layer.
2. Whether map-generation is currently active for individual layers.
3. Whether player gravity changes for each layer (off by default).
4. Whether crafting recipes are enabled.
4. Whether crafting recipes are enabled.
Note: It is advised to turn off map-generation after you have generated the required number of asteroids.
Licenses and Attribution
Licenses and Attribution
-----------------------
Components of this mod use multiple licenses and were the work of several individuals. Please see license.txt for the full list.
Components of this mod use multiple licenses and were the work of several individuals. Please see license.txt for the full list.

View File

@ -2,34 +2,36 @@
-- submodule
otherworlds.asteroids = {}
-- Approximate realm limits.
-- Approximate realm limits
local XMIN = -33000
local XMAX = 33000
local ZMIN = -33000
local ZMAX = 33000
local ASCOT = 1.0 -- Large asteroid / comet nucleus noise threshold.
local SASCOT = 1.0 -- Small asteroid / comet nucleus noise threshold.
local STOT = 0.125 -- Asteroid stone threshold.
local COBT = 0.05 -- Asteroid cobble threshold.
local GRAT = 0.02 -- Asteroid gravel threshold.
local ICET = 0.05 -- Comet ice threshold.
local ATMOT = -0.2 -- Comet atmosphere threshold.
local FISTS = 0.01 -- Fissure noise threshold at surface. Controls size of fissures and amount / size of fissure entrances.
local FISEXP = 0.3 -- Fissure expansion rate under surface.
local ORECHA = 3*3*3 -- Ore 1/x chance per stone node.
local CPCHU = 0 -- Maximum craters per chunk.
local CRMIN = 5 -- Crater radius minimum, radius includes dust and obsidian layers.
local CRRAN = 8 -- Crater radius range.
local ASCOT = 1.0 -- Large asteroid / comet nucleus noise threshold
local SASCOT = 1.0 -- Small asteroid / comet nucleus noise threshold
local STOT = 0.125 -- Asteroid stone threshold
local COBT = 0.05 -- Asteroid cobble threshold
local GRAT = 0.02 -- Asteroid gravel threshold
local ICET = 0.05 -- Comet ice threshold
local ATMOT = -0.2 -- Comet atmosphere threshold
local FISTS = 0.01 -- Fissure noise threshold at surface. Controls size of fissures and amount / size of fissure entrances
local FISEXP = 0.3 -- Fissure expansion rate under surface
local ORECHA = 3*3*3 -- Ore 1/x chance per stone node
local CPCHU = 0 -- Maximum craters per chunk
local CRMIN = 5 -- Crater radius minimum, radius includes dust and obsidian layers
local CRRAN = 8 -- Crater radius range
local random = math.random
local floor = math.floor
-- Note: for fewer large objects: increase the 'spread' numbers in 'np_large' noise parameters. For fewer small objects do the same in 'np_small'. Then tune size with 'ASCOT'.
-- Note: for fewer large objects: increase the 'spread' numbers in 'np_large' noise parameters. For fewer small objects do the same in 'np_small'. Then tune size with 'ASCOT'
-- 3D Perlin noise 1 for large structures
local np_large = {
offset = 0,
scale = 1,
spread = {x=256, y=128, z=256},
spread = {x = 256, y = 128, z = 256},
seed = -83928935,
octaves = 5,
persist = 0.6
@ -39,7 +41,7 @@ local np_large = {
local np_fissure = {
offset = 0,
scale = 1,
spread = {x=64, y=64, z=64},
spread = {x = 64, y = 64, z = 64},
seed = -188881,
octaves = 4,
persist = 0.5
@ -49,7 +51,7 @@ local np_fissure = {
local np_small = {
offset = 0,
scale = 1,
spread = {x=128, y=64, z=128},
spread = {x = 128, y = 64, z = 128},
seed = 1000760700090,
octaves = 4,
persist = 0.6
@ -59,7 +61,7 @@ local np_small = {
local np_ores = {
offset = 0,
scale = 1,
spread = {x=128, y=128, z=128},
spread = {x = 128, y = 128, z = 128},
seed = -70242,
octaves = 1,
persist = 0.5
@ -69,7 +71,7 @@ local np_ores = {
local np_latmos = {
offset = 0,
scale = 1,
spread = {x=256, y=128, z=256},
spread = {x = 256, y = 128, z = 256},
seed = -83928935,
octaves = 3,
persist = 0.6
@ -79,7 +81,7 @@ local np_latmos = {
local np_satmos = {
offset = 0,
scale = 1,
spread = {x=128, y=64, z=128},
spread = {x = 128, y = 64, z = 128},
seed = 1000760700090,
octaves = 2,
persist = 0.6
@ -88,13 +90,16 @@ local np_satmos = {
-- On dignode function. Atmosphere flows into a dug hole.
minetest.register_on_dignode(function(pos, oldnode, digger)
if minetest.find_node_near(pos, 1, {"asteroid:atmos"}) then
minetest.set_node(pos, {name = "asteroid:atmos"})
end
end)
-- Generate on_generated function based on parameters
function otherworlds.asteroids.create_on_generated(ymin, ymax, content_ids)
local YMIN = ymin
local YMAX = ymax
@ -115,55 +120,88 @@ function otherworlds.asteroids.create_on_generated(ymin, ymax, content_ids)
-- return the function closed over the upvalues we want
return function(minp, maxp, seed)
if minp.x < XMIN or maxp.x > XMAX
or minp.y < YMIN or maxp.y > YMAX
or minp.z < ZMIN or maxp.z > ZMAX then
return
end
-- local t1 = os.clock()
local x1 = maxp.x
local y1 = maxp.y
local z1 = maxp.z
local x0 = minp.x
local y0 = minp.y
local z0 = minp.z
--print ("[asteroid] chunk ("..x0.." "..y0.." "..z0..")")
-- local t1 = os.clock()
--print ("[asteroid] chunk ("..x0.." "..y0.." "..z0..")")
local sidelen = x1 - x0 + 1 -- chunk side length
--local vplanarea = sidelen ^ 2 -- vertical plane area, used if calculating noise index from x y z
local chulens = {x=sidelen, y=sidelen, z=sidelen}
local minpos = {x=x0, y=y0, z=z0}
local chulens = {x = sidelen, y = sidelen, z = sidelen}
local minpos = {x = x0, y = y0, z = z0}
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 nvals1 = minetest.get_perlin_map(np_large, chulens):get3dMap_flat(minpos)
local nvals3 = minetest.get_perlin_map(np_fissure, chulens):get3dMap_flat(minpos)
local nvals4 = minetest.get_perlin_map(np_small, chulens):get3dMap_flat(minpos)
local nvals5 = minetest.get_perlin_map(np_ores, chulens):get3dMap_flat(minpos)
local nvals6 = minetest.get_perlin_map(np_latmos, chulens):get3dMap_flat(minpos)
local nvals7 = minetest.get_perlin_map(np_satmos, chulens):get3dMap_flat(minpos)
local nvals1 = minetest.get_perlin_map(np_large,
chulens):get3dMap_flat(minpos)
local nvals3 = minetest.get_perlin_map(np_fissure,
chulens):get3dMap_flat(minpos)
local nvals4 = minetest.get_perlin_map(np_small,
chulens):get3dMap_flat(minpos)
local nvals5 = minetest.get_perlin_map(np_ores,
chulens):get3dMap_flat(minpos)
local nvals6 = minetest.get_perlin_map(np_latmos,
chulens):get3dMap_flat(minpos)
local nvals7 = minetest.get_perlin_map(np_satmos,
chulens):get3dMap_flat(minpos)
local ni = 1
for z = z0, z1 do -- for each vertical plane do
for y = y0, y1 do -- for each horizontal row do
local vi = area:index(x0, y, z) -- LVM index for first node in x row
for x = x0, x1 do -- for each node do
local noise1abs = math.abs(nvals1[ni])
local noise4abs = math.abs(nvals4[ni])
local noise1abs = math.abs(nvals1[ni])
local noise4abs = math.abs(nvals4[ni])
local comet = false
if nvals6[ni] < -(ASCOT + ATMOT) or (nvals7[ni] < -(SASCOT + ATMOT) and nvals1[ni] < ASCOT) then
comet = true -- comet biome
-- comet biome
if nvals6[ni] < -(ASCOT + ATMOT)
or (nvals7[ni] < -(SASCOT + ATMOT) and nvals1[ni] < ASCOT) then
comet = true
end
if noise1abs > ASCOT or noise4abs > SASCOT then -- if below surface then
local noise1dep = noise1abs - ASCOT -- noise1dep zero at surface, positive beneath
if math.abs(nvals3[ni]) > FISTS + noise1dep * FISEXP then -- if no fissure then
local noise4dep = noise4abs - SASCOT -- noise4dep zero at surface, positive beneath
if not comet or (comet and (noise1dep > math.random() + ICET or noise4dep > math.random() + ICET)) then
-- if below surface
if noise1abs > ASCOT or noise4abs > SASCOT then
-- noise1dep zero at surface, positive beneath
local noise1dep = noise1abs - ASCOT
-- if no fissure
if math.abs(nvals3[ni]) > FISTS + noise1dep * FISEXP then
-- noise4dep zero at surface, positive beneath
local noise4dep = noise4abs - SASCOT
if not comet
or (comet and (noise1dep > random() + ICET
or noise4dep > random() + ICET)) then
-- asteroid or asteroid materials in comet
if noise1dep >= STOT or noise4dep >= STOT then
-- stone/ores
if math.random(ORECHA) == 2 then
if random(ORECHA) == 2 then
if nvals5[ni] > 0.6 then
data[vi] = c_goldore
elseif nvals5[ni] < -0.6 then
@ -178,6 +216,7 @@ function otherworlds.asteroids.create_on_generated(ymin, ymax, content_ids)
else
data[vi] = c_stone
end
elseif noise1dep >= COBT or noise4dep >= COBT then
data[vi] = c_cobble
elseif noise1dep >= GRAT or noise4dep >= GRAT then
@ -192,32 +231,42 @@ function otherworlds.asteroids.create_on_generated(ymin, ymax, content_ids)
data[vi] = c_snowblock
end
end
elseif comet then -- fissures, if comet then add comet atmosphere
elseif comet then -- fissures, if comet then add atmosphere
data[vi] = c_atmos
end
elseif comet then -- if comet atmosphere then
data[vi] = c_atmos
end
ni = ni + 1
vi = vi + 1
end
end
end
-- craters
for ci = 1, CPCHU do -- iterate
local cr = CRMIN + math.floor(math.random() ^ 2 * CRRAN) -- exponential radius
local cx = math.random(minp.x + cr, maxp.x - cr) -- centre x
local cz = math.random(minp.z + cr, maxp.z - cr) -- centre z
-- exponential radius
local cr = CRMIN + floor(random() ^ 2 * CRRAN)
local cx = random(minp.x + cr, maxp.x - cr) -- centre x
local cz = random(minp.z + cr, maxp.z - cr) -- centre z
local comet = false
local surfy = false
for y = y1, y0 + cr, -1 do
local vi = area:index(cx, y, cz) -- LVM index for node
local nodeid = data[vi]
if nodeid == c_dust
or nodeid == c_gravel
or nodeid == c_cobble then
surfy = y
break
elseif nodename == c_snowblock
or nodename == c_waterice then
comet = true
@ -225,48 +274,65 @@ function otherworlds.asteroids.create_on_generated(ymin, ymax, content_ids)
break
end
end
if surfy and y1 - surfy > 8 then -- if surface found and 8 node space above impact node then
-- if surface found and 8 node space above impact node then
if surfy and y1 - surfy > 8 then
for x = cx - cr, cx + cr do -- for each plane do
for z = cz - cr, cz + cr do -- for each column do
for y = surfy - cr, surfy + cr do -- for each node do
local vi = area:index(x, y, z) -- LVM index for node
local nr = ((x - cx) ^ 2 + (y - surfy) ^ 2 + (z - cz) ^ 2) ^ 0.5
if nr <= cr - 2 then
if comet then
data[vi] = c_atmos
else
data[vi] = c_air
end
elseif nr <= cr - 1 then
local nodeid = data[vi]
if nodeid == c_gravel
or nodeid == c_cobble
or nodeid == c_stone
or nodeid == c_diamondore
or nodeid == c_goldore
or nodeid == c_meseore
or nodeid == c_copperore
or nodeid == c_ironore then
data[vi] = c_dust
end
elseif nr <= cr then
local nodeid = data[vi]
if nodeid == c_cobble
or nodeid == c_stone then
data[vi] = c_obsidian -- obsidian buried under dust
end
end
for z = cz - cr, cz + cr do -- for each column do
for y = surfy - cr, surfy + cr do -- for each node do
-- LVM index for node
local vi = area:index(x, y, z)
local nr = ((x - cx) ^ 2 + (y - surfy) ^ 2
+ (z - cz) ^ 2) ^ 0.5
if nr <= cr - 2 then
if comet then
data[vi] = c_atmos
else
data[vi] = c_air
end
elseif nr <= cr - 1 then
local nodeid = data[vi]
if nodeid == c_gravel
or nodeid == c_cobble
or nodeid == c_stone
or nodeid == c_diamondore
or nodeid == c_goldore
or nodeid == c_meseore
or nodeid == c_copperore
or nodeid == c_ironore then
data[vi] = c_dust
end
elseif nr <= cr then
local nodeid = data[vi]
if nodeid == c_cobble
or nodeid == c_stone then
data[vi] = c_obsidian -- obsidian buried under dust
end
end
end
end
end
end
end
vm:set_data(data)
vm:set_lighting({day=0, night=0})
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
vm:write_to_map(data)
-- local chugent = math.ceil((os.clock() - t1) * 1000)
--print ("[asteroid] time "..chugent.." ms")
-- local chugent = math.ceil((os.clock() - t1) * 1000)
--print ("[asteroid] time "..chugent.." ms")
data = nil
end
end

View File

@ -41,5 +41,4 @@ if otherworlds.settings.crafting.enable then
{"asteroid:redgravel"},
},
})
end

View File

@ -4,21 +4,23 @@ local sbox = {
fixed = {-5/16, -8/16, -6/16, 5/16, -1/32, 5/16},
}
local crystal_list = {
{"ghost_crystal", "ghost_crystal.png",},
{"red_crystal", "red_crystal.png",},
{"rose_quartz", "rose_quartz.png",},
local crystal_list = {
{"ghost_crystal", "ghost_crystal.png"},
{"red_crystal", "red_crystal.png"},
{"rose_quartz", "rose_quartz.png"},
}
for i in ipairs(crystal_list) do
local name = crystal_list[i][1]
local texture = crystal_list[i][2]
minetest.register_node(":crystals:"..name.."_1", {
minetest.register_node(":crystals:" .. name .. "_1", {
description = "Glowing Crystal",
drawtype = "mesh",
mesh = "crystal_shape01.obj",
tiles = {"crystals_"..texture,},
tiles = {"crystals_" .. texture},
paramtype = "light",
paramtype2 = "facedir",
selection_box = sbox,
@ -26,15 +28,15 @@ for i in ipairs(crystal_list) do
light_source = 10,
use_texture_alpha = true,
visual_scale = 10,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
})
minetest.register_node(":crystals:"..name.."_2", {
minetest.register_node(":crystals:" .. name .. "_2", {
description = "Glowing Crystal",
drawtype = "mesh",
mesh = "crystal_shape02.obj",
tiles = {"crystals_"..texture,},
tiles = {"crystals_" .. texture},
paramtype = "light",
paramtype2 = "facedir",
selection_box = sbox,
@ -42,9 +44,7 @@ for i in ipairs(crystal_list) do
light_source = 10,
use_texture_alpha = true,
visual_scale = 10,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
})
end

View File

@ -1 +1 @@
Adds asteroid layers and height-based skybox switches to create space environments.
Adds asteroid layers and height-based skybox switches to create space environments.

View File

@ -1,4 +1,4 @@
local modpath = minetest.get_modpath("other_worlds").. DIR_DELIM
local modpath = minetest.get_modpath("other_worlds") .. DIR_DELIM
otherworlds = {}
@ -6,8 +6,16 @@ dofile(modpath .. "settings.lua")
dofile(modpath .. "mars_plants.lua")
dofile(modpath .. "crystals.lua")
dofile(modpath .. "space_nodes.lua")
dofile(modpath .. "crafting.lua")
dofile(modpath .. "crafting.lua")
dofile(modpath .. "skybox.lua")
dofile(modpath .. "asteroid_layer_helpers.lua") -- required helpers for mapgen options below
dofile(modpath .. "space_asteroids.lua")
dofile(modpath .. "redsky_asteroids.lua")
-- required helpers for mapgen options below
dofile(modpath .. "asteroid_layer_helpers.lua")
if otherworlds.settings.space_asteroids.enable then
dofile(modpath .. "space_asteroids.lua")
end
if otherworlds.settings.redsky_asteroids.enable then
dofile(modpath .. "redsky_asteroids.lua")
end

View File

@ -10,12 +10,12 @@ minetest.register_node(":mars:redgrass", {
sunlight_propagates = true,
walkable = false,
buildable_to = true,
groups = {snappy=3,flora=1,attached_node=1},
groups = {snappy = 3, flora = 1, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
},
}
})
minetest.register_node(":mars:redweed", {
@ -30,12 +30,12 @@ minetest.register_node(":mars:redweed", {
sunlight_propagates = true,
walkable = false,
buildable_to = true,
groups = {snappy=3,flora=1,attached_node=1},
groups = {snappy = 3, flora = 1, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
},
}
})
minetest.register_node(":mars:moss", {
@ -49,18 +49,17 @@ minetest.register_node(":mars:moss", {
sunlight_propagates = true,
walkable = false,
node_box = {
type = "fixed",
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -15/32, 1/2},
},
selection_box = {
type = "fixed",
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -15/32, 1/2},
},
groups = {snappy=3,flora=1,attached_node=1},
sounds = default.node_sound_leaves_defaults(),
groups = {snappy = 3, flora = 1, attached_node = 1},
sounds = default.node_sound_leaves_defaults()
})
--mars grass
minetest.register_node(":mars:grass_1", {
description = "Martian Grass",
@ -73,7 +72,7 @@ minetest.register_node(":mars:grass_1", {
sunlight_propagates = true,
walkable = false,
buildable_to = true,
groups = {snappy=3,flora=1,attached_node=1},
groups = {snappy = 3, flora = 1, attached_node = 1},
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
@ -81,31 +80,38 @@ minetest.register_node(":mars:grass_1", {
},
on_place = function(itemstack, placer, pointed_thing)
-- place a random grass node
local stack = ItemStack("mars:grass_"..math.random(1,5))
local stack = ItemStack("mars:grass_" .. math.random(5))
local ret = minetest.item_place(stack, placer, pointed_thing)
return ItemStack("mars:grass_1 "..itemstack:get_count()-(1-ret:get_count()))
end,
return ItemStack("mars:grass_1 "
.. itemstack:get_count() - (1 - ret:get_count()))
end
})
for i=2,5 do
minetest.register_node(":mars:grass_"..i, {
for i = 2, 5 do
minetest.register_node(":mars:grass_" .. i, {
description = "Martian Grass",
drawtype = "plantlike",
waving = 1,
tiles = {"mars_grass_"..i..".png"},
inventory_image = "mars_grass_"..i..".png",
wield_image = "mars_grass_"..i..".png",
tiles = {"mars_grass_" .. i .. ".png"},
inventory_image = "mars_grass_" .. i .. ".png",
wield_image = "mars_grass_" .. i .. ".png",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
buildable_to = true,
drop = "mars:grass_1",
groups = {snappy=3,flora=1,attached_node=1,not_in_creative_inventory=1},
groups = {
snappy = 3, flora = 1, attached_node = 1,
not_in_creative_inventory = 1
},
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
},
}
})
end
end

View File

@ -1,76 +1,80 @@
if otherworlds.settings.redsky_asteroids.enable then
-- Approximate realm limits
local YMIN = otherworlds.settings.redsky_asteroids.YMIN or 6000
local YMAX = otherworlds.settings.redsky_asteroids.YMAX or 7000
-- Register on_generated function for this layer
minetest.register_on_generated(otherworlds.asteroids.create_on_generated(YMIN, YMAX, {
c_air = minetest.get_content_id("air"),
c_obsidian = minetest.get_content_id("default:obsidian"),
c_stone = minetest.get_content_id("asteroid:redstone"),
c_cobble = minetest.get_content_id("air"),
c_gravel = minetest.get_content_id("asteroid:redgravel"),
c_dust = minetest.get_content_id("asteroid:reddust"),
c_ironore = minetest.get_content_id("asteroid:ironore"),
c_copperore = minetest.get_content_id("asteroid:copperore"),
c_goldore = minetest.get_content_id("asteroid:goldore"),
c_diamondore = minetest.get_content_id("asteroid:diamondore"),
c_meseore = minetest.get_content_id("asteroid:meseore"),
c_waterice = minetest.get_content_id("default:ice"),
c_atmos = minetest.get_content_id("asteroid:atmos"),
c_snowblock = minetest.get_content_id("default:snowblock"),
}))
-- Approximate realm limits
local YMIN = otherworlds.settings.redsky_asteroids.YMIN or 6000
local YMAX = otherworlds.settings.redsky_asteroids.YMAX or 7000
-- Deco code for grass and crystal
-- Register on_generated function for this layer
minetest.register_on_generated(
otherworlds.asteroids.create_on_generated(YMIN, YMAX, {
local TOPDECO = 500 -- how often surface decoration appears on top of asteroid cobble
c_air = minetest.get_content_id("air"),
c_obsidian = minetest.get_content_id("default:obsidian"),
c_stone = minetest.get_content_id("asteroid:redstone"),
c_cobble = minetest.get_content_id("air"),
c_gravel = minetest.get_content_id("asteroid:redgravel"),
c_dust = minetest.get_content_id("asteroid:reddust"),
c_ironore = minetest.get_content_id("asteroid:ironore"),
c_copperore = minetest.get_content_id("asteroid:copperore"),
c_goldore = minetest.get_content_id("asteroid:goldore"),
c_diamondore = minetest.get_content_id("asteroid:diamondore"),
c_meseore = minetest.get_content_id("asteroid:meseore"),
c_waterice = minetest.get_content_id("default:ice"),
c_atmos = minetest.get_content_id("asteroid:atmos"),
c_snowblock = minetest.get_content_id("default:snowblock"),
}))
local grass = {
"mars:grass_1", "mars:grass_2", "mars:grass_3",
"mars:grass_4", "mars:grass_5"
}
local flower = {
"mars:moss", "mars:redweed", "mars:redgrass"
}
local crystal = {
"crystals:ghost_crystal_1", "crystals:ghost_crystal_2",
"crystals:red_crystal_1", "crystals:red_crystal_2",
"crystals:rose_quartz_1", "crystals:rose_quartz_2",
}
-- Add surface decoration
minetest.register_on_generated(function(minp, maxp)
-- Deco code for grass and crystal
if minp.y < YMIN or maxp.y > YMAX then
return
end
-- how often surface decoration appears on top of asteroid cobble
local TOPDECO = 500
local bpos, ran
local coal = minetest.find_nodes_in_area_under_air(minp, maxp,
local grass = {
"mars:grass_1", "mars:grass_2", "mars:grass_3",
"mars:grass_4", "mars:grass_5"
}
local flower = {
"mars:moss", "mars:redweed", "mars:redgrass"
}
local crystal = {
"crystals:ghost_crystal_1", "crystals:ghost_crystal_2",
"crystals:red_crystal_1", "crystals:red_crystal_2",
"crystals:rose_quartz_1", "crystals:rose_quartz_2",
}
local random = math.random
-- Add surface decoration
minetest.register_on_generated(function(minp, maxp)
if minp.y < YMIN or maxp.y > YMAX then
return
end
local bpos, ran
local coal = minetest.find_nodes_in_area_under_air(minp, maxp,
{"asteroid:redgravel"})
for n = 1, #coal do
for n = 1, #coal do
bpos = {x = coal[n].x, y = coal[n].y + 1, z = coal[n].z }
bpos = {x = coal[n].x, y = coal[n].y + 1, z = coal[n].z}
ran = math.random(TOPDECO)
ran = random(TOPDECO)
if ran < 100 then -- grass
if ran < 100 then -- grass
minetest.swap_node(bpos, {name = grass[ math.random(1, #grass) ] })
minetest.swap_node(bpos, {name = grass[random(#grass)]})
elseif ran >= 180 and ran <= 200 then -- other plants
elseif ran >= 180 and ran <= 200 then -- other plants
minetest.swap_node(bpos, {name = flower[ math.random(1, #flower) ] })
minetest.swap_node(bpos, {name = flower[random(#flower)]})
elseif ran == TOPDECO then -- crystals
elseif ran == TOPDECO then -- crystals
minetest.swap_node(bpos, {name = crystal[ math.random(1, #crystal) ] })
end
minetest.swap_node(bpos, {name = crystal[random(#crystal)]})
end
end)
end
end
end)

View File

@ -23,4 +23,4 @@ otherworlds.settings.redsky_asteroids = {
-- gravity
otherworlds.settings.gravity = {
enable = false, -- set to true to enable gravity
}
}

View File

@ -1,11 +1,12 @@
--Heights for skyboxes
local space_low = 5000
local underground = -50
local space_low = 5000
local space_high = 5999
local redsky_low = 6000
local redsky_high = 6999
local player_list = {} -- Holds name of skybox showing for each player
-- Holds name of skybox showing for each player
local player_list = {}
--Outerspace skybox
local spaceskybox = {
@ -46,38 +47,99 @@ minetest.register_globalstep(function(dtime)
local pos = player:getpos()
local current = player_list[name] or ""
-- Underground
if pos.y < underground and current ~= "underground" then
player:set_sky({
type = "plain",
clouds = false,
sunrise_visible = false,
base_color = 000000,
})
player:set_moon({visible = false})
player:set_stars({visible = false})
player:set_sun({visible = false, sunrise_visible = false})
player_list[name] = "underground"
-- Earth
if pos.y < space_low and current ~= "earth" then
player:set_sky({}, "regular", {})
player:set_clouds({density = 0.4})
elseif pos.y > underground and pos.y < space_low
and current ~= "earth" then
player:set_sky({
type = "regular",
clouds = true,
sunrise_visible = true,
})
player:set_moon({visible = true})
player:set_stars({visible = true})
player:set_sun({visible = true, scale = 1.0, sunrise_visible = true})
player_list[name] = "earth"
if otherworlds.settings.gravity.enable then
player:set_physics_override({gravity = 1})
end
-- Outerspace
elseif pos.y > space_low and pos.y < space_high and current ~= "space" then
player:set_sky({}, "skybox", spaceskybox)
player:set_clouds({density = 0})
elseif pos.y > space_low and pos.y < space_high
and current ~= "space" then
player:set_sky({
type = "skybox",
textures = spaceskybox,
clouds = false,
sunrise_visible = false,
})
player:set_moon({visible = false})
player:set_stars({visible = false})
player:set_sun({visible = true, scale = 1.0, sunrise_visible = false})
player_list[name] = "space"
if otherworlds.settings.gravity.enable then
player:set_physics_override({gravity = 0.4})
end
-- Redsky
elseif pos.y > redsky_low and pos.y < redsky_high and current ~= "redsky" then
player:set_sky({}, "skybox", redskybox)
player:set_clouds({density = 0})
elseif pos.y > redsky_low and pos.y < redsky_high
and current ~= "redsky" then
player:set_sky({
type = "skybox",
textures = redskybox,
clouds = false,
sunrise_visible = false,
})
player:set_moon({visible = false})
player:set_stars({visible = false})
player:set_sun({visible = true, scale = 0.5, sunrise_visible = false})
player_list[name] = "redsky"
if otherworlds.settings.gravity.enable then
player:set_physics_override({gravity = 0.2})
end
-- Everything else (blackness)
elseif pos.y > redsky_high and current ~= "blackness" then
player:set_sky(000000, "plain", {})
player:set_clouds({density = 0})
player:set_sky({
type = "plain",
clouds = false,
sunrise_visible = false,
base_color = 000000,
})
player:set_moon({visible = false})
player:set_stars({visible = true})
player:set_sun({visible = true, scale = 0.1})
player_list[name] = "blackness"
if otherworlds.settings.gravity.enable then
player:set_physics_override({gravity = 0.1})
end
@ -86,8 +148,11 @@ minetest.register_globalstep(function(dtime)
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
player_list[name] = nil
if otherworlds.settings.gravity.enable then
player:set_physics_override({gravity = 1})
end

View File

@ -1,26 +1,23 @@
if otherworlds.settings.space_asteroids.enable then
-- Approximate realm limits
local YMIN = otherworlds.settings.space_asteroids.YMIN or 5000
local YMAX = otherworlds.settings.space_asteroids.YMAX or 6000
-- Approximate realm limits
local YMIN = otherworlds.settings.space_asteroids.YMIN or 5000
local YMAX = otherworlds.settings.space_asteroids.YMAX or 6000
-- Register on_generated function for this layer
minetest.register_on_generated(
otherworlds.asteroids.create_on_generated(YMIN, YMAX, {
-- Register on_generated function for this layer
minetest.register_on_generated(otherworlds.asteroids.create_on_generated(YMIN, YMAX, {
c_air = minetest.get_content_id("air"),
c_obsidian = minetest.get_content_id("default:obsidian"),
c_stone = minetest.get_content_id("asteroid:stone"),
c_cobble = minetest.get_content_id("asteroid:cobble"),
c_gravel = minetest.get_content_id("asteroid:gravel"),
c_dust = minetest.get_content_id("asteroid:dust"),
c_ironore = minetest.get_content_id("default:stone_with_iron"),
c_copperore = minetest.get_content_id("default:stone_with_copper"),
c_goldore = minetest.get_content_id("default:stone_with_gold"),
c_diamondore = minetest.get_content_id("default:stone_with_diamond"),
c_meseore = minetest.get_content_id("default:stone_with_messe"),
c_waterice = minetest.get_content_id("default:ice"),
c_atmos = minetest.get_content_id("asteroid:atmos"),
c_snowblock = minetest.get_content_id("default:snowblock"),
}))
end
c_air = minetest.get_content_id("air"),
c_obsidian = minetest.get_content_id("default:obsidian"),
c_stone = minetest.get_content_id("asteroid:stone"),
c_cobble = minetest.get_content_id("asteroid:cobble"),
c_gravel = minetest.get_content_id("asteroid:gravel"),
c_dust = minetest.get_content_id("asteroid:dust"),
c_ironore = minetest.get_content_id("default:stone_with_iron"),
c_copperore = minetest.get_content_id("default:stone_with_copper"),
c_goldore = minetest.get_content_id("default:stone_with_gold"),
c_diamondore = minetest.get_content_id("default:stone_with_diamond"),
c_meseore = minetest.get_content_id("default:stone_with_mese"),
c_waterice = minetest.get_content_id("default:ice"),
c_atmos = minetest.get_content_id("asteroid:atmos"),
c_snowblock = minetest.get_content_id("default:snowblock"),
}))

View File

@ -5,8 +5,8 @@ minetest.register_node(":asteroid:stone", {
tiles = {"default_stone.png"},
is_ground_content = false,
drop = 'asteroid:cobble',
groups = {cracky = 3, not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
groups = {cracky = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:redstone", {
@ -15,7 +15,7 @@ minetest.register_node(":asteroid:redstone", {
is_ground_content = false,
drop = 'asteroid:redcobble',
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:cobble", {
@ -23,7 +23,7 @@ minetest.register_node(":asteroid:cobble", {
tiles = {"asteroid_cobble.png"},
is_ground_content = false,
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:redcobble", {
@ -31,7 +31,7 @@ minetest.register_node(":asteroid:redcobble", {
tiles = {"asteroid_redcobble.png"},
is_ground_content = false,
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:gravel", {
@ -41,7 +41,7 @@ minetest.register_node(":asteroid:gravel", {
groups = {crumbly = 2},
sounds = default.node_sound_dirt_defaults({
footstep = {name = "default_gravel_footstep", gain = 0.2},
}),
})
})
minetest.register_node(":asteroid:redgravel", {
@ -51,7 +51,7 @@ minetest.register_node(":asteroid:redgravel", {
groups = {crumbly = 2},
sounds = default.node_sound_dirt_defaults({
footstep = {name = "default_gravel_footstep", gain = 0.2},
}),
})
})
minetest.register_node(":asteroid:dust", {
@ -61,7 +61,7 @@ minetest.register_node(":asteroid:dust", {
groups = {crumbly = 3},
sounds = default.node_sound_dirt_defaults({
footstep = {name = "default_gravel_footstep", gain = 0.1},
}),
})
})
minetest.register_node(":asteroid:reddust", {
@ -71,7 +71,7 @@ minetest.register_node(":asteroid:reddust", {
groups = {crumbly = 3},
sounds = default.node_sound_dirt_defaults({
footstep = {name = "default_gravel_footstep", gain = 0.1},
}),
})
})
minetest.register_node(":asteroid:ironore", {
@ -80,7 +80,7 @@ minetest.register_node(":asteroid:ironore", {
is_ground_content = false,
groups = {cracky = 2},
drop = "default:iron_lump",
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:copperore", {
@ -89,7 +89,7 @@ minetest.register_node(":asteroid:copperore", {
is_ground_content = false,
groups = {cracky = 2},
drop = "default:copper_lump",
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:goldore", {
@ -98,7 +98,7 @@ minetest.register_node(":asteroid:goldore", {
is_ground_content = false,
groups = {cracky = 2},
drop = "default:gold_lump",
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:diamondore", {
@ -107,7 +107,7 @@ minetest.register_node(":asteroid:diamondore", {
is_ground_content = false,
groups = {cracky = 1},
drop = "default:diamond",
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:meseore", {
@ -116,7 +116,7 @@ minetest.register_node(":asteroid:meseore", {
is_ground_content = false,
groups = {cracky = 1},
drop = "default:mese_crystal",
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults()
})
minetest.register_node(":asteroid:atmos", {
@ -132,5 +132,5 @@ minetest.register_node(":asteroid:atmos", {
is_ground_content = false,
use_texture_alpha = true,
post_effect_color = {a = 31, r = 241, g = 248, b = 255},
groups = {not_in_creative_inventory = 1},
groups = {not_in_creative_inventory = 1}
})