Skip to content

Instantly share code, notes, and snippets.

@corarona
Last active May 11, 2022 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corarona/fce0c397a1f9631adddb9e0cc6a684e3 to your computer and use it in GitHub Desktop.
Save corarona/fce0c397a1f9631adddb9e0cc6a684e3 to your computer and use it in GitHub Desktop.
mcl_lua_nether
minetest.register_biome({ --overwrite nether "biome" so we dont get c++ mapgen stone/netherrack
name = "Nether",
node_filler = "air",
node_stone = "air",
node_water = "air",
node_river_water = "air",
node_cave_liquid = "air",
y_min = mcl_vars.mg_nether_min,
-- FIXME: For some reason the Nether stops generating early if this constant is not added.
-- Figure out why.
y_max = mcl_vars.mg_nether_max + 80,
heat_point = 100,
humidity_point = 0,
_mcl_biome_type = "hot",
_mcl_palette_index = 17,
})
minetest.register_on_generated(function(minp, maxp, blockseed)
if not (minp.y <= mcl_vars.mg_nether_max and maxp.y >= mcl_vars.mg_nether_min) then return end
local t1=os.clock()
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local a = VoxelArea:new{
MinEdge={x=emin.x, y=emin.y, z=emin.z},
MaxEdge={x=emax.x, y=emax.y, z=emax.z},
}
local data = vm:get_data()
local c_dirt = minetest.get_content_id("mcl_nether:netherrack")
local c_water = minetest.get_content_id("mcl_nether:nether_lava_source")
local c_air = minetest.get_content_id("air")
local water_l=-29035
local sidelen = maxp.x - minp.x + 1
local noise = minetest.get_perlin_map(
{offset=0, scale=1, spread={x=200, y=125, z=200}, seed=5, octaves=5, persist=0.6},
{x=sidelen, y=sidelen, z=sidelen}
)
local nvals = noise:get_3d_map_flat({x=minp.x, y=minp.y, z=minp.z})
local ni = 1
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
for x = minp.x, maxp.x do
if nvals[ni] - (1 - 25) / 55 > 0.5 then
local vi = a:index(x, y, z)
data[vi] = c_dirt
elseif y < water_l then
local vi = a:index(x, y, z)
data[vi] = c_water
end
ni = ni + 1
end
end
end
vm:set_data(data)
vm:calc_lighting(
{x=minp.x-16, y=minp.y, z=minp.z-16},
{x=maxp.x+16, y=maxp.y, z=maxp.z+16}
)
vm:write_to_map(data)
print(string.format("elapsed time: %.2fms", (os.clock() - t1) * 1000))
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment