Compare commits

...

5 Commits

24 changed files with 689 additions and 586 deletions

View File

@ -1,4 +1,4 @@
moonrealm 0.10.0 by paramat
For Minetest 0.4.14 or later
Depends default
Licenses: Code LGPL 2.1. Media CC BY-SA 3.0
moonrealm 0.11.1 by paramat
For Minetest 0.4.16 or later
Depends: default
Licenses: Source code LGPL (2.1). Media (textures) CC BY-SA (3.0)

View File

@ -1 +1,2 @@
default
flowers

View File

@ -75,6 +75,17 @@ function moonrealm_appletree(pos)
end
minetest.register_abm({
nodenames = {"moonrealm:sapling"},
interval = 31,
chance = 7,
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
moonrealm_appletree(pos)
end,
})
-- Vacuum or air flows into a dug hole
minetest.register_on_dignode(function(pos, oldnode, digger)
@ -278,14 +289,156 @@ minetest.register_abm({
})
-- Space appletree from sapling ABM
-- Spawn newplayer function
minetest.register_abm({
nodenames = {"moonrealm:sapling"},
interval = 31,
chance = 7,
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
moonrealm_appletree(pos)
end,
})
minetest.register_on_newplayer(function(player)
local inv = player:get_inventory()
inv:add_item("main", "default:pick_diamond 4")
inv:add_item("main", "default:shovel_diamond 4")
inv:add_item("main", "default:axe_diamond 4")
inv:add_item("main", "default:apple 64")
inv:add_item("main", "moonrealm:photovoltaic 256")
inv:add_item("main", "moonrealm:light 16")
inv:add_item("main", "moonrealm:glass 16")
inv:add_item("main", "moonrealm:storage 4")
inv:add_item("main", "moonrealm:airlock 4")
inv:add_item("main", "moonrealm:airgen 4")
inv:add_item("main", "moonrealm:air_cylinder 4")
inv:add_item("main", "moonrealm:hlsource 4")
inv:add_item("main", "moonrealm:sapling 4")
inv:add_item("main", "moonrealm:spacesuit 4")
inv:add_item("main", "moonrealm:rover")
end)
-- Respawn player function
minetest.register_on_respawnplayer(function(player)
local inv = player:get_inventory()
inv:add_item("main", "default:pick_diamond")
inv:add_item("main", "default:shovel_diamond 4")
inv:add_item("main", "default:apple 16")
inv:add_item("main", "moonrealm:spacesuit")
return true
end)
-- Player positions, spacesuit texture status
-- Set gravity and skybox, override light
local player_pos = {}
local player_pos_previous = {}
local player_spacesuit = {} -- To avoid unnecessary resetting of character model
local skytextures = {
"moonrealm_posy.png",
"moonrealm_negy.png",
"moonrealm_posz.png",
"moonrealm_negz.png",
"moonrealm_negx.png",
"moonrealm_posx.png",
}
minetest.register_on_joinplayer(function(player)
player_pos_previous[player:get_player_name()] = {x = 0, y = 0, z = 0}
if player:get_inventory():contains_item("main", "moonrealm:spacesuit") then
player:set_properties({textures = {"moonrealm_space_character.png"}})
player_spacesuit[player:get_player_name()] = true
player:get_inventory():set_stack("hand", 1, "moonrealm:glove")
else
player:set_properties({textures = {"character.png"}})
player_spacesuit[player:get_player_name()] = false
player:get_inventory():set_stack("hand", 1, "")
end
player:set_physics_override(1, 0.6, 0.2) -- Speed, jump, gravity
player:set_sky({r = 0, g = 0, b = 0, a = 0}, "skybox", skytextures, false)
player:override_day_night_ratio(1)
end)
minetest.register_on_leaveplayer(function(player)
player_pos_previous[player:get_player_name()] = nil
player_spacesuit[player:get_player_name()] = nil
end)
-- Globalstep function
local FOOT = true
minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
-- Footprints
if FOOT and not default.player_attached[player:get_player_name()] and
math.random() < 0.15 and
player_pos_previous[player:get_player_name()] ~= nil then
local pos = player:getpos()
player_pos[player:get_player_name()] = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y + 0.2),
z = math.floor(pos.z + 0.5)
}
local p_ground = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y + 0.4),
z = math.floor(pos.z + 0.5)
}
local n_ground = minetest.get_node(p_ground).name
local p_groundpl = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y - 0.5),
z = math.floor(pos.z + 0.5)
}
if player_pos[player:get_player_name()].x ~=
player_pos_previous[player:get_player_name()].x or
player_pos[player:get_player_name()].y <
player_pos_previous[player:get_player_name()].y or
player_pos[player:get_player_name()].z ~=
player_pos_previous[player:get_player_name()].z then
if n_ground == "moonrealm:dust" then
if math.random() < 0.5 then
minetest.add_node(
p_groundpl,
{name = "moonrealm:dustprint1"}
)
else
minetest.add_node(
p_groundpl,
{name = "moonrealm:dustprint2"}
)
end
end
end
player_pos_previous[player:get_player_name()] = {
x = player_pos[player:get_player_name()].x,
y = player_pos[player:get_player_name()].y,
z = player_pos[player:get_player_name()].z
}
end
-- Spacesuit. Restore breath, reset spacesuit texture and glove
if math.random() < 0.04 then
if player:get_inventory():contains_item("main", "moonrealm:spacesuit") then
-- Spacesuit in inventory
if player:get_breath() < 10 then
player:set_breath(10)
end
if player_spacesuit[player:get_player_name()] == false then
player:set_properties({textures = {"moonrealm_space_character.png"}})
player_spacesuit[player:get_player_name()] = true
player:get_inventory():set_stack("hand", 1, "moonrealm:glove")
end
else
-- No spacesuit in inventory
if player_spacesuit[player:get_player_name()] == true then
player:set_properties({textures = {"character.png"}})
player_spacesuit[player:get_player_name()] = false
player:get_inventory():set_stack("hand", 1, "")
end
end
end
end
end)

559
init.lua
View File

@ -1,562 +1,7 @@
-- Parameters
local YMIN = -8000 -- Approx lower limit
local GRADCEN = 1 -- Gradient centre / terrain centre average level
local YMAX = 8000 -- Approx upper limit
local XMIN = -8000 -- Approx horizontal limits
local XMAX = 8000
local ZMIN = -8000
local ZMAX = 8000
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 ICECHA = 1 / (13 * 13 * 13) -- Ice chance per dust node at terrain centre, decreases with altitude
local ICEGRAD = 128 -- Ice gradient, vertical distance for no ice
local ORECHA = 7 * 7 * 7 -- Ore 1/x chance per stone node
local TFIS = 0.01 -- Fissure threshold. Controls size of fissures
local FOOT = true -- Footprints in dust
-- 3D noise for terrain
local np_terrain = {
offset = 0,
scale = 1,
spread = {x = 384, y = 384, z = 384},
seed = 58588900033,
octaves = 5,
persist = 0.67
}
-- 3D noise for alt terrain, 414 / 256 = golden ratio
local np_terralt = {
offset = 0,
scale = 1,
spread = {x = 311, y = 311, z = 311},
seed = 13331930910,
octaves = 5,
persist = 0.67
}
-- 2D noise for smooth terrain
local np_smooth = {
offset = 0,
scale = 1,
spread = {x = 512, y = 512, z = 512},
seed = 113,
octaves = 3,
persist = 0.4
}
-- 3D noise for fissures
local np_fissure = {
offset = 0,
scale = 1,
spread = {x = 192, y = 192, z = 192},
seed = 8181112,
octaves = 4,
persist = 0.5
}
-- 3D noise for faults
local np_fault = {
offset = 0,
scale = 1,
spread = {x = 414, y = 828, z = 414},
seed = 14440002,
octaves = 4,
persist = 0.5
}
-- 2D noise for terrain centre
local np_gradcen = {
offset = 0,
scale = 1,
spread = {x = 1024, y = 1024, z = 1024},
seed = 9344,
octaves = 4,
persist = 0.4
}
-- 2D noise for terrain blend
local np_terblen = {
offset = 0,
scale = 1,
spread = {x = 1024, y = 1024, z = 1024},
seed = -13002,
octaves = 3,
persist = 0.4
}
-- Do files
dofile(minetest.get_modpath("moonrealm") .. "/nodes.lua")
dofile(minetest.get_modpath("moonrealm") .. "/crafting.lua")
dofile(minetest.get_modpath("moonrealm") .. "/functions.lua")
-- Set mapgen parameters
minetest.set_mapgen_params({mgname = "singlenode", water_level = -31000})
-- Player positions, spacesuit texture status
local player_pos = {}
local player_pos_previous = {}
local player_spacesuit = {}
minetest.register_on_joinplayer(function(player)
player_pos_previous[player:get_player_name()] = {x = 0, y = 0, z = 0}
if player:get_inventory():contains_item("main", "moonrealm:spacesuit") then
player:set_properties({textures = {"moonrealm_space_character.png"}})
player_spacesuit[player:get_player_name()] = true
else
player:set_properties({textures = {"moonrealm_character.png"}})
player_spacesuit[player:get_player_name()] = false
end
end)
minetest.register_on_leaveplayer(function(player)
player_pos_previous[player:get_player_name()] = nil
player_spacesuit[player:get_player_name()] = nil
end)
-- Globalstep function
minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
if FOOT and math.random() < 0.15 and -- footprints
player_pos_previous[player:get_player_name()] ~= nil then
local pos = player:getpos()
player_pos[player:get_player_name()] = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y + 0.2),
z = math.floor(pos.z + 0.5)
}
local p_ground = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y + 0.4),
z = math.floor(pos.z + 0.5)
}
local n_ground = minetest.get_node(p_ground).name
local p_groundpl = {
x = math.floor(pos.x + 0.5),
y = math.floor(pos.y - 0.5),
z = math.floor(pos.z + 0.5)
}
if player_pos[player:get_player_name()].x ~=
player_pos_previous[player:get_player_name()].x or
player_pos[player:get_player_name()].y <
player_pos_previous[player:get_player_name()].y or
player_pos[player:get_player_name()].z ~=
player_pos_previous[player:get_player_name()].z then
if n_ground == "moonrealm:dust" then
if math.random() < 0.5 then
minetest.add_node(
p_groundpl,
{name = "moonrealm:dustprint1"}
)
else
minetest.add_node(
p_groundpl,
{name = "moonrealm:dustprint2"}
)
end
end
end
player_pos_previous[player:get_player_name()] = {
x = player_pos[player:get_player_name()].x,
y = player_pos[player:get_player_name()].y,
z = player_pos[player:get_player_name()].z
}
end
if math.random() < 0.04 then -- spacesuit restores breath, reset spacesuit texture
if player:get_inventory():contains_item("main", "moonrealm:spacesuit") then
if player:get_breath() < 10 then
player:set_breath(10)
end
if player_spacesuit[player:get_player_name()] == false then -- if no spacesuit texture, add
player:set_properties({textures = {"moonrealm_space_character.png"}})
player_spacesuit[player:get_player_name()] = true
end
else -- no spacesuit in inventory
if player_spacesuit[player:get_player_name()] == true then -- if spacesuit texture, remove
player:set_properties({textures = {"moonrealm_character.png"}})
player_spacesuit[player:get_player_name()] = false
end
end
end
if math.random() < 0.01 then -- set gravity, skybox and override light
local pos = player:getpos()
if pos.y > YMIN and pos.y < YMAX then -- entering realm
player:set_physics_override(1, 0.6, 0.2) -- speed, jump, gravity
local skytextures = {
"moonrealm_posy.png",
"moonrealm_negy.png",
"moonrealm_posz.png",
"moonrealm_negz.png",
"moonrealm_negx.png",
"moonrealm_posx.png",
}
player:set_sky({r = 0, g = 0, b = 0, a = 0}, "skybox", skytextures)
player:override_day_night_ratio(1)
else -- on leaving realm
player:set_physics_override(1, 1, 1)
player:set_sky({}, "regular", {})
player:override_day_night_ratio(nil)
end
end
end
end)
-- Initialize noise objects to nil
local nobj_terrain = nil
local nobj_terralt = nil
local nobj_fissure = nil
local nobj_fault = nil
local nobj_smooth = nil
local nobj_terblen = nil
local nobj_gradcen = nil
-- Localise noise buffers
local nbuf_terrain
local nbuf_terralt
local nbuf_fissure
local nbuf_fault
local nbuf_smooth
local nbuf_terblen
local nbuf_gradcen
-- On generated function
minetest.register_on_generated(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
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
local c_mese = minetest.get_content_id("moonrealm:mese")
local c_mrironore = minetest.get_content_id("moonrealm:ironore")
local c_mrcopperore = minetest.get_content_id("moonrealm:copperore")
local c_mrgoldore = minetest.get_content_id("moonrealm:goldore")
local c_mrdiamondore = minetest.get_content_id("moonrealm:diamondore")
local c_mrstone = minetest.get_content_id("moonrealm:stone")
local c_waterice = minetest.get_content_id("moonrealm:waterice")
local c_dust = minetest.get_content_id("moonrealm:dust")
local c_vacuum = minetest.get_content_id("moonrealm:vacuum")
local chulens = x1 - x0 + 1
local pmaplens2d = {x = chulens, y = chulens, z = 1}
local pmaplens3d = {x = chulens, y = chulens, z = chulens}
local minpos2d = {x = x0, y = z0}
local minpos3d = {x = x0, y = y0, z = z0}
nobj_terrain = nobj_terrain or minetest.get_perlin_map(np_terrain, pmaplens3d)
nobj_terralt = nobj_terralt or minetest.get_perlin_map(np_terralt, pmaplens3d)
nobj_fissure = nobj_fissure or minetest.get_perlin_map(np_fissure, pmaplens3d)
nobj_fault = nobj_fault or minetest.get_perlin_map(np_fault, pmaplens3d)
nobj_smooth = nobj_smooth or minetest.get_perlin_map(np_smooth, pmaplens2d)
nobj_terblen = nobj_terblen or minetest.get_perlin_map(np_terblen, pmaplens2d)
nobj_gradcen = nobj_gradcen or minetest.get_perlin_map(np_gradcen, pmaplens2d)
local nvals_terrain = nobj_terrain:get3dMap_flat(minpos3d, nbuf_terrain)
local nvals_terralt = nobj_terralt:get3dMap_flat(minpos3d, nbuf_terralt)
local nvals_fissure = nobj_fissure:get3dMap_flat(minpos3d, nbuf_fissure)
local nvals_fault = nobj_fault :get3dMap_flat(minpos3d, nbuf_fault)
local nvals_smooth = nobj_smooth :get2dMap_flat(minpos2d, nbuf_smooth)
local nvals_terblen = nobj_terblen:get2dMap_flat(minpos2d, nbuf_terblen)
local nvals_gradcen = nobj_gradcen:get2dMap_flat(minpos2d, nbuf_gradcen)
local ni3d = 1
local ni2d = 1
local stable = {}
for z = z0, z1 do
local viu = area:index(x0, y0 - 1, z)
for x = x0, x1 do
local si = x - x0 + 1
local nodid = data[viu]
if nodid == c_vacuum then
stable[si] = false
else
stable[si] = true
end
viu = viu + 1
end
for y = y0, y1 do
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
local nodid = data[vi]
local empty = (nodid == c_air or nodid == c_ignore)
local grad
local density
local si = x - x0 + 1
local terblen = math.max(math.min(
math.abs(nvals_terblen[ni2d]) * 4, 1.5), 0.5) - 0.5
local gradcen = GRADCEN + nvals_gradcen[ni2d] * CENAMP
if y > gradcen then
grad = -((y - gradcen) / HIGRAD) ^ HEXP
else
grad = ((gradcen - y) / LOGRAD) ^ LEXP
end
if nvals_fault[ni3d] >= 0 then
density = (nvals_terrain[ni3d] +
nvals_terralt[ni3d]) / 2 * (1 - terblen) +
nvals_smooth[ni2d] * terblen + grad
else
density = (nvals_terrain[ni3d] -
nvals_terralt[ni3d]) / 2 * (1 - terblen) -
nvals_smooth[ni2d] * terblen + grad
end
if density > 0 and empty then -- if terrain and node empty
local nofis = false
if math.abs(nvals_fissure[ni3d]) > TFIS then
nofis = true
end
if density >= STOT and nofis then -- stone, ores
if math.random(ORECHA) == 2 then
local osel = math.random(25)
if osel == 25 then
data[vi] = c_mese
elseif osel >= 22 then
data[vi] = c_mrdiamondore
elseif osel >= 19 then
data[vi] = c_mrgoldore
elseif osel >= 10 then
data[vi] = c_mrcopperore
else
data[vi] = c_mrironore
end
else
data[vi] = c_mrstone
end
stable[si] = true
elseif density < STOT then -- fine materials
if nofis and stable[si] then
if math.random() < icecha then
data[vi] = c_waterice
else
data[vi] = c_dust
end
else -- fissure
data[vi] = c_vacuum
stable[si] = false
end
else -- fissure or unstable missing node
data[vi] = c_vacuum
stable[si] = false
end
else -- vacuum or spawn egg
if empty then
data[vi] = c_vacuum
end
stable[si] = false
end
ni3d = ni3d + 1
ni2d = ni2d + 1
vi = vi + 1
end
ni2d = ni2d - chulens
end
ni2d = ni2d + chulens
end
vm:set_data(data)
--vm:set_lighting({day=0, night=0})
vm:calc_lighting()
vm:write_to_map(data)
local chugent = math.ceil((os.clock() - t1) * 1000)
print ("[moonrealm] chunk generation " .. chugent .. " ms")
end)
-- Find spawn function, dependant on chunk size of 80 nodes
-- TODO allow any chunksize, search using 2D noises first
local function moonrealm_find_spawn()
local PSCA = 8
local nobj_terrain = nil
local nobj_terralt = nil
local nobj_fault = nil
local nobj_smooth = nil
local nobj_terblen = nil
local nobj_gradcen = nil
for chunk = 1, 128 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 = 80 * math.floor((GRADCEN + 32) / 80) - 32
local x1 = x0 + 79
local z1 = z0 + 79
local y1 = y0 + 79
local chulens = x1 - x0 + 1
local pmaplens2d = {x = chulens, y = chulens, z = 1}
local pmaplens3d = {x = chulens, y = chulens, z = chulens}
local minpos2d = {x = x0, y = z0}
local minpos3d = {x = x0, y = y0, z = z0}
nobj_terrain = nobj_terrain or minetest.get_perlin_map(np_terrain, pmaplens3d)
nobj_terralt = nobj_terralt or minetest.get_perlin_map(np_terralt, pmaplens3d)
nobj_fault = nobj_fault or minetest.get_perlin_map(np_fault, pmaplens3d)
nobj_smooth = nobj_smooth or minetest.get_perlin_map(np_smooth, pmaplens2d)
nobj_terblen = nobj_terblen or minetest.get_perlin_map(np_terblen, pmaplens2d)
nobj_gradcen = nobj_gradcen or minetest.get_perlin_map(np_gradcen, pmaplens2d)
local nvals_terrain = nobj_terrain:get3dMap_flat(minpos3d)
local nvals_terralt = nobj_terralt:get3dMap_flat(minpos3d)
local nvals_fault = nobj_fault :get3dMap_flat(minpos3d)
local nvals_smooth = nobj_smooth :get2dMap_flat(minpos2d)
local nvals_terblen = nobj_terblen:get2dMap_flat(minpos2d)
local nvals_gradcen = nobj_gradcen:get2dMap_flat(minpos2d)
local ni3d = 1
local ni2d = 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[ni2d]) * 4, 1.5), 0.5) - 0.5
local gradcen = GRADCEN + nvals_gradcen[ni2d] * CENAMP
if y > gradcen then
grad = -((y - gradcen) / HIGRAD) ^ HEXP
else
grad = ((gradcen - y) / LOGRAD) ^ LEXP
end
if nvals_fault[ni3d] >= 0 then
density = (nvals_terrain[ni3d] +
nvals_terralt[ni3d]) / 2 * (1 - terblen) +
nvals_smooth[ni2d] * terblen + grad
else
density = (nvals_terrain[ni3d] -
nvals_terralt[ni3d]) / 2 * (1 - terblen) -
nvals_smooth[ni2d] * terblen + grad
end
if density >= STOT then
stable[si] = true
-- just above ground, smooth terrain, away from faults
elseif stable[si] and density < 0 and terblen == 1 and
math.abs(nvals_fault[ni3d]) > 0.25 then
return {x = x, y = y, z = z}
end
ni3d = ni3d + 1
ni2d = ni2d + 1
end
ni2d = ni2d - chulens
end
ni2d = ni2d + chulens
end
end
return {x = 0, y = GRADCEN, z = 0} -- fallback spawn point
end
-- Spawn newplayer function
minetest.register_on_newplayer(function(player)
local spawn_pos = moonrealm_find_spawn()
print ("[moonrealm] spawn new player (" .. spawn_pos.x .. " " ..
spawn_pos.y .. " " .. spawn_pos.z .. ")")
player:setpos(spawn_pos)
local inv = player:get_inventory()
inv:add_item("main", "default:pick_diamond 4")
inv:add_item("main", "default:shovel_diamond 4")
inv:add_item("main", "default:axe_diamond 4")
inv:add_item("main", "default:apple 64")
inv:add_item("main", "moonrealm:photovoltaic 256")
inv:add_item("main", "moonrealm:light 16")
inv:add_item("main", "moonrealm:glass 16")
inv:add_item("main", "moonrealm:storage 4")
inv:add_item("main", "moonrealm:airlock 4")
inv:add_item("main", "moonrealm:airgen 4")
inv:add_item("main", "moonrealm:air_cylinder 4")
inv:add_item("main", "moonrealm:hlsource 4")
inv:add_item("main", "moonrealm:sapling 4")
inv:add_item("main", "moonrealm:spacesuit 4")
end)
-- Respawn player function
minetest.register_on_respawnplayer(function(player)
local spawn_pos = moonrealm_find_spawn()
print ("[moonrealm] respawn player (" .. spawn_pos.x .. " " ..
spawn_pos.y .. " " .. spawn_pos.z .. ")")
player:setpos(spawn_pos)
local inv = player:get_inventory()
inv:add_item("main", "default:pick_diamond")
inv:add_item("main", "default:shovel_diamond 4")
inv:add_item("main", "default:apple 16")
inv:add_item("main", "moonrealm:spacesuit")
return true
end)
dofile(minetest.get_modpath("moonrealm") .. "/rover.lua")
dofile(minetest.get_modpath("moonrealm") .. "/mapgen.lua")

211
mapgen.lua Normal file
View File

@ -0,0 +1,211 @@
-- Clear stuff
minetest.clear_registered_biomes()
minetest.clear_registered_ores()
minetest.clear_registered_decorations()
-- Set mapgen settings
minetest.set_mapgen_setting("mg_name", "v7", true)
minetest.set_mapgen_setting("water_level", -15, true)
minetest.set_mapgen_setting("mg_flags", "caves,nodungeons,light,nodecorations", true)
-- Register biome
minetest.register_biome({
name = "moon",
--node_dust = "",
node_top = "moonrealm:dust",
depth_top = 1,
node_filler = "moonrealm:dust",
depth_filler = 2,
node_stone = "moonrealm:stone",
--node_water_top = "",
--depth_water_top = ,
node_water = "moonrealm:dust",
--node_river_water = "",
--node_riverbed = "",
--depth_riverbed = ,
y_min = -31000,
y_max = 31000,
heat_point = 50,
humidity_point = 50,
})
-- Register ores
-- Iron
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:ironore",
wherein = "moonrealm:stone",
clust_scarcity = 7 * 7 * 7,
clust_num_ores = 5,
clust_size = 3,
y_min = -31000,
y_max = 0,
})
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:ironore",
wherein = "moonrealm:stone",
clust_scarcity = 24 * 24 * 24,
clust_num_ores = 27,
clust_size = 6,
y_min = -31000,
y_max = -64,
})
-- Copper
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:copperore",
wherein = "moonrealm:stone",
clust_scarcity = 12 * 12 * 12,
clust_num_ores = 4,
clust_size = 3,
y_min = -63,
y_max = -16,
})
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:copperore",
wherein = "moonrealm:stone",
clust_scarcity = 9 * 9 * 9,
clust_num_ores = 5,
clust_size = 3,
y_min = -31000,
y_max = -64,
})
-- Gold
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:goldore",
wherein = "moonrealm:stone",
clust_scarcity = 15 * 15 * 15,
clust_num_ores = 3,
clust_size = 2,
y_min = -255,
y_max = -64,
})
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:goldore",
wherein = "moonrealm:stone",
clust_scarcity = 13 * 13 * 13,
clust_num_ores = 5,
clust_size = 3,
y_min = -31000,
y_max = -256,
})
-- Mese block
minetest.register_ore({
ore_type = "scatter",
ore = "default:mese",
wherein = "moonrealm:stone",
clust_scarcity = 18 * 18 * 18,
clust_num_ores = 3,
clust_size = 2,
y_min = -255,
y_max = -64,
})
minetest.register_ore({
ore_type = "scatter",
ore = "default:mese",
wherein = "moonrealm:stone",
clust_scarcity = 14 * 14 * 14,
clust_num_ores = 5,
clust_size = 3,
y_min = -31000,
y_max = -256,
})
-- Diamond
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:diamondore",
wherein = "moonrealm:stone",
clust_scarcity = 17 * 17 * 17,
clust_num_ores = 4,
clust_size = 3,
y_min = -255,
y_max = -128,
})
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:diamondore",
wherein = "moonrealm:stone",
clust_scarcity = 15 * 15 * 15,
clust_num_ores = 4,
clust_size = 3,
y_min = -31000,
y_max = -256,
})
-- Water ice
minetest.register_ore({
ore_type = "scatter",
ore = "moonrealm:waterice",
wherein = "moonrealm:dust",
clust_scarcity = 13 * 13 * 13,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000,
y_max = 0,
})
-- Localise data buffer
local dbuf = {}
-- On generated function
-- Convert air nodes to mod vacuum nodes
minetest.register_on_generated(function(minp, maxp, seed)
local x0 = minp.x
local y0 = minp.y
local z0 = minp.z
local x1 = maxp.x
local y1 = maxp.y
local z1 = maxp.z
local c_air = minetest.CONTENT_AIR
local c_vacuum = minetest.get_content_id("moonrealm:vacuum")
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data(dbuf)
for z = z0, z1 do
for y = y0 - 1, y1 + 1 do
local vi = area:index(x0, y, z)
for x = x0, x1 do
if data[vi] == c_air then
data[vi] = c_vacuum
end
vi = vi + 1
end
end
end
vm:set_data(data)
vm:write_to_map(data)
end)

View File

@ -44,17 +44,6 @@ minetest.register_node("moonrealm:diamondore", {
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("moonrealm:mese", {
description = "Mese Block",
tiles = {"moonrealm_mese.png"},
paramtype = "light",
light_source = 3,
is_ground_content = false,
groups = {cracky = 1, level = 2},
drop = "default:mese",
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("moonrealm:dust", {
description = "Moon Dust",
tiles = {"moonrealm_dust.png"},
@ -66,7 +55,7 @@ minetest.register_node("moonrealm:dust", {
})
minetest.register_node("moonrealm:dustprint1", {
description = "Moon Dust Footprint1",
description = "Moon Dust Footprint 1",
tiles = {"moonrealm_dustprint1.png", "moonrealm_dust.png"},
is_ground_content = false,
groups = {crumbly = 3},
@ -77,7 +66,7 @@ minetest.register_node("moonrealm:dustprint1", {
})
minetest.register_node("moonrealm:dustprint2", {
description = "Moon Dust Footprint2",
description = "Moon Dust Footprint 2",
tiles = {"moonrealm_dustprint2.png", "moonrealm_dust.png"},
is_ground_content = false,
groups = {crumbly = 3},
@ -87,6 +76,17 @@ minetest.register_node("moonrealm:dustprint2", {
}),
})
minetest.register_node("moonrealm:dusttrack", {
description = "Moon Rover Track",
tiles = {"moonrealm_dusttrack.png", "moonrealm_dust.png"},
is_ground_content = false,
groups = {crumbly = 3},
drop = "moonrealm:dust",
sounds = default.node_sound_sand_defaults({
footstep = {name = "default_sand_footstep", gain = 0.05},
}),
})
minetest.register_node("moonrealm:vacuum", {
description = "Vacuum",
drawtype = "airlike",
@ -131,8 +131,8 @@ minetest.register_node("moonrealm:airgen", {
local c_airgen_empty = minetest.get_content_id("moonrealm:airgen_empty")
local vm = minetest.get_voxel_manip()
local pos1 = {x = px - 8, y = py - 8, z = pz - 8}
local pos2 = {x = px + 8, y = py + 9, z = pz + 8}
local pos1 = {x = px - 16, y = py - 16, z = pz - 16}
local pos2 = {x = px + 16, y = py + 17, z = pz + 16}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
@ -497,3 +497,24 @@ minetest.register_craftitem("moonrealm:lifesupport", {
inventory_image = "moonrealm_lifesupport.png",
groups = {not_in_creative_inventory = 1},
})
-- Glove
minetest.register_item("moonrealm:glove", {
type = "none",
wield_image = "moonrealm_glove.png",
wield_scale = {x = 1, y = 1, z = 2.5},
stack_max = 1,
tool_capabilities = {
full_punch_interval = 0.9,
max_drop_level = 0,
groupcaps = {
crumbly = {times = {[2] = 3.00, [3] = 0.70}, uses = 0, maxlevel = 1},
snappy = {times = {[3] = 0.40}, uses = 0, maxlevel = 1},
oddly_breakable_by_hand =
{times = {[1] = 3.50, [2] = 2.00, [3] = 0.70}, uses = 0}
},
damage_groups = {fleshy = 1},
}
})

272
rover.lua Normal file
View File

@ -0,0 +1,272 @@
-- Parameters
local ACDC = 0.15 -- Acceleration / decelleration
local TURNSP = 0.02 -- Maximum yaw speed
-- Functions
local function get_sign(i)
if i == 0 then
return 0
else
return i / math.abs(i)
end
end
local function get_velocity(v, yaw, y)
local x = -math.sin(yaw) * v
local z = math.cos(yaw) * v
return {x = x, y = y, z = z}
end
local function get_v(v)
return math.sqrt(v.x ^ 2 + v.z ^ 2)
end
-- Rover entity
local rover = {
physical = true,
collide_with_objects = true,
collisionbox = {-0.7, 0.4, -0.7, 0.7, 1.0, 0.7},
visual = "cube",
visual_size = {x = 2.0, y = 2.0},
textures = {
-- Top, base, right, left, front, back
"moonrealm_rover_top.png",
"moonrealm_rover_base.png",
"moonrealm_rover_right.png",
"moonrealm_rover_left.png",
"moonrealm_rover_front.png",
"moonrealm_rover_back.png",
},
stepheight = 0,
driver = nil,
v = 0,
last_v = 0,
removed = false,
}
-- Rover item
minetest.register_craftitem("moonrealm:rover", {
description = "Rover",
inventory_image = "moonrealm_rover_front.png",
wield_scale = {x = 2, y = 2, z = 2},
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end
if pointed_thing.type == "node" and
minetest.registered_nodes[node.name].walkable then
under.y = under.y + 1.5
local rover = minetest.add_entity(under, "moonrealm:rover")
if rover then
rover:setyaw(placer:get_look_horizontal())
if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item()
end
end
end
return itemstack
end,
})
-- Register entity
minetest.register_entity("moonrealm:rover", rover)
-- Rover entity functions
function rover:on_rightclick(clicker)
if not clicker or not clicker:is_player() then
return
end
local name = clicker:get_player_name()
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
default.player_attached[name] = false
default.player_set_animation(clicker, "stand" , 30)
elseif not self.driver then
local attach = clicker:get_attach()
if attach and attach:get_luaentity() then
local luaentity = attach:get_luaentity()
if luaentity.driver then
luaentity.driver = nil
end
clicker:set_detach()
end
self.driver = clicker
clicker:set_attach(self.object, "",
{x = 0, y = 3, z = -2}, {x = 0, y = 0, z = 0})
default.player_attached[name] = true
minetest.after(0.2, function()
default.player_set_animation(clicker, "sit" , 30)
end)
clicker:set_look_horizontal(self.object:getyaw())
end
end
function rover.on_activate(self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
if staticdata then
self.v = tonumber(staticdata)
end
self.last_v = self.v
end
function rover.get_staticdata(self)
return tostring(self.v)
end
function rover.on_punch(self, puncher, time_from_last_punch,
tool_capabilities, direction)
if not puncher or not puncher:is_player() or self.removed then
return
end
if self.driver and puncher == self.driver then
self.driver = nil
puncher:set_detach()
default.player_attached[puncher:get_player_name()] = false
end
if not self.driver then
self.removed = true
local inv = puncher:get_inventory()
if not minetest.setting_getbool("creative_mode")
or not inv:contains_item("main", "moonrealm:rover") then
local leftover = inv:add_item("main", "moonrealm:rover")
-- If no room in inventory add a replacement rover to the world
if not leftover:is_empty() then
minetest.add_item(self.object:getpos(), leftover)
end
end
-- Delay remove to ensure player is detached
minetest.after(0.1, function()
self.object:remove()
end)
end
end
function rover:on_step(dtime)
local ctrl
if self.driver then
ctrl = self.driver:get_player_control()
end
if (not ctrl or not (ctrl.up or ctrl.down)) and
vector.equals(self.object:getvelocity(), {x = 0, y = 0, z = 0}) then
-- Either no driver or driver but no accelerator, and stationary
return
end
-- Touching ground?
local obj_pos = self.object:getpos()
obj_pos.y = obj_pos.y - 1.1
local under_pos = obj_pos
local node_under = minetest.get_node(under_pos)
local nodedef_under = minetest.registered_nodes[node_under.name]
local touch_ground = nodedef_under.walkable
local absv = get_v(self.object:getvelocity())
self.v = absv * get_sign(self.v)
if touch_ground then
-- Acceleration and steering
if self.driver then
if ctrl.up then
self.v = self.v + ACDC
elseif ctrl.down then
self.v = self.v - ACDC
end
local turn
local maxturn = (1 + dtime * 2) * TURNSP
if absv < 4 then
turn = maxturn * absv / 4
else
turn = maxturn * (1 - (absv - 4) / 8)
end
if ctrl.left then
self.object:setyaw(self.object:getyaw() + turn)
elseif ctrl.right then
self.object:setyaw(self.object:getyaw() - turn)
end
end
-- Slowing from resistence
local s = get_sign(self.v)
self.v = self.v - 0.04 * s
if s ~= get_sign(self.v) then
self.object:setvelocity({x = 0, y = 0, z = 0})
self.v = 0
return
end
-- Limit to max speed
if absv > 8 then
self.v = 8 * get_sign(self.v)
end
end
-- Vertical behaviour
local obj_pos = self.object:getpos()
obj_pos.y = obj_pos.y - 0.5
local nodedef_in = minetest.registered_nodes[minetest.get_node(obj_pos).name]
if nodedef_in.walkable then
-- In node, jump up
self.object:setacceleration({x = 0, y = 0, z = 0})
self.object:setvelocity(get_velocity(self.v,
self.object:getyaw(), math.max(absv / 2, 1)))
self.object:setpos(self.object:getpos())
else
if not touch_ground then
-- No node under, freefall
self.object:setacceleration({x = 0, y = -1.962, z = 0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(),
self.object:getvelocity().y))
self.object:setpos(self.object:getpos())
else
-- Node under, on surface, check y velocity
if self.object:getvelocity().y < 0 then
-- Landing on surface
local pos = self.object:getpos()
pos.y = math.floor(pos.y) + 0.5
self.object:setacceleration({x = 0, y = 0, z = 0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
self.object:setpos(pos)
else
-- On surface or jumping up through surface
self.object:setacceleration({x = 0, y = 0, z = 0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(),
self.object:getvelocity().y))
self.object:setpos(self.object:getpos())
end
if node_under.name == "moonrealm:dust" or
node_under.name == "moonrealm:dustprint1" or
node_under.name == "moonrealm:dustprint2" then
minetest.set_node(under_pos, {name = "moonrealm:dusttrack"})
end
end
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 625 B