Shared mapgen API, add hard stone strata.

This commit is contained in:
Aaron Suen 2019-02-23 22:48:39 -05:00
parent 2091c6621e
commit 44b6a1d228
9 changed files with 94 additions and 35 deletions

View File

@ -36,6 +36,7 @@ include("match")
include("fx_digparticles")
include("register_limited_abm")
include("mapgen_shared")
include("item_on_register")
include("item_drop_in_place")

View File

@ -0,0 +1,23 @@
-- LUALOCALS < ---------------------------------------------------------
local VoxelArea, ipairs, minetest, nodecore
= VoxelArea, ipairs, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
nodecore.register_mapgen_shared,
nodecore.registered_mapgen_shared
= nodecore.mkreg()
minetest.register_on_generated(function(minp, maxp)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
for _, v in ipairs(nodecore.registered_mapgen_shared) do
v(minp, maxp, area, data, vm, emin, emax)
end
vm:set_data(data)
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
vm:write_to_map()
end)

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local VoxelArea, minetest, nodecore
= VoxelArea, minetest, nodecore
local minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -42,6 +42,7 @@ reg("Cobble", {
local function regore(name, def)
return minetest.register_ore(nodecore.underride(def, {
y_min = -64,
name = name,
ore_type = "scatter",
ore = name,
@ -74,11 +75,7 @@ local c_ore = minetest.get_content_id(ore)
local c_istone = minetest.get_content_id(stone)
local c_stone = minetest.get_content_id("nc_terrain:stone")
minetest.register_on_generated(function(minp, maxp)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
nodecore.register_mapgen_shared(function(minp, maxp, area, data, vm, emin, emax)
local function bad(x, y, z)
local c = data[area:index(x, y, z)]
return c ~= c_stone and c ~= c_istone
@ -107,8 +104,4 @@ minetest.register_on_generated(function(minp, maxp)
end
end
end
vm:set_data(data)
-- Nothing here should affect light; skip recalc.
vm:write_to_map()
end)

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local VoxelArea, math, minetest
= VoxelArea, math, minetest
local math, minetest, nodecore
= math, minetest, nodecore
local math_floor, math_random
= math.floor, math.random
-- LUALOCALS > ---------------------------------------------------------
@ -14,16 +14,9 @@ local c_sand = minetest.get_content_id("nc_terrain:sand")
local c_water = minetest.get_content_id("nc_terrain:water_source")
local c_sponge = minetest.get_content_id(modname .. ":sponge_living")
minetest.register_on_generated(function(minp, maxp)
nodecore.register_mapgen_shared(function(minp, maxp, area, data, vm, emin, emax)
if minp.y > maxy or maxp.y < miny then return end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local dirty
local qty = math_floor(math_random() * (maxp.x - minp.x)
* (maxp.z - minp.z) / (16 * 16))
for n = 1, qty do
@ -41,18 +34,10 @@ minetest.register_on_generated(function(minp, maxp)
waterabove = true
elseif cur == c_sand and waterabove then
data[area:index(x, y + 1, z)] = c_sponge
dirty = true
break
else
break
end
end
end
if not dirty then return end
vm:set_data(data)
vm:set_lighting{day = 0, night = 0}
vm:calc_lighting()
vm:write_to_map()
end)

View File

@ -1,11 +1,13 @@
-- LUALOCALS < ---------------------------------------------------------
local dofile, minetest
= dofile, minetest
local dofile, minetest, nodecore
= dofile, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local path = minetest.get_modpath(modname)
nodecore.hard_stone_strata = 7
dofile(path .. "/node.lua")
dofile(path .. "/biome.lua")
dofile(path .. "/ore.lua")

View File

@ -1,6 +1,8 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, pairs
= ipairs, minetest, pairs
local ipairs, math, minetest, nodecore, pairs
= ipairs, math, minetest, nodecore, pairs
local math_floor, math_sqrt
= math.floor, math.sqrt
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -60,6 +62,22 @@ regterrain({
},
drop_in_place = modname .. ":cobble"
})
for i = 1, nodecore.hard_stone_strata do
regterrain({
description = "Hard Stone " .. i,
drawtype = "glasslike",
paramtype = "light",
light_source = i * 3,
tiles = { modname .. "_stone.png^(" .. modname
.. "_stone_hard.png^[opacity:"
.. math_floor(math_sqrt(i) * 96) .. ")" },
groups = {
cracky = i + 2
},
drop_in_place = modname .. ":cobble"
})
end
regterrain({
description = "Cobble",
tiles = { modname .. "_gravel.png^" .. modname .. "_cobble.png" },

View File

@ -1,6 +1,8 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest
= minetest
local math, minetest, nodecore
= math, minetest, nodecore
local math_floor, math_random
= math.floor, math.random
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -24,3 +26,38 @@ minetest.register_ore({
},
noise_threshold = 1.2
})
local c_stone = minetest.get_content_id(modname .. ":stone")
local hard = {}
for i = 1, nodecore.hard_stone_strata do
hard[i] = minetest.get_content_id(modname .. ":hard_stone_" .. i)
end
hard[0] = c_stone
nodecore.register_mapgen_shared(function(minp, maxp, area, data, vm, emin, emax)
if minp.y > -64 then return end
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local raw = y / -64
local strat = math_floor(raw)
local dither = raw - strat
if strat > #hard then
strat = #hard
dither = nil
elseif dither > 4/64 then
dither = nil
else
dither = (dither * 64 + 1)/5
end
for x = minp.x, maxp.x do
local i = area:index(x, y, z)
if data[i] == c_stone then
if dither and math_random() >= dither then
data[i] = hard[strat - 1]
else
data[i] = hard[strat]
end
end
end
end
end
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B